Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit639ed4e

Browse files
committed
Add pg_xlogdump contrib program
This program relies on rm_desc backend routines and the xlogreaderinfrastructure to emit human-readable rendering of WAL records.Author: Andres Freund, with many reworks by ÁlvaroReviewed (in a much earlier version) by Peter Eisentraut
1 parentc0c6acd commit639ed4e

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+
ifdefUSE_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+
overrideCPPFLAGS := -DFRONTEND$(CPPFLAGS)
27+
28+
rmgrdesc.cxlogreader.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+
#defineFRONTEND 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(TimestampTzt)
29+
{
30+
pg_time_tresult;
31+
32+
#ifdefHAVE_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+
returnresult;
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+
constchar*
50+
timestamptz_to_str(TimestampTzdt)
51+
{
52+
staticcharbuf[MAXDATELEN+1];
53+
staticcharts[MAXDATELEN+1];
54+
staticcharzone[MAXDATELEN+1];
55+
pg_time_tresult=timestamptz_to_time_t(dt);
56+
structtm*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+
#ifdefHAVE_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+
returnbuf;
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(StringInfostr,constchar*fmt, ...)
76+
{
77+
va_listargs;
78+
79+
va_start(args,fmt);
80+
vprintf(fmt,args);
81+
va_end(args);
82+
}
83+
84+
void
85+
appendStringInfoString(StringInfostr,constchar*string)
86+
{
87+
appendStringInfo(str,"%s",string);
88+
}
89+
90+
void
91+
appendStringInfoChar(StringInfostr,charch)
92+
{
93+
appendStringInfo(str,"%c",ch);
94+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp