1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>pg_resetxlog</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="reference-server.html" title="PostgreSQL Server Applications">
<link rel="prev" href="app-pg-ctl.html" title="pg_ctl">
<link rel="next" href="app-postgres.html" title="postgres">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
<a name="app-pgresetxlog"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>pg_resetxlog — 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><code class="command">pg_resetxlog</code> [ -f ] [ -n ] [ -o <em class="replaceable"><code>oid</code></em> ] [ -x <em class="replaceable"><code>xid</code></em> ] [ -m <em class="replaceable"><code>mxid</code></em> ] [ -O <em class="replaceable"><code>mxoff</code></em> ] [ -l <em class="replaceable"><code>timelineid</code></em>,<em class="replaceable"><code>fileid</code></em>,<em class="replaceable"><code>seg</code></em> ] <em class="replaceable"><code>datadir</code></em> </p></div>
</div>
<div class="refsect1" lang="en">
<a name="r1-app-pgresetxlog-1"></a><h2>Description</h2>
<p> <code class="command">pg_resetxlog</code> clears the write-ahead log (WAL) and
optionally resets some other control information stored in the
<code class="filename">pg_control</code> 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.
</p>
<p> After running this command, it should be possible to start the server,
but bear in mind that the database may contain inconsistent data due to
partially-committed transactions. You should immediately dump your data,
run <code class="command">initdb</code>, and reload. After reload, check for
inconsistencies and repair as needed.
</p>
<p> This utility can only be run by the user who installed the server, because
it requires read/write access to the data directory.
For safety reasons, you must specify the data directory on the command line.
<code class="command">pg_resetxlog</code> does not use the environment variable
<code class="envar">PGDATA</code>.
</p>
<p> If <code class="command">pg_resetxlog</code> complains that it cannot determine
valid data for <code class="filename">pg_control</code>, you can force it to proceed anyway
by specifying the <code class="literal">-f</code> (force) switch. In this case plausible
values will be substituted for the missing data. Most of the fields can be
expected to match, but manual assistance may be needed for the next OID,
next transaction ID, next multitransaction ID and offset,
WAL starting address, and database locale fields.
The first five of these can be set using the switches discussed below.
<code class="command">pg_resetxlog</code>'s own environment is the source for its
guess at the locale fields; take care that <code class="envar">LANG</code> and so forth
match the environment that <code class="command">initdb</code> was run in.
If you are not able to determine correct values for all these fields,
<code class="literal">-f</code> can still be used, but
the recovered database must be treated with even more suspicion than
usual: an immediate dump and reload is imperative. <span class="emphasis"><em>Do not</em></span>
execute any data-modifying operations in the database before you dump;
as any such action is likely to make the corruption worse.
</p>
<p> The <code class="literal">-o</code>, <code class="literal">-x</code>, <code class="literal">-m</code>, <code class="literal">-O</code>,
and <code class="literal">-l</code>
switches allow the next OID, next transaction ID, next multitransaction
ID, next multitransaction offset, and WAL starting address values to
be set manually. These are only needed when
<code class="command">pg_resetxlog</code> is unable to determine appropriate values
by reading <code class="filename">pg_control</code>. Safe values may be determined as
follows:
</p>
<div class="itemizedlist"><ul type="disc">
<li><p> A safe value for the next transaction ID (<code class="literal">-x</code>)
may be determined by looking for the numerically largest
file name in the directory <code class="filename">pg_clog</code> under the data directory,
adding one,
and then multiplying by 1048576. Note that the file names are in
hexadecimal. It is usually easiest to specify the switch value in
hexadecimal too. For example, if <code class="filename">0011</code> is the largest entry
in <code class="filename">pg_clog</code>, <code class="literal">-x 0x1200000</code> will work (five
trailing zeroes provide the proper multiplier).
</p></li>
<li><p> A safe value for the next multitransaction ID (<code class="literal">-m</code>)
may be determined by looking for the numerically largest
file name in the directory <code class="filename">pg_multixact/offsets</code> under the
data directory, adding one, and then multiplying by 65536. As above,
the file names are in hexadecimal, so the easiest way to do this is to
specify the switch value in hexadecimal and add four zeroes.
</p></li>
<li><p> A safe value for the next multitransaction offset (<code class="literal">-O</code>)
may be determined by looking for the numerically largest
file name in the directory <code class="filename">pg_multixact/members</code> under the
data directory, adding one, and then multiplying by 65536. As above,
the file names are in hexadecimal, so the easiest way to do this is to
specify the switch value in hexadecimal and add four zeroes.
</p></li>
<li><p> The WAL starting address (<code class="literal">-l</code>) should be
larger than any file name currently existing in
the directory <code class="filename">pg_xlog</code> under the data directory.
These names are also in hexadecimal and have three parts. The first
part is the “<span class="quote">timeline ID</span>” and should usually be kept the same.
Do not choose a value larger than 255 (<code class="literal">0xFF</code>) for the third
part; instead increment the second part and reset the third part to 0.
For example, if <code class="filename">00000001000000320000004A</code> is the
largest entry in <code class="filename">pg_xlog</code>, <code class="literal">-l 0x1,0x32,0x4B</code> will
work; but if the largest entry is
<code class="filename">000000010000003A000000FF</code>, choose <code class="literal">-l 0x1,0x3B,0x0</code>
or more.
</p></li>
<li><p> There is no comparably easy way to determine a next OID that's beyond
the largest one in the database, but fortunately it is not critical to
get the next-OID setting right.
</p></li>
</ul></div>
<p>
</p>
<p> The <code class="literal">-n</code> (no operation) switch instructs
<code class="command">pg_resetxlog</code> to print the values reconstructed from
<code class="filename">pg_control</code> and then exit without modifying anything.
This is mainly a debugging tool, but may be useful as a sanity check
before allowing <code class="command">pg_resetxlog</code> to proceed for real.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id811635"></a><h2>Notes</h2>
<p> This command must not be used when the server is
running. <code class="command">pg_resetxlog</code> will refuse to start up if
it finds a server lock file in the data directory. If the
server crashed then a lock file may have been left
behind; in that case you can remove the lock file to allow
<code class="command">pg_resetxlog</code> to run. But before you do
so, make doubly certain that there
is no <code class="command">postmaster</code> nor any backend server process still alive.
</p>
</div>
</div></body>
</html>
|