Skip to content

Commit 639ed4e

Browse files
committed
Add pg_xlogdump contrib program
This program relies on rm_desc backend routines and the xlogreader infrastructure to emit human-readable rendering of WAL records. Author: Andres Freund, with many reworks by Álvaro Reviewed (in a much earlier version) by Peter Eisentraut
1 parent c0c6acd commit 639ed4e

File tree

10 files changed

+1104
-3
lines changed

10 files changed

+1104
-3
lines changed

contrib/pg_xlogdump/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# contrib/pg_xlogdump/Makefile
2+
3+
PGFILEDESC = "pg_xlogdump"
4+
PGAPPICON=win32
5+
6+
PROGRAM = pg_xlogdump
7+
OBJS = pg_xlogdump.o compat.o xlogreader.o rmgrdesc.o \
8+
$(RMGRDESCOBJS) $(WIN32RES)
9+
10+
RMGRDESCSOURCES = $(notdir $(wildcard $(top_srcdir)/src/backend/access/rmgrdesc/*desc.c))
11+
RMGRDESCOBJS = $(patsubst %.c,%.o,$(RMGRDESCSOURCES))
12+
13+
EXTRA_CLEAN = $(RMGRDESCSOURCES) xlogreader.c rmgrdesc.c
14+
15+
ifdef USE_PGXS
16+
PG_CONFIG = pg_config
17+
PGXS := $(shell $(PG_CONFIG) --pgxs)
18+
include $(PGXS)
19+
else
20+
subdir = contrib/pg_xlogdump
21+
top_builddir = ../..
22+
include $(top_builddir)/src/Makefile.global
23+
include $(top_srcdir)/contrib/contrib-global.mk
24+
endif
25+
26+
override CPPFLAGS := -DFRONTEND $(CPPFLAGS)
27+
28+
rmgrdesc.c xlogreader.c: % : $(top_srcdir)/src/backend/access/transam/%
29+
rm -f $@ && $(LN_S) $< .
30+
31+
$(RMGRDESCSOURCES): % : $(top_srcdir)/src/backend/access/rmgrdesc/%
32+
rm -f $@ && $(LN_S) $< .

contrib/pg_xlogdump/compat.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* compat.c
4+
* Reimplementations of various backend functions.
5+
*
6+
* Portions Copyright (c) 2012, PostgreSQL Global Development Group
7+
*
8+
* IDENTIFICATION
9+
* contrib/pg_xlogdump/compat.c
10+
*
11+
* This file contains client-side implementations for various backend
12+
* functions that the rm_desc functions in *desc.c files rely on.
13+
*
14+
*-------------------------------------------------------------------------
15+
*/
16+
17+
/* ugly hack, same as in e.g pg_controldata */
18+
#define FRONTEND 1
19+
#include "postgres.h"
20+
21+
#include <time.h>
22+
23+
#include "utils/datetime.h"
24+
#include "lib/stringinfo.h"
25+
26+
/* copied from timestamp.c */
27+
pg_time_t
28+
timestamptz_to_time_t(TimestampTz t)
29+
{
30+
pg_time_t result;
31+
32+
#ifdef HAVE_INT64_TIMESTAMP
33+
result = (pg_time_t) (t / USECS_PER_SEC +
34+
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
35+
#else
36+
result = (pg_time_t) (t +
37+
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
38+
#endif
39+
return result;
40+
}
41+
42+
/*
43+
* Stopgap implementation of timestamptz_to_str that doesn't depend on backend
44+
* infrastructure.
45+
*
46+
* XXX: The backend timestamp infrastructure should instead be split out and
47+
* moved into src/common.
48+
*/
49+
const char *
50+
timestamptz_to_str(TimestampTz dt)
51+
{
52+
static char buf[MAXDATELEN + 1];
53+
static char ts[MAXDATELEN + 1];
54+
static char zone[MAXDATELEN + 1];
55+
pg_time_t result = timestamptz_to_time_t(dt);
56+
struct tm *ltime = localtime(&result);
57+
58+
strftime(ts, sizeof(zone), "%Y-%m-%d %H:%M:%S", ltime);
59+
strftime(zone, sizeof(zone), "%Z", ltime);
60+
61+
#ifdef HAVE_INT64_TIMESTAMP
62+
sprintf(buf, "%s.%06d %s", ts, (int)(dt % USECS_PER_SEC), zone);
63+
#else
64+
sprintf(buf, "%s.%.6f %s", ts, fabs(dt - floor(dt)), zone);
65+
#endif
66+
67+
return buf;
68+
}
69+
70+
/*
71+
* Provide a hacked up compat layer for StringInfos so xlog desc functions can
72+
* be linked/called.
73+
*/
74+
void
75+
appendStringInfo(StringInfo str, const char *fmt, ...)
76+
{
77+
va_list args;
78+
79+
va_start(args, fmt);
80+
vprintf(fmt, args);
81+
va_end(args);
82+
}
83+
84+
void
85+
appendStringInfoString(StringInfo str, const char *string)
86+
{
87+
appendStringInfo(str, "%s", string);
88+
}
89+
90+
void
91+
appendStringInfoChar(StringInfo str, char ch)
92+
{
93+
appendStringInfo(str, "%c", ch);
94+
}

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