]> begriffs open source - ai-pg/blob - full-docs/man1/pg_resetwal.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / pg_resetwal.1
1 '\" t
2 .\"     Title: pg_resetwal
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 pg_resetwal \- reset the write\-ahead log and other control information of a PostgreSQL database cluster
32 .SH "SYNOPSIS"
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
35 .SH "DESCRIPTION"
36 .PP
37 \fBpg_resetwal\fR
38 clears the write\-ahead log (WAL) and optionally resets some other control information stored in the
39 pg_control
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\&.
41 .PP
42 Some options, such as
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\&.
46 .PP
47 If
48 \fBpg_resetwal\fR
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\&.
50 \fBpg_resetwal\fR
51 will require the
52 \fB\-f\fR
53 (force) option to be specified before working on a data directory in an unclean shutdown state or with a corrupted control file\&.
54 .PP
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\&.
57 .PP
58 If
59 \fBpg_resetwal\fR
60 complains that it cannot determine valid data for
61 pg_control, you can force it to proceed anyway by specifying the
62 \fB\-f\fR
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,
64 \fB\-f\fR
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\&.
66 \fIDo not\fR
67 execute any data\-modifying operations in the database before you dump, as any such action is likely to make the corruption worse\&.
68 .PP
69 This utility can only be run by the user who installed the server, because it requires read/write access to the data directory\&.
70 .SH "OPTIONS"
71 .PP
72 \fIdatadir\fR
73 .br
74 \fB\-D \fR\fB\fIdatadir\fR\fR
75 .br
76 \fB\-\-pgdata=\fR\fB\fIdatadir\fR\fR
77 .RS 4
78 Specifies the location of the database directory\&. For safety reasons, you must specify the data directory on the command line\&.
79 \fBpg_resetwal\fR
80 does not use the environment variable
81 \fBPGDATA\fR\&.
82 .RE
83 .PP
84 \fB\-f\fR
85 .br
86 \fB\-\-force\fR
87 .RS 4
88 Force
89 \fBpg_resetwal\fR
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
91 \fBpg_resetwal\fR
92 cannot determine valid data for
93 pg_control\&.
94 .RE
95 .PP
96 \fB\-n\fR
97 .br
98 \fB\-\-dry\-run\fR
99 .RS 4
100 The
101 \fB\-n\fR/\fB\-\-dry\-run\fR
102 option instructs
103 \fBpg_resetwal\fR
104 to print the values reconstructed from
105 pg_control
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
107 \fBpg_resetwal\fR
108 to proceed for real\&.
109 .RE
110 .PP
111 \fB\-V\fR
112 .br
113 \fB\-\-version\fR
114 .RS 4
115 Display version information, then exit\&.
116 .RE
117 .PP
118 \fB\-?\fR
119 .br
120 \fB\-\-help\fR
121 .RS 4
122 Show help, then exit\&.
123 .RE
124 .PP
125 The following options are only needed when
126 \fBpg_resetwal\fR
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\&.
130 .PP
131 \fB\-c \fR\fB\fIxid\fR\fR\fB,\fR\fB\fIxid\fR\fR
132 .br
133 \fB\-\-commit\-timestamp\-ids=\fR\fB\fIxid\fR\fR\fB,\fR\fB\fIxid\fR\fR
134 .RS 4
135 Manually set the oldest and newest transaction IDs for which the commit time can be retrieved\&.
136 .sp
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
138 pg_commit_ts
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\&.
140 .RE
141 .PP
142 \fB\-e \fR\fB\fIxid_epoch\fR\fR
143 .br
144 \fB\-\-epoch=\fR\fB\fIxid_epoch\fR\fR
145 .RS 4
146 Manually set the next transaction ID\*(Aqs epoch\&.
147 .sp
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
150 Slony\-I
151 and
152 Skytools
153 work correctly \(em if so, an appropriate value should be obtainable from the state of the downstream replicated database\&.
154 .RE
155 .PP
156 \fB\-l \fR\fB\fIwalfile\fR\fR
157 .br
158 \fB\-\-next\-wal\-file=\fR\fB\fIwalfile\fR\fR
159 .RS 4
160 Manually set the WAL starting location by specifying the name of the next WAL segment file\&.
161 .sp
162 The name of next WAL segment file should be larger than any WAL segment file name currently existing in the directory
163 pg_wal
164 under the data directory\&. These names are also in hexadecimal and have three parts\&. The first part is the
165 \(lqtimeline ID\(rq
166 and should usually be kept the same\&. For example, if
167 00000001000000320000004A
168 is the largest entry in
169 pg_wal, use
170 \-l 00000001000000320000004B
171 or higher\&.
172 .sp
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\&.
174 .if n \{\
175 .sp
176 .\}
177 .RS 4
178 .it 1 an-trap
179 .nr an-no-space-flag 1
180 .nr an-break-flag 1
181 .br
182 .ps +1
183 \fBNote\fR
184 .ps -1
185 .br
186 \fBpg_resetwal\fR
187 itself looks at the files in
188 pg_wal
189 and chooses a default
190 \fB\-l\fR
191 setting beyond the last existing file name\&. Therefore, manual adjustment of
192 \fB\-l\fR
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
195 pg_wal
196 have been lost entirely\&.
197 .sp .5v
198 .RE
199 .RE
200 .PP
201 \fB\-m \fR\fB\fImxid\fR\fR\fB,\fR\fB\fImxid\fR\fR
202 .br
203 \fB\-\-multixact\-ids=\fR\fB\fImxid\fR\fR\fB,\fR\fB\fImxid\fR\fR
204 .RS 4
205 Manually set the next and oldest multitransaction ID\&.
206 .sp
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
208 pg_multixact/offsets
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\&.
211 .RE
212 .PP
213 \fB\-o \fR\fB\fIoid\fR\fR
214 .br
215 \fB\-\-next\-oid=\fR\fB\fIoid\fR\fR
216 .RS 4
217 Manually set the next OID\&.
218 .sp
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\&.
220 .RE
221 .PP
222 \fB\-O \fR\fB\fImxoff\fR\fR
223 .br
224 \fB\-\-multixact\-offset=\fR\fB\fImxoff\fR\fR
225 .RS 4
226 Manually set the next multitransaction offset\&.
227 .sp
228 A safe value can be determined by looking for the numerically largest file name in the directory
229 pg_multixact/members
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\&.
231 .RE
232 .PP
233 \fB\-u \fR\fB\fIxid\fR\fR
234 .br
235 \fB\-\-oldest\-transaction\-id=\fR\fB\fIxid\fR\fR
236 .RS 4
237 Manually set the oldest unfrozen transaction ID\&.
238 .sp
239 A safe value can be determined by looking for the numerically smallest file name in the directory
240 pg_xact
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
242 0007
243 is the smallest entry in
244 pg_xact,
245 \-u 0x700000
246 will work (five trailing zeroes provide the proper multiplier)\&.
247 .RE
248 .PP
249 \fB\-x \fR\fB\fIxid\fR\fR
250 .br
251 \fB\-\-next\-transaction\-id=\fR\fB\fIxid\fR\fR
252 .RS 4
253 Manually set the next transaction ID\&.
254 .sp
255 A safe value can be determined by looking for the numerically largest file name in the directory
256 pg_xact
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
258 0011
259 is the largest entry in
260 pg_xact,
261 \-x 0x1200000
262 will work (five trailing zeroes provide the proper multiplier)\&.
263 .RE
264 .PP
265 \fB\-\-char\-signedness=\fR\fB\fIoption\fR\fR
266 .RS 4
267 Manually set the default char signedness\&. Possible values are
268 signed
269 and
270 unsigned\&.
271 .sp
272 For a database cluster that
273 \fBpg_upgrade\fR
274 upgraded from a
275 PostgreSQL
276 version before 18, the safe value would be the default
277 char
278 signedness of the platform that ran the cluster before that upgrade\&. For all other clusters,
279 signed
280 would be the safe value\&. However, this option is exclusively for use with
281 \fBpg_upgrade\fR
282 and should not normally be used manually\&.
283 .RE
284 .PP
285 \fB\-\-wal\-segsize=\fR\fB\fIwal_segment_size\fR\fR
286 .RS 4
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
288 \fBinitdb\fR(1)
289 for more information\&.
290 .sp
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\&.
292 .if n \{\
293 .sp
294 .\}
295 .RS 4
296 .it 1 an-trap
297 .nr an-no-space-flag 1
298 .nr an-break-flag 1
299 .br
300 .ps +1
301 \fBNote\fR
302 .ps -1
303 .br
304 While
305 \fBpg_resetwal\fR
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
307 \fB\-l\fR
308 together with this option to manually set the WAL starting address if WAL file name overlap will cause problems with your archiving strategy\&.
309 .sp .5v
310 .RE
311 .RE
312 .SH "ENVIRONMENT"
313 .PP
314 \fBPG_COLOR\fR
315 .RS 4
316 Specifies whether to use color in diagnostic messages\&. Possible values are
317 always,
318 auto
319 and
320 never\&.
321 .RE
322 .SH "NOTES"
323 .PP
324 This command must not be used when the server is running\&.
325 \fBpg_resetwal\fR
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
327 \fBpg_resetwal\fR
328 to run\&. But before you do so, make doubly certain that there is no server process still alive\&.
329 .PP
330 \fBpg_resetwal\fR
331 works only with servers of the same major version\&.
332 .SH "SEE ALSO"
333 \fBpg_controldata\fR(1)