1PG_RESETWAL(1)           PostgreSQL 10.7 Documentation          PG_RESETWAL(1)
2
3
4

NAME

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

SYNOPSIS

10       pg_resetwal [-f] [-n] [option...] {[-D] datadir}
11

DESCRIPTION

13       pg_resetwal clears the write-ahead log (WAL) and optionally resets some
14       other control information stored in the pg_control file. This function
15       is sometimes needed if these files have become corrupted. It should be
16       used only as a last resort, when the server will not start due to such
17       corruption.
18
19       After running this command, it should be possible to start the server,
20       but bear in mind that the database might contain inconsistent data due
21       to partially-committed transactions. You should immediately dump your
22       data, run initdb, and reload. After reload, check for inconsistencies
23       and repair as needed.
24
25       This utility can only be run by the user who installed the server,
26       because it requires read/write access to the data directory. For safety
27       reasons, you must specify the data directory on the command line.
28       pg_resetwal does not use the environment variable PGDATA.
29
30       If pg_resetwal complains that it cannot determine valid data for
31       pg_control, you can force it to proceed anyway by specifying the -f
32       (force) option. In this case plausible values will be substituted for
33       the missing data. Most of the fields can be expected to match, but
34       manual assistance might be needed for the next OID, next transaction ID
35       and epoch, next multitransaction ID and offset, and WAL starting
36       address fields. These fields can be set using the options discussed
37       below. If you are not able to determine correct values for all these
38       fields, -f can still be used, but the recovered database must be
39       treated with even more suspicion than usual: an immediate dump and
40       reload is imperative.  Do not execute any data-modifying operations in
41       the database before you dump, as any such action is likely to make the
42       corruption worse.
43

OPTIONS

45       -f
46           Force pg_resetwal to proceed even if it cannot determine valid data
47           for pg_control, as explained above.
48
49       -n
50           The -n (no operation) option instructs pg_resetwal to print the
51           values reconstructed from pg_control and values about to be
52           changed, and then exit without modifying anything. This is mainly a
53           debugging tool, but can be useful as a sanity check before allowing
54           pg_resetwal to proceed for real.
55
56       -V
57       --version
58           Display version information, then exit.
59
60       -?
61       --help
62           Show help, then exit.
63
64       The following options are only needed when pg_resetwal is unable to
65       determine appropriate values by reading pg_control. Safe values can be
66       determined as described below. For values that take numeric arguments,
67       hexadecimal values can be specified by using the prefix 0x.
68
69       -c xid,xid
70           Manually set the oldest and newest transaction IDs for which the
71           commit time can be retrieved.
72
73           A safe value for the oldest transaction ID for which the commit
74           time can be retrieved (first part) can be determined by looking for
75           the numerically smallest file name in the directory pg_commit_ts
76           under the data directory. Conversely, a safe value for the newest
77           transaction ID for which the commit time can be retrieved (second
78           part) can be determined by looking for the numerically greatest
79           file name in the same directory. The file names are in hexadecimal.
80
81       -e xid_epoch
82           Manually set the next transaction ID's epoch.
83
84           The transaction ID epoch is not actually stored anywhere in the
85           database except in the field that is set by pg_resetwal, so any
86           value will work so far as the database itself is concerned. You
87           might need to adjust this value to ensure that replication systems
88           such as Slony-I and Skytools work correctly — if so, an appropriate
89           value should be obtainable from the state of the downstream
90           replicated database.
91
92       -l walfile
93           Manually set the WAL starting address.
94
95           The WAL starting address should be larger than any WAL segment file
96           name currently existing in the directory pg_wal under the data
97           directory. These names are also in hexadecimal and have three
98           parts. The first part is the “timeline ID” and should usually be
99           kept the same. For example, if 00000001000000320000004A is the
100           largest entry in pg_wal, use -l 00000001000000320000004B or higher.
101
102               Note
103               pg_resetwal itself looks at the files in pg_wal and chooses a
104               default -l setting beyond the last existing file name.
105               Therefore, manual adjustment of -l should only be needed if you
106               are aware of WAL segment files that are not currently present
107               in pg_wal, such as entries in an offline archive; or if the
108               contents of pg_wal have been lost entirely.
109
110       -m mxid,mxid
111           Manually set the next and oldest multitransaction ID.
112
113           A safe value for the next multitransaction ID (first part) can be
114           determined by looking for the numerically largest file name in the
115           directory pg_multixact/offsets under the data directory, adding
116           one, and then multiplying by 65536 (0x10000). Conversely, a safe
117           value for the oldest multitransaction ID (second part of -m) can be
118           determined by looking for the numerically smallest file name in the
119           same directory and multiplying by 65536. The file names are in
120           hexadecimal, so the easiest way to do this is to specify the option
121           value in hexadecimal and append four zeroes.
122
123       -o oid
124           Manually set the next OID.
125
126           There is no comparably easy way to determine a next OID that's
127           beyond the largest one in the database, but fortunately it is not
128           critical to get the next-OID setting right.
129
130       -O mxoff
131           Manually set the next multitransaction offset.
132
133           A safe value can be determined by looking for the numerically
134           largest file name in the directory pg_multixact/members under the
135           data directory, adding one, and then multiplying by 52352 (0xCC80).
136           The file names are in hexadecimal. There is no simple recipe such
137           as the ones for other options of appending zeroes.
138
139       -x xid
140           Manually set the next transaction ID.
141
142           A safe value can be determined by looking for the numerically
143           largest file name in the directory pg_xact under the data
144           directory, adding one, and then multiplying by 1048576 (0x100000).
145           Note that the file names are in hexadecimal. It is usually easiest
146           to specify the option value in hexadecimal too. For example, if
147           0011 is the largest entry in pg_xact, -x 0x1200000 will work (five
148           trailing zeroes provide the proper multiplier).
149

NOTES

151       This command must not be used when the server is running.  pg_resetwal
152       will refuse to start up if it finds a server lock file in the data
153       directory. If the server crashed then a lock file might have been left
154       behind; in that case you can remove the lock file to allow pg_resetwal
155       to run. But before you do so, make doubly certain that there is no
156       server process still alive.
157
158       pg_resetwal works only with servers of the same major version.
159

SEE ALSO

161       pg_controldata(1)
162
163
164
165PostgreSQL 10.7                      2019                       PG_RESETWAL(1)
Impressum