Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 39969e2

Browse files
committed
Remove exclusive backup mode
Exclusive-mode backups have been deprecated since 9.6 (when non-exclusive backups were introduced) due to the issues they can cause should the system crash while one is running and generally because non-exclusive provides a much better interface. Further, exclusive backup mode wasn't really being tested (nor was most of the related code- like being able to log in just to stop an exclusive backup and the bits of the state machine related to that) and having to possibly deal with an exclusive backup and the backup_label file existing during pg_basebackup, pg_rewind, etc, added other complexities that we are better off without. This patch removes the exclusive backup mode, the various special cases for dealing with it, and greatly simplifies the online backup code and documentation. Authors: David Steele, Nathan Bossart Reviewed-by: Chapman Flack Discussion: https://postgr.es/m/ac7339ca-3718-3c93-929f-99e725d1172c@pgmasters.net https://postgr.es/m/CAHg+QDfiM+WU61tF6=nPZocMZvHDzCK47Kneyb0ZRULYzV5sKQ@mail.gmail.com
1 parent 14d3f24 commit 39969e2

File tree

24 files changed

+247
-1200
lines changed

24 files changed

+247
-1200
lines changed

doc/src/sgml/backup.sgml

Lines changed: 27 additions & 214 deletions
Large diffs are not rendered by default.

doc/src/sgml/func.sgml

Lines changed: 24 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -25618,9 +25618,8 @@ LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
2561825618
The functions shown in <xref
2561925619
linkend="functions-admin-backup-table"/> assist in making on-line backups.
2562025620
These functions cannot be executed during recovery (except
25621-
non-exclusive <function>pg_start_backup</function>,
25622-
non-exclusive <function>pg_stop_backup</function>,
25623-
<function>pg_is_in_backup</function>, <function>pg_backup_start_time</function>
25621+
<function>pg_backup_start</function>,
25622+
<function>pg_backup_stop</function>,
2562425623
and <function>pg_wal_lsn_diff</function>).
2562525624
</para>
2562625625

