pg_resetxlogpg_resetxlog1Applicationpg_resetxlogreset the write-ahead log and other control information of a PostgreSQL database clusterpg_resetxlogoptiondatadirDescriptionpg_resetxlog clears the write-ahead log (WAL) and
optionally resets some other control information stored in the
pg_control> file. This function is sometimes needed
if these files have become corrupted. It should be used only as a
last resort, when the server will not start due to such corruption.
After running this command, it should be possible to start the server,
but bear in mind that the database might contain inconsistent data due to
partially-committed transactions. You should immediately dump your data,
run initdb>, and reload. After reload, check for
inconsistencies and repair as needed.
This utility can only be run by the user who installed the server, because
it requires read/write access to the data directory.
For safety reasons, you must specify the data directory on the command line.
pg_resetxlog does not use the environment variable
PGDATA>.
If pg_resetxlog complains that it cannot determine
valid data for pg_control>, you can force it to proceed anyway
by specifying the Options
Force pg_resetxlog to proceed even if it cannot determine
valid data for pg_control>, as explained above.
The Display version information, then exit.Show help, then exit.
The following options are only needed when
pg_resetxlog is unable to determine appropriate values
by reading pg_control>. Safe values can be determined as
described below. For values that take numeric arguments, hexadecimal
values can be specified by using the prefix 0x.
xid,xid
Manually set the oldest and newest transaction IDs for which the commit
time can be retrieved.
A safe value for the oldest transaction ID for which the commit time can
be retrieved (first part) can be determined by looking
for the numerically smallest file name in the directory
pg_commit_ts> under the data directory. Conversely, a safe
value for the newest transaction ID for which the commit time can be
retrieved (second part) can be determined by looking for the numerically
greatest file name in the same directory. The file names are in
hexadecimal.
xid_epoch
Manually set the next transaction ID's epoch.
The transaction ID epoch is not actually stored anywhere in the database
except in the field that is set by pg_resetxlog,
so any value will work so far as the database itself is concerned.
You might need to adjust this value to ensure that replication
systems such as Slony-I> and
Skytools> work correctly —
if so, an appropriate value should be obtainable from the state of
the downstream replicated database.
xlogfile
Manually set the WAL starting address.
The WAL starting address should be
larger than any WAL segment file name currently existing in
the directory pg_xlog> under the data directory.
These names are also in hexadecimal and have three parts. The first
part is the timeline ID> and should usually be kept the same.
For example, if 00000001000000320000004A> is the
largest entry in pg_xlog>, use -l 00000001000000320000004B> or higher.
pg_resetxlog itself looks at the files in
pg_xlog> and chooses a default mxid,mxid
Manually set the next and oldest multitransaction ID.
A safe value for the next multitransaction ID (first part) can be
determined by looking for the numerically largest file name in the
directory pg_multixact/offsets> under the data directory,
adding one, and then multiplying by 65536 (0x10000). Conversely, a safe
value for the oldest multitransaction ID (second part of
oid
Manually set the next OID.
There is no comparably easy way to determine a next OID that's beyond
the largest one in the database, but fortunately it is not critical to
get the next-OID setting right.
mxoff
Manually set the next multitransaction offset.
A safe value can be determined by looking for the numerically largest
file name in the directory pg_multixact/members> under the
data directory, adding one, and then multiplying by 52352 (0xCC80).
The file names are in hexadecimal. There is no simple recipe such as
the ones for other options of appending zeroes.
xid
Manually set the next transaction ID.
A safe value can be determined by looking for the numerically largest
file name in the directory pg_clog> under the data directory,
adding one,
and then multiplying by 1048576 (0x100000). Note that the file names are in
hexadecimal. It is usually easiest to specify the option value in
hexadecimal too. For example, if 0011> is the largest entry
in pg_clog>, -x 0x1200000> will work (five
trailing zeroes provide the proper multiplier).
Notes
This command must not be used when the server is
running. pg_resetxlog will refuse to start up if
it finds a server lock file in the data directory. If the
server crashed then a lock file might have been left
behind; in that case you can remove the lock file to allow
pg_resetxlog to run. But before you do
so, make doubly certain that there is no server process still alive.
pg_resetxlog works only with servers of the same
major version.
See Also