Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

fsmfuncs.c File Reference

#include "postgres.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
#include "miscadmin.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

Datum fsm_page_contents (PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1 (fsm_page_contents)

Function Documentation

Datum fsm_page_contents ( PG_FUNCTION_ARGS   ) 

Definition at line 36 of file fsmfuncs.c.

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

{
    bytea      *raw_page = PG_GETARG_BYTEA_P(0);
    StringInfoData sinfo;
    FSMPage     fsmpage;
    int         i;

    if (!superuser())
        ereport(ERROR,
                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                 (errmsg("must be superuser to use raw page functions"))));

    fsmpage = (FSMPage) PageGetContents(VARDATA(raw_page));

    initStringInfo(&sinfo);

    for (i = 0; i < NodesPerPage; i++)
    {
        if (fsmpage->fp_nodes[i] != 0)
            appendStringInfo(&sinfo, "%d: %d\n", i, fsmpage->fp_nodes[i]);
    }
    appendStringInfo(&sinfo, "fp_next_slot: %d\n", fsmpage->fp_next_slot);

    PG_RETURN_TEXT_P(cstring_to_text(sinfo.data));
}

PG_FUNCTION_INFO_V1 ( fsm_page_contents   )