00001 /*------------------------------------------------------------------------- 00002 * 00003 * fsmfuncs.c 00004 * Functions to investigate FSM pages 00005 * 00006 * These functions are restricted to superusers for the fear of introducing 00007 * security holes if the input checking isn't as water-tight as it should. 00008 * You'd need to be superuser to obtain a raw page image anyway, so 00009 * there's hardly any use case for using these without superuser-rights 00010 * anyway. 00011 * 00012 * Copyright (c) 2007-2013, PostgreSQL Global Development Group 00013 * 00014 * IDENTIFICATION 00015 * contrib/pageinspect/fsmfuncs.c 00016 * 00017 *------------------------------------------------------------------------- 00018 */ 00019 00020 #include "postgres.h" 00021 00022 #include "funcapi.h" 00023 #include "lib/stringinfo.h" 00024 #include "miscadmin.h" 00025 #include "storage/fsm_internals.h" 00026 #include "utils/builtins.h" 00027 00028 Datum fsm_page_contents(PG_FUNCTION_ARGS); 00029 00030 /* 00031 * Dumps the contents of a FSM page. 00032 */ 00033 PG_FUNCTION_INFO_V1(fsm_page_contents); 00034 00035 Datum 00036 fsm_page_contents(PG_FUNCTION_ARGS) 00037 { 00038 bytea *raw_page = PG_GETARG_BYTEA_P(0); 00039 StringInfoData sinfo; 00040 FSMPage fsmpage; 00041 int i; 00042 00043 if (!superuser()) 00044 ereport(ERROR, 00045 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), 00046 (errmsg("must be superuser to use raw page functions")))); 00047 00048 fsmpage = (FSMPage) PageGetContents(VARDATA(raw_page)); 00049 00050 initStringInfo(&sinfo); 00051 00052 for (i = 0; i < NodesPerPage; i++) 00053 { 00054 if (fsmpage->fp_nodes[i] != 0) 00055 appendStringInfo(&sinfo, "%d: %d\n", i, fsmpage->fp_nodes[i]); 00056 } 00057 appendStringInfo(&sinfo, "fp_next_slot: %d\n", fsmpage->fp_next_slot); 00058 00059 PG_RETURN_TEXT_P(cstring_to_text(sinfo.data)); 00060 }