From 277e49eca73a719695d0b74360b54124e76c6833 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 15 Aug 2020 15:43:34 -0400 Subject: [PATCH] Doc: various improvements for pg_basebackup reference page. Put the -r option in the right section (it certainly isn't an option controlling "the location and format of the output"). Clarify the behavior of the tablespace and waldir options (that part per gripe from robert@interactive.co.uk). Make a large number of small copy-editing fixes in text that visibly wasn't written by native speakers, and try to avoid grammatical inconsistencies between the descriptions of the different options. Back-patch to v13, since HEAD hasn't meaningfully diverged yet. Discussion: https://postgr.es/m/159749418850.14322.216503677134569752@wrigleys.postgresql.org --- doc/src/sgml/ref/pg_basebackup.sgml | 330 +++++++++++++++------------- 1 file changed, 174 insertions(+), 156 deletions(-) diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml index 91cfd92ab2..aa0b27c9f3 100644 --- a/doc/src/sgml/ref/pg_basebackup.sgml +++ b/doc/src/sgml/ref/pg_basebackup.sgml @@ -9,7 +9,7 @@ PostgreSQL documentation - pg_basebackup + pg_basebackup 1 Application @@ -29,51 +29,51 @@ PostgreSQL documentation Description - pg_basebackup is used to take base backups of - a running PostgreSQL database cluster. These - are taken without affecting other clients to the database, and can be used + pg_basebackup is used to take a base backup of + a running PostgreSQL database cluster. The backup + is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see ) - and as the starting point for a log shipping or streaming replication standby - servers (see ). + and as the starting point for a log-shipping or streaming-replication standby + server (see ). - pg_basebackup makes a binary copy of the database - cluster files, while making sure the system is put in and + pg_basebackup makes an exact copy of the database + cluster's files, while making sure the server is put into and out of backup mode automatically. Backups are always taken of the entire database cluster; it is not possible to back up individual databases or - database objects. For individual database backups, a tool such as + database objects. For selective backups, another tool such as must be used. The backup is made over a regular PostgreSQL - connection, and uses the replication protocol. The connection must be made - with a user having REPLICATION permissions - (see ) or a superuser, - and pg_hba.conf must explicitly permit the replication - connection. The server must also be configured - with set high enough to leave at least - one session available for the backup and one for WAL streaming (if used). + connection that uses the replication protocol. The connection must be made + with a user ID that has REPLICATION permissions + (see ) or is a superuser, + and pg_hba.conf + must permit the replication connection. The server must also be configured + with set high enough to provide at + least one walsender for the backup plus one for WAL streaming (if used). - There can be multiple pg_basebackups running at the same time, but it is + There can be multiple pg_basebackups running at the same time, but it is usually better from a performance point of view to take only one backup, and copy the result. pg_basebackup can make a base backup from - not only the master but also the standby. To take a backup from the standby, + not only a primary server but also a standby. To take a backup from a standby, set up the standby so that it can accept replication connections (that is, set max_wal_senders and , - and configure host-based authentication). - You will also need to enable on the master. + and configure its pg_hba.conf appropriately). + You will also need to enable on the primary. - Note that there are some limitations in an online backup from the standby: + Note that there are some limitations in taking a backup from a standby: @@ -89,13 +89,13 @@ PostgreSQL documentation - If the standby is promoted to the master during online backup, the backup fails. + If the standby is promoted to be primary during backup, the backup fails. All WAL records required for the backup must contain sufficient full-page writes, - which requires you to enable full_page_writes on the master and + which requires you to enable full_page_writes on the primary and not to use a tool like pg_compresslog as archive_command to remove full-page writes from WAL files. @@ -105,7 +105,7 @@ PostgreSQL documentation Whenever pg_basebackup is taking a base - backup, the pg_stat_progress_basebackup + backup, the server's pg_stat_progress_basebackup view will report the progress of the backup. See for details. @@ -116,7 +116,7 @@ PostgreSQL documentation The following command-line options control the location and format of the - output. + output: @@ -124,15 +124,15 @@ PostgreSQL documentation - Directory to write the output to. - pg_basebackup will create the directory and - any parent directories if necessary. The directory may already exist, - but it is an error if the directory already exists and is not empty. + Sets the target directory to write the output to. + pg_basebackup will create this directory + (and any missing parent directories) if it does not exist. If it + already exists, it must be empty. - When the backup is in tar mode, and the directory is specified as - - (dash), the tar file will be written to - stdout. + When the backup is in tar format, the target directory may be + specified as - (dash), causing the tar file to be + written to stdout. This option is required. @@ -155,12 +155,12 @@ PostgreSQL documentation Write the output as plain files, with the same layout as the - current data directory and tablespaces. When the cluster has + source server's data directory and tablespaces. When the cluster has no additional tablespaces, the whole database will be placed in the target directory. If the cluster contains additional tablespaces, the main data directory will be placed in the target directory, but all other tablespaces will be placed - in the same absolute path as they have on the server. + in the same absolute path as they have on the source server. This is the default format. @@ -174,15 +174,15 @@ PostgreSQL documentation Write the output as tar files in the target directory. The main - data directory will be written to a file named - base.tar, and all other tablespaces will - be named after the tablespace OID. - + data directory's contents will be written to a file named + base.tar, and each other tablespace will be + written to a separate tar file named after that tablespace's OID. + - If the value - (dash) is specified as - target directory, the tar contents will be written to - standard output, suitable for piping to for example - gzip. This is only possible if + If the target directory is specified as - + (dash), the tar contents will be written to + standard output, suitable for piping to (for example) + gzip. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used. @@ -192,40 +192,22 @@ PostgreSQL documentation - - - - - - The maximum transfer rate of data transferred from the server. Values are - in kilobytes per second. Use a suffix of M to indicate megabytes - per second. A suffix of k is also accepted, and has no effect. - Valid values are between 32 kilobytes per second and 1024 megabytes per second. - - - The purpose is to limit the impact of pg_basebackup - on the running server. - - - This option always affects transfer of the data directory. Transfer of - WAL files is only affected if the collection method is fetch. - - - - - Create standby.signal and append connection settings - to postgresql.auto.conf in the output - directory (or into the base archive file when using tar format) to - ease setting up a standby server. + Creates a standby.signal file and appends + connection settings to the postgresql.auto.conf + file in the target directory (or within the base archive file when + using tar format). This eases setting up a standby server using the + results of the backup. + + The postgresql.auto.conf file will record the connection settings and, if specified, the replication slot - that pg_basebackup is using, so that the + that pg_basebackup is using, so that streaming replication will use the same settings later on. @@ -237,17 +219,21 @@ PostgreSQL documentation - Relocate the tablespace in directory olddir + Relocates the tablespace in directory olddir to newdir during the backup. To be effective, olddir must exactly match the - path specification of the tablespace as it is currently defined. (But - it is not an error if there is no tablespace - in olddir contained in the backup.) + path specification of the tablespace as it is defined on the source + server. (But it is not an error if there is no tablespace + in olddir on the source server.) + Meanwhile newdir is a directory in the + receiving host's filesystem. As with the main target directory, + newdir need not exist already, but if + it does exist it must be empty. Both olddir - and newdir must be absolute paths. If a - path happens to contain a = sign, escape it with a - backslash. This option can be specified multiple times for multiple - tablespaces. See examples below. + and newdir must be absolute paths. If + either path needs to contain an equal sign (=), + precede that with a backslash. This option can be specified multiple + times for multiple tablespaces. @@ -263,10 +249,16 @@ PostgreSQL documentation - Specifies the location for the write-ahead log directory. + Sets the directory to write WAL (write-ahead log) files to. + By default WAL files will be placed in + the pg_wal subdirectory of the target + directory, but this option can be used to place them elsewhere. waldir must be an absolute path. - The write-ahead log directory can only be specified when - the backup is in plain mode. + As with the main target directory, + waldir need not exist already, but if + it does exist it must be empty. + This option can only be specified when + the backup is in plain format. @@ -276,16 +268,16 @@ PostgreSQL documentation - Includes the required write-ahead log files (WAL files) in the + Includes the required WAL (write-ahead log) files in the backup. This will include all write-ahead logs generated during the backup. Unless the method none is specified, - it is possible to start a postmaster directly in the extracted + it is possible to start a postmaster in the target directory without the need to consult the log archive, thus - making this a completely standalone backup. + making the output a completely standalone backup. - The following methods for collecting the write-ahead logs are - supported: + The following methods for collecting the + write-ahead logs are supported: @@ -293,7 +285,7 @@ PostgreSQL documentation none - Don't include write-ahead log in the backup. + Don't include write-ahead logs in the backup. @@ -304,15 +296,16 @@ PostgreSQL documentation The write-ahead log files are collected at the end of the backup. - Therefore, it is necessary for the + Therefore, it is necessary for the source server's parameter to be set high - enough that the log is not removed before the end of the backup. - If the log has been rotated when it's time to transfer it, the - backup will fail and be unusable. + enough that the required log data is not removed before the end + of the backup. If the required log data has been recycled + before it's time to transfer it, the backup will fail and be + unusable. - When tar format mode is used, the write-ahead log files will be - written to the base.tar file. + When tar format is used, the write-ahead log files will be + included in the base.tar file. @@ -322,16 +315,16 @@ PostgreSQL documentation stream - Stream the write-ahead log while the backup is created. This will - open a second connection to the server and start streaming the - write-ahead log in parallel while running the backup. Therefore, - it will use up two connections configured by the - parameter. As long as the - client can keep up with write-ahead log received, using this mode - requires no extra write-ahead logs to be saved on the master. + Stream write-ahead log data while the backup is being taken. + This method will open a second connection to the server and + start streaming the write-ahead log in parallel while running + the backup. Therefore, it will require two replication + connections not just one. As long as the client can keep up + with the write-ahead log data, using this method requires no + extra write-ahead logs to be saved on the source server. - When tar format mode is used, the write-ahead log files will be + When tar format is used, the write-ahead log files will be written to a separate file named pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar). @@ -375,7 +368,7 @@ PostgreSQL documentation The following command-line options control the generation of the - backup and the running of the program. + backup and the running of the program: @@ -383,7 +376,8 @@ PostgreSQL documentation - Sets checkpoint mode to fast (immediate) or spread (default) (see ). + Sets checkpoint mode to fast (immediate) or spread (the default) + (see ). @@ -393,9 +387,9 @@ PostgreSQL documentation - This option causes creation of a replication slot named by the - --slot option before starting the backup. - An error is raised if the slot already exists. + Specifies that the replication slot named by the + --slot option should be created before starting + the backup. An error is raised if the slot already exists. @@ -418,9 +412,9 @@ PostgreSQL documentation By default, when pg_basebackup aborts with an error, it removes any directories it might have created before - discovering that it cannot finish the job (for example, data directory - and write-ahead log directory). This option inhibits tidying-up and is - thus useful for debugging. + discovering that it cannot finish the job (for example, the target + directory and write-ahead log directory). This option inhibits + tidying-up and is thus useful for debugging. @@ -460,19 +454,41 @@ PostgreSQL documentation + + + + + + Sets the maximum transfer rate at which data is collected from the + source server. This can be useful to limit the impact + of pg_basebackup on the server. Values + are in kilobytes per second. Use a suffix of M + to indicate megabytes per second. A suffix of k + is also accepted, and has no effect. Valid values are between 32 + kilobytes per second and 1024 megabytes per second. + + + This option always affects transfer of the data directory. Transfer of + WAL files is only affected if the collection method + is fetch. + + + + This option can only be used together with -X - stream. It causes the WAL streaming to use the specified + stream. It causes WAL streaming to use the specified replication slot. If the base backup is intended to be used as a - streaming replication standby using replication slots, it should then - use the same replication slot name - in . That way, it is ensured that - the server does not remove any necessary WAL data in the time between - the end of the base backup and the start of streaming replication. + streaming-replication standby using a replication slot, the standby + should then use the same replication slot name as + . This ensures that the + primary server does not remove any necessary WAL data in the time + between the end of the base backup and the start of streaming + replication on the new standby. The specified replication slot has to exist unless the @@ -522,15 +538,15 @@ PostgreSQL documentation Using a SHA hash function provides a cryptographically secure digest of each file for users who wish to verify that the backup has not been - tampered with, while the CRC32C algorithm provides a checksum which is - much faster to calculate and good at catching errors due to accidental + tampered with, while the CRC32C algorithm provides a checksum that is + much faster to calculate; it is good at catching errors due to accidental changes but is not resistant to targeted modifications. Note that, to be useful against an adversary who has access to the backup, the backup manifest would need to be stored securely elsewhere or otherwise verified not to have been modified since the backup was taken. - can be used to check the + can be used to check the integrity of a backup against the backup manifest. @@ -552,11 +568,11 @@ PostgreSQL documentation - This option prevents the server from estimating the total + Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the - backup_total column in the - pg_stat_progress_basebackup - to be NULL. + backup_total column in the + pg_stat_progress_basebackup view + always being NULL. Without this option, the backup will start by enumerating @@ -578,7 +594,7 @@ PostgreSQL documentation Disables generation of a backup manifest. If this option is not specified, the server will generate and send a backup manifest - which can be verified using . + which can be verified using . The manifest is a list of every file present in the backup with the exception of any WAL files that may be included. It also stores the size, last modification time, and an optional checksum for each file. @@ -590,16 +606,17 @@ PostgreSQL documentation - This option prevents the creation of a temporary replication slot - during the backup even if it's supported by the server. + Prevents the creation of a temporary replication slot + for the backup. - Temporary replication slots are created by default if no slot name - is given with the option when using log streaming. + By default, if log streaming is selected but no slot name is given + with the option, then a temporary replication + slot is created (if supported by the source server). The main purpose of this option is to allow taking a base backup when - the server is out of free replication slots. Using replication slots + the server has no free replication slots. Using a replication slot is almost always preferred, because it prevents needed WAL from being removed by the server during the backup. @@ -617,7 +634,7 @@ PostgreSQL documentation By default, checksums are verified and checksum failures will result in a non-zero exit status. However, the base backup will not be removed in such a case, as if the option - had been used. Checksum verifications failures will also be reported + had been used. Checksum verification failures will also be reported in the pg_stat_database view. @@ -627,7 +644,8 @@ PostgreSQL documentation - The following command-line options control the database connection parameters. + The following command-line options control the connection to the source + server: @@ -641,7 +659,7 @@ PostgreSQL documentation The option is called --dbname for consistency with other client applications, but because pg_basebackup - doesn't connect to any particular database in the cluster, database + doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored. @@ -654,7 +672,7 @@ PostgreSQL documentation Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the - directory for the Unix domain socket. The default is taken + directory for a Unix domain socket. The default is taken from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted. @@ -679,11 +697,12 @@ PostgreSQL documentation - Specifies the number of seconds between status packets sent back to the - server. This allows for easier monitoring of the progress from server. - A value of zero disables the periodic status updates completely, + Specifies the number of seconds between status packets sent back to + the source server. Smaller values allow more accurate monitoring of + backup progress from the server. + A value of zero disables periodic status updates completely, although an update will still be sent when requested by the server, to - avoid timeout disconnect. The default value is 10 seconds. + avoid timeout-based disconnects. The default value is 10 seconds. @@ -693,7 +712,7 @@ PostgreSQL documentation - User name to connect as. + Specifies the user name to connect as. @@ -703,7 +722,7 @@ PostgreSQL documentation - Never issue a password prompt. If the server requires + Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in @@ -718,8 +737,8 @@ PostgreSQL documentation - Force pg_basebackup to prompt for a - password before connecting to a database. + Forces pg_basebackup to prompt for a + password before connecting to the source server. @@ -745,7 +764,7 @@ PostgreSQL documentation - Print the pg_basebackup version and exit. + Prints the pg_basebackup version and exits. @@ -755,8 +774,8 @@ PostgreSQL documentation - Show help about pg_basebackup command line - arguments, and exit. + Shows help about pg_basebackup command line + arguments, and exits. @@ -787,11 +806,10 @@ PostgreSQL documentation Notes - At the beginning of the backup, a checkpoint needs to be written on the - server the backup is taken from. Especially if the option - --checkpoint=fast is not used, this can take some time - during which pg_basebackup will be appear - to be idle. + At the beginning of the backup, a checkpoint needs to be performed on the + source server. This can take some time (especially if the option + --checkpoint=fast is not used), during + which pg_basebackup will appear to be idle. @@ -806,8 +824,8 @@ PostgreSQL documentation - Tablespaces will in plain format by default be backed up to the same path - they have on the server, unless the + In plain format, tablespaces will be backed up to the same path + they have on the source server, unless the option --tablespace-mapping is used. Without this option, running a plain format base backup on the same host as the server will not work if tablespaces are in use, because the backup would @@ -816,8 +834,9 @@ PostgreSQL documentation - When tar format mode is used, it is the user's responsibility to unpack each - tar file before starting the PostgreSQL server. If there are additional tablespaces, the + When tar format is used, it is the user's responsibility to unpack each + tar file before starting a PostgreSQL server that uses the data. If there + are additional tablespaces, the tar files for them need to be unpacked in the correct locations. In this case the symbolic links for those tablespaces will be created by the server according to the contents of the tablespace_map file that is @@ -827,15 +846,14 @@ PostgreSQL documentation pg_basebackup works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (-X - stream) only works with server version 9.3 and later, and tar format mode - (--format=tar) of the current version only works with server version 9.5 - or later. + stream) only works with server version 9.3 and later, and tar format + (--format=tar) only works with server version 9.5 + and later. - pg_basebackup will preserve group permissions in - both the plain and tar formats if group - permissions are enabled on the source cluster. + pg_basebackup will preserve group permissions + for data files if group permissions are enabled on the source cluster.