PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
fsmfuncs.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * fsmfuncs.c
4  * Functions to investigate FSM pages
5  *
6  * These functions are restricted to superusers for the fear of introducing
7  * security holes if the input checking isn't as water-tight as it should.
8  * You'd need to be superuser to obtain a raw page image anyway, so
9  * there's hardly any use case for using these without superuser-rights
10  * anyway.
11  *
12  * Copyright (c) 2007-2017, PostgreSQL Global Development Group
13  *
14  * IDENTIFICATION
15  * contrib/pageinspect/fsmfuncs.c
16  *
17  *-------------------------------------------------------------------------
18  */
19 
20 #include "postgres.h"
21 
22 #include "pageinspect.h"
23 
24 #include "funcapi.h"
25 #include "lib/stringinfo.h"
26 #include "miscadmin.h"
27 #include "storage/fsm_internals.h"
28 #include "utils/builtins.h"
29 
30 /*
31  * Dumps the contents of a FSM page.
32  */
34 
35 Datum
37 {
38  bytea *raw_page = PG_GETARG_BYTEA_P(0);
39  StringInfoData sinfo;
40  FSMPage fsmpage;
41  int i;
42 
43  if (!superuser())
44  ereport(ERROR,
45  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
46  (errmsg("must be superuser to use raw page functions"))));
47 
48  fsmpage = (FSMPage) PageGetContents(VARDATA(raw_page));
49 
50  initStringInfo(&sinfo);
51 
52  for (i = 0; i < NodesPerPage; i++)
53  {
54  if (fsmpage->fp_nodes[i] != 0)
55  appendStringInfo(&sinfo, "%d: %d\n", i, fsmpage->fp_nodes[i]);
56  }
57  appendStringInfo(&sinfo, "fp_next_slot: %d\n", fsmpage->fp_next_slot);
58 
60 }
#define VARDATA(PTR)
Definition: postgres.h:303
uint8 fp_nodes[FLEXIBLE_ARRAY_MEMBER]
Definition: fsm_internals.h:42
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
Datum fsm_page_contents(PG_FUNCTION_ARGS)
Definition: fsmfuncs.c:36
#define PG_GETARG_BYTEA_P(n)
Definition: fmgr.h:299
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
#define ERROR
Definition: elog.h:43
FSMPageData * FSMPage
Definition: fsm_internals.h:45
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:161
#define ereport(elevel, rest)
Definition: elog.h:122
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
PG_FUNCTION_INFO_V1(fsm_page_contents)
#define PageGetContents(page)
Definition: bufpage.h:243
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:330
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Definition: c.h:439
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
#define NodesPerPage
Definition: fsm_internals.h:51