Skip to content

Commit 8efe819

Browse files
committed
Update backup.sgml
1 parent f507fe2 commit 8efe819

File tree

1 file changed

+67
-34
lines changed

1 file changed

+67
-34
lines changed

postgresql/doc/src/sgml/backup.sgml

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ ____________________________________________________________________________-->
286286

287287
<!--==========================orignal english content==========================
288288
<para>
289-
After restoring a backup, it is wise to run <xref
290-
linkend="sql-analyze"/> on each
289+
After restoring a backup, it is wise to run <link
290+
linkend="sql-analyze"><command>ANALYZE</command></link> on each
291291
database so the query optimizer has useful statistics;
292292
see <xref linkend="vacuum-for-statistics"/>
293293
and <xref linkend="autovacuum"/> for more information.
@@ -297,7 +297,7 @@ ____________________________________________________________________________-->
297297
</para>
298298
____________________________________________________________________________-->
299299
<para>
300-
一旦完成恢复,在每个数据库上运行<xref linkend="sql-analyze"/>是明智的举动,这样优化器就有有用的统计数据了,更多信息参见<xref linkend="vacuum-for-statistics"/>和<xref linkend="autovacuum"/>。更多关于如何有效地向<productname>PostgreSQL</productname>里装载大量数据的建议, 请参考<xref linkend="populate"/>。
300+
一旦完成恢复,在每个数据库上运行<link linkend="sql-analyze"><command>ANALYZE</command></link>是明智的举动,这样优化器就有有用的统计数据了,更多信息参见<xref linkend="vacuum-for-statistics"/>和<xref linkend="autovacuum"/>。更多关于如何有效地向<productname>PostgreSQL</productname>里装载大量数据的建议, 请参考<xref linkend="populate"/>。
301301
</para>
302302
</sect2>
303303

@@ -448,31 +448,48 @@ ____________________________________________________________________________-->
448448
The <command>split</command> command
449449
allows you to split the output into smaller files that are
450450
acceptable in size to the underlying file system. For example, to
451-
make chunks of 1 megabyte:
451+
make 2 gigabyte chunks:
452452

453453
<programlisting>
454-
pg_dump <replaceable class="parameter">dbname</replaceable> | split -b 1m - <replaceable class="parameter">filename</replaceable>
454+
pg_dump <replaceable class="parameter">dbname</replaceable> | split -b 2G - <replaceable class="parameter">filename</replaceable>
455455
</programlisting>
456456

457457
Reload with:
458458

459459
<programlisting>
460460
cat <replaceable class="parameter">filename</replaceable>* | psql <replaceable class="parameter">dbname</replaceable>
461461
</programlisting>
462+
463+
If using GNU <application>split</application>, it is possible to
464+
use it and <application>gzip</application> together:
465+
466+
<programlisting>
467+
pg_dump <replaceable class="parameter">dbname</replaceable> | split -b 2G -&minus;filter='gzip > $FILE.gz'
468+
</programlisting>
469+
470+
It can be restored using <command>zcat</command>.
462471
</para>
463472
____________________________________________________________________________-->
464473
<para>
465-
<command>split</command>命令允许你将输出分割成较小的文件以便能够适应底层文件系统的尺寸要求。例如,让每一块的大小为1兆字节
474+
<command>split</command>命令允许你将输出分割成较小的文件以便能够适应底层文件系统的尺寸要求。例如,让每一块的大小为2吉字节
466475

467476
<programlisting>
468-
pg_dump <replaceable class="parameter">dbname</replaceable> | split -b 1m - <replaceable class="parameter">filename</replaceable>
477+
pg_dump <replaceable class="parameter">dbname</replaceable> | split -b 2G - <replaceable class="parameter">filename</replaceable>
469478
</programlisting>
470479

471480
恢复:
472481

473482
<programlisting>
474483
cat <replaceable class="parameter">filename</replaceable>* | psql <replaceable class="parameter">dbname</replaceable>
475484
</programlisting>
485+
486+
如果使用 GNU <application>split</application>, 可能会把它和 <application>gzip</application> 一起使用:
487+
488+
<programlisting>
489+
pg_dump <replaceable class="parameter">dbname</replaceable> | split -b 2G -&minus;filter='gzip > $FILE.gz'
490+
</programlisting>
491+
492+
它可以用 <command>zcat</command> 恢复。
476493
</para>
477494
</formalpara>
478495

