]> granicus.if.org Git - postgresql/commitdiff
pageinspect: Use new pg_lsn datatype.
authorRobert Haas <rhaas@postgresql.org>
Mon, 3 Mar 2014 12:14:31 +0000 (07:14 -0500)
committerRobert Haas <rhaas@postgresql.org>
Mon, 3 Mar 2014 12:15:04 +0000 (07:15 -0500)
Michael Paquier, with slight comment changes by me

contrib/pageinspect/Makefile
contrib/pageinspect/pageinspect--1.1--1.2.sql [new file with mode: 0644]
contrib/pageinspect/pageinspect--1.2.sql [moved from contrib/pageinspect/pageinspect--1.1.sql with 97% similarity]
contrib/pageinspect/pageinspect.control
contrib/pageinspect/rawpage.c

index 0e267eb8694be7d9b0028ec642aa142c3b38e835..ee78cb29894f4797ffe1b96d16d0ac6fc3d3f688 100644 (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
diff --git a/contrib/pageinspect/pageinspect--1.1--1.2.sql b/contrib/pageinspect/pageinspect--1.1--1.2.sql
new file mode 100644 (file)
index 0000000..5e23ca4
--- /dev/null
@@ -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;
similarity index 97%
rename from contrib/pageinspect/pageinspect--1.1.sql
rename to contrib/pageinspect/pageinspect--1.2.sql
index 22a47d53e7544e430fdd8a773807879960f36600..15e8e1e3811c7a5b7b21dd7e1f3620ea50fbc7d2 100644 (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,
index a412cf13ddbb5037c70380c731ebabcd347c389e..aecd91a711b8cd5aee1e1b1bd83c54bbd47a5d7b 100644 (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
index ff541ed40d65d1fea1d74aeb9f45072730e23c49..f1e0944c0e0beafcffefb0594194a0fff2165db8 100644 (file)
 #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);