1PG_RESETWAL(1)           PostgreSQL 15.4 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 | --force] [-n | --dry-run] [option...] [-D |
11                   --pgdata]datadir
12

DESCRIPTION

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

OPTIONS

46       -f
47       --force
48           Force pg_resetwal to proceed even if it cannot determine valid data
49           for pg_control, as explained above.
50
51       -n
52       --dry-run
53           The -n/--dry-run option instructs pg_resetwal to print the values
54           reconstructed from pg_control and values about to be changed, and
55           then exit without modifying anything. This is mainly a debugging
56           tool, but can be useful as a sanity check before allowing
57           pg_resetwal to proceed for real.
58
59       -V
60       --version
61           Display version information, then exit.
62
63       -?
64       --help
65           Show help, then exit.
66
67       The following options are only needed when pg_resetwal is unable to
68       determine appropriate values by reading pg_control. Safe values can be
69       determined as described below. For values that take numeric arguments,
70       hexadecimal values can be specified by using the prefix 0x.
71
72       -c xid,xid
73       --commit-timestamp-ids=xid,xid
74           Manually set the oldest and newest transaction IDs for which the
75           commit time can be retrieved.
76
77           A safe value for the oldest transaction ID for which the commit
78           time can be retrieved (first part) can be determined by looking for
79           the numerically smallest file name in the directory pg_commit_ts
80           under the data directory. Conversely, a safe value for the newest
81           transaction ID for which the commit time can be retrieved (second
82           part) can be determined by looking for the numerically greatest
83           file name in the same directory. The file names are in hexadecimal.
84
85       -e xid_epoch
86       --epoch=xid_epoch
87           Manually set the next transaction ID's epoch.
88
89           The transaction ID epoch is not actually stored anywhere in the
90           database except in the field that is set by pg_resetwal, so any
91           value will work so far as the database itself is concerned. You
92           might need to adjust this value to ensure that replication systems
93           such as Slony-I and Skytools work correctly — if so, an appropriate
94           value should be obtainable from the state of the downstream
95           replicated database.
96
97       -l walfile
98       --next-wal-file=walfile
99           Manually set the WAL starting location by specifying the name of
100           the next WAL segment file.
101
102           The name of next WAL segment file should be larger than any WAL
103           segment file name currently existing in the directory pg_wal under
104           the data directory. These names are also in hexadecimal and have
105           three parts. The first part is the “timeline ID” and should usually
106           be kept the same. For example, if 00000001000000320000004A is the
107           largest entry in pg_wal, use -l 00000001000000320000004B or higher.
108
109           Note that when using nondefault WAL segment sizes, the numbers in
110           the WAL file names are different from the LSNs that are reported by
111           system functions and system views. This option takes a WAL file
112           name, not an LSN.
113
114               Note
115               pg_resetwal itself looks at the files in pg_wal and chooses a
116               default -l setting beyond the last existing file name.
117               Therefore, manual adjustment of -l should only be needed if you
118               are aware of WAL segment files that are not currently present
119               in pg_wal, such as entries in an offline archive; or if the
120               contents of pg_wal have been lost entirely.
121
122       -m mxid,mxid
123       --multixact-ids=mxid,mxid
124           Manually set the next and oldest multitransaction ID.
125
126           A safe value for the next multitransaction ID (first part) can be
127           determined by looking for the numerically largest file name in the
128           directory pg_multixact/offsets under the data directory, adding
129           one, and then multiplying by 65536 (0x10000). Conversely, a safe
130           value for the oldest multitransaction ID (second part of -m) can be
131           determined by looking for the numerically smallest file name in the
132           same directory and multiplying by 65536. The file names are in
133           hexadecimal, so the easiest way to do this is to specify the option
134           value in hexadecimal and append four zeroes.
135
136       -o oid
137       --next-oid=oid
138           Manually set the next OID.
139
140           There is no comparably easy way to determine a next OID that's
141           beyond the largest one in the database, but fortunately it is not
142           critical to get the next-OID setting right.
143
144       -O mxoff
145       --multixact-offset=mxoff
146           Manually set the next multitransaction offset.
147
148           A safe value can be determined by looking for the numerically
149           largest file name in the directory pg_multixact/members under the
150           data directory, adding one, and then multiplying by 52352 (0xCC80).
151           The file names are in hexadecimal. There is no simple recipe such
152           as the ones for other options of appending zeroes.
153
154       --wal-segsize=wal_segment_size
155           Set the new WAL segment size, in megabytes. The value must be set
156           to a power of 2 between 1 and 1024 (megabytes). See the same option
157           of initdb(1) for more information.
158
159               Note
160               While pg_resetwal will set the WAL starting address beyond the
161               latest existing WAL segment file, some segment size changes can
162               cause previous WAL file names to be reused. It is recommended
163               to use -l together with this option to manually set the WAL
164               starting address if WAL file name overlap will cause problems
165               with your archiving strategy.
166
167       -u xid
168       --oldest-transaction-id=xid
169           Manually set the oldest unfrozen transaction ID.
170
171           A safe value can be determined by looking for the numerically
172           smallest file name in the directory pg_xact under the data
173           directory and then multiplying by 1048576 (0x100000). Note that the
174           file names are in hexadecimal. It is usually easiest to specify the
175           option value in hexadecimal too. For example, if 0007 is the
176           smallest entry in pg_xact, -u 0x700000 will work (five trailing
177           zeroes provide the proper multiplier).
178
179       -x xid
180       --next-transaction-id=xid
181           Manually set the next transaction ID.
182
183           A safe value can be determined by looking for the numerically
184           largest file name in the directory pg_xact under the data
185           directory, adding one, and then multiplying by 1048576 (0x100000).
186           Note that the file names are in hexadecimal. It is usually easiest
187           to specify the option value in hexadecimal too. For example, if
188           0011 is the largest entry in pg_xact, -x 0x1200000 will work (five
189           trailing zeroes provide the proper multiplier).
190

ENVIRONMENT

192       PG_COLOR
193           Specifies whether to use color in diagnostic messages. Possible
194           values are always, auto and never.
195

NOTES

197       This command must not be used when the server is running.  pg_resetwal
198       will refuse to start up if it finds a server lock file in the data
199       directory. If the server crashed then a lock file might have been left
200       behind; in that case you can remove the lock file to allow pg_resetwal
201       to run. But before you do so, make doubly certain that there is no
202       server process still alive.
203
204       pg_resetwal works only with servers of the same major version.
205

SEE ALSO

207       pg_controldata(1)
208
209
210
211PostgreSQL 15.4                      2023                       PG_RESETWAL(1)
Impressum