@@ -25709,13 +25708,12 @@ LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
2570925708
<row>
2571025709
<entry role="func_table_entry"><para role="func_signature">
2571125710
<indexterm>
25712-
<primary>pg_start_backup</primary>
25711+
<primary>pg_backup_start</primary>
2571325712
</indexterm>
25714-
<function>pg_start_backup</function> (
25713+
<function>pg_backup_start</function> (
2571525714
<parameter>label</parameter> <type>text</type>
2571625715
<optional>, <parameter>fast</parameter> <type>boolean</type>
25717-
<optional>, <parameter>exclusive</parameter> <type>boolean</type>
25718-
</optional></optional> )
25716+
</optional> )
2571925717
<returnvalue>pg_lsn</returnvalue>
2572025718
</para>
2572125719
<para>
@@ -25724,23 +25722,9 @@ LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
2572425722
(Typically this would be the name under which the backup dump file
2572525723
will be stored.)
2572625724
If the optional second parameter is given as <literal>true</literal>,
25727-
it specifies executing <function>pg_start_backup</function> as quickly
25725+
it specifies executing <function>pg_backup_start</function> as quickly
2572825726
as possible. This forces an immediate checkpoint which will cause a
2572925727
spike in I/O operations, slowing any concurrently executing queries.
25730-
The optional third parameter specifies whether to perform an exclusive
25731-
or non-exclusive backup (default is exclusive).
25732-
</para>
25733-
<para>
25734-
When used in exclusive mode, this function writes a backup label file
25735-
(<filename>backup_label</filename>) and, if there are any links in
25736-
the <filename>pg_tblspc/</filename> directory, a tablespace map file
25737-
(<filename>tablespace_map</filename>) into the database cluster's data
25738-
directory, then performs a checkpoint, and then returns the backup's
25739-
starting write-ahead log location. (The user can ignore this
25740-
result value, but it is provided in case it is useful.) When used in
25741-
non-exclusive mode, the contents of these files are instead returned
25742-
by the <function>pg_stop_backup</function> function, and should be
25743-
copied to the backup area by the user.
2574425728
</para>
2574525729
<para>
2574625730
This function is restricted to superusers by default, but other users
@@ -25751,36 +25735,32 @@ LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
2575125735
<row>
2575225736
<entry role="func_table_entry"><para role="func_signature">
2575325737
<indexterm>
25754-
<primary>pg_stop_backup</primary>
25738+
<primary>pg_backup_stop</primary>
2575525739
</indexterm>
25756-
<function>pg_stop_backup</function> (
25757-
<parameter>exclusive</parameter> <type>boolean</type>
25758-
<optional>, <parameter>wait_for_archive</parameter> <type>boolean</type>
25740+
<function>pg_backup_stop</function> (
25741+
<optional><parameter>wait_for_archive</parameter> <type>boolean</type>
2575925742
</optional> )
2576025743
<returnvalue>record</returnvalue>
2576125744
( <parameter>lsn</parameter> <type>pg_lsn</type>,
2576225745
<parameter>labelfile</parameter> <type>text</type>,
2576325746
<parameter>spcmapfile</parameter> <type>text</type> )
2576425747
</para>
2576525748
<para>
25766-
Finishes performing an exclusive or non-exclusive on-line backup.
25767-
The <parameter>exclusive</parameter> parameter must match the
25768-
previous <function>pg_start_backup</function> call.
25769-
In an exclusive backup, <function>pg_stop_backup</function> removes
25770-
the backup label file and, if it exists, the tablespace map file
25771-
created by <function>pg_start_backup</function>. In a non-exclusive
25772-
backup, the desired contents of these files are returned as part of
25773-
the result of the function, and should be written to files in the
25774-
backup area (not in the data directory).
25749+
Finishes performing an on-line backup. The desired contents of the
25750+
backup label file and the tablespace map file are returned as part of
25751+
the result of the function and must be written to files in the
25752+
backup area. These files must not be written to the live data directory
25753+
(doing so will cause PostgreSQL to fail to restart in the event of a
25754+
crash).
2577525755
</para>
2577625756
<para>
25777-
There is an optional second parameter of type <type>boolean</type>.
25757+
There is an optional parameter of type <type>boolean</type>.
2577825758
If false, the function will return immediately after the backup is
2577925759
completed, without waiting for WAL to be archived. This behavior is
2578025760
only useful with backup software that independently monitors WAL
2578125761
archiving. Otherwise, WAL required to make the backup consistent might
2578225762
be missing and make the backup useless. By default or when this
25783-
parameter is true, <function>pg_stop_backup</function> will wait for
25763+
parameter is true, <function>pg_backup_stop</function> will wait for
2578425764
WAL to be archived when archiving is enabled. (On a standby, this
2578525765
means that it will wait only when <varname>archive_mode</varname> =
2578625766
<literal>always</literal>. If write activity on the primary is low,
@@ -25790,7 +25770,7 @@ LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
2579025770
<para>
2579125771
When executed on a primary, this function also creates a backup
2579225772
history file in the write-ahead log archive area. The history file
25793-
includes the label given to <function>pg_start_backup</function>, the
25773+
includes the label given to <function>pg_backup_start</function>, the
2579425774
starting and ending write-ahead log locations for the backup, and the
2579525775
starting and ending times of the backup. After recording the ending
2579625776
location, the current write-ahead log insertion point is automatically
@@ -25801,61 +25781,18 @@ LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
2580125781
<para>
2580225782
The result of the function is a single record.
2580325783
The <parameter>lsn</parameter> column holds the backup's ending
25804-
write-ahead log location (which again can be ignored). The second and
25805-
third columns are <literal>NULL</literal> when ending an exclusive
25806-
backup; after a non-exclusive backup they hold the desired contents of
25807-
the label and tablespace map files.
25808-
</para>
25809-
<para>
25810-
This function is restricted to superusers by default, but other users
25811-
can be granted EXECUTE to run the function.
25812-
</para></entry>
25813-
</row>
25814-
25815-
<row>
25816-
<entry role="func_table_entry"><para role="func_signature">
25817-
<function>pg_stop_backup</function> ()
25818-
<returnvalue>pg_lsn</returnvalue>
25819-
</para>
25820-
<para>
25821-
Finishes performing an exclusive on-line backup. This simplified
25822-
version is equivalent to <literal>pg_stop_backup(true,
25823-
true)</literal>, except that it only returns the <type>pg_lsn</type>
25824-
result.
25784+
write-ahead log location (which again can be ignored). The second
25785+
column returns the contents of the backup label file, and the third
25786+
column returns the contents of the tablespace map file. These must be
25787+
stored as part of the backup and are required as part of the restore
25788+
process.
2582525789
</para>
2582625790
<para>
2582725791
This function is restricted to superusers by default, but other users
2582825792
can be granted EXECUTE to run the function.
2582925793
</para></entry>
2583025794
</row>
2583125795

25832-
<row>
25833-
<entry role="func_table_entry"><para role="func_signature">
25834-
<indexterm>
25835-
<primary>pg_is_in_backup</primary>
25836-
</indexterm>
25837-
<function>pg_is_in_backup</function> ()
25838-
<returnvalue>boolean</returnvalue>
25839-
</para>
25840-
<para>
25841-
Returns true if an on-line exclusive backup is in progress.
25842-
</para></entry>
25843-
</row>
25844-
25845-
<row>
25846-
<entry role="func_table_entry"><para role="func_signature">
25847-
<indexterm>
25848-
<primary>pg_backup_start_time</primary>
25849-
</indexterm>
25850-
<function>pg_backup_start_time</function> ()
25851-
<returnvalue>timestamp with time zone</returnvalue>
25852-
</para>
25853-
<para>
25854-
Returns the start time of the current on-line exclusive backup if one
25855-
is in progress, otherwise <literal>NULL</literal>.
25856-
</para></entry>
25857-
</row>
25858-
2585925796
<row>
2586025797
<entry role="func_table_entry"><para role="func_signature">
2586125798
<indexterm>
@@ -25953,7 +25890,7 @@ LOG: Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560
2595325890
corresponding write-ahead log file name and byte offset from
2595425891
a <type>pg_lsn</type> value. For example:
2595525892
<programlisting>
25956-
postgres=# SELECT * FROM pg_walfile_name_offset(pg_stop_backup());
25893+
postgres=# SELECT * FROM pg_walfile_name_offset((pg_backup_stop()).lsn);
2595725894
file_name | file_offset
2595825895
--------------------------+-------------
2595925896
00000001000000000000000D | 4039624

doc/src/sgml/high-availability.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,8 +1361,8 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)'
13611361

13621362
<para>
13631363
If you need to re-create a standby server while transactions are
1364-
waiting, make sure that the commands pg_start_backup() and
1365-
pg_stop_backup() are run in a session with
1364+
waiting, make sure that the commands pg_backup_start() and
1365+
pg_backup_stop() are run in a session with
13661366
<varname>synchronous_commit</varname> = <literal>off</literal>, otherwise those
13671367
requests will wait forever for the standby to appear.
13681368
</para>
@@ -2159,7 +2159,7 @@ HINT: You can then restart the server after making the necessary configuration
21592159

21602160
<para>
21612161
WAL file control commands will not work during recovery,
2162-
e.g., <function>pg_start_backup</function>, <function>pg_switch_wal</function> etc.
2162+
e.g., <function>pg_backup_start</function>, <function>pg_switch_wal</function> etc.
21632163
</para>
21642164

21652165
<para>

doc/src/sgml/monitoring.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6674,7 +6674,7 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
66746674
<entry><literal>waiting for checkpoint to finish</literal></entry>
66756675
<entry>
66766676
The WAL sender process is currently performing
6677-
<function>pg_start_backup</function> to prepare to
6677+
<function>pg_backup_start</function> to prepare to
66786678
take a base backup, and waiting for the start-of-backup
66796679
checkpoint to finish.
66806680
</entry>
@@ -6697,7 +6697,7 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
66976697
<entry><literal>waiting for wal archiving to finish</literal></entry>
66986698
<entry>
66996699
The WAL sender process is currently performing
6700-
<function>pg_stop_backup</function> to finish the backup,
6700+
<function>pg_backup_stop</function> to finish the backup,
67016701
and waiting for all the WAL files required for the base backup
67026702
to be successfully archived.
67036703
If either <literal>--wal-method=none</literal> or

doc/src/sgml/ref/pg_ctl-ref.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ PostgreSQL documentation
186186
the specified data directory. Three different
187187
shutdown methods can be selected with the <option>-m</option>
188188
option. <quote>Smart</quote> mode disallows new connections, then waits
189-
for all existing clients to disconnect and any online backup to finish.
189+
for all existing clients to disconnect.
190190
If the server is in hot standby, recovery and streaming replication
191191
will be terminated once all clients have disconnected.
192-
<quote>Fast</quote> mode (the default) does not wait for clients to disconnect and
193-
will terminate an online backup in progress. All active transactions are
192+
<quote>Fast</quote> mode (the default) does not wait for clients to disconnect.
193+
All active transactions are
194194
rolled back and clients are forcibly disconnected, then the
195195
server is shut down. <quote>Immediate</quote> mode will abort
196196
all server processes immediately, without a clean shutdown. This choice

doc/src/sgml/ref/pgupgrade.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ rsync --archive --delete --hard-links --size-only --no-inc-recursive /vol1/pg_tb
618618

619619
<para>
620620
Configure the servers for log shipping. (You do not need to run
621-
<function>pg_start_backup()</function> and <function>pg_stop_backup()</function>
621+
<function>pg_backup_start()</function> and <function>pg_backup_stop()</function>
622622
or take a file system backup as the standbys are still synchronized
623623
with the primary.)
624624
</para>

doc/src/sgml/runtime.sgml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,11 +1552,7 @@ $ <userinput>cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages</userinp
15521552
After receiving <systemitem>SIGTERM</systemitem>, the server
15531553
disallows new connections, but lets existing sessions end their
15541554
work normally. It shuts down only after all of the sessions terminate.
1555-
If the server is in online backup mode, it additionally waits
1556-
until online backup mode is no longer active. While backup mode is
1557-
active, new connections will still be allowed, but only to superusers
1558-
(this exception allows a superuser to connect to terminate
1559-
online backup mode). If the server is in recovery when a smart
1555+
If the server is in recovery when a smart
15601556
shutdown is requested, recovery and streaming replication will be
15611557
stopped only after all regular sessions have terminated.
15621558
</para>
@@ -1572,8 +1568,6 @@ $ <userinput>cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages</userinp
15721568
server processes <systemitem>SIGTERM</systemitem>, which will cause them
15731569
to abort their current transactions and exit promptly. It then
15741570
waits for all server processes to exit and finally shuts down.
1575-
If the server is in online backup mode, backup mode will be
1576-
terminated, rendering the backup useless.
15771571
</para>
15781572
</listitem>
15791573
</varlistentry>

0 commit comments

Comments
 (0)