@@ -818,6 +818,21 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_xlog/
818
818
simple. It is very important that these steps are executed in
819
819
sequence, and that the success of a step is verified before
820
820
proceeding to the next step.
821
+ </para>
822
+ <para>
823
+ Low level base backups can be made in a non-exclusive or an exclusive
824
+ way. The non-exclusive method is recommended and the exclusive one is
825
+ deprecated and will eventually be removed.
826
+ </para>
827
+ <sect3 id="backup-lowlevel-base-backup-nonexclusive">
828
+ <title>Making a non-exclusive low level backup</title>
829
+ <para>
830
+ A non-exclusive low level backup is one that allows other
831
+ concurrent backups to be running (both those started using
832
+ the same backup API and those started using
833
+ <xref linkend="app-pgbasebackup">.
834
+ </para>
835
+ <para>
821
836
<orderedlist>
822
837
<listitem>
823
838
<para>
@@ -826,31 +841,129 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_xlog/
826
841
</listitem>
827
842
<listitem>
828
843
<para>
829
- Connect to the database as a user with rights to run pg_start_backup
830
- (superuser, or a user who has been granted EXECUTE on the function)
831
- and issue the command:
844
+ Connect to the server (it does not matter which database) as a user with
845
+ rights to run pg_start_backup (superuser, or a user who has been granted
846
+ EXECUTE on the function) and issue the command:
847
+ <programlisting>
848
+ SELECT pg_start_backup('label', false, false);
849
+ </programlisting>
850
+ where <literal>label</> is any string you want to use to uniquely
851
+ identify this backup operation. The connection
852
+ calling <function>pg_start_backup</> must be maintained until the end of
853
+ the backup, or the backup will be automatically aborted.
854
+ </para>
855
+
856
+ <para>
857
+ By default, <function>pg_start_backup</> can take a long time to finish.
858
+ This is because it performs a checkpoint, and the I/O
859
+ required for the checkpoint will be spread out over a significant
860
+ period of time, by default half your inter-checkpoint interval
861
+ (see the configuration parameter
862
+ <xref linkend="guc-checkpoint-completion-target">). This is
863
+ usually what you want, because it minimizes the impact on query
864
+ processing. If you want to start the backup as soon as
865
+ possible, change the second parameter to <literal>true</>.
866
+ </para>
867
+
868
+ <para>
869
+ The third parameter being <literal>false</> tells
870
+ <function>pg_start_backup</> to initiate a non-exclusive base backup.
871
+ </para>
872
+ </listitem>
873
+ <listitem>
874
+ <para>
875
+ Perform the backup, using any convenient file-system-backup tool
876
+ such as <application>tar</> or <application>cpio</> (not
877
+ <application>pg_dump</application> or
878
+ <application>pg_dumpall</application>). It is neither
879
+ necessary nor desirable to stop normal operation of the database
880
+ while you do this. See section
881
+ <xref linkend="backup-lowlevel-base-backup-data"> for things to
882
+ consider during this backup.
883
+ </para>
884
+ </listitem>
885
+ <listitem>
886
+ <para>
887
+ In the same connection as before, issue the command:
888
+ <programlisting>
889
+ SELECT * FROM pg_stop_backup(false);
890
+ </programlisting>
891
+ This terminates the backup mode and performs an automatic switch to
892
+ the next WAL segment. The reason for the switch is to arrange for
893
+ the last WAL segment file written during the backup interval to be
894
+ ready to archive.
895
+ </para>
896
+ <para>
897
+ The <function>pg_stop_backup</> will return one row with three
898
+ values. The second of these fields should be written to a file named
899
+ <filename>backup_label</> in the root directory of the backup. The
900
+ third field should be written to a file named
901
+ <filename>tablespace_map</> unless the field is empty. These files are
902
+ vital to the backup working, and must be written without modification.
903
+ </para>
904
+ </listitem>
905
+ <listitem>
906
+ <para>
907
+ Once the WAL segment files active during the backup are archived, you are
908
+ done. The file identified by <function>pg_stop_backup</>'s first return
909
+ value the last segment that is required to form a complete set of backup
910
+ files. If <varname>archive_mode</> is enabled,
911
+ <function>pg_stop_backup</> does not return until the last segment has
912
+ been archived.
913
+ Archiving of these files happens automatically since you have
914
+ already configured <varname>archive_command</>. In most cases this
915
+ happens quickly, but you are advised to monitor your archive
916
+ system to ensure there are no delays.
917
+ If the archive process has fallen behind
918
+ because of failures of the archive command, it will keep retrying
919
+ until the archive succeeds and the backup is complete.
920
+ If you wish to place a time limit on the execution of
921
+ <function>pg_stop_backup</>, set an appropriate
922
+ <varname>statement_timeout</varname> value, but make note that if
923
+ <function>pg_stop_backup</> terminates because of this your backup
924
+ may not be valid.
925
+ </para>
926
+ </listitem>
927
+ </orderedlist>
928
+ </para>
929
+ </sect3>
930
+ <sect3 id="backup-lowlevel-base-backup-exclusive">
931
+ <title>Making an exclusive low level backup</title>
932
+ <para>
933
+ The process for an exclusive backup is mostly the same as for a
934
+ non-exclusive one, but it differs in a few key steps. It does not allow
935
+ more than one concurrent backup to run, and there can be some issues on
936
+ the server if it crashes during the backup. Prior to PostgreSQL 9.6, this
937
+ was the only low-level method available, but it is now recommended that
938
+ all users upgrade their scripts to use non-exclusive backups if possible.
939
+ </para>
940
+ <para>
941
+ <orderedlist>
942
+ <listitem>
943
+ <para>
944
+ Ensure that WAL archiving is enabled and working.
945
+ </para>
946
+ </listitem>
947
+ <listitem>
948
+ <para>
949
+ Connect to the server (it does not matter which database) as a user with
950
+ rights to run pg_start_backup (superuser, or a user who has been granted
951
+ EXECUTE on the function) and issue the command:
832
952
<programlisting>
833
953
SELECT pg_start_backup('label');
834
954
</programlisting>
835
955
where <literal>label</> is any string you want to use to uniquely
836
- identify this backup operation. (One good practice is to use the
837
- full path where you intend to put the backup dump file.)
956
+ identify this backup operation.
838
957
<function>pg_start_backup</> creates a <firstterm>backup label</> file,
839
958
called <filename>backup_label</>, in the cluster directory with
840
- information about your backup, including the start time and label
841
- string. The function also creates a <firstterm>tablespace map</> file,
959
+ information about your backup, including the start time and label string.
960
+ The function also creates a <firstterm>tablespace map</> file,
842
961
called <filename>tablespace_map</>, in the cluster directory with
843
- information about tablespace symbolic links in <filename>pg_tblspc/</>
844
- if one or more such link is present. Both files are critical to the
962
+ information about tablespace symbolic links in <filename>pg_tblspc/</> if
963
+ one or more such link is present. Both files are critical to the
845
964
integrity of the backup, should you need to restore from it.
846
965
</para>
847
966
848
- <para>
849
- It does not matter which database within the cluster you connect to to
850
- issue this command. You can ignore the result returned by the function;
851
- but if it reports an error, deal with that before proceeding.
852
- </para>
853
-
854
967
<para>
855
968
By default, <function>pg_start_backup</> can take a long time to finish.
856
969
This is because it performs a checkpoint, and the I/O
@@ -874,7 +987,9 @@ SELECT pg_start_backup('label', true);
874
987
<application>pg_dump</application> or
875
988
<application>pg_dumpall</application>). It is neither
876
989
necessary nor desirable to stop normal operation of the database
877
- while you do this.
990
+ while you do this. See section
991
+ <xref linkend="backup-lowlevel-base-backup-data"> for things to
992
+ consider during this backup.
878
993
</para>
879
994
</listitem>
880
995
<listitem>
@@ -908,12 +1023,16 @@ SELECT pg_stop_backup();
908
1023
until the archive succeeds and the backup is complete.
909
1024
If you wish to place a time limit on the execution of
910
1025
<function>pg_stop_backup</>, set an appropriate
911
- <varname>statement_timeout</varname> value.
1026
+ <varname>statement_timeout</varname> value, but make note that if
1027
+ <function>pg_stop_backup</> terminates because of this your backup
1028
+ may not be valid.
912
1029
</para>
913
1030
</listitem>
914
1031
</orderedlist>
915
- </para>
916
-
1032
+ </para>
1033
+ </sect3>
1034
+ <sect3 id="backup-lowlevel-base-backup-data">
1035
+ <title>Backing up the data directory</title>
917
1036
<para>
918
1037
Some file system backup tools emit warnings or errors
919
1038
if the files they are trying to copy change while the copy proceeds.
@@ -933,16 +1052,16 @@ SELECT pg_stop_backup();
933
1052
</para>
934
1053
935
1054
<para>
936
- Be certain that your backup dump includes all of the files under
1055
+ Be certain that your backup includes all of the files under
937
1056
the database cluster directory (e.g., <filename>/usr/local/pgsql/data</>).
938
1057
If you are using tablespaces that do not reside underneath this directory,
939
- be careful to include them as well (and be sure that your backup dump
1058
+ be careful to include them as well (and be sure that your backup
940
1059
archives symbolic links as links, otherwise the restore will corrupt
941
1060
your tablespaces).
942
1061
</para>
943
1062
944
1063
<para>
945
- You can , however, omit from the backup dump the files within the
1064
+ You should , however, omit from the backup the files within the
946
1065
cluster's <filename>pg_xlog/</> subdirectory. This
947
1066
slight adjustment is worthwhile because it reduces the risk
948
1067
of mistakes when restoring. This is easy to arrange if
@@ -956,7 +1075,7 @@ SELECT pg_stop_backup();
956
1075
</para>
957
1076
958
1077
<para>
959
- It is often a good idea to also omit from the backup dump the files
1078
+ It is often a good idea to also omit from the backup the files
960
1079
within the cluster's <filename>pg_replslot/</> directory, so that
961
1080
replication slots that exist on the master do not become part of the
962
1081
backup. Otherwise, the subsequent use of the backup to create a standby
@@ -971,15 +1090,11 @@ SELECT pg_stop_backup();
971
1090
</para>
972
1091
973
1092
<para>
974
- It's also worth noting that the <function>pg_start_backup</> function
975
- makes files named <filename>backup_label</> and
976
- <filename>tablespace_map</> in the database cluster directory,
977
- which are removed by <function>pg_stop_backup</>. These files will of
978
- course be archived as a part of your backup dump file. The backup label
1093
+ The backup label
979
1094
file includes the label string you gave to <function>pg_start_backup</>,
980
1095
as well as the time at which <function>pg_start_backup</> was run, and
981
1096
the name of the starting WAL file. In case of confusion it is therefore
982
- possible to look inside a backup dump file and determine exactly which
1097
+ possible to look inside a backup file and determine exactly which
983
1098
backup session the dump file came from. The tablespace map file includes
984
1099
the symbolic link names as they exist in the directory
985
1100
<filename>pg_tblspc/</> and the full path of each symbolic link.
@@ -989,13 +1104,14 @@ SELECT pg_stop_backup();
989
1104
</para>
990
1105
991
1106
<para>
992
- It is also possible to make a backup dump while the server is
1107
+ It is also possible to make a backup while the server is
993
1108
stopped. In this case, you obviously cannot use
994
1109
<function>pg_start_backup</> or <function>pg_stop_backup</>, and
995
1110
you will therefore be left to your own devices to keep track of which
996
- backup dump is which and how far back the associated WAL files go.
1111
+ backup is which and how far back the associated WAL files go.
997
1112
It is generally better to follow the continuous archiving procedure above.
998
1113
</para>
1114
+ </sect3>
999
1115
</sect2>
1000
1116
1001
1117
<sect2 id="backup-pitr-recovery">
0 commit comments