ok
Direktori : /opt/alt/postgresql11/usr/share/doc/alt-postgresql11-9.2.24/html/ |
Current File : //opt/alt/postgresql11/usr/share/doc/alt-postgresql11-9.2.24/html/app-pgresetxlog.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >pg_resetxlog</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 9.2.24 Documentation" HREF="index.html"><LINK REL="UP" TITLE="PostgreSQL Server Applications" HREF="reference-server.html"><LINK REL="PREVIOUS" TITLE="pg_ctl" HREF="app-pg-ctl.html"><LINK REL="NEXT" TITLE="postgres" HREF="app-postgres.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2017-11-06T22:43:11"></HEAD ><BODY CLASS="REFENTRY" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" ><A HREF="index.html" >PostgreSQL 9.2.24 Documentation</A ></TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A TITLE="pg_ctl" HREF="app-pg-ctl.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="reference-server.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="20%" ALIGN="right" VALIGN="top" ><A TITLE="postgres" HREF="app-postgres.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="APP-PGRESETXLOG" ></A ><SPAN CLASS="APPLICATION" >pg_resetxlog</SPAN ></H1 ><DIV CLASS="REFNAMEDIV" ><A NAME="AEN87418" ></A ><H2 >Name</H2 >pg_resetxlog -- reset the write-ahead log and other control information of a <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > database cluster</DIV ><DIV CLASS="REFSYNOPSISDIV" ><A NAME="AEN87424" ></A ><H2 >Synopsis</H2 ><P ><TT CLASS="COMMAND" >pg_resetxlog</TT > [<TT CLASS="OPTION" >-f</TT >] [<TT CLASS="OPTION" >-n</TT >] [<TT CLASS="OPTION" >-o</TT > <TT CLASS="REPLACEABLE" ><I >oid</I ></TT >] [<TT CLASS="OPTION" >-x</TT > <TT CLASS="REPLACEABLE" ><I >xid</I ></TT >] [<TT CLASS="OPTION" >-e</TT > <TT CLASS="REPLACEABLE" ><I >xid_epoch</I ></TT >] [<TT CLASS="OPTION" >-m</TT > <TT CLASS="REPLACEABLE" ><I >mxid</I ></TT >] [<TT CLASS="OPTION" >-O</TT > <TT CLASS="REPLACEABLE" ><I >mxoff</I ></TT >] [<TT CLASS="OPTION" >-l</TT > <TT CLASS="REPLACEABLE" ><I >timelineid</I ></TT >,<TT CLASS="REPLACEABLE" ><I >fileid</I ></TT >,<TT CLASS="REPLACEABLE" ><I >seg</I ></TT >] <TT CLASS="REPLACEABLE" ><I >datadir</I ></TT > </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="R1-APP-PGRESETXLOG-1" ></A ><H2 >Description</H2 ><P > <TT CLASS="COMMAND" >pg_resetxlog</TT > clears the write-ahead log (WAL) and optionally resets some other control information stored in the <TT CLASS="FILENAME" >pg_control</TT > 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 might contain inconsistent data due to partially-committed transactions. You should immediately dump your data, run <TT CLASS="COMMAND" >initdb</TT >, 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. <TT CLASS="COMMAND" >pg_resetxlog</TT > does not use the environment variable <TT CLASS="ENVAR" >PGDATA</TT >. </P ><P > If <TT CLASS="COMMAND" >pg_resetxlog</TT > complains that it cannot determine valid data for <TT CLASS="FILENAME" >pg_control</TT >, you can force it to proceed anyway by specifying the <TT CLASS="OPTION" >-f</TT > (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 address fields. These fields can be set using the options discussed below. If you are not able to determine correct values for all these fields, <TT CLASS="OPTION" >-f</TT > 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" ><I CLASS="EMPHASIS" >Do not</I ></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 <TT CLASS="OPTION" >-o</TT >, <TT CLASS="OPTION" >-x</TT >, <TT CLASS="OPTION" >-e</TT >, <TT CLASS="OPTION" >-m</TT >, <TT CLASS="OPTION" >-O</TT >, and <TT CLASS="OPTION" >-l</TT > options allow the next OID, next transaction ID, next transaction ID's epoch, next multitransaction ID, next multitransaction offset, and WAL starting address values to be set manually. These are only needed when <TT CLASS="COMMAND" >pg_resetxlog</TT > is unable to determine appropriate values by reading <TT CLASS="FILENAME" >pg_control</TT >. Safe values can be determined as follows: <P ></P ></P><UL ><LI ><P > A safe value for the next transaction ID (<TT CLASS="OPTION" >-x</TT >) can be determined by looking for the numerically largest file name in the directory <TT CLASS="FILENAME" >pg_clog</TT > 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 option value in hexadecimal too. For example, if <TT CLASS="FILENAME" >0011</TT > is the largest entry in <TT CLASS="FILENAME" >pg_clog</TT >, <TT CLASS="LITERAL" >-x 0x1200000</TT > will work (five trailing zeroes provide the proper multiplier). </P ></LI ><LI ><P > A safe value for the next multitransaction ID (<TT CLASS="OPTION" >-m</TT >) can be determined by looking for the numerically largest file name in the directory <TT CLASS="FILENAME" >pg_multixact/offsets</TT > 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 option value in hexadecimal and add four zeroes. </P ></LI ><LI ><P > A safe value for the next multitransaction offset (<TT CLASS="OPTION" >-O</TT >) can be determined by looking for the numerically largest file name in the directory <TT CLASS="FILENAME" >pg_multixact/members</TT > 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 option value in hexadecimal and add four zeroes. </P ></LI ><LI ><P > The WAL starting address (<TT CLASS="OPTION" >-l</TT >) should be larger than any WAL segment file name currently existing in the directory <TT CLASS="FILENAME" >pg_xlog</TT > 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 (<TT CLASS="LITERAL" >0xFF</TT >) for the third part; instead increment the second part and reset the third part to 0. For example, if <TT CLASS="FILENAME" >00000001000000320000004A</TT > is the largest entry in <TT CLASS="FILENAME" >pg_xlog</TT >, <TT CLASS="LITERAL" >-l 0x1,0x32,0x4B</TT > will work; but if the largest entry is <TT CLASS="FILENAME" >000000010000003A000000FF</TT >, choose <TT CLASS="LITERAL" >-l 0x1,0x3B,0x0</TT > or more. </P ><DIV CLASS="NOTE" ><BLOCKQUOTE CLASS="NOTE" ><P ><B >Note: </B > <TT CLASS="COMMAND" >pg_resetxlog</TT > itself looks at the files in <TT CLASS="FILENAME" >pg_xlog</TT > and chooses a default <TT CLASS="OPTION" >-l</TT > setting beyond the last existing file name. Therefore, manual adjustment of <TT CLASS="OPTION" >-l</TT > should only be needed if you are aware of WAL segment files that are not currently present in <TT CLASS="FILENAME" >pg_xlog</TT >, such as entries in an offline archive; or if the contents of <TT CLASS="FILENAME" >pg_xlog</TT > have been lost entirely. </P ></BLOCKQUOTE ></DIV ></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 ><LI ><P > The transaction ID epoch is not actually stored anywhere in the database except in the field that is set by <TT CLASS="COMMAND" >pg_resetxlog</TT >, 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 <SPAN CLASS="APPLICATION" >Slony-I</SPAN > work correctly — if so, an appropriate value should be obtainable from the state of the downstream replicated database. </P ></LI ></UL ><P> </P ><P > The <TT CLASS="OPTION" >-n</TT > (no operation) option instructs <TT CLASS="COMMAND" >pg_resetxlog</TT > to print the values reconstructed from <TT CLASS="FILENAME" >pg_control</TT > and then exit without modifying anything. This is mainly a debugging tool, but can be useful as a sanity check before allowing <TT CLASS="COMMAND" >pg_resetxlog</TT > to proceed for real. </P ><P > The <TT CLASS="OPTION" >-V</TT > and <TT CLASS="OPTION" >--version</TT > options print the <SPAN CLASS="APPLICATION" >pg_resetxlog</SPAN > version and exit. The options <TT CLASS="OPTION" >-?</TT > and <TT CLASS="OPTION" >--help</TT > show supported arguments, and exit. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN87530" ></A ><H2 >Notes</H2 ><P > This command must not be used when the server is running. <TT CLASS="COMMAND" >pg_resetxlog</TT > 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 <TT CLASS="COMMAND" >pg_resetxlog</TT > to run. But before you do so, make doubly certain that there is no server process still alive. </P ><P > <TT CLASS="COMMAND" >pg_resetxlog</TT > works only with servers of the same major version. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="app-pg-ctl.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="app-postgres.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><SPAN CLASS="APPLICATION" >pg_ctl</SPAN ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="reference-server.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><SPAN CLASS="APPLICATION" >postgres</SPAN ></TD ></TR ></TABLE ></DIV ></BODY ></HTML >