PostgreSQL Source Code  git master
fsmfuncs.c File Reference
#include "postgres.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "pageinspect.h"
#include "storage/fsm_internals.h"
#include "utils/builtins.h"
Include dependency graph for fsmfuncs.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (fsm_page_contents)
 
Datum fsm_page_contents (PG_FUNCTION_ARGS)
 

Function Documentation

◆ fsm_page_contents()

Datum fsm_page_contents ( PG_FUNCTION_ARGS  )

Definition at line 35 of file fsmfuncs.c.

References appendStringInfo(), cstring_to_text_with_len(), StringInfoData::data, ereport, errcode(), errmsg(), ERROR, FSMPageData::fp_next_slot, FSMPageData::fp_nodes, i, initStringInfo(), StringInfoData::len, NodesPerPage, PageGetContents, PG_GETARG_BYTEA_P, PG_RETURN_TEXT_P, superuser(), and VARDATA.

36 {
37  bytea *raw_page = PG_GETARG_BYTEA_P(0);
38  StringInfoData sinfo;
39  FSMPage fsmpage;
40  int i;
41 
42  if (!superuser())
43  ereport(ERROR,
44  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
45  errmsg("must be superuser to use raw page functions")));
46 
47  fsmpage = (FSMPage) PageGetContents(VARDATA(raw_page));
48 
49  initStringInfo(&sinfo);
50 
51  for (i = 0; i < NodesPerPage; i++)
52  {
53  if (fsmpage->fp_nodes[i] != 0)
54  appendStringInfo(&sinfo, "%d: %d\n", i, fsmpage->fp_nodes[i]);
55  }
56  appendStringInfo(&sinfo, "fp_next_slot: %d\n", fsmpage->fp_next_slot);
57 
59 }
#define VARDATA(PTR)
Definition: postgres.h:302
uint8 fp_nodes[FLEXIBLE_ARRAY_MEMBER]
Definition: fsm_internals.h:42
int errcode(int sqlerrcode)
Definition: elog.c:610
bool superuser(void)
Definition: superuser.c:46
#define PG_GETARG_BYTEA_P(n)
Definition: fmgr.h:334
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
#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:184
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define PageGetContents(page)
Definition: bufpage.h:246
#define ereport(elevel,...)
Definition: elog.h:144
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:370
int errmsg(const char *fmt,...)
Definition: elog.c:824
int i
Definition: c.h:562
#define NodesPerPage
Definition: fsm_internals.h:51

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( fsm_page_contents  )