Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eeaf3fc

Browse files
committed
First cut at XLOG file reset utility.
Could do with more testing, but it works in the simple cases.
1 parent f192da1 commit eeaf3fc

File tree

5 files changed

+1079
-2
lines changed

5 files changed

+1079
-2
lines changed

contrib/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Header: /cvsroot/pgsql/contrib/Makefile,v 1.17 2001/03/13 19:28:02 petere Exp $
1+
# $Header: /cvsroot/pgsql/contrib/Makefile,v 1.18 2001/03/14 00:57:43 tgl Exp $
22

33
subdir = contrib
44
top_builddir = ..
@@ -18,8 +18,10 @@ WANTED_DIRS = \
1818
miscutil \
1919
noupdate \
2020
oid2name \
21+
pg_controldata \
2122
pg_dumplo \
2223
pg_logger \
24+
pg_resetxlog \
2325
pgbench \
2426
pgcrypto \
2527
rserv \

contrib/README

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ intarray -
5252
by Teodor Sigaev <[email protected]> and Oleg Bartunov
5353
5454

55+
ipc_check -
56+
Simple test script to help in configuring IPC.
57+
FreeBSD only, for now.
58+
5559
isbn_issn -
5660
PostgreSQL type extensions for ISBN (books) and ISSN (serials)
5761
by Garrett A. Wollman <[email protected]>
@@ -86,7 +90,7 @@ oid2name -
8690
by B Palmer <[email protected]>
8791

8892
pg_controldata -
89-
Dump internal database site structures
93+
Dump contents of pg_control (database master file)
9094
by Oliver Elphick <[email protected]>
9195

9296
pg_dumplo -
@@ -97,6 +101,10 @@ pg_logger -
97101
Stdin-to-syslog gateway for PostgreSQL
98102
by Nathan Myers <[email protected]>
99103

104+
pg_resetxlog -
105+
Reset the WAL log (pg_xlog) to recover from crash or format change
106+
by Tom Lane <[email protected]>
107+
100108
pgbench -
101109
TPC-B like benchmarking tool
102110
by Tatsuo Ishii <[email protected]>

contrib/pg_resetxlog/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/Makefile,v 1.1 2001/03/14 00:57:43 tgl Exp $
3+
#
4+
5+
subdir = contrib/pg_resetxlog
6+
top_builddir = ../..
7+
include $(top_builddir)/src/Makefile.global
8+
9+
OBJS = pg_resetxlog.o pg_crc.o
10+
11+
all: pg_resetxlog
12+
13+
pg_resetxlog: $(OBJS)
14+
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
15+
16+
pg_crc.c: $(top_builddir)/src/backend/utils/hash/pg_crc.c
17+
rm -f $@ && $(LN_S) $< .
18+
19+
install: all installdirs
20+
$(INSTALL_PROGRAM) pg_resetxlog$(X) $(bindir)
21+
$(INSTALL_DATA) README.pg_resetxlog $(docdir)/contrib
22+
23+
installdirs:
24+
$(mkinstalldirs) $(bindir) $(docdir)/contrib
25+
26+
uninstall:
27+
rm -f $(bindir)/pg_resetxlog$(X) $(docdir)/contrib/README.pg_resetxlog
28+
29+
clean distclean maintainer-clean:
30+
rm -f pg_resetxlog$(X) $(OBJS) pg_crc.c
31+
32+
depend dep:
33+
$(CC) -MM -MG $(CFLAGS) *.c > depend
34+
35+
ifeq (depend,$(wildcard depend))
36+
include depend
37+
endif
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
pg_resetxlog is a program to clear the WAL transaction log (stored in
2+
$PGDATA/pg_xlog/), replacing whatever had been in it with just a dummy
3+
shutdown-checkpoint record. It also regenerates the pg_control file
4+
if necessary.
5+
6+
THIS PROGRAM WILL DESTROY VALUABLE LOG DATA!!! Don't run it unless you
7+
really need it!!!
8+
9+
pg_resetxlog is primarily intended for disaster recovery --- that is,
10+
if your pg_control and/or xlog are hosed badly enough that Postgres refuses
11+
to start up, this program will get you past that problem and let you get to
12+
your data files. But realize that without the xlog, your data files may be
13+
corrupt due to partially-applied transactions, incomplete index-file
14+
updates, etc. You should dump your data, check it for accuracy, then initdb
15+
and reload.
16+
17+
A secondary purpose is to cope with xlog format changes without requiring
18+
initdb. To use pg_resetxlog for this purpose, just be sure that you have
19+
cleanly shut down your old postmaster (if you're not sure, see the contrib
20+
module pg_controldata and run it to be sure the DB state is SHUTDOWN).
21+
Then run pg_resetxlog, and finally install and start the new version of
22+
the database software.
23+
24+
To run the program, make sure your postmaster is not running, then
25+
(as the Postgres admin user) do
26+
27+
pg_resetxlog $PGDATA
28+
29+
As a safety measure, the target data directory must be specified on the
30+
command line, it cannot be defaulted.
31+
32+
If pg_resetxlog complains that it can't reconstruct valid data for pg_control,
33+
you can force it to invent plausible data values with
34+
35+
pg_resetxlog -f $PGDATA
36+
37+
If this turns out to be necessary then you *definitely* should plan on
38+
immediate dump, initdb, reload --- any modifications you do to the database
39+
after "pg_resetxlog -f" would be likely to corrupt things even worse.

0 commit comments

Comments
 (0)