Skip to content

Commit 45ffeb7

Browse files
committed
pageinspect: Use new pg_lsn datatype.
Michael Paquier, with slight comment changes by me
1 parent ae95f5f commit 45ffeb7

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

contrib/pageinspect/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ MODULE_big = pageinspect
44
OBJS = rawpage.o heapfuncs.o btreefuncs.o fsmfuncs.o
55

66
EXTENSION = pageinspect
7-
DATA = pageinspect--1.1.sql pageinspect--1.0--1.1.sql \
8-
pageinspect--unpackaged--1.0.sql
7+
DATA = pageinspect--1.2.sql pageinspect--1.0--1.1.sql \
8+
pageinspect--1.1--1.2.sql pageinspect--unpackaged--1.0.sql
99

1010
ifdef USE_PGXS
1111
PG_CONFIG = pg_config
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* contrib/pageinspect/pageinspect--1.1--1.2.sql */
2+
3+
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
4+
\echo Use "ALTER EXTENSION pageinspect UPDATE TO 1.2" to load this file. \quit
5+
6+
DROP FUNCTION page_header(bytea);
7+
CREATE FUNCTION page_header(IN page bytea,
8+
OUT lsn pg_lsn,
9+
OUT checksum smallint,
10+
OUT flags smallint,
11+
OUT lower smallint,
12+
OUT upper smallint,
13+
OUT special smallint,
14+
OUT pagesize smallint,
15+
OUT version smallint,
16+
OUT prune_xid xid)
17+
AS 'MODULE_PATHNAME', 'page_header'
18+
LANGUAGE C STRICT;

contrib/pageinspect/pageinspect--1.1.sql renamed to contrib/pageinspect/pageinspect--1.2.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* contrib/pageinspect/pageinspect--1.1.sql */
1+
/* contrib/pageinspect/pageinspect--1.2.sql */
22

33
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44
\echo Use "CREATE EXTENSION pageinspect" to load this file. \quit
@@ -20,7 +20,7 @@ LANGUAGE C STRICT;
2020
-- page_header()
2121
--
2222
CREATE FUNCTION page_header(IN page bytea,
23-
OUT lsn text,
23+
OUT lsn pg_lsn,
2424
OUT checksum smallint,
2525
OUT flags smallint,
2626
OUT lower smallint,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pageinspect extension
22
comment = 'inspect the contents of database pages at a low level'
3-
default_version = '1.1'
3+
default_version = '1.2'
44
module_pathname = '$libdir/pageinspect'
55
relocatable = true

contrib/pageinspect/rawpage.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#include "access/htup_details.h"
1919
#include "catalog/catalog.h"
2020
#include "catalog/namespace.h"
21+
#include "catalog/pg_type.h"
2122
#include "funcapi.h"
2223
#include "miscadmin.h"
2324
#include "storage/bufmgr.h"
2425
#include "utils/builtins.h"
26+
#include "utils/pg_lsn.h"
2527
#include "utils/rel.h"
2628

2729
PG_MODULE_MAGIC;
@@ -180,7 +182,6 @@ page_header(PG_FUNCTION_ARGS)
180182

181183
PageHeader page;
182184
XLogRecPtr lsn;
183-
char lsnchar[64];
184185

185186
if (!superuser())
186187
ereport(ERROR,
@@ -207,10 +208,17 @@ page_header(PG_FUNCTION_ARGS)
207208
/* Extract information from the page header */
208209

209210
lsn = PageGetLSN(page);
210-
snprintf(lsnchar, sizeof(lsnchar), "%X/%X",
211-
(uint32) (lsn >> 32), (uint32) lsn);
212211

213-
values[0] = CStringGetTextDatum(lsnchar);
212+
/* pageinspect >= 1.2 uses pg_lsn instead of text for the LSN field. */
213+
if (tupdesc->attrs[0]->atttypid == TEXTOID)
214+
{
215+
char lsnchar[64];
216+
snprintf(lsnchar, sizeof(lsnchar), "%X/%X",
217+
(uint32) (lsn >> 32), (uint32) lsn);
218+
values[0] = CStringGetTextDatum(lsnchar);
219+
}
220+
else
221+
values[0] = LSNGetDatum(lsn);
214222
values[1] = UInt16GetDatum(page->pd_checksum);
215223
values[2] = UInt16GetDatum(page->pd_flags);
216224
values[3] = UInt16GetDatum(page->pd_lower);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy