1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>pg_resetwal</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="app-pg-ctl.html" title="pg_ctl" /><link rel="next" href="app-pgrewind.html" title="pg_rewind" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span class="application">pg_resetwal</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pg-ctl.html" title="pg_ctl">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-server.html" title="PostgreSQL Server Applications">Up</a></td><th width="60%" align="center">PostgreSQL Server Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="app-pgrewind.html" title="pg_rewind">Next</a></td></tr></table><hr /></div><div class="refentry" id="APP-PGRESETWAL"><div class="titlepage"></div><a id="id-1.9.5.9.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">pg_resetwal</span></span></h2><p>pg_resetwal — reset the write-ahead log and other control information of a <span class="productname">PostgreSQL</span> database cluster</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.5.9.4.1"><code class="command">pg_resetwal</code> [ <code class="option">-f</code> | <code class="option">--force</code> ] [ <code class="option">-n</code> | <code class="option">--dry-run</code> ] [<em class="replaceable"><code>option</code></em>...] [ <code class="option">-D</code> | <code class="option">--pgdata</code> ]<em class="replaceable"><code>datadir</code></em> </p></div></div><div class="refsect1" id="R1-APP-PGRESETWAL-1"><h2>Description</h2><p>
3 <code class="command">pg_resetwal</code> clears the write-ahead log (WAL) and
4 optionally resets some other control information stored in the
5 <code class="filename">pg_control</code> file. This function is sometimes needed
6 if these files have become corrupted. It should be used only as a
7 last resort, when the server will not start due to such corruption.
9 Some options, such as <code class="option">--wal-segsize</code> (see below), can also
10 be used to modify certain global settings of a database cluster without the
11 need to rerun <code class="command">initdb</code>. This can be done safely on an
12 otherwise sound database cluster, if none of the dangerous modes mentioned
15 If <code class="command">pg_resetwal</code> is used on a data directory where the
16 server has been cleanly shut down and the control file is sound, then it
17 will have no effect on the contents of the database system, except that no
18 longer used WAL files are cleared away. Any other use is potentially
19 dangerous and must be done with great care. <code class="command">pg_resetwal</code>
20 will require the <code class="option">-f</code> (force) option to be specified before
21 working on a data directory in an unclean shutdown state or with a
22 corrupted control file.
24 After running this command on a data directory with corrupted WAL or a
25 corrupted control file, it should be possible to start the server,
26 but bear in mind that the database might contain inconsistent data due to
27 partially-committed transactions. You should immediately dump your data,
28 run <code class="command">initdb</code>, and restore. After restore, check for
29 inconsistencies and repair as needed.
31 If <code class="command">pg_resetwal</code> complains that it cannot determine
32 valid data for <code class="filename">pg_control</code>, you can force it to proceed anyway
33 by specifying the <code class="option">-f</code> (force) option. In this case plausible
34 values will be substituted for the missing data. Most of the fields can be
35 expected to match, but manual assistance might be needed for the next OID,
36 next transaction ID and epoch, next multitransaction ID and offset, and
37 WAL starting location fields. These fields can be set using the options
38 discussed below. If you are not able to determine correct values for all
39 these fields, <code class="option">-f</code> can still be used, but
40 the recovered database must be treated with even more suspicion than
41 usual: an immediate dump and restore is imperative. <span class="emphasis"><em>Do not</em></span>
42 execute any data-modifying operations in the database before you dump,
43 as any such action is likely to make the corruption worse.
45 This utility can only be run by the user who installed the server, because
46 it requires read/write access to the data directory.
47 </p></div><div class="refsect1" id="id-1.9.5.9.6"><h2>Options</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>datadir</code></em><br /></span><span class="term"><code class="option">-D <em class="replaceable"><code>datadir</code></em></code><br /></span><span class="term"><code class="option">--pgdata=<em class="replaceable"><code>datadir</code></em></code></span></dt><dd><p>
48 Specifies the location of the database directory.
49 For safety reasons, you must specify the data directory on the command
50 line. <code class="command">pg_resetwal</code> does not use the environment
51 variable <code class="envar">PGDATA</code>.
52 </p></dd><dt><span class="term"><code class="option">-f</code><br /></span><span class="term"><code class="option">--force</code></span></dt><dd><p>
53 Force <code class="command">pg_resetwal</code> to proceed even in situations where
54 it could be dangerous, as explained above. Specifically, this option is
55 required to proceed if the server had not been cleanly shut down or if
56 <code class="command">pg_resetwal</code> cannot determine valid data for
57 <code class="filename">pg_control</code>.
58 </p></dd><dt><span class="term"><code class="option">-n</code><br /></span><span class="term"><code class="option">--dry-run</code></span></dt><dd><p>
59 The <code class="option">-n</code>/<code class="option">--dry-run</code> option instructs
60 <code class="command">pg_resetwal</code> to print the values reconstructed from
61 <code class="filename">pg_control</code> and values about to be changed, and then exit
62 without modifying anything. This is mainly a debugging tool, but can be
63 useful as a sanity check before allowing <code class="command">pg_resetwal</code>
65 </p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>Display version information, then exit.</p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>Show help, then exit.</p></dd></dl></div><p>
66 The following options are only needed when
67 <code class="command">pg_resetwal</code> is unable to determine appropriate values
68 by reading <code class="filename">pg_control</code>. Safe values can be determined as
69 described below. For values that take numeric arguments, hexadecimal
70 values can be specified by using the prefix <code class="literal">0x</code>. Note
71 that these instructions only apply with the standard block size of 8 kB.
72 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-c <em class="replaceable"><code>xid</code></em>,<em class="replaceable"><code>xid</code></em></code><br /></span><span class="term"><code class="option">--commit-timestamp-ids=<em class="replaceable"><code>xid</code></em>,<em class="replaceable"><code>xid</code></em></code></span></dt><dd><p>
73 Manually set the oldest and newest transaction IDs for which the commit
74 time can be retrieved.
76 A safe value for the oldest transaction ID for which the commit time can
77 be retrieved (first part) can be determined by looking
78 for the numerically smallest file name in the directory
79 <code class="filename">pg_commit_ts</code> under the data directory. Conversely, a safe
80 value for the newest transaction ID for which the commit time can be
81 retrieved (second part) can be determined by looking for the numerically
82 greatest file name in the same directory. The file names are in
84 </p></dd><dt><span class="term"><code class="option">-e <em class="replaceable"><code>xid_epoch</code></em></code><br /></span><span class="term"><code class="option">--epoch=<em class="replaceable"><code>xid_epoch</code></em></code></span></dt><dd><p>
85 Manually set the next transaction ID's epoch.
87 The transaction ID epoch is not actually stored anywhere in the database
88 except in the field that is set by <code class="command">pg_resetwal</code>,
89 so any value will work so far as the database itself is concerned.
90 You might need to adjust this value to ensure that replication
91 systems such as <span class="application">Slony-I</span> and
92 <span class="application">Skytools</span> work correctly —
93 if so, an appropriate value should be obtainable from the state of
94 the downstream replicated database.
95 </p></dd><dt><span class="term"><code class="option">-l <em class="replaceable"><code>walfile</code></em></code><br /></span><span class="term"><code class="option">--next-wal-file=<em class="replaceable"><code>walfile</code></em></code></span></dt><dd><p>
96 Manually set the WAL starting location by specifying the name of the
97 next WAL segment file.
99 The name of next WAL segment file should be
100 larger than any WAL segment file name currently existing in
101 the directory <code class="filename">pg_wal</code> under the data directory.
102 These names are also in hexadecimal and have three parts. The first
103 part is the <span class="quote">“<span class="quote">timeline ID</span>”</span> and should usually be kept the same.
104 For example, if <code class="filename">00000001000000320000004A</code> is the
105 largest entry in <code class="filename">pg_wal</code>, use <code class="literal">-l 00000001000000320000004B</code> or higher.
107 Note that when using nondefault WAL segment sizes, the numbers in the WAL
108 file names are different from the LSNs that are reported by system
109 functions and system views. This option takes a WAL file name, not an
111 </p><div class="note"><h3 class="title">Note</h3><p>
112 <code class="command">pg_resetwal</code> itself looks at the files in
113 <code class="filename">pg_wal</code> and chooses a default <code class="option">-l</code> setting
114 beyond the last existing file name. Therefore, manual adjustment of
115 <code class="option">-l</code> should only be needed if you are aware of WAL segment
116 files that are not currently present in <code class="filename">pg_wal</code>, such as
117 entries in an offline archive; or if the contents of
118 <code class="filename">pg_wal</code> have been lost entirely.
119 </p></div></dd><dt><span class="term"><code class="option">-m <em class="replaceable"><code>mxid</code></em>,<em class="replaceable"><code>mxid</code></em></code><br /></span><span class="term"><code class="option">--multixact-ids=<em class="replaceable"><code>mxid</code></em>,<em class="replaceable"><code>mxid</code></em></code></span></dt><dd><p>
120 Manually set the next and oldest multitransaction ID.
122 A safe value for the next multitransaction ID (first part) can be
123 determined by looking for the numerically largest file name in the
124 directory <code class="filename">pg_multixact/offsets</code> under the data directory,
125 adding one, and then multiplying by 65536 (0x10000). Conversely, a safe
126 value for the oldest multitransaction ID (second part of
127 <code class="option">-m</code>) can be determined by looking for the numerically smallest
128 file name in the same directory and multiplying by 65536. The file
129 names are in hexadecimal, so the easiest way to do this is to specify
130 the option value in hexadecimal and append four zeroes.
131 </p></dd><dt><span class="term"><code class="option">-o <em class="replaceable"><code>oid</code></em></code><br /></span><span class="term"><code class="option">--next-oid=<em class="replaceable"><code>oid</code></em></code></span></dt><dd><p>
132 Manually set the next OID.
134 There is no comparably easy way to determine a next OID that's beyond
135 the largest one in the database, but fortunately it is not critical to
136 get the next-OID setting right.
137 </p></dd><dt><span class="term"><code class="option">-O <em class="replaceable"><code>mxoff</code></em></code><br /></span><span class="term"><code class="option">--multixact-offset=<em class="replaceable"><code>mxoff</code></em></code></span></dt><dd><p>
138 Manually set the next multitransaction offset.
140 A safe value can be determined by looking for the numerically largest
141 file name in the directory <code class="filename">pg_multixact/members</code> under the
142 data directory, adding one, and then multiplying by 52352 (0xCC80).
143 The file names are in hexadecimal. There is no simple recipe such as
144 the ones for other options of appending zeroes.
145 </p></dd><dt><span class="term"><code class="option">-u <em class="replaceable"><code>xid</code></em></code><br /></span><span class="term"><code class="option">--oldest-transaction-id=<em class="replaceable"><code>xid</code></em></code></span></dt><dd><p>
146 Manually set the oldest unfrozen transaction ID.
148 A safe value can be determined by looking for the numerically smallest
149 file name in the directory <code class="filename">pg_xact</code> under the data directory
150 and then multiplying by 1048576 (0x100000). Note that the file names are in
151 hexadecimal. It is usually easiest to specify the option value in
152 hexadecimal too. For example, if <code class="filename">0007</code> is the smallest entry
153 in <code class="filename">pg_xact</code>, <code class="literal">-u 0x700000</code> will work (five
154 trailing zeroes provide the proper multiplier).
155 </p></dd><dt><span class="term"><code class="option">-x <em class="replaceable"><code>xid</code></em></code><br /></span><span class="term"><code class="option">--next-transaction-id=<em class="replaceable"><code>xid</code></em></code></span></dt><dd><p>
156 Manually set the next transaction ID.
158 A safe value can be determined by looking for the numerically largest
159 file name in the directory <code class="filename">pg_xact</code> under the data directory,
161 and then multiplying by 1048576 (0x100000). Note that the file names are in
162 hexadecimal. It is usually easiest to specify the option value in
163 hexadecimal too. For example, if <code class="filename">0011</code> is the largest entry
164 in <code class="filename">pg_xact</code>, <code class="literal">-x 0x1200000</code> will work (five
165 trailing zeroes provide the proper multiplier).
166 </p></dd><dt><span class="term"><code class="option">--char-signedness=<em class="replaceable"><code>option</code></em></code></span></dt><dd><p>
167 Manually set the default char signedness. Possible values are
168 <code class="literal">signed</code> and <code class="literal">unsigned</code>.
170 For a database cluster that <code class="command">pg_upgrade</code> upgraded from
171 a <span class="productname">PostgreSQL</span> version before 18, the safe
172 value would be the default <code class="type">char</code> signedness of the platform
173 that ran the cluster before that upgrade. For all other
174 clusters, <code class="literal">signed</code> would be the safe value. However,
175 this option is exclusively for use with <code class="command">pg_upgrade</code>
176 and should not normally be used manually.
177 </p></dd><dt><span class="term"><code class="option">--wal-segsize=<em class="replaceable"><code>wal_segment_size</code></em></code></span></dt><dd><p>
178 Set the new WAL segment size, in megabytes. The value must be set to a
179 power of 2 between 1 and 1024 (megabytes). See the same option of <a class="xref" href="app-initdb.html" title="initdb"><span class="refentrytitle"><span class="application">initdb</span></span></a> for more information.
181 This option can also be used to change the WAL segment size of an
182 existing database cluster, avoiding the need to
183 re-<code class="command">initdb</code>.
184 </p><div class="note"><h3 class="title">Note</h3><p>
185 While <code class="command">pg_resetwal</code> will set the WAL starting address
186 beyond the latest existing WAL segment file, some segment size changes
187 can cause previous WAL file names to be reused. It is recommended to
188 use <code class="option">-l</code> together with this option to manually set the
189 WAL starting address if WAL file name overlap will cause problems with
190 your archiving strategy.
191 </p></div></dd></dl></div></div><div class="refsect1" id="id-1.9.5.9.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
192 Specifies whether to use color in diagnostic messages. Possible values
193 are <code class="literal">always</code>, <code class="literal">auto</code> and
194 <code class="literal">never</code>.
195 </p></dd></dl></div></div><div class="refsect1" id="id-1.9.5.9.8"><h2>Notes</h2><p>
196 This command must not be used when the server is
197 running. <code class="command">pg_resetwal</code> will refuse to start up if
198 it finds a server lock file in the data directory. If the
199 server crashed then a lock file might have been left
200 behind; in that case you can remove the lock file to allow
201 <code class="command">pg_resetwal</code> to run. But before you do
202 so, make doubly certain that there is no server process still alive.
204 <code class="command">pg_resetwal</code> works only with servers of the same
206 </p></div><div class="refsect1" id="id-1.9.5.9.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-pgcontroldata.html" title="pg_controldata"><span class="refentrytitle"><span class="application">pg_controldata</span></span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-pg-ctl.html" title="pg_ctl">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-server.html" title="PostgreSQL Server Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-pgrewind.html" title="pg_rewind">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_ctl</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">pg_rewind</span></td></tr></table></div></body></html>