pageinspect: Use new pg_lsn datatype.

Michael Paquier, with slight comment changes by me
This commit is contained in:
Robert Haas 2014-03-03 07:14:31 -05:00
parent ae95f5f74a
commit 45ffeb7e00
5 changed files with 35 additions and 9 deletions

View File

@ -4,8 +4,8 @@ MODULE_big = pageinspect
OBJS = rawpage.o heapfuncs.o btreefuncs.o fsmfuncs.o
EXTENSION = pageinspect
DATA = pageinspect--1.1.sql pageinspect--1.0--1.1.sql \
pageinspect--unpackaged--1.0.sql
DATA = pageinspect--1.2.sql pageinspect--1.0--1.1.sql \
pageinspect--1.1--1.2.sql pageinspect--unpackaged--1.0.sql
ifdef USE_PGXS
PG_CONFIG = pg_config

View File

@ -0,0 +1,18 @@
/* contrib/pageinspect/pageinspect--1.1--1.2.sql */
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pageinspect UPDATE TO 1.2" to load this file. \quit
DROP FUNCTION page_header(bytea);
CREATE FUNCTION page_header(IN page bytea,
OUT lsn pg_lsn,
OUT checksum smallint,
OUT flags smallint,
OUT lower smallint,
OUT upper smallint,
OUT special smallint,
OUT pagesize smallint,
OUT version smallint,
OUT prune_xid xid)
AS 'MODULE_PATHNAME', 'page_header'
LANGUAGE C STRICT;

View File

@ -1,4 +1,4 @@
/* contrib/pageinspect/pageinspect--1.1.sql */
/* contrib/pageinspect/pageinspect--1.2.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pageinspect" to load this file. \quit
@ -20,7 +20,7 @@ LANGUAGE C STRICT;
-- page_header()
--
CREATE FUNCTION page_header(IN page bytea,
OUT lsn text,
OUT lsn pg_lsn,
OUT checksum smallint,
OUT flags smallint,
OUT lower smallint,

View File

@ -1,5 +1,5 @@
# pageinspect extension
comment = 'inspect the contents of database pages at a low level'
default_version = '1.1'
default_version = '1.2'
module_pathname = '$libdir/pageinspect'
relocatable = true

View File

@ -18,10 +18,12 @@
#include "access/htup_details.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
#include "utils/builtins.h"
#include "utils/pg_lsn.h"
#include "utils/rel.h"
PG_MODULE_MAGIC;
@ -180,7 +182,6 @@ page_header(PG_FUNCTION_ARGS)
PageHeader page;
XLogRecPtr lsn;
char lsnchar[64];
if (!superuser())
ereport(ERROR,
@ -207,10 +208,17 @@ page_header(PG_FUNCTION_ARGS)
/* Extract information from the page header */
lsn = PageGetLSN(page);
snprintf(lsnchar, sizeof(lsnchar), "%X/%X",
(uint32) (lsn >> 32), (uint32) lsn);
values[0] = CStringGetTextDatum(lsnchar);
/* pageinspect >= 1.2 uses pg_lsn instead of text for the LSN field. */
if (tupdesc->attrs[0]->atttypid == TEXTOID)
{
char lsnchar[64];
snprintf(lsnchar, sizeof(lsnchar), "%X/%X",
(uint32) (lsn >> 32), (uint32) lsn);
values[0] = CStringGetTextDatum(lsnchar);
}
else
values[0] = LSNGetDatum(lsn);
values[1] = UInt16GetDatum(page->pd_checksum);
values[2] = UInt16GetDatum(page->pd_flags);
values[3] = UInt16GetDatum(page->pd_lower);