PostgreSQL Source Code  git master
pgstattuple.c
Go to the documentation of this file.
1 /*
2  * contrib/pgstattuple/pgstattuple.c
3  *
4  * Copyright (c) 2001,2002 Tatsuo Ishii
5  *
6  * Permission to use, copy, modify, and distribute this software and
7  * its documentation for any purpose, without fee, and without a
8  * written agreement is hereby granted, provided that the above
9  * copyright notice and this paragraph and the following two
10  * paragraphs appear in all copies.
11  *
12  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
13  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
14  * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
15  * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED
16  * OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS
21  * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
22  * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  */
24 
25 #include "postgres.h"
26 
27 #include "access/gist_private.h"
28 #include "access/hash.h"
29 #include "access/heapam.h"
30 #include "access/nbtree.h"
31 #include "access/relscan.h"
32 #include "access/tableam.h"
33 #include "catalog/namespace.h"
34 #include "catalog/pg_am_d.h"
35 #include "funcapi.h"
36 #include "miscadmin.h"
37 #include "storage/bufmgr.h"
38 #include "storage/lmgr.h"
39 #include "utils/builtins.h"
40 #include "utils/varlena.h"
41 
43 
48 
49 /*
50  * struct pgstattuple_type
51  *
52  * tuple_percent, dead_tuple_percent and free_percent are computable,
53  * so not defined here.
54  */
55 typedef struct pgstattuple_type
56 {
57  uint64 table_len;
58  uint64 tuple_count;
59  uint64 tuple_len;
62  uint64 free_space; /* free/reusable space in bytes */
64 
67 
69  FunctionCallInfo fcinfo);
71 static Datum pgstat_heap(Relation rel, FunctionCallInfo fcinfo);
73  Relation rel, BlockNumber blkno,
74  BufferAccessStrategy bstrategy);
76  Relation rel, BlockNumber blkno,
77  BufferAccessStrategy bstrategy);
79  Relation rel, BlockNumber blkno,
80  BufferAccessStrategy bstrategy);
81 static Datum pgstat_index(Relation rel, BlockNumber start,
82  pgstat_page pagefn, FunctionCallInfo fcinfo);
83 static void pgstat_index_page(pgstattuple_type *stat, Page page,
84  OffsetNumber minoff, OffsetNumber maxoff);
85 
86 /*
87  * build_pgstattuple_type -- build a pgstattuple_type tuple
88  */
89 static Datum
91 {
92 #define NCOLUMNS 9
93 #define NCHARS 314
94 
95  HeapTuple tuple;
96  char *values[NCOLUMNS];
97  char values_buf[NCOLUMNS][NCHARS];
98  int i;
99  double tuple_percent;
100  double dead_tuple_percent;
101  double free_percent; /* free/reusable space in % */
102  TupleDesc tupdesc;
103  AttInMetadata *attinmeta;
104 
105  /* Build a tuple descriptor for our result type */
106  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
107  elog(ERROR, "return type must be a row type");
108 
109  /*
110  * Generate attribute metadata needed later to produce tuples from raw C
111  * strings
112  */
113  attinmeta = TupleDescGetAttInMetadata(tupdesc);
114 
115  if (stat->table_len == 0)
116  {
117  tuple_percent = 0.0;
118  dead_tuple_percent = 0.0;
119  free_percent = 0.0;
120  }
121  else
122  {
123  tuple_percent = 100.0 * stat->tuple_len / stat->table_len;
124  dead_tuple_percent = 100.0 * stat->dead_tuple_len / stat->table_len;
125  free_percent = 100.0 * stat->free_space / stat->table_len;
126  }
127 
128  /*
129  * Prepare a values array for constructing the tuple. This should be an
130  * array of C strings which will be processed later by the appropriate
131  * "in" functions.
132  */
133  for (i = 0; i < NCOLUMNS; i++)
134  values[i] = values_buf[i];
135  i = 0;
136  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->table_len);
137  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->tuple_count);
138  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->tuple_len);
139  snprintf(values[i++], NCHARS, "%.2f", tuple_percent);
140  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->dead_tuple_count);
141  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->dead_tuple_len);
142  snprintf(values[i++], NCHARS, "%.2f", dead_tuple_percent);
143  snprintf(values[i++], NCHARS, INT64_FORMAT, stat->free_space);
144  snprintf(values[i++], NCHARS, "%.2f", free_percent);
145 
146  /* build a tuple */
147  tuple = BuildTupleFromCStrings(attinmeta, values);
148 
149  /* make the tuple into a datum */
150  return HeapTupleGetDatum(tuple);
151 }
152 
153 /* ----------
154  * pgstattuple:
155  * returns live/dead tuples info
156  *
157  * C FUNCTION definition
158  * pgstattuple(text) returns pgstattuple_type
159  *
160  * The superuser() check here must be kept as the library might be upgraded
161  * without the extension being upgraded, meaning that in pre-1.5 installations
162  * these functions could be called by any user.
163  * ----------
164  */
165 
166 Datum
168 {
170  RangeVar *relrv;
171  Relation rel;
172 
173  if (!superuser())
174  ereport(ERROR,
175  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
176  (errmsg("must be superuser to use pgstattuple functions"))));
177 
178  /* open relation */
180  rel = relation_openrv(relrv, AccessShareLock);
181 
182  PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
183 }
184 
185 /*
186  * As of pgstattuple version 1.5, we no longer need to check if the user
187  * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
188  * Users can then grant access to it based on their policies.
189  *
190  * Otherwise identical to pgstattuple (above).
191  */
192 Datum
194 {
196  RangeVar *relrv;
197  Relation rel;
198 
199  /* open relation */
201  rel = relation_openrv(relrv, AccessShareLock);
202 
203  PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
204 }
205 
206 /* Must keep superuser() check, see above. */
207 Datum
209 {
210  Oid relid = PG_GETARG_OID(0);
211  Relation rel;
212 
213  if (!superuser())
214  ereport(ERROR,
215  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
216  (errmsg("must be superuser to use pgstattuple functions"))));
217 
218  /* open relation */
219  rel = relation_open(relid, AccessShareLock);
220 
221  PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
222 }
223 
224 /* Remove superuser() check for 1.5 version, see above */
225 Datum
227 {
228  Oid relid = PG_GETARG_OID(0);
229  Relation rel;
230 
231  /* open relation */
232  rel = relation_open(relid, AccessShareLock);
233 
234  PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
235 }
236 
237 /*
238  * pgstat_relation
239  */
240 static Datum
242 {
243  const char *err;
244 
245  /*
246  * Reject attempts to read non-local temporary relations; we would be
247  * likely to get wrong data since we have no visibility into the owning
248  * session's local buffers.
249  */
250  if (RELATION_IS_OTHER_TEMP(rel))
251  ereport(ERROR,
252  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
253  errmsg("cannot access temporary tables of other sessions")));
254 
255  switch (rel->rd_rel->relkind)
256  {
257  case RELKIND_RELATION:
258  case RELKIND_MATVIEW:
259  case RELKIND_TOASTVALUE:
260  case RELKIND_SEQUENCE:
261  return pgstat_heap(rel, fcinfo);
262  case RELKIND_INDEX:
263  switch (rel->rd_rel->relam)
264  {
265  case BTREE_AM_OID:
266  return pgstat_index(rel, BTREE_METAPAGE + 1,
267  pgstat_btree_page, fcinfo);
268  case HASH_AM_OID:
269  return pgstat_index(rel, HASH_METAPAGE + 1,
270  pgstat_hash_page, fcinfo);
271  case GIST_AM_OID:
272  return pgstat_index(rel, GIST_ROOT_BLKNO + 1,
273  pgstat_gist_page, fcinfo);
274  case GIN_AM_OID:
275  err = "gin index";
276  break;
277  case SPGIST_AM_OID:
278  err = "spgist index";
279  break;
280  case BRIN_AM_OID:
281  err = "brin index";
282  break;
283  default:
284  err = "unknown index";
285  break;
286  }
287  break;
288  case RELKIND_VIEW:
289  err = "view";
290  break;
291  case RELKIND_COMPOSITE_TYPE:
292  err = "composite type";
293  break;
294  case RELKIND_FOREIGN_TABLE:
295  err = "foreign table";
296  break;
297  case RELKIND_PARTITIONED_TABLE:
298  err = "partitioned table";
299  break;
300  case RELKIND_PARTITIONED_INDEX:
301  err = "partitioned index";
302  break;
303  default:
304  err = "unknown";
305  break;
306  }
307 
308  ereport(ERROR,
309  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
310  errmsg("\"%s\" (%s) is not supported",
311  RelationGetRelationName(rel), err)));
312  return 0; /* should not happen */
313 }
314 
315 /*
316  * pgstat_heap -- returns live/dead tuples info in a heap
317  */
318 static Datum
320 {
321  TableScanDesc scan;
322  HeapScanDesc hscan;
323  HeapTuple tuple;
324  BlockNumber nblocks;
325  BlockNumber block = 0; /* next block to count free space in */
326  BlockNumber tupblock;
327  Buffer buffer;
328  pgstattuple_type stat = {0};
329  SnapshotData SnapshotDirty;
330 
331  if (rel->rd_rel->relam != HEAP_TABLE_AM_OID)
332  ereport(ERROR,
333  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
334  errmsg("only heap AM is supported")));
335 
336  /* Disable syncscan because we assume we scan from block zero upwards */
337  scan = table_beginscan_strat(rel, SnapshotAny, 0, NULL, true, false);
338  hscan = (HeapScanDesc) scan;
339 
340  InitDirtySnapshot(SnapshotDirty);
341 
342  nblocks = hscan->rs_nblocks; /* # blocks to be scanned */
343 
344  /* scan the relation */
345  while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
346  {
348 
349  /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
351 
352  if (HeapTupleSatisfiesVisibility(tuple, &SnapshotDirty, hscan->rs_cbuf))
353  {
354  stat.tuple_len += tuple->t_len;
355  stat.tuple_count++;
356  }
357  else
358  {
359  stat.dead_tuple_len += tuple->t_len;
360  stat.dead_tuple_count++;
361  }
362 
364 
365  /*
366  * To avoid physically reading the table twice, try to do the
367  * free-space scan in parallel with the heap scan. However,
368  * heap_getnext may find no tuples on a given page, so we cannot
369  * simply examine the pages returned by the heap scan.
370  */
371  tupblock = ItemPointerGetBlockNumber(&tuple->t_self);
372 
373  while (block <= tupblock)
374  {
376 
377  buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
378  RBM_NORMAL, hscan->rs_strategy);
379  LockBuffer(buffer, BUFFER_LOCK_SHARE);
381  UnlockReleaseBuffer(buffer);
382  block++;
383  }
384  }
385 
386  while (block < nblocks)
387  {
389 
390  buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
391  RBM_NORMAL, hscan->rs_strategy);
392  LockBuffer(buffer, BUFFER_LOCK_SHARE);
394  UnlockReleaseBuffer(buffer);
395  block++;
396  }
397 
398  table_endscan(scan);
400 
401  stat.table_len = (uint64) nblocks * BLCKSZ;
402 
403  return build_pgstattuple_type(&stat, fcinfo);
404 }
405 
406 /*
407  * pgstat_btree_page -- check tuples in a btree page
408  */
409 static void
411  BufferAccessStrategy bstrategy)
412 {
413  Buffer buf;
414  Page page;
415 
416  buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
417  LockBuffer(buf, BT_READ);
418  page = BufferGetPage(buf);
419 
420  /* Page is valid, see what to do with it */
421  if (PageIsNew(page))
422  {
423  /* fully empty page */
424  stat->free_space += BLCKSZ;
425  }
426  else
427  {
428  BTPageOpaque opaque;
429 
430  opaque = (BTPageOpaque) PageGetSpecialPointer(page);
431  if (P_IGNORE(opaque))
432  {
433  /* recyclable page */
434  stat->free_space += BLCKSZ;
435  }
436  else if (P_ISLEAF(opaque))
437  {
438  pgstat_index_page(stat, page, P_FIRSTDATAKEY(opaque),
439  PageGetMaxOffsetNumber(page));
440  }
441  else
442  {
443  /* root or node */
444  }
445  }
446 
447  _bt_relbuf(rel, buf);
448 }
449 
450 /*
451  * pgstat_hash_page -- check tuples in a hash page
452  */
453 static void
455  BufferAccessStrategy bstrategy)
456 {
457  Buffer buf;
458  Page page;
459 
460  buf = _hash_getbuf_with_strategy(rel, blkno, HASH_READ, 0, bstrategy);
461  page = BufferGetPage(buf);
462 
463  if (PageGetSpecialSize(page) == MAXALIGN(sizeof(HashPageOpaqueData)))
464  {
465  HashPageOpaque opaque;
466 
467  opaque = (HashPageOpaque) PageGetSpecialPointer(page);
468  switch (opaque->hasho_flag & LH_PAGE_TYPE)
469  {
470  case LH_UNUSED_PAGE:
471  stat->free_space += BLCKSZ;
472  break;
473  case LH_BUCKET_PAGE:
474  case LH_OVERFLOW_PAGE:
476  PageGetMaxOffsetNumber(page));
477  break;
478  case LH_BITMAP_PAGE:
479  case LH_META_PAGE:
480  default:
481  break;
482  }
483  }
484  else
485  {
486  /* maybe corrupted */
487  }
488 
489  _hash_relbuf(rel, buf);
490 }
491 
492 /*
493  * pgstat_gist_page -- check tuples in a gist page
494  */
495 static void
497  BufferAccessStrategy bstrategy)
498 {
499  Buffer buf;
500  Page page;
501 
502  buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
503  LockBuffer(buf, GIST_SHARE);
504  gistcheckpage(rel, buf);
505  page = BufferGetPage(buf);
506 
507  if (GistPageIsLeaf(page))
508  {
510  PageGetMaxOffsetNumber(page));
511  }
512  else
513  {
514  /* root or node */
515  }
516 
517  UnlockReleaseBuffer(buf);
518 }
519 
520 /*
521  * pgstat_index -- returns live/dead tuples info in a generic index
522  */
523 static Datum
525  FunctionCallInfo fcinfo)
526 {
527  BlockNumber nblocks;
528  BlockNumber blkno;
529  BufferAccessStrategy bstrategy;
530  pgstattuple_type stat = {0};
531 
532  /* prepare access strategy for this index */
533  bstrategy = GetAccessStrategy(BAS_BULKREAD);
534 
535  blkno = start;
536  for (;;)
537  {
538  /* Get the current relation length */
540  nblocks = RelationGetNumberOfBlocks(rel);
542 
543  /* Quit if we've scanned the whole relation */
544  if (blkno >= nblocks)
545  {
546  stat.table_len = (uint64) nblocks * BLCKSZ;
547 
548  break;
549  }
550 
551  for (; blkno < nblocks; blkno++)
552  {
554 
555  pagefn(&stat, rel, blkno, bstrategy);
556  }
557  }
558 
560 
561  return build_pgstattuple_type(&stat, fcinfo);
562 }
563 
564 /*
565  * pgstat_index_page -- for generic index page
566  */
567 static void
569  OffsetNumber minoff, OffsetNumber maxoff)
570 {
571  OffsetNumber i;
572 
573  stat->free_space += PageGetFreeSpace(page);
574 
575  for (i = minoff; i <= maxoff; i = OffsetNumberNext(i))
576  {
577  ItemId itemid = PageGetItemId(page, i);
578 
579  if (ItemIdIsDead(itemid))
580  {
581  stat->dead_tuple_count++;
582  stat->dead_tuple_len += ItemIdGetLength(itemid);
583  }
584  else
585  {
586  stat->tuple_count++;
587  stat->tuple_len += ItemIdGetLength(itemid);
588  }
589  }
590 }
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:542
static void pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:454
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:86
static void pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:410
#define InitDirtySnapshot(snapshotdata)
Definition: snapmgr.h:77
PG_FUNCTION_INFO_V1(pgstattuple)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:196
#define LH_BITMAP_PAGE
Definition: hash.h:55
#define P_IGNORE(opaque)
Definition: nbtree.h:194
PG_MODULE_MAGIC
Definition: pgstattuple.c:42
#define LH_META_PAGE
Definition: hash.h:56
#define ExclusiveLock
Definition: lockdefs.h:44
Buffer _hash_getbuf_with_strategy(Relation rel, BlockNumber blkno, int access, int flags, BufferAccessStrategy bstrategy)
Definition: hashpage.c:238
#define P_FIRSTDATAKEY(opaque)
Definition: nbtree.h:219
struct BufferAccessStrategyData * BufferAccessStrategy
Definition: buf.h:44
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:642
#define NCOLUMNS
uint64 dead_tuple_count
Definition: pgstattuple.c:60
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:570
bool superuser(void)
Definition: superuser.c:47
uint32 BlockNumber
Definition: block.h:31
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3054
Form_pg_class rd_rel
Definition: rel.h:83
NameData relname
Definition: pg_class.h:35
unsigned int Oid
Definition: postgres_ext.h:31
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:357
BTPageOpaqueData * BTPageOpaque
Definition: nbtree.h:68
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)
Definition: tableam.h:760
Size PageGetFreeSpace(Page page)
Definition: bufpage.c:581
struct HeapScanDescData * HeapScanDesc
Definition: heapam.h:72
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2112
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define LH_UNUSED_PAGE
Definition: hash.h:52
uint16 OffsetNumber
Definition: off.h:24
#define LH_PAGE_TYPE
Definition: hash.h:62
#define HASH_READ
Definition: hash.h:321
uint64 dead_tuple_len
Definition: pgstattuple.c:61
#define BT_READ
Definition: nbtree.h:402
struct RelationData * Relation
Definition: relcache.h:26
#define ItemIdGetLength(itemId)
Definition: itemid.h:59
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3376
#define ERROR
Definition: elog.h:43
Size PageGetHeapFreeSpace(Page page)
Definition: bufpage.c:665
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
static char * buf
Definition: pg_test_fsync.c:68
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1290
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
#define FirstOffsetNumber
Definition: off.h:27
#define RelationGetRelationName(relation)
Definition: rel.h:450
#define BufferGetPage(buffer)
Definition: bufmgr.h:159
#define ereport(elevel, rest)
Definition: elog.h:141
#define BTREE_METAPAGE
Definition: nbtree.h:131
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3611
#define GistPageIsLeaf(page)
Definition: gist.h:140
static Datum pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:319
#define stat(a, b)
Definition: win32_port.h:264
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:235
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:402
Datum pgstattuple(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:167
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:452
#define NCHARS
#define HASH_METAPAGE
Definition: hash.h:195
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
#define LH_OVERFLOW_PAGE
Definition: hash.h:53
static Datum pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:524
BlockNumber rs_nblocks
Definition: heapam.h:51
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2063
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:3590
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
BufferAccessStrategy rs_strategy
Definition: heapam.h:63
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:198
Datum pgstattuplebyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:226
void _bt_relbuf(Relation rel, Buffer buf)
Definition: nbtpage.c:912
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:265
#define LH_BUCKET_PAGE
Definition: hash.h:54
Buffer rs_cbuf
Definition: heapam.h:59
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:546
static void pgstat_gist_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:496
void gistcheckpage(Relation rel, Buffer buf)
Definition: gistutil.c:771
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
#define PageGetSpecialPointer(page)
Definition: bufpage.h:326
HashPageOpaqueData * HashPageOpaque
Definition: hash.h:85
struct pgstattuple_type pgstattuple_type
#define MAXALIGN(LEN)
Definition: c.h:685
void(* pgstat_page)(pgstattuple_type *, Relation, BlockNumber, BufferAccessStrategy)
Definition: pgstattuple.c:65
#define GIST_SHARE
Definition: gist_private.h:42
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
#define PageGetSpecialSize(page)
Definition: bufpage.h:300
static void pgstat_index_page(pgstattuple_type *stat, Page page, OffsetNumber minoff, OffsetNumber maxoff)
Definition: pgstattuple.c:568
#define INT64_FORMAT
Definition: c.h:400
#define SnapshotAny
Definition: snapmgr.h:70
uint16 hasho_flag
Definition: hash.h:81
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:831
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define PageIsNew(page)
Definition: bufpage.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
int i
#define GIST_ROOT_BLKNO
Definition: gist_private.h:259
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:87
Definition: c.h:549
#define PG_FUNCTION_ARGS
Definition: fmgr.h:188
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
static Datum pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:241
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
static Datum build_pgstattuple_type(pgstattuple_type *stat, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:90
Datum pgstattuplebyid(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:208
#define snprintf
Definition: port.h:192
int Buffer
Definition: buf.h:23
uint64 tuple_count
Definition: pgstattuple.c:58
Datum pgstattuple_v1_5(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:193
Pointer Page
Definition: bufpage.h:78
bool HeapTupleSatisfiesVisibility(HeapTuple tup, Snapshot snapshot, Buffer buffer)
#define P_ISLEAF(opaque)
Definition: nbtree.h:189