PostgreSQL Source Code
git master
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-2024, PostgreSQL Global Development Group
13
*
14
* IDENTIFICATION
15
* contrib/pageinspect/fsmfuncs.c
16
*
17
*-------------------------------------------------------------------------
18
*/
19
20
#include "
postgres.h
"
21
22
#include "
fmgr.h
"
23
#include "
lib/stringinfo.h
"
24
#include "
miscadmin.h
"
25
#include "
pageinspect.h
"
26
#include "
storage/fsm_internals.h
"
27
#include "
utils/builtins.h
"
28
29
/*
30
* Dumps the contents of a FSM page.
31
*/
32
PG_FUNCTION_INFO_V1
(
fsm_page_contents
);
33
34
Datum
35
fsm_page_contents
(
PG_FUNCTION_ARGS
)
36
{
37
bytea
*raw_page =
PG_GETARG_BYTEA_P
(0);
38
StringInfoData
sinfo;
39
Page
page;
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
page =
get_page_from_raw
(raw_page);
49
50
if
(
PageIsNew
(page))
51
PG_RETURN_NULL
();
52
53
fsmpage = (
FSMPage
)
PageGetContents
(page);
54
55
initStringInfo
(&sinfo);
56
57
for
(
i
= 0;
i
<
NodesPerPage
;
i
++)
58
{
59
if
(fsmpage->
fp_nodes
[
i
] != 0)
60
appendStringInfo
(&sinfo,
"%d: %d\n"
,
i
, fsmpage->
fp_nodes
[
i
]);
61
}
62
appendStringInfo
(&sinfo,
"fp_next_slot: %d\n"
, fsmpage->
fp_next_slot
);
63
64
PG_RETURN_TEXT_P
(
cstring_to_text_with_len
(sinfo.
data
, sinfo.
len
));
65
}
PageGetContents
static char * PageGetContents(Page page)
Definition:
bufpage.h:257
Page
Pointer Page
Definition:
bufpage.h:81
PageIsNew
static bool PageIsNew(Page page)
Definition:
bufpage.h:233
builtins.h
errcode
int errcode(int sqlerrcode)
Definition:
elog.c:853
errmsg
int errmsg(const char *fmt,...)
Definition:
elog.c:1070
ERROR
#define ERROR
Definition:
elog.h:39
ereport
#define ereport(elevel,...)
Definition:
elog.h:149
fmgr.h
PG_RETURN_NULL
#define PG_RETURN_NULL()
Definition:
fmgr.h:345
PG_RETURN_TEXT_P
#define PG_RETURN_TEXT_P(x)
Definition:
fmgr.h:372
PG_GETARG_BYTEA_P
#define PG_GETARG_BYTEA_P(n)
Definition:
fmgr.h:335
PG_FUNCTION_ARGS
#define PG_FUNCTION_ARGS
Definition:
fmgr.h:193
fsm_internals.h
NodesPerPage
#define NodesPerPage
Definition:
fsm_internals.h:51
FSMPage
FSMPageData * FSMPage
Definition:
fsm_internals.h:45
fsm_page_contents
Datum fsm_page_contents(PG_FUNCTION_ARGS)
Definition:
fsmfuncs.c:35
PG_FUNCTION_INFO_V1
PG_FUNCTION_INFO_V1(fsm_page_contents)
i
int i
Definition:
isn.c:72
miscadmin.h
pageinspect.h
get_page_from_raw
Page get_page_from_raw(bytea *raw_page)
Definition:
rawpage.c:215
postgres.h
Datum
uintptr_t Datum
Definition:
postgres.h:64
appendStringInfo
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition:
stringinfo.c:94
initStringInfo
void initStringInfo(StringInfo str)
Definition:
stringinfo.c:56
stringinfo.h
FSMPageData
Definition:
fsm_internals.h:25
FSMPageData::fp_nodes
uint8 fp_nodes[FLEXIBLE_ARRAY_MEMBER]
Definition:
fsm_internals.h:42
FSMPageData::fp_next_slot
int fp_next_slot
Definition:
fsm_internals.h:35
StringInfoData
Definition:
stringinfo.h:47
StringInfoData::data
char * data
Definition:
stringinfo.h:48
StringInfoData::len
int len
Definition:
stringinfo.h:49
varlena
Definition:
c.h:666
superuser
bool superuser(void)
Definition:
superuser.c:46
cstring_to_text_with_len
text * cstring_to_text_with_len(const char *s, int len)
Definition:
varlena.c:196
contrib
pageinspect
fsmfuncs.c
Generated on Tue Dec 3 2024 06:13:13 for PostgreSQL Source Code by
1.9.1