1PG_RESETXLOG(1)         PostgreSQL Server Applications         PG_RESETXLOG(1)
2
3
4

NAME

6       pg_resetxlog  - reset the write-ahead log and other control information
7       of a PostgreSQL database cluster
8

SYNOPSIS

10       pg_resetxlog [ -f ]  [ -n ]  [ -ooid  ]  [ -x xid  ]  [ -e xid_epoch  ]
11       [ -m mxid  ]  [ -O mxoff  ]  [ -l timelineid,fileid,seg  ]  datadir
12

DESCRIPTION

14       pg_resetxlog  clears  the  write-ahead  log (WAL) and optionally resets
15       some other control information stored  in  the  pg_control  file.  This
16       function  is  sometimes needed if these files have become corrupted. It
17       should be used only as a last resort, when the server  will  not  start
18       due to such corruption.
19
20       After  running this command, it should be possible to start the server,
21       but bear in mind that the database may contain inconsistent data due to
22       partially-committed  transactions.  You  should  immediately  dump your
23       data, run initdb, and reload. After reload, check  for  inconsistencies
24       and repair as needed.
25
26       This  utility  can  only  be  run by the user who installed the server,
27       because it requires read/write  access  to  the  data  directory.   For
28       safety  reasons,  you  must  specify  the data directory on the command
29       line.  pg_resetxlog does not use the environment variable PGDATA.
30
31       If pg_resetxlog complains that  it  cannot  determine  valid  data  for
32       pg_control,  you  can  force  it to proceed anyway by specifying the -f
33       (force) switch. In this case plausible values will be  substituted  for
34       the missing data. Most of the fields can be expected to match, but man‐
35       ual assistance may be needed for the next OID, next transaction ID  and
36       epoch,  next  multitransaction ID and offset, WAL starting address, and
37       database locale fields.  The first six of these can be  set  using  the
38       switches discussed below.  pg_resetxlog's own environment is the source
39       for its guess at the locale fields; take care that LANG  and  so  forth
40       match  the  environment that initdb was run in.  If you are not able to
41       determine correct values for all these fields, -f can  still  be  used,
42       but  the  recovered  database  must be treated with even more suspicion
43       than usual: an immediate dump and reload is imperative. Do not  execute
44       any  data-modifying  operations in the database before you dump; as any
45       such action is likely to make the corruption worse.
46
47       The -o, -x, -e, -m, -O, and -l switches allow the next OID, next trans‐
48       action  ID, next transaction ID's epoch, next multitransaction ID, next
49       multitransaction offset, and WAL starting address values to be set man‐
50       ually.  These  are only needed when pg_resetxlog is unable to determine
51       appropriate values by reading pg_control. Safe values may be determined
52       as follows:
53
54       · A  safe  value  for the next transaction ID (-x) may be determined by
55         looking for the  numerically  largest  file  name  in  the  directory
56         pg_clog under the data directory, adding one, and then multiplying by
57         1048576. Note that the file names are in hexadecimal. It  is  usually
58         easiest  to specify the switch value in hexadecimal too. For example,
59         if 0011 is the largest entry in pg_clog, -x 0x1200000 will work (five
60         trailing zeroes provide the proper multiplier).
61
62       · A  safe value for the next multitransaction ID (-m) may be determined
63         by looking for the numerically largest file  name  in  the  directory
64         pg_multixact/offsets  under  the data directory, adding one, and then
65         multiplying by 65536. As above, the file names are in hexadecimal, so
66         the easiest way to do this is to specify the switch value in hexadec‐
67         imal and add four zeroes.
68
69       · A safe value for the next multitransaction offset (-O) may be  deter‐
70         mined  by looking for the numerically largest file name in the direc‐
71         tory pg_multixact/members under the data directory, adding  one,  and
72         then  multiplying by 65536. As above, the file names are in hexadeci‐
73         mal, so the easiest way to do this is to specify the switch value  in
74         hexadecimal and add four zeroes.
75
76       · The  WAL  starting  address  (-l) should be larger than any file name
77         currently existing in the directory pg_xlog under the data directory.
78         These  names  are also in hexadecimal and have three parts. The first
79         part is the ``timeline ID'' and should usually be kept the same.   Do
80         not choose a value larger than 255 (0xFF) for the third part; instead
81         increment the second part and reset the third part to 0.   For  exam‐
82         ple,  if 00000001000000320000004A is the largest entry in pg_xlog, -l
83         0x1,0x32,0x4B   will   work;   but   if   the   largest   entry    is
84         000000010000003A000000FF, choose -l 0x1,0x3B,0x0 or more.
85
86       · There is no comparably easy way to determine a next OID that's beyond
87         the largest one in the database, but fortunately it is  not  critical
88         to get the next-OID setting right.
89
90       · The transaction ID epoch is not actually stored anywhere in the data‐
91         base except in the field that is set by pg_resetxlog,  so  any  value
92         will work so far as the database itself is concerned.  You might need
93         to adjust this value to  ensure  that  replication  systems  such  as
94         Slony-I  work  correctly  —  if  so,  an  appropriate value should be
95         obtainable from the state of the downstream replicated database.
96
97       The -n (no operation) switch instructs pg_resetxlog to print the values
98       reconstructed from pg_control and then exit without modifying anything.
99       This is mainly a debugging tool, but may be useful as  a  sanity  check
100       before allowing pg_resetxlog to proceed for real.
101

NOTES

103       This  command must not be used when the server is running. pg_resetxlog
104       will refuse to start up if it finds a server  lock  file  in  the  data
105       directory.  If  the  server crashed then a lock file may have been left
106       behind; in that case you can remove the lock file to allow pg_resetxlog
107       to  run.  But  before  you  do so, make doubly certain that there is no
108       server process still alive.
109
110
111
112Application                       2008-06-08                   PG_RESETXLOG(1)
Impressum