3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "PG_RESETWAL" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 pg_resetwal \- reset the write\-ahead log and other control information of a PostgreSQL database cluster
33 .HP \w'\fBpg_resetwal\fR\ 'u
34 \fBpg_resetwal\fR [\fB\-f\fR | \fB\-\-force\fR] [\fB\-n\fR | \fB\-\-dry\-run\fR] [\fIoption\fR...] [\fB\-D\fR | \fB\-\-pgdata\fR]\fIdatadir\fR
38 clears the write\-ahead log (WAL) and optionally resets some other control information stored in the
40 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\&.
43 \fB\-\-wal\-segsize\fR
44 (see below), can also be used to modify certain global settings of a database cluster without the need to rerun
45 \fBinitdb\fR\&. This can be done safely on an otherwise sound database cluster, if none of the dangerous modes mentioned below are used\&.
49 is used on a data directory where the server has been cleanly shut down and the control file is sound, then it will have no effect on the contents of the database system, except that no longer used WAL files are cleared away\&. Any other use is potentially dangerous and must be done with great care\&.
53 (force) option to be specified before working on a data directory in an unclean shutdown state or with a corrupted control file\&.
55 After running this command on a data directory with corrupted WAL or a corrupted control file, 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
56 \fBinitdb\fR, and restore\&. After restore, check for inconsistencies and repair as needed\&.
60 complains that it cannot determine valid data for
61 pg_control, you can force it to proceed anyway by specifying the
63 (force) option\&. In this case plausible values will be substituted for the missing data\&. Most of the fields can be expected to match, but manual assistance might be needed for the next OID, next transaction ID and epoch, next multitransaction ID and offset, and WAL starting location fields\&. These fields can be set using the options discussed below\&. If you are not able to determine correct values for all these fields,
65 can still be used, but the recovered database must be treated with even more suspicion than usual: an immediate dump and restore is imperative\&.
67 execute any data\-modifying operations in the database before you dump, as any such action is likely to make the corruption worse\&.
69 This utility can only be run by the user who installed the server, because it requires read/write access to the data directory\&.
74 \fB\-D \fR\fB\fIdatadir\fR\fR
76 \fB\-\-pgdata=\fR\fB\fIdatadir\fR\fR
78 Specifies the location of the database directory\&. For safety reasons, you must specify the data directory on the command line\&.
80 does not use the environment variable
90 to proceed even in situations where it could be dangerous, as explained above\&. Specifically, this option is required to proceed if the server had not been cleanly shut down or if
92 cannot determine valid data for
101 \fB\-n\fR/\fB\-\-dry\-run\fR
104 to print the values reconstructed from
106 and values about to be changed, and then exit without modifying anything\&. This is mainly a debugging tool, but can be useful as a sanity check before allowing
108 to proceed for real\&.
115 Display version information, then exit\&.
122 Show help, then exit\&.
125 The following options are only needed when
127 is unable to determine appropriate values by reading
128 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
129 0x\&. Note that these instructions only apply with the standard block size of 8 kB\&.
131 \fB\-c \fR\fB\fIxid\fR\fR\fB,\fR\fB\fIxid\fR\fR
133 \fB\-\-commit\-timestamp\-ids=\fR\fB\fIxid\fR\fR\fB,\fR\fB\fIxid\fR\fR
135 Manually set the oldest and newest transaction IDs for which the commit time can be retrieved\&.
137 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
139 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\&.
142 \fB\-e \fR\fB\fIxid_epoch\fR\fR
144 \fB\-\-epoch=\fR\fB\fIxid_epoch\fR\fR
146 Manually set the next transaction ID\*(Aqs epoch\&.
148 The transaction ID epoch is not actually stored anywhere in the database except in the field that is set by
149 \fBpg_resetwal\fR, 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
153 work correctly \(em if so, an appropriate value should be obtainable from the state of the downstream replicated database\&.
156 \fB\-l \fR\fB\fIwalfile\fR\fR
158 \fB\-\-next\-wal\-file=\fR\fB\fIwalfile\fR\fR
160 Manually set the WAL starting location by specifying the name of the next WAL segment file\&.
162 The name of next WAL segment file should be larger than any WAL segment file name currently existing in the directory
164 under the data directory\&. These names are also in hexadecimal and have three parts\&. The first part is the
166 and should usually be kept the same\&. For example, if
167 00000001000000320000004A
168 is the largest entry in
170 \-l 00000001000000320000004B
173 Note that when using nondefault WAL segment sizes, the numbers in the WAL file names are different from the LSNs that are reported by system functions and system views\&. This option takes a WAL file name, not an LSN\&.
179 .nr an-no-space-flag 1
187 itself looks at the files in
189 and chooses a default
191 setting beyond the last existing file name\&. Therefore, manual adjustment of
193 should only be needed if you are aware of WAL segment files that are not currently present in
194 pg_wal, such as entries in an offline archive; or if the contents of
196 have been lost entirely\&.
201 \fB\-m \fR\fB\fImxid\fR\fR\fB,\fR\fB\fImxid\fR\fR
203 \fB\-\-multixact\-ids=\fR\fB\fImxid\fR\fR\fB,\fR\fB\fImxid\fR\fR
205 Manually set the next and oldest multitransaction ID\&.
207 A safe value for the next multitransaction ID (first part) can be determined by looking for the numerically largest file name in the directory
209 under the data directory, adding one, and then multiplying by 65536 (0x10000)\&. Conversely, a safe value for the oldest multitransaction ID (second part of
210 \fB\-m\fR) can be determined by looking for the numerically smallest file name in the same directory and multiplying by 65536\&. The file names are in hexadecimal, so the easiest way to do this is to specify the option value in hexadecimal and append four zeroes\&.
213 \fB\-o \fR\fB\fIoid\fR\fR
215 \fB\-\-next\-oid=\fR\fB\fIoid\fR\fR
217 Manually set the next OID\&.
219 There is no comparably easy way to determine a next OID that\*(Aqs beyond the largest one in the database, but fortunately it is not critical to get the next\-OID setting right\&.
222 \fB\-O \fR\fB\fImxoff\fR\fR
224 \fB\-\-multixact\-offset=\fR\fB\fImxoff\fR\fR
226 Manually set the next multitransaction offset\&.
228 A safe value can be determined by looking for the numerically largest file name in the directory
230 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\&.
233 \fB\-u \fR\fB\fIxid\fR\fR
235 \fB\-\-oldest\-transaction\-id=\fR\fB\fIxid\fR\fR
237 Manually set the oldest unfrozen transaction ID\&.
239 A safe value can be determined by looking for the numerically smallest file name in the directory
241 under the data directory 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
243 is the smallest entry in
246 will work (five trailing zeroes provide the proper multiplier)\&.
249 \fB\-x \fR\fB\fIxid\fR\fR
251 \fB\-\-next\-transaction\-id=\fR\fB\fIxid\fR\fR
253 Manually set the next transaction ID\&.
255 A safe value can be determined by looking for the numerically largest file name in the directory
257 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
259 is the largest entry in
262 will work (five trailing zeroes provide the proper multiplier)\&.
265 \fB\-\-char\-signedness=\fR\fB\fIoption\fR\fR
267 Manually set the default char signedness\&. Possible values are
272 For a database cluster that
276 version before 18, the safe value would be the default
278 signedness of the platform that ran the cluster before that upgrade\&. For all other clusters,
280 would be the safe value\&. However, this option is exclusively for use with
282 and should not normally be used manually\&.
285 \fB\-\-wal\-segsize=\fR\fB\fIwal_segment_size\fR\fR
287 Set the new WAL segment size, in megabytes\&. The value must be set to a power of 2 between 1 and 1024 (megabytes)\&. See the same option of
289 for more information\&.
291 This option can also be used to change the WAL segment size of an existing database cluster, avoiding the need to re\-\fBinitdb\fR\&.
297 .nr an-no-space-flag 1
306 will set the WAL starting address beyond the latest existing WAL segment file, some segment size changes can cause previous WAL file names to be reused\&. It is recommended to use
308 together with this option to manually set the WAL starting address if WAL file name overlap will cause problems with your archiving strategy\&.
316 Specifies whether to use color in diagnostic messages\&. Possible values are
324 This command must not be used when the server is running\&.
326 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
328 to run\&. But before you do so, make doubly certain that there is no server process still alive\&.
331 works only with servers of the same major version\&.
333 \fBpg_controldata\fR(1)