@@ -1022,6 +1039,21 @@ ____________________________________________________________________________-->
10221039
有一点很重要:当且仅当归档命令成功时,它才返回零退出。在得到一个零值结果之后,<productname>PostgreSQL</productname>将假设该文件已经成功归档, 因此它稍后将被删除或者被新的数据覆盖。但是,一个非零值告诉<productname>PostgreSQL</productname>该文件没有被归档; 因此它会周期性的重试直到成功。
10231040
</para>
10241041

1042+
<!--==========================orignal english content==========================
1043+
<para>
1044+
When the archive command is terminated by a signal (other than
1045+
<systemitem>SIGTERM</systemitem> that is used as part of a server
1046+
shutdown) or an error by the shell with an exit status greater than
1047+
125 (such as command not found), the archiver process aborts and gets
1048+
restarted by the postmaster. In such cases, the failure is
1049+
not reported in <xref linkend="pg-stat-archiver-view"/>.
1050+
</para>
1051+
____________________________________________________________________________-->
1052+
<para>
1053+
当归档命令被一个信号(不是作为服务器关闭的一部分所用的<systemitem>SIGTERM</systemitem>)或者是退出状态超过125(例如命令没有发现)的脚本的一个错误所终止时,
1054+
归档进程会退出并且被postmaster重新启动。当这种情况下,<xref linkend="pg-stat-archiver-view"/> 中不会报告故障。
1055+
</para>
1056+
10251057
<!--==========================orignal english content==========================
10261058
<para>
10271059
The archive command should generally be designed to refuse to overwrite
@@ -1385,7 +1417,8 @@ SELECT * FROM pg_stop_backup(false, true);
13851417
<filename>backup_label</filename> in the root directory of the backup. The
13861418
third field should be written to a file named
13871419
<filename>tablespace_map</filename> unless the field is empty. These files are
1388-
vital to the backup working, and must be written without modification.
1420+
vital to the backup working and must be written byte for byte without
1421+
modification, which may require opening the file in binary mode.
13891422
</para>
13901423
</listitem>
13911424
<listitem>
@@ -1474,16 +1507,15 @@ SELECT pg_start_backup('label', false, false);
14741507
<para>
14751508
在同一个连接中,发出命令:
14761509
<programlisting>
1477-
SELECT * FROM pg_stop_backup(false);
1510+
SELECT * FROM pg_stop_backup(false, true);
14781511
</programlisting>
14791512
这会终止备份模式。在主控机上,它还执行一次自动切换到下一个WAL段。在后备机上,它无法自动切换WAL段,因此用户可能希望在主控机上运行<function>pg_switch_wal</function>来执行一次手工切换。要做切换的原因是让在备份期间写入的最后一个WAL段文件能准备好被归档。
14801513
</para>
14811514
<para>
14821515
<function>pg_stop_backup</function>将返回一个具有三个值的行。这些域的
14831516
第二个应该被写入到该备份根目录中名为<filename>backup_label</filename>的
14841517
文件。第三个域应该被写入到一个名为<filename>tablespace_map</filename>
1485-
的文件,除非该域为空。这些文件对该备份正常工作来说是至关重要的,
1486-
不能被随意修改。
1518+
的文件,除非该域为空。这些文件对该备份正常工作来说是至关重要的,必须逐个字节的写入而不能被随意修改,可能需要采用二进制的方式打开文件。
14871519
</para>
14881520
</listitem>
14891521
<listitem>
@@ -1533,7 +1565,7 @@ ____________________________________________________________________________-->
15331565
non-exclusive one, but it differs in a few key steps. This type of
15341566
backup can only be taken on a primary and does not allow concurrent
15351567
backups. Moreover, because it creates a backup label file, as
1536-
described below, it can block automatic restart of the master server
1568+
described below, it can block automatic restart of the primary server
15371569
after a crash. On the other hand, the erroneous removal of this
15381570
file from a backup or standby is a common mistake, which can result
15391571
in serious data corruption. If it is necessary to use this method,
@@ -1607,9 +1639,9 @@ SELECT pg_start_backup('label', true);
16071639
this will result in corruption. Confusion about when it is appropriate
16081640
to remove this file is a common cause of data corruption when using this
16091641
method; be very certain that you remove the file only on an existing
1610-
master and never when building a standby or restoring a backup, even if
1642+
primary and never when building a standby or restoring a backup, even if
16111643
you are building a standby that will subsequently be promoted to a new
1612-
master.
1644+
primary.
16131645
</para>
16141646
</listitem>
16151647
<listitem>
@@ -1794,16 +1826,16 @@ ____________________________________________________________________________-->
17941826
<para>
17951827
It is often a good idea to also omit from the backup the files
17961828
within the cluster's <filename>pg_replslot/</filename> directory, so that
1797-
replication slots that exist on the master do not become part of the
1829+
replication slots that exist on the primary do not become part of the
17981830
backup. Otherwise, the subsequent use of the backup to create a standby
17991831
may result in indefinite retention of WAL files on the standby, and
1800-
possibly bloat on the master if hot standby feedback is enabled, because
1832+
possibly bloat on the primary if hot standby feedback is enabled, because
18011833
the clients that are using those replication slots will still be connecting
1802-
to and updating the slots on the master, not the standby. Even if the
1803-
backup is only intended for use in creating a new master, copying the
1834+
to and updating the slots on the primary, not the standby. Even if the
1835+
backup is only intended for use in creating a new primary, copying the
18041836
replication slots isn't expected to be particularly useful, since the
18051837
contents of those slots will likely be badly out of date by the time
1806-
the new master comes on line.
1838+
the new primary comes on line.
18071839
</para>
18081840
____________________________________________________________________________-->
18091841
<para>
@@ -2280,16 +2312,17 @@ ____________________________________________________________________________-->
22802312

22812313
<!--==========================orignal english content==========================
22822314
<para>
2283-
The default behavior of recovery is to recover along the same timeline
2284-
that was current when the base backup was taken. If you wish to recover
2285-
into some child timeline (that is, you want to return to some state that
2286-
was itself generated after a recovery attempt), you need to specify the
2287-
target timeline ID in <xref linkend="guc-recovery-target-timeline"/>. You cannot recover into
2288-
timelines that branched off earlier than the base backup.
2315+
The default behavior of recovery is to recover to the latest timeline found
2316+
in the archive. If you wish to recover to the timeline that was current
2317+
when the base backup was taken or into a specific child timeline (that
2318+
is, you want to return to some state that was itself generated after a
2319+
recovery attempt), you need to specify <literal>current</literal> or the
2320+
target timeline ID in <xref linkend="guc-recovery-target-timeline"/>. You
2321+
cannot recover into timelines that branched off earlier than the base backup.
22892322
</para>
22902323
____________________________________________________________________________-->
22912324
<para>
2292-
恢复的默认行为是沿着相同的时间线进行恢复,该时间线是基础备份创建时的当前时间线。如果你希望恢复到某个子女时间线(即,你希望回到在一次恢复尝试后产生的某个状态),你需要在<xref linkend="guc-recovery-target-timeline"/>中指定目标时间线ID。你不能恢复到早于该基础备份之前分支出去的时间线。
2325+
恢复的默认行为是沿着归档中所发现的最新的时间线进行恢复。如果你希望恢复到执行基础备份时的当前时间线或者某个指定的子时间线(即,你希望回到在一次恢复尝试后产生的某个状态),你需要指定<literal>current</literal>或者在<xref linkend="guc-recovery-target-timeline"/>中指定目标时间线ID。你不能恢复到早于该基础备份之前分支出去的时间线。
22932326
</para>
22942327
</sect2>
22952328

@@ -2416,22 +2449,22 @@ ____________________________________________________________________________-->
24162449
If archive storage size is a concern, you can use
24172450
<application>gzip</application> to compress the archive files:
24182451
<programlisting>
2419-
archive_command = 'gzip &lt; %p &gt; /var/lib/pgsql/archive/%f'
2452+
archive_command = 'gzip &lt; %p &gt; /mnt/server/archivedir/%f.gz'
24202453
</programlisting>
24212454
You will then need to use <application>gunzip</application> during recovery:
24222455
<programlisting>
2423-
restore_command = 'gunzip &lt; /mnt/server/archivedir/%f &gt; %p'
2456+
restore_command = 'gunzip &lt; /mnt/server/archivedir/%f.gz &gt; %p'
24242457
</programlisting>
24252458
</para>
24262459
____________________________________________________________________________-->
24272460
<para>
24282461
如果担心归档存储的尺寸,你可以使用<application>gzip</application>来压缩归档文件:
24292462
<programlisting>
2430-
archive_command = 'gzip &lt; %p &gt; /var/lib/pgsql/archive/%f'
2463+
archive_command = 'gzip &lt; %p &gt; /mnt/server/archivedir/%f.gz'
24312464
</programlisting>
24322465
那么在恢复时你将需要使用<application>gunzip</application>:
24332466
<programlisting>
2434-
restore_command = 'gunzip &lt; /mnt/server/archivedir/%f &gt; %p'
2467+
restore_command = 'gunzip &lt; /mnt/server/archivedir/%f.gz &gt; %p'
24352468
</programlisting>
24362469
</para>
24372470
</sect3>
@@ -2550,7 +2583,7 @@ ____________________________________________________________________________-->
25502583
<itemizedlist>
25512584
<listitem>
25522585
<para>
2553-
If a <xref linkend="sql-createdatabase"/>
2586+
If a <link linkend="sql-createdatabase"><command>CREATE DATABASE</command></link>
25542587
command is executed while a base backup is being taken, and then
25552588
the template database that the <command>CREATE DATABASE</command> copied
25562589
is modified while the base backup is still in progress, it is
@@ -2563,7 +2596,7 @@ ____________________________________________________________________________-->
25632596

25642597
<listitem>
25652598
<para>
2566-
<xref linkend="sql-createtablespace"/>
2599+
<link linkend="sql-createtablespace"><command>CREATE TABLESPACE</command></link>
25672600
commands are WAL-logged with the literal absolute path, and will
25682601
therefore be replayed as tablespace creations with the same
25692602
absolute path. This might be undesirable if the log is being
@@ -2584,13 +2617,13 @@ ____________________________________________________________________________-->
25842617
<itemizedlist>
25852618
<listitem>
25862619
<para>
2587-
如果一个<xref linkend="sql-createdatabase"/>命令在基础备份时被执行,然后在基础备份进行时<command>CREATE DATABASE</command>所复制的模板数据库被修改,恢复中可能会导致这些修改也被传播到已创建的数据库中。这当然是我们不希望的。为了避免这种风险,最好不要在创建基础备份时修改任何模板数据库。
2620+
如果一个<link linkend="sql-createdatabase"><command>CREATE DATABASE</command></link>命令在基础备份时被执行,然后在基础备份进行时<command>CREATE DATABASE</command>所复制的模板数据库被修改,恢复中可能会导致这些修改也被传播到已创建的数据库中。这当然是我们不希望的。为了避免这种风险,最好不要在创建基础备份时修改任何模板数据库。
25882621
</para>
25892622
</listitem>
25902623

25912624
<listitem>
25922625
<para>
2593-
<xref linkend="sql-createtablespace"/>命令会WAL以其字面绝对路径记录,并且因此将在重放时以相同的绝对路径来创建表空间。当日志在一台不同的机器上被重放时,这可能也不是我们希望的。即使日志在同一台机器上被重放也是危险的,就算是恢复到一个新的数据目录重放过程也会覆盖原来表空间的内容。为了避免这种潜在的陷阱,最佳做法是在创建或丢弃表空间后创建一个新的基础备份。
2626+
<link linkend="sql-createtablespace"><command>CREATE TABLESPACE</command></link>命令会WAL以其字面绝对路径记录,并且因此将在重放时以相同的绝对路径来创建表空间。当日志在一台不同的机器上被重放时,这可能也不是我们希望的。即使日志在同一台机器上被重放也是危险的,就算是恢复到一个新的数据目录重放过程也会覆盖原来表空间的内容。为了避免这种潜在的陷阱,最佳做法是在创建或丢弃表空间后创建一个新的基础备份。
25942627
</para>
25952628
</listitem>
25962629
</itemizedlist>

0 commit comments

Comments
 (0)