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/varlena.h"
40
42
47
48/*
49 * struct pgstattuple_type
50 *
51 * tuple_percent, dead_tuple_percent and free_percent are computable,
52 * so not defined here.
53 */
54typedef struct pgstattuple_type
55{
61 uint64 free_space; /* free/reusable space in bytes */
63
66
68 FunctionCallInfo fcinfo);
70static Datum pgstat_heap(Relation rel, FunctionCallInfo fcinfo);
72 Relation rel, BlockNumber blkno,
73 BufferAccessStrategy bstrategy);
75 Relation rel, BlockNumber blkno,
76 BufferAccessStrategy bstrategy);
78 Relation rel, BlockNumber blkno,
79 BufferAccessStrategy bstrategy);
81 pgstat_page pagefn, FunctionCallInfo fcinfo);
83 OffsetNumber minoff, OffsetNumber maxoff);
84
85/*
86 * build_pgstattuple_type -- build a pgstattuple_type tuple
87 */
88static Datum
90{
91#define NCOLUMNS 9
92#define NCHARS 314
93
94 HeapTuple tuple;
95 char *values[NCOLUMNS];
96 char values_buf[NCOLUMNS][NCHARS];
97 int i;
98 double tuple_percent;
99 double dead_tuple_percent;
100 double free_percent; /* free/reusable space in % */
101 TupleDesc tupdesc;
102 AttInMetadata *attinmeta;
103
104 /* Build a tuple descriptor for our result type */
105 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
106 elog(ERROR, "return type must be a row type");
107
108 /*
109 * Generate attribute metadata needed later to produce tuples from raw C
110 * strings
111 */
112 attinmeta = TupleDescGetAttInMetadata(tupdesc);
113
114 if (stat->table_len == 0)
115 {
116 tuple_percent = 0.0;
117 dead_tuple_percent = 0.0;
118 free_percent = 0.0;
119 }
120 else
121 {
122 tuple_percent = 100.0 * stat->tuple_len / stat->table_len;
123 dead_tuple_percent = 100.0 * stat->dead_tuple_len / stat->table_len;
124 free_percent = 100.0 * stat->free_space / stat->table_len;
125 }
126
127 /*
128 * Prepare a values array for constructing the tuple. This should be an
129 * array of C strings which will be processed later by the appropriate
130 * "in" functions.
131 */
132 for (i = 0; i < NCOLUMNS; i++)
133 values[i] = values_buf[i];
134 i = 0;
135 snprintf(values[i++], NCHARS, INT64_FORMAT, stat->table_len);
136 snprintf(values[i++], NCHARS, INT64_FORMAT, stat->tuple_count);
137 snprintf(values[i++], NCHARS, INT64_FORMAT, stat->tuple_len);
138 snprintf(values[i++], NCHARS, "%.2f", tuple_percent);
139 snprintf(values[i++], NCHARS, INT64_FORMAT, stat->dead_tuple_count);
140 snprintf(values[i++], NCHARS, INT64_FORMAT, stat->dead_tuple_len);
141 snprintf(values[i++], NCHARS, "%.2f", dead_tuple_percent);
142 snprintf(values[i++], NCHARS, INT64_FORMAT, stat->free_space);
143 snprintf(values[i++], NCHARS, "%.2f", free_percent);
144
145 /* build a tuple */
146 tuple = BuildTupleFromCStrings(attinmeta, values);
147
148 /* make the tuple into a datum */
149 return HeapTupleGetDatum(tuple);
150}
151
152/* ----------
153 * pgstattuple:
154 * returns live/dead tuples info
155 *
156 * C FUNCTION definition
157 * pgstattuple(text) returns pgstattuple_type
158 *
159 * The superuser() check here must be kept as the library might be upgraded
160 * without the extension being upgraded, meaning that in pre-1.5 installations
161 * these functions could be called by any user.
162 * ----------
163 */
164
165Datum
167{
169 RangeVar *relrv;
170 Relation rel;
171
172 if (!superuser())
174 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
175 errmsg("must be superuser to use pgstattuple functions")));
176
177 /* open relation */
179 rel = relation_openrv(relrv, AccessShareLock);
180
181 PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
182}
183
184/*
185 * As of pgstattuple version 1.5, we no longer need to check if the user
186 * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
187 * Users can then grant access to it based on their policies.
188 *
189 * Otherwise identical to pgstattuple (above).
190 */
191Datum
193{
195 RangeVar *relrv;
196 Relation rel;
197
198 /* open relation */
200 rel = relation_openrv(relrv, AccessShareLock);
201
202 PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
203}
204
205/* Must keep superuser() check, see above. */
206Datum
208{
209 Oid relid = PG_GETARG_OID(0);
210 Relation rel;
211
212 if (!superuser())
214 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
215 errmsg("must be superuser to use pgstattuple functions")));
216
217 /* open relation */
218 rel = relation_open(relid, AccessShareLock);
219
220 PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
221}
222
223/* Remove superuser() check for 1.5 version, see above */
224Datum
226{
227 Oid relid = PG_GETARG_OID(0);
228 Relation rel;
229
230 /* open relation */
231 rel = relation_open(relid, AccessShareLock);
232
233 PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
234}
235
236/*
237 * pgstat_relation
238 */
239static Datum
241{
242 const char *err;
243
244 /*
245 * Reject attempts to read non-local temporary relations; we would be
246 * likely to get wrong data since we have no visibility into the owning
247 * session's local buffers.
248 */
249 if (RELATION_IS_OTHER_TEMP(rel))
251 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
252 errmsg("cannot access temporary tables of other sessions")));
253
254 if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind) ||
255 rel->rd_rel->relkind == RELKIND_SEQUENCE)
256 {
257 return pgstat_heap(rel, fcinfo);
258 }
259 else if (rel->rd_rel->relkind == RELKIND_INDEX)
260 {
261 /* see pgstatindex_impl */
262 if (!rel->rd_index->indisvalid)
264 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
265 errmsg("index \"%s\" is not valid",
267
268 switch (rel->rd_rel->relam)
269 {
270 case BTREE_AM_OID:
271 return pgstat_index(rel, BTREE_METAPAGE + 1,
272 pgstat_btree_page, fcinfo);
273 case HASH_AM_OID:
274 return pgstat_index(rel, HASH_METAPAGE + 1,
275 pgstat_hash_page, fcinfo);
276 case GIST_AM_OID:
277 return pgstat_index(rel, GIST_ROOT_BLKNO + 1,
278 pgstat_gist_page, fcinfo);
279 case GIN_AM_OID:
280 err = "gin index";
281 break;
282 case SPGIST_AM_OID:
283 err = "spgist index";
284 break;
285 case BRIN_AM_OID:
286 err = "brin index";
287 break;
288 default:
289 err = "unknown index";
290 break;
291 }
293 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
294 errmsg("index \"%s\" (%s) is not supported",
296 }
297 else
298 {
300 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
301 errmsg("cannot get tuple-level statistics for relation \"%s\"",
304 }
305
306 return 0; /* should not happen */
307}
308
309/*
310 * pgstat_heap -- returns live/dead tuples info in a heap
311 */
312static Datum
314{
315 TableScanDesc scan;
316 HeapScanDesc hscan;
317 HeapTuple tuple;
318 BlockNumber nblocks;
319 BlockNumber block = 0; /* next block to count free space in */
320 BlockNumber tupblock;
321 Buffer buffer;
323 SnapshotData SnapshotDirty;
324
325 /*
326 * Sequences always use heap AM, but they don't show that in the catalogs.
327 */
328 if (rel->rd_rel->relkind != RELKIND_SEQUENCE &&
329 rel->rd_rel->relam != HEAP_TABLE_AM_OID)
331 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
332 errmsg("only heap AM is supported")));
333
334 /* Disable syncscan because we assume we scan from block zero upwards */
335 scan = table_beginscan_strat(rel, SnapshotAny, 0, NULL, true, false);
336 hscan = (HeapScanDesc) scan;
337
338 InitDirtySnapshot(SnapshotDirty);
339
340 nblocks = hscan->rs_nblocks; /* # blocks to be scanned */
341
342 /* scan the relation */
343 while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
344 {
346
347 /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
349
350 if (HeapTupleSatisfiesVisibility(tuple, &SnapshotDirty, hscan->rs_cbuf))
351 {
352 stat.tuple_len += tuple->t_len;
353 stat.tuple_count++;
354 }
355 else
356 {
357 stat.dead_tuple_len += tuple->t_len;
358 stat.dead_tuple_count++;
359 }
360
362
363 /*
364 * To avoid physically reading the table twice, try to do the
365 * free-space scan in parallel with the heap scan. However,
366 * heap_getnext may find no tuples on a given page, so we cannot
367 * simply examine the pages returned by the heap scan.
368 */
369 tupblock = ItemPointerGetBlockNumber(&tuple->t_self);
370
371 while (block <= tupblock)
372 {
374
375 buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
376 RBM_NORMAL, hscan->rs_strategy);
378 stat.free_space += PageGetExactFreeSpace((Page) BufferGetPage(buffer));
379 UnlockReleaseBuffer(buffer);
380 block++;
381 }
382 }
383
384 while (block < nblocks)
385 {
387
388 buffer = ReadBufferExtended(rel, MAIN_FORKNUM, block,
389 RBM_NORMAL, hscan->rs_strategy);
391 stat.free_space += PageGetExactFreeSpace((Page) BufferGetPage(buffer));
392 UnlockReleaseBuffer(buffer);
393 block++;
394 }
395
396 table_endscan(scan);
398
399 stat.table_len = (uint64) nblocks * BLCKSZ;
400
401 return build_pgstattuple_type(&stat, fcinfo);
402}
403
404/*
405 * pgstat_btree_page -- check tuples in a btree page
406 */
407static void
409 BufferAccessStrategy bstrategy)
410{
411 Buffer buf;
412 Page page;
413
414 buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
416 page = BufferGetPage(buf);
417
418 /* Page is valid, see what to do with it */
419 if (PageIsNew(page))
420 {
421 /* fully empty page */
422 stat->free_space += BLCKSZ;
423 }
424 else
425 {
426 BTPageOpaque opaque;
427
428 opaque = BTPageGetOpaque(page);
429 if (P_IGNORE(opaque))
430 {
431 /* deleted or half-dead page */
432 stat->free_space += BLCKSZ;
433 }
434 else if (P_ISLEAF(opaque))
435 {
438 }
439 else
440 {
441 /* internal page */
442 }
443 }
444
445 _bt_relbuf(rel, buf);
446}
447
448/*
449 * pgstat_hash_page -- check tuples in a hash page
450 */
451static void
453 BufferAccessStrategy bstrategy)
454{
455 Buffer buf;
456 Page page;
457
458 buf = _hash_getbuf_with_strategy(rel, blkno, HASH_READ, 0, bstrategy);
459 page = BufferGetPage(buf);
460
461 if (PageGetSpecialSize(page) == MAXALIGN(sizeof(HashPageOpaqueData)))
462 {
463 HashPageOpaque opaque;
464
465 opaque = HashPageGetOpaque(page);
466 switch (opaque->hasho_flag & LH_PAGE_TYPE)
467 {
468 case LH_UNUSED_PAGE:
469 stat->free_space += BLCKSZ;
470 break;
471 case LH_BUCKET_PAGE:
472 case LH_OVERFLOW_PAGE:
475 break;
476 case LH_BITMAP_PAGE:
477 case LH_META_PAGE:
478 default:
479 break;
480 }
481 }
482 else
483 {
484 /* maybe corrupted */
485 }
486
487 _hash_relbuf(rel, buf);
488}
489
490/*
491 * pgstat_gist_page -- check tuples in a gist page
492 */
493static void
495 BufferAccessStrategy bstrategy)
496{
497 Buffer buf;
498 Page page;
499
500 buf = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL, bstrategy);
502 gistcheckpage(rel, buf);
503 page = BufferGetPage(buf);
504
505 if (GistPageIsLeaf(page))
506 {
509 }
510 else
511 {
512 /* root or node */
513 }
514
516}
517
518/*
519 * pgstat_index -- returns live/dead tuples info in a generic index
520 */
521static Datum
523 FunctionCallInfo fcinfo)
524{
525 BlockNumber nblocks;
526 BlockNumber blkno;
527 BufferAccessStrategy bstrategy;
529
530 /* prepare access strategy for this index */
531 bstrategy = GetAccessStrategy(BAS_BULKREAD);
532
533 blkno = start;
534 for (;;)
535 {
536 /* Get the current relation length */
538 nblocks = RelationGetNumberOfBlocks(rel);
540
541 /* Quit if we've scanned the whole relation */
542 if (blkno >= nblocks)
543 {
544 stat.table_len = (uint64) nblocks * BLCKSZ;
545
546 break;
547 }
548
549 for (; blkno < nblocks; blkno++)
550 {
552
553 pagefn(&stat, rel, blkno, bstrategy);
554 }
555 }
556
558
559 return build_pgstattuple_type(&stat, fcinfo);
560}
561
562/*
563 * pgstat_index_page -- for generic index page
564 */
565static void
567 OffsetNumber minoff, OffsetNumber maxoff)
568{
570
571 stat->free_space += PageGetExactFreeSpace(page);
572
573 for (i = minoff; i <= maxoff; i = OffsetNumberNext(i))
574 {
575 ItemId itemid = PageGetItemId(page, i);
576
577 if (ItemIdIsDead(itemid))
578 {
579 stat->dead_tuple_count++;
580 stat->dead_tuple_len += ItemIdGetLength(itemid);
581 }
582 else
583 {
584 stat->tuple_count++;
585 stat->tuple_len += ItemIdGetLength(itemid);
586 }
587 }
588}
uint32 BlockNumber
Definition: block.h:31
static Datum values[MAXATTR]
Definition: bootstrap.c:151
int Buffer
Definition: buf.h:23
struct BufferAccessStrategyData * BufferAccessStrategy
Definition: buf.h:44
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4880
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:5097
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:793
@ BAS_BULKREAD
Definition: bufmgr.h:36
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:189
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:190
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:273
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:396
@ RBM_NORMAL
Definition: bufmgr.h:45
Size PageGetExactFreeSpace(const PageData *page)
Definition: bufpage.c:947
static uint16 PageGetSpecialSize(const PageData *page)
Definition: bufpage.h:317
static bool PageIsNew(const PageData *page)
Definition: bufpage.h:234
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:244
PageData * Page
Definition: bufpage.h:82
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
Definition: bufpage.h:372
#define MAXALIGN(LEN)
Definition: c.h:768
#define INT64_FORMAT
Definition: c.h:506
uint64_t uint64
Definition: c.h:489
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define ereport(elevel,...)
Definition: elog.h:149
void err(int eval, const char *fmt,...)
Definition: err.c:43
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
Definition: execTuples.c:2322
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
Definition: execTuples.c:2273
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:541
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
#define GistPageIsLeaf(page)
Definition: gist.h:170
#define GIST_ROOT_BLKNO
Definition: gist_private.h:262
#define GIST_SHARE
Definition: gist_private.h:42
void gistcheckpage(Relation rel, Buffer buf)
Definition: gistutil.c:785
#define HashPageGetOpaque(page)
Definition: hash.h:88
#define LH_BUCKET_PAGE
Definition: hash.h:55
#define LH_UNUSED_PAGE
Definition: hash.h:53
#define LH_META_PAGE
Definition: hash.h:57
#define HASH_READ
Definition: hash.h:339
#define HASH_METAPAGE
Definition: hash.h:198
#define LH_PAGE_TYPE
Definition: hash.h:63
#define LH_BITMAP_PAGE
Definition: hash.h:56
#define LH_OVERFLOW_PAGE
Definition: hash.h:54
return str start
void _hash_relbuf(Relation rel, Buffer buf)
Definition: hashpage.c:266
Buffer _hash_getbuf_with_strategy(Relation rel, BlockNumber blkno, int access, int flags, BufferAccessStrategy bstrategy)
Definition: hashpage.c:239
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1266
struct HeapScanDescData * HeapScanDesc
Definition: heapam.h:100
bool HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot, Buffer buffer)
int i
Definition: isn.c:72
#define ItemIdGetLength(itemId)
Definition: itemid.h:59
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:419
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:469
#define AccessShareLock
Definition: lockdefs.h:36
#define ExclusiveLock
Definition: lockdefs.h:42
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:122
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3554
void _bt_relbuf(Relation rel, Buffer buf)
Definition: nbtpage.c:1023
#define P_ISLEAF(opaque)
Definition: nbtree.h:220
#define BTPageGetOpaque(page)
Definition: nbtree.h:73
#define P_FIRSTDATAKEY(opaque)
Definition: nbtree.h:369
#define BTREE_METAPAGE
Definition: nbtree.h:148
#define BT_READ
Definition: nbtree.h:724
#define P_IGNORE(opaque)
Definition: nbtree.h:225
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
NameData relname
Definition: pg_class.h:38
static char * buf
Definition: pg_test_fsync.c:72
Datum pgstattuplebyid(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:207
static Datum pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:240
#define NCHARS
static Datum pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:522
PG_MODULE_MAGIC
Definition: pgstattuple.c:41
static void pgstat_index_page(pgstattuple_type *stat, Page page, OffsetNumber minoff, OffsetNumber maxoff)
Definition: pgstattuple.c:566
Datum pgstattuple_v1_5(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:192
PG_FUNCTION_INFO_V1(pgstattuple)
static void pgstat_gist_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:494
struct pgstattuple_type pgstattuple_type
void(* pgstat_page)(pgstattuple_type *, Relation, BlockNumber, BufferAccessStrategy)
Definition: pgstattuple.c:64
static Datum build_pgstattuple_type(pgstattuple_type *stat, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:89
#define NCOLUMNS
static void pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:408
Datum pgstattuplebyid_v1_5(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:225
static Datum pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
Definition: pgstattuple.c:313
Datum pgstattuple(PG_FUNCTION_ARGS)
Definition: pgstattuple.c:166
static void pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno, BufferAccessStrategy bstrategy)
Definition: pgstattuple.c:452
#define snprintf
Definition: port.h:239
uintptr_t Datum
Definition: postgres.h:69
unsigned int Oid
Definition: postgres_ext.h:32
#define RelationGetRelationName(relation)
Definition: rel.h:546
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:665
struct RelationData * Relation
Definition: relcache.h:27
@ MAIN_FORKNUM
Definition: relpath.h:58
@ ForwardScanDirection
Definition: sdir.h:28
#define SnapshotAny
Definition: snapmgr.h:33
#define InitDirtySnapshot(snapshotdata)
Definition: snapmgr.h:42
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:137
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
uint16 hasho_flag
Definition: hash.h:82
BufferAccessStrategy rs_strategy
Definition: heapam.h:71
Buffer rs_cbuf
Definition: heapam.h:68
BlockNumber rs_nblocks
Definition: heapam.h:59
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
Form_pg_index rd_index
Definition: rel.h:192
Form_pg_class rd_rel
Definition: rel.h:111
uint64 tuple_count
Definition: pgstattuple.c:57
uint64 dead_tuple_len
Definition: pgstattuple.c:60
uint64 dead_tuple_count
Definition: pgstattuple.c:59
Definition: c.h:644
bool superuser(void)
Definition: superuser.c:46
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1025
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)
Definition: tableam.h:937
List * textToQualifiedNameList(text *textval)
Definition: varlena.c:3374