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
138
139
140
|
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_resetxlog.sgml,v 1.6 2002/10/02 21:30:13 tgl Exp $
PostgreSQL documentation
-->
<refentry id="APP-PGRESETXLOG">
<refmeta>
<refentrytitle id="APP-PGRESETXLOG-TITLE"><application>pg_resetxlog</application></refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo>Application</refmiscinfo>
</refmeta>
<refnamediv>
<refname>pg_resetxlog</refname>
<refpurpose>reset write-ahead log and pg_control contents</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>pg_resetxlog</command>
<arg> -f </arg>
<arg> -n </arg>
<arg> -o <replaceable class="parameter">oid</replaceable> </arg>
<arg> -x <replaceable class="parameter">xid</replaceable> </arg>
<arg> -l <replaceable class="parameter">fileid</replaceable>,<replaceable class="parameter">seg</replaceable> </arg>
<arg choice="plain"><replaceable>datadir</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1 id="R1-APP-PGRESETXLOG-1">
<title>Description</title>
<para>
<command>pg_resetxlog</command> clears the write-ahead log and
optionally resets some fields in the <filename>pg_control</> 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.
</para>
<para>
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 <application>initdb</>, and reload. After reload, check for
inconsistencies and repair as needed.
</para>
<para>
This utility can only be run by the user who installed the server, because
it requires read/write access to the <literal>datadir</>.
For safety reasons, you must specify the data directory on the command line.
<command>pg_resetxlog</command> does not use the environment variable
<envar>PGDATA</>.
</para>
<para>
If <command>pg_resetxlog</command> complains that it cannot determine
valid data for <filename>pg_control</>, you can force it to proceed anyway
by specifying the <literal>-f</> (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, WAL starting address, and database locale fields.
The first three of these can be set using the switches discussed below.
<command>pg_resetxlog</command>'s own environment is the source for its
guess at the locale fields; take care that <envar>LANG</> and so forth
match the environment that <application>initdb</> was run in.
If you are not able to determine correct values for all these fields,
<literal>-f</> can still be used, but
the recovered database must be treated with even more suspicion than
usual --- an immediate dump and reload is imperative. <emphasis>Do not</>
execute any data-modifying operations in the database before you dump,
as any such action is likely to make the corruption worse.
</para>
<para>
The <literal>-o</>, <literal>-x</>, and <literal>-l</> switches allow
the next OID, next transaction ID, and WAL starting address values to
be set manually. These are only needed when
<command>pg_resetxlog</command> is unable to determine appropriate values
by reading <filename>pg_control</>. A safe value for the
next transaction ID may be determined by looking for the largest
file name in <envar>$PGDATA</><filename>/pg_clog</>, 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 <filename>0011</> is the largest entry
in <filename>pg_clog</>, <literal>-x 0x1200000</> will work (five trailing
zeroes provide the proper multiplier).
The WAL starting address should be
larger than any file number currently existing in
<envar>$PGDATA</><filename>/pg_xlog</>. These also are in hex, and
have two parts. For example, if <filename>000000FF0000003A</> is the
largest entry in <filename>pg_xlog</>, <literal>-l 0xFF,0x3B</> will work.
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.
</para>
<para>
The <literal>-n</> (no operation) switch instructs
<command>pg_resetxlog</command> to print the values reconstructed from
<filename>pg_control</> and then exit without modifying anything.
This is mainly a debugging tool, but may be useful as a sanity check
before allowing <command>pg_resetxlog</command> to proceed for real.
</para>
</refsect1>
<refsect1>
<title>Notes</title>
<para>
This command must not be used when the <application>postmaster</> is
running. <command>pg_resetxlog</command> will refuse to start up if
it finds a postmaster lock file in the <literal>datadir</>. If the
<application>postmaster</> crashed then a lock file may have been left
behind; in that case you can remove the lock file to allow
<command>pg_resetxlog</command> to run. But before you do
so, make doubly certain that there
is no postmaster nor any backend server process still alive.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
|