📄 backup.sgml
字号:
The precise stopping point is also influenced by <xref linkend="recovery-target-inclusive">. </para> </listitem> </varlistentry> <varlistentry id="recovery-target-xid" xreflabel="recovery_target_xid"> <term><varname>recovery_target_xid</varname> (<type>string</type>)</term> <listitem> <para> This parameter specifies the transaction ID up to which recovery will proceed. Keep in mind that while transaction IDs are assigned sequentially at transaction start, transactions can complete in a different numeric order. The transactions that will be recovered are those that committed before (and optionally including) the specified one. At most one of <varname>recovery_target_xid</> and <xref linkend="recovery-target-time"> can be specified. The default is to recover to the end of the WAL log. The precise stopping point is also influenced by <xref linkend="recovery-target-inclusive">. </para> </listitem> </varlistentry> <varlistentry id="recovery-target-inclusive" xreflabel="recovery_target_inclusive"> <term><varname>recovery_target_inclusive</varname> (<type>boolean</type>) </term> <listitem> <para> Specifies whether we stop just after the specified recovery target (<literal>true</literal>), or just before the recovery target (<literal>false</literal>). Applies to both <xref linkend="recovery-target-time"> and <xref linkend="recovery-target-xid">, whichever one is specified for this recovery. This indicates whether transactions having exactly the target commit time or ID, respectively, will be included in the recovery. Default is <literal>true</>. </para> </listitem> </varlistentry> <varlistentry id="recovery-target-timeline" xreflabel="recovery_target_timeline"> <term><varname>recovery_target_timeline</varname> (<type>string</type>) </term> <listitem> <para> Specifies recovering into a particular timeline. The default is to recover along the same timeline that was current when the base backup was taken. You would only need to set this parameter in complex re-recovery situations, where you need to return to a state that itself was reached after a point-in-time recovery. See <xref linkend="backup-timelines"> for discussion. </para> </listitem> </varlistentry> </variablelist> </sect3> </sect2> <sect2 id="backup-timelines"> <title>Timelines</title> <indexterm zone="backup"> <primary>timelines</primary> </indexterm> <para> The ability to restore the database to a previous point in time creates some complexities that are akin to science-fiction stories about time travel and parallel universes. In the original history of the database, perhaps you dropped a critical table at 5:15PM on Tuesday evening. Unfazed, you get out your backup, restore to the point-in-time 5:14PM Tuesday evening, and are up and running. In <emphasis>this</> history of the database universe, you never dropped the table at all. But suppose you later realize this wasn't such a great idea after all, and would like to return to some later point in the original history. You won't be able to if, while your database was up-and-running, it overwrote some of the sequence of WAL segment files that led up to the time you now wish you could get back to. So you really want to distinguish the series of WAL records generated after you've done a point-in-time recovery from those that were generated in the original database history. </para> <para> To deal with these problems, <productname>PostgreSQL</> has a notion of <firstterm>timelines</>. Each time you recover to a point-in-time earlier than the end of the WAL sequence, a new timeline is created to identify the series of WAL records generated after that recovery. (If recovery proceeds all the way to the end of WAL, however, we do not start a new timeline: we just extend the existing one.) The timeline ID number is part of WAL segment file names, and so a new timeline does not overwrite the WAL data generated by previous timelines. It is in fact possible to archive many different timelines. While that might seem like a useless feature, it's often a lifesaver. Consider the situation where you aren't quite sure what point-in-time to recover to, and so have to do several point-in-time recoveries by trial and error until you find the best place to branch off from the old history. Without timelines this process would soon generate an unmanageable mess. With timelines, you can recover to <emphasis>any</> prior state, including states in timeline branches that you later abandoned. </para> <para> Each time a new timeline is created, <productname>PostgreSQL</> creates a <quote>timeline history</> file that shows which timeline it branched off from and when. These history files are necessary to allow the system to pick the right WAL segment files when recovering from an archive that contains multiple timelines. Therefore, they are archived into the WAL archive area just like WAL segment files. The history files are just small text files, so it's cheap and appropriate to keep them around indefinitely (unlike the segment files which are large). You can, if you like, add comments to a history file to make your own notes about how and why this particular timeline came to be. Such comments will be especially valuable when you have a thicket of different timelines as a result of experimentation. </para> <para> The default behavior of recovery is to recover along the same timeline that was current when the base backup was taken. If you want to recover into some child timeline (that is, you want to return to some state that was itself generated after a recovery attempt), you need to specify the target timeline ID in <filename>recovery.conf</>. You cannot recover into timelines that branched off earlier than the base backup. </para> </sect2> <sect2 id="backup-online-caveats"> <title>Caveats</title> <para> At this writing, there are several limitations of the on-line backup technique. These will probably be fixed in future releases: <itemizedlist> <listitem> <para> Operations on hash and R-tree indexes are not presently WAL-logged, so replay will not update these index types. The recommended workaround is to manually <command>REINDEX</> each such index after completing a recovery operation. </para> </listitem> <listitem> <para> If a <command>CREATE DATABASE</> command is executed while a base backup is being taken, and then the template database that the <command>CREATE DATABASE</> copied is modified while the base backup is still in progress, it is possible that recovery will cause those modifications to be propagated into the created database as well. This is of course undesirable. To avoid this risk, it is best not to modify any template databases while taking a base backup. </para> </listitem> <listitem> <para> <command>CREATE TABLESPACE</> commands are WAL-logged with the literal absolute path, and will therefore be replayed as tablespace creations with the same absolute path. This might be undesirable if the log is being replayed on a different machine. It can be dangerous even if the log is being replayed on the same machine, but into a new data directory: the replay will still overwrite the contents of the original tablespace. To avoid potential gotchas of this sort, the best practice is to take a new base backup after creating or dropping tablespaces. </para> </listitem> </itemizedlist> </para> <para> It should also be noted that the default <acronym>WAL</acronym> format is fairly bulky since it includes many disk page snapshots. These page snapshots are designed to support crash recovery, since we may need to fix partially-written disk pages. Depending on your system hardware and software, the risk of partial writes may be small enough to ignore, in which case you can significantly reduce the total volume of archived logs by turning off page snapshots using the <xref linkend="guc-full-page-writes"> parameter. (Read the notes and warnings in <xref linkend="wal"> before you do so.) Turning off page snapshots does not prevent use of the logs for PITR operations. An area for future development is to compress archived WAL data by removing unnecessary page copies even when <varname>full_page_writes</> is on. In the meantime, administrators may wish to reduce the number of page snapshots included in WAL by increasing the checkpoint interval parameters as much as feasible. </para> </sect2> </sect1> <sect1 id="migration"> <title>Migration Between Releases</title> <indexterm zone="migration"> <primary>upgrading</primary> </indexterm> <indexterm zone="migration"> <primary>version</primary> <secondary>compatibility</secondary> </indexterm> <para> This section discusses how to migrate your database data from one <productname>PostgreSQL</> release to a newer one. The software installation procedure <foreignphrase>per se</> is not the subject of this section; those details are in <xref linkend="installation">. </para> <para> As a general rule, the internal data storage format is subject to change between major releases of <productname>PostgreSQL</> (where the number after the first dot changes). This does not apply to different minor releases under the same major release (where the number after the second dot changes); these always have compatible storage formats. For example, releases 7.0.1, 7.1.2, and 7.2 are not compatible, whereas 7.1.1 and 7.1.2 are. When you update between compatible versions, you can simply replace the executables and reuse the data directory on disk. Otherwise you need to back up your data and restore it on the new server. This has to be done using <application>pg_dump</>; file system level backup methods obviously won't work. There are checks in place that prevent you from using a data directory with an incompatible version of <productname>PostgreSQL</productname>, so no great harm can be done by trying to start the wrong server version on a data directory. </para> <para> It is recommended that you use the <application>pg_dump</> and <application>pg_dumpall</> programs from the newer version of <productname>PostgreSQL</>, to take advantage of any enhancements that may have been made in these programs. Current releases of the dump programs can read data from any server version back to 7.0. </para> <para> The least downtime can be achieved by installing the new server in a different directory and running both the old and the new servers in parallel, on different ports. Then you can use something like<programlisting>pg_dumpall -p 5432 | psql -d postgres -p 6543</programlisting> to transfer your data. Or use an intermediate file if you want. Then you can shut down the old server and start the new server at the port the old one was running at. You should make sure that the old database is not updated after you run <application>pg_dumpall</>, otherwise you will obviously lose that data. See <xref linkend="client-authentication"> for information on how to prohibit access. </para> <para> In practice you probably want to test your client applications on the new setup before switching over completely. This is another reason for setting up concurrent installations of old and new versions. </para> <para> If you cannot or do not want to run two servers in parallel you can do the backup step before installing the new version, bring down the server, move the old version out of the way, install the new version, start the new server, restore the data. For example:<programlisting>pg_dumpall > backuppg_ctl stopmv /usr/local/pgsql /usr/local/pgsql.oldcd ~/postgresql-&version;gmake installinitdb -D /usr/local/pgsql/datapostmaster -D /usr/local/pgsql/datapsql -f backup postgres</programlisting> See <xref linkend="runtime"> about ways to start and stop the server and other details. The installation instructions will advise you of strategic places to perform these steps. </para> <note> <para> When you <quote>move the old installation out of the way</quote> it may no longer be perfectly usable. Some of the executable programs contain absolute paths to various installed programs and data files. This is usually not a big problem but if you plan on using two installations in parallel for a while you should assign them different installation directories at build time. (This problem is rectified in <productname>PostgreSQL</> 8.0 and later, but you need to be wary of moving older installations.) </para> </note> </sect1></chapter><!-- Keep this comment at the end of the fileLocal variables:mode:sgmlsgml-omittag:nilsgml-shorttag:tsgml-minimize-attributes:nilsgml-always-quote-attributes:tsgml-indent-step:1sgml-indent-tabs-mode:nilsgml-indent-data:tsgml-parent-document:nilsgml-default-dtd-file:"./reference.ced"sgml-exposed-tags:nilsgml-local-catalogs:("/usr/share/sgml/catalog")sgml-local-ecat-files:nilEnd:-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -