{
    "content": [
        {
            "type": "text",
            "text": "# pg_basebackup (man)\n\n## NAME\n\npgbasebackup - take a base backup of a PostgreSQL cluster\n\n## SYNOPSIS\n\npgbasebackup [option...]\n\n## DESCRIPTION\n\npgbasebackup is used to take a base backup of a running PostgreSQL database cluster. The\nbackup is taken without affecting other clients of the database, and can be used both for\npoint-in-time recovery (see Section 26.3) and as the starting point for a log-shipping or\nstreaming-replication standby server (see Section 27.2).\n\n## TLDR\n\n> Take a base backup of a running PostgreSQL cluster.\n\n- Take a base backup from a remote PostgreSQL server:\n  `pg_basebackup {{-h|--host}} {{host}} {{-D|--pgdata}} {{path/to/backup_dir}}`\n- Take a backup with progress shown:\n  `pg_basebackup {{-h|--host}} {{host}} {{-D|--pgdata}} {{path/to/backup_dir}} {{-P|--progress}}`\n- Create a compressed backup (`gzip`) in tar format:\n  `pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-F|--format}} {{t|tar}} {{-z|--gzip}}`\n- Create an incremental backup using a previous manifest file:\n  `pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-i|--incremental}} {{path/to/old_manifest}}`\n- Write a recovery configuration for setting up a standby:\n  `pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-R|--write-recovery-conf}}`\n- Relocate a tablespace during backup:\n  `pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-T|--tablespace-mapping}} {{path/to/old_tablespace}}={{path/to/new_tablespace}}`\n- Limit transfer rate to reduce server load:\n  `pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-r|--max-rate}} {{100M}}`\n- Stream WAL logs while taking the backup:\n  `pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-X|--wal-method}} stream`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **OPTIONS** (40 subsections)\n- **ENVIRONMENT**\n- **NOTES**\n- **EXAMPLES**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "pg_basebackup",
        "section": "",
        "mode": "man",
        "summary": "pgbasebackup - take a base backup of a PostgreSQL cluster",
        "synopsis": "pgbasebackup [option...]",
        "tldr_summary": "Take a base backup of a running PostgreSQL cluster.",
        "tldr_examples": [
            {
                "description": "Take a base backup from a remote PostgreSQL server",
                "command": "pg_basebackup {{-h|--host}} {{host}} {{-D|--pgdata}} {{path/to/backup_dir}}"
            },
            {
                "description": "Take a backup with progress shown",
                "command": "pg_basebackup {{-h|--host}} {{host}} {{-D|--pgdata}} {{path/to/backup_dir}} {{-P|--progress}}"
            },
            {
                "description": "Create a compressed backup (`gzip`) in tar format",
                "command": "pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-F|--format}} {{t|tar}} {{-z|--gzip}}"
            },
            {
                "description": "Create an incremental backup using a previous manifest file",
                "command": "pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-i|--incremental}} {{path/to/old_manifest}}"
            },
            {
                "description": "Write a recovery configuration for setting up a standby",
                "command": "pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-R|--write-recovery-conf}}"
            },
            {
                "description": "Relocate a tablespace during backup",
                "command": "pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-T|--tablespace-mapping}} {{path/to/old_tablespace}}={{path/to/new_tablespace}}"
            },
            {
                "description": "Limit transfer rate to reduce server load",
                "command": "pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-r|--max-rate}} {{100M}}"
            },
            {
                "description": "Stream WAL logs while taking the backup",
                "command": "pg_basebackup {{-D|--pgdata}} {{path/to/backup_dir}} {{-X|--wal-method}} stream"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "-D",
                "long": null,
                "arg": null,
                "description": "--pgdata=directory Sets the target directory to write the output to. pgbasebackup 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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout. This option is required."
            },
            {
                "flag": "-F",
                "long": null,
                "arg": null,
                "description": "--format=format Selects the format for the output. format can be one of the following: p plain Write the output as plain files, with the same layout as the 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 source server. (See --tablespace-mapping to change that.) This is the default format. t tar Write the output as tar files in the target directory. The main 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 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."
            },
            {
                "flag": "-R",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--write-recovery-conf",
                "arg": null,
                "description": "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 pgbasebackup is using, so that streaming replication will use the same settings later on."
            },
            {
                "flag": "-T",
                "long": null,
                "arg": null,
                "description": "--tablespace-mapping=olddir=newdir 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 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 either path needs to contain an equal sign (=), precede that with a backslash. This option can be specified multiple times for multiple tablespaces. If a tablespace is relocated in this way, the symbolic links inside the main data directory are updated to point to the new location. So the new data directory is ready to be used for a new server instance with all tablespaces in the updated locations. Currently, this option only works with plain output format; it is ignored if tar format is selected. --waldir=waldir Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the pgwal subdirectory of the target directory, but this option can be used to place them elsewhere. waldir must be an absolute path. 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."
            },
            {
                "flag": "-X",
                "long": null,
                "arg": null,
                "description": "--wal-method=method 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 in the target directory without the need to consult the log archive, thus making the output a completely standalone backup. The following methods for collecting the write-ahead logs are supported: n none Don't include write-ahead logs in the backup. f fetch The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's walkeepsize parameter to be set high 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 is used, the write-ahead log files will be included in the base.tar file. s stream 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 is used, the write-ahead log files will be written to a separate file named pgwal.tar (if the server is a version earlier than 10, the file will be named pgxlog.tar). This value is the default."
            },
            {
                "flag": "-z",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--gzip",
                "arg": null,
                "description": "Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix .gz will automatically be added to all tar filenames."
            },
            {
                "flag": "-Z",
                "long": null,
                "arg": null,
                "description": "--compress=level Enables gzip compression of tar file output, and specifies the compression level (0 through 9, 0 being no compression and 9 being best compression). Compression is only available when using the tar format, and the suffix .gz will automatically be added to all tar filenames. The following command-line options control the generation of the backup and the invocation of the program:"
            },
            {
                "flag": "-c",
                "long": null,
                "arg": null,
                "description": "--checkpoint=fast|spread Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3)."
            },
            {
                "flag": "-C",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--create-slot",
                "arg": null,
                "description": "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."
            },
            {
                "flag": "-l",
                "long": null,
                "arg": null,
                "description": "--label=label Sets the label for the backup. If none is specified, a default value of “pgbasebackup base backup” will be used."
            },
            {
                "flag": "-n",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--no-clean",
                "arg": null,
                "description": "By default, when pgbasebackup aborts with an error, it removes any directories it might have created before 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. Note that tablespace directories are not cleaned up either way."
            },
            {
                "flag": "-N",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--no-sync",
                "arg": null,
                "description": "By default, pgbasebackup will wait for all files to be written safely to disk. This option causes pgbasebackup to return without waiting, which is faster, but means that a subsequent operating system crash can leave the base backup corrupt. Generally, this option is useful for testing but should not be used when creating a production installation."
            },
            {
                "flag": "-P",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--progress",
                "arg": null,
                "description": "Enables progress reporting. Turning this on will deliver an approximate progress report during the backup. Since the database may change during the backup, this is only an approximation and may not end at exactly 100%. In particular, when WAL log is included in the backup, the total amount of data cannot be estimated in advance, and in this case the estimated target size will increase once it passes the total estimate without WAL."
            },
            {
                "flag": "-r",
                "long": null,
                "arg": null,
                "description": "--max-rate=rate Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of pgbasebackup 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."
            },
            {
                "flag": "-S",
                "long": null,
                "arg": null,
                "description": "--slot=slotname This option can only be used together with -X 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 a replication slot, the standby should then use the same replication slot name as primaryslotname. 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 option -C is also used. If this option is not specified and the server supports temporary replication slots (version 10 and later), then a temporary replication slot is automatically used for WAL streaming."
            },
            {
                "flag": "-v",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--verbose",
                "arg": null,
                "description": "Enables verbose mode. Will output some extra steps during startup and shutdown, as well as show the exact file name that is currently being processed if progress reporting is also enabled. --manifest-checksums=algorithm Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are NONE, CRC32C, SHA224, SHA256, SHA384, and SHA512. The default is CRC32C. If NONE is selected, the backup manifest will not contain any checksums. Otherwise, it will contain a checksum of each file in the backup using the specified algorithm. In addition, the manifest will always contain a SHA256 checksum of its own contents. The SHA algorithms are significantly more CPU-intensive than CRC32C, so selecting one of them may increase the time required to complete the backup. 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 that is much faster to calculate; it is good at catching errors due to accidental changes but is not resistant to malicious 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. pgverifybackup(1) can be used to check the integrity of a backup against the backup manifest."
            },
            {
                "flag": "",
                "long": "--manifest-force-encode",
                "arg": null,
                "description": "Forces all filenames in the backup manifest to be hex-encoded. If this option is not specified, only non-UTF8 filenames are hex-encoded. This option is mostly intended to test that tools which read a backup manifest file properly handle this case."
            },
            {
                "flag": "",
                "long": "--no-estimate-size",
                "arg": null,
                "description": "Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the backuptotal column in the pgstatprogressbasebackup view always being NULL. Without this option, the backup will start by enumerating the size of the entire database, and then go back and send the actual contents. This may make the backup take slightly longer, and in particular it will take longer before the first data is sent. This option is useful to avoid such estimation time if it's too long. This option is not allowed when using --progress."
            },
            {
                "flag": "",
                "long": "--no-manifest",
                "arg": null,
                "description": "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 pgverifybackup(1). 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."
            },
            {
                "flag": "",
                "long": "--no-slot",
                "arg": null,
                "description": "Prevents the creation of a temporary replication slot for the backup. By default, if log streaming is selected but no slot name is given with the -S 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 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."
            },
            {
                "flag": "",
                "long": "--no-verify-checksums",
                "arg": null,
                "description": "Disables verification of checksums, if they are enabled on the server the base backup is taken from. 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 --no-clean option had been used. Checksum verification failures will also be reported in the pgstatdatabase view. The following command-line options control the connection to the source server:"
            },
            {
                "flag": "-d",
                "long": null,
                "arg": null,
                "description": "--dbname=connstr Specifies parameters used to connect to the server, as a connection string; these will override any conflicting command line options. The option is called --dbname for consistency with other client applications, but because pgbasebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."
            },
            {
                "flag": "-h",
                "long": null,
                "arg": null,
                "description": "--host=host 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 a Unix domain socket. The default is taken from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."
            },
            {
                "flag": "-p",
                "long": null,
                "arg": null,
                "description": "--port=port Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the PGPORT environment variable, if set, or a compiled-in default."
            },
            {
                "flag": "-s",
                "long": null,
                "arg": null,
                "description": "--status-interval=interval 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-based disconnects. The default value is 10 seconds."
            },
            {
                "flag": "-U",
                "long": null,
                "arg": null,
                "description": "--username=username Specifies the user name to connect as."
            },
            {
                "flag": "-w",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--no-password",
                "arg": null,
                "description": "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 batch jobs and scripts where no user is present to enter a password."
            },
            {
                "flag": "-W",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--password",
                "arg": null,
                "description": "Forces pgbasebackup to prompt for a password before connecting to the source server. This option is never essential, since pgbasebackup will automatically prompt for a password if the server demands password authentication. However, pgbasebackup will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. Other options are also available:"
            },
            {
                "flag": "-V",
                "long": null,
                "arg": null,
                "description": ""
            },
            {
                "flag": "",
                "long": "--version",
                "arg": null,
                "description": "Prints the pgbasebackup version and exits. -?"
            },
            {
                "flag": "",
                "long": "--help",
                "arg": null,
                "description": "Shows help about pgbasebackup command line arguments, and exits."
            }
        ],
        "examples": [
            "To create a base backup of the server at mydbserver and store it in the local directory",
            "/usr/local/pgsql/data:",
            "$ pgbasebackup -h mydbserver -D /usr/local/pgsql/data",
            "To create a backup of the local server with one compressed tar file for each tablespace, and",
            "store it in the directory backup, showing a progress report while running:",
            "$ pgbasebackup -D backup -Ft -z -P",
            "To create a backup of a single-tablespace local database and compress this with bzip2:",
            "$ pgbasebackup -D - -Ft -X fetch | bzip2 > backup.tar.bz2",
            "(This command will fail if there are multiple tablespaces in the database.)",
            "To create a backup of a local database where the tablespace in /opt/ts is relocated to",
            "./backup/ts:",
            "$ pgbasebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts"
        ],
        "see_also": [
            {
                "name": "pgdump",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/pgdump/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 43,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 2,
                "subsections": [
                    {
                        "name": "-D",
                        "lines": 10,
                        "flag": "-D"
                    },
                    {
                        "name": "-F",
                        "lines": 24,
                        "flag": "-F"
                    },
                    {
                        "name": "-R",
                        "lines": 1,
                        "flag": "-R"
                    },
                    {
                        "name": "--write-recovery-conf",
                        "lines": 10,
                        "long": "--write-recovery-conf"
                    },
                    {
                        "name": "-T",
                        "lines": 24,
                        "flag": "-T"
                    },
                    {
                        "name": "-X",
                        "lines": 37,
                        "flag": "-X"
                    },
                    {
                        "name": "-z",
                        "lines": 1,
                        "flag": "-z"
                    },
                    {
                        "name": "--gzip",
                        "lines": 4,
                        "long": "--gzip"
                    },
                    {
                        "name": "-Z",
                        "lines": 9,
                        "flag": "-Z"
                    },
                    {
                        "name": "-c",
                        "lines": 3,
                        "flag": "-c"
                    },
                    {
                        "name": "-C",
                        "lines": 1,
                        "flag": "-C"
                    },
                    {
                        "name": "--create-slot",
                        "lines": 3,
                        "long": "--create-slot"
                    },
                    {
                        "name": "-l",
                        "lines": 4,
                        "flag": "-l"
                    },
                    {
                        "name": "-n",
                        "lines": 1,
                        "flag": "-n"
                    },
                    {
                        "name": "--no-clean",
                        "lines": 7,
                        "long": "--no-clean"
                    },
                    {
                        "name": "-N",
                        "lines": 1,
                        "flag": "-N"
                    },
                    {
                        "name": "--no-sync",
                        "lines": 6,
                        "long": "--no-sync"
                    },
                    {
                        "name": "-P",
                        "lines": 1,
                        "flag": "-P"
                    },
                    {
                        "name": "--progress",
                        "lines": 6,
                        "long": "--progress"
                    },
                    {
                        "name": "-r",
                        "lines": 10,
                        "flag": "-r"
                    },
                    {
                        "name": "-S",
                        "lines": 14,
                        "flag": "-S"
                    },
                    {
                        "name": "-v",
                        "lines": 1,
                        "flag": "-v"
                    },
                    {
                        "name": "--verbose",
                        "lines": 26,
                        "long": "--verbose"
                    },
                    {
                        "name": "--manifest-force-encode",
                        "lines": 4,
                        "long": "--manifest-force-encode"
                    },
                    {
                        "name": "--no-estimate-size",
                        "lines": 11,
                        "long": "--no-estimate-size"
                    },
                    {
                        "name": "--no-manifest",
                        "lines": 6,
                        "long": "--no-manifest"
                    },
                    {
                        "name": "--no-slot",
                        "lines": 9,
                        "long": "--no-slot"
                    },
                    {
                        "name": "--no-verify-checksums",
                        "lines": 10,
                        "long": "--no-verify-checksums"
                    },
                    {
                        "name": "-d",
                        "lines": 8,
                        "flag": "-d"
                    },
                    {
                        "name": "-h",
                        "lines": 6,
                        "flag": "-h"
                    },
                    {
                        "name": "-p",
                        "lines": 5,
                        "flag": "-p"
                    },
                    {
                        "name": "-s",
                        "lines": 7,
                        "flag": "-s"
                    },
                    {
                        "name": "-U",
                        "lines": 3,
                        "flag": "-U"
                    },
                    {
                        "name": "-w",
                        "lines": 1,
                        "flag": "-w"
                    },
                    {
                        "name": "--no-password",
                        "lines": 5,
                        "long": "--no-password"
                    },
                    {
                        "name": "-W",
                        "lines": 1,
                        "flag": "-W"
                    },
                    {
                        "name": "--password",
                        "lines": 9,
                        "long": "--password"
                    },
                    {
                        "name": "-V",
                        "lines": 1,
                        "flag": "-V"
                    },
                    {
                        "name": "--version",
                        "lines": 3,
                        "long": "--version"
                    },
                    {
                        "name": "--help",
                        "lines": 2,
                        "long": "--help"
                    }
                ]
            },
            {
                "name": "ENVIRONMENT",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 31,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "pgbasebackup - take a base backup of a PostgreSQL cluster\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "pgbasebackup [option...]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "pgbasebackup is used to take a base backup of a running PostgreSQL database cluster. The\nbackup is taken without affecting other clients of the database, and can be used both for\npoint-in-time recovery (see Section 26.3) and as the starting point for a log-shipping or\nstreaming-replication standby server (see Section 27.2).\n\npgbasebackup makes an exact copy of the database cluster's files, while making sure the\nserver is put into and out of backup mode automatically. Backups are always taken of the\nentire database cluster; it is not possible to back up individual databases or database\nobjects. For selective backups, another tool such as pgdump(1) must be used.\n\nThe backup is made over a regular PostgreSQL connection that uses the replication protocol.\nThe connection must be made with a user ID that has REPLICATION permissions (see\nSection 22.2) or is a superuser, and pghba.conf must permit the replication connection. The\nserver must also be configured with maxwalsenders set high enough to provide at least one\nwalsender for the backup plus one for WAL streaming (if used).\n\nThere can be multiple pgbasebackups running at the same time, but it is usually better from\na performance point of view to take only one backup, and copy the result.\n\npgbasebackup can make a base backup from not only a primary server but also a standby. To\ntake a backup from a standby, set up the standby so that it can accept replication\nconnections (that is, set maxwalsenders and hotstandby, and configure its pghba.conf\nappropriately). You will also need to enable fullpagewrites on the primary.\n\nNote that there are some limitations in taking a backup from a standby:\n\n•   The backup history file is not created in the database cluster backed up.\n\n•   pgbasebackup cannot force the standby to switch to a new WAL file at the end of backup.\nWhen you are using -X none, if write activity on the primary is low, pgbasebackup may\nneed to wait a long time for the last WAL file required for the backup to be switched and\narchived. In this case, it may be useful to run pgswitchwal on the primary in order to\ntrigger an immediate WAL file switch.\n\n•   If the standby is promoted to be primary during backup, the backup fails.\n\n•   All WAL records required for the backup must contain sufficient full-page writes, which\nrequires you to enable fullpagewrites on the primary and not to use a tool like\npgcompresslog as archivecommand to remove full-page writes from WAL files.\n\nWhenever pgbasebackup is taking a base backup, the server's pgstatprogressbasebackup view\nwill report the progress of the backup. See Section 28.4.5 for details.\n",
                "subsections": []
            },
            "OPTIONS": {
                "content": "The following command-line options control the location and format of the output:\n",
                "subsections": [
                    {
                        "name": "-D",
                        "content": "--pgdata=directory\nSets the target directory to write the output to.  pgbasebackup will create this\ndirectory (and any missing parent directories) if it does not exist. If it already\nexists, it must be empty.\n\nWhen the backup is in tar format, the target directory may be specified as - (dash),\ncausing the tar file to be written to stdout.\n\nThis option is required.\n",
                        "flag": "-D"
                    },
                    {
                        "name": "-F",
                        "content": "--format=format\nSelects the format for the output.  format can be one of the following:\n\np\nplain\nWrite the output as plain files, with the same layout as the source server's data\ndirectory and tablespaces. When the cluster has no additional tablespaces, the whole\ndatabase will be placed in the target directory. If the cluster contains additional\ntablespaces, the main data directory will be placed in the target directory, but all\nother tablespaces will be placed in the same absolute path as they have on the source\nserver. (See --tablespace-mapping to change that.)\n\nThis is the default format.\n\nt\ntar\nWrite the output as tar files in the target directory. The main data directory's\ncontents will be written to a file named base.tar, and each other tablespace will be\nwritten to a separate tar file named after that tablespace's OID.\n\nIf the target directory is specified as - (dash), the tar contents will be written to\nstandard output, suitable for piping to (for example) gzip. This is only allowed if\nthe cluster has no additional tablespaces and WAL streaming is not used.\n",
                        "flag": "-F"
                    },
                    {
                        "name": "-R",
                        "content": "",
                        "flag": "-R"
                    },
                    {
                        "name": "--write-recovery-conf",
                        "content": "Creates a standby.signal\n\nfile and appends connection settings to the postgresql.auto.conf file in the target\ndirectory (or within the base archive file when using tar format). This eases setting up\na standby server using the results of the backup.\n\nThe postgresql.auto.conf file will record the connection settings and, if specified, the\nreplication slot that pgbasebackup is using, so that streaming replication will use the\nsame settings later on.\n",
                        "long": "--write-recovery-conf"
                    },
                    {
                        "name": "-T",
                        "content": "--tablespace-mapping=olddir=newdir\nRelocates the tablespace in directory olddir to newdir during the backup. To be\neffective, olddir must exactly match the path specification of the tablespace as it is\ndefined on the source server. (But it is not an error if there is no tablespace in olddir\non the source server.) Meanwhile newdir is a directory in the receiving host's\nfilesystem. As with the main target directory, newdir need not exist already, but if it\ndoes exist it must be empty. Both olddir and newdir must be absolute paths. If either\npath needs to contain an equal sign (=), precede that with a backslash. This option can\nbe specified multiple times for multiple tablespaces.\n\nIf a tablespace is relocated in this way, the symbolic links inside the main data\ndirectory are updated to point to the new location. So the new data directory is ready to\nbe used for a new server instance with all tablespaces in the updated locations.\n\nCurrently, this option only works with plain output format; it is ignored if tar format\nis selected.\n\n--waldir=waldir\nSets the directory to write WAL (write-ahead log) files to. By default WAL files will be\nplaced in the pgwal subdirectory of the target directory, but this option can be used to\nplace them elsewhere.  waldir must be an absolute path. As with the main target\ndirectory, waldir need not exist already, but if it does exist it must be empty. This\noption can only be specified when the backup is in plain format.\n",
                        "flag": "-T"
                    },
                    {
                        "name": "-X",
                        "content": "--wal-method=method\nIncludes the required WAL (write-ahead log) files in the backup. This will include all\nwrite-ahead logs generated during the backup. Unless the method none is specified, it is\npossible to start a postmaster in the target directory without the need to consult the\nlog archive, thus making the output a completely standalone backup.\n\nThe following methods for collecting the write-ahead logs are supported:\n\nn\nnone\nDon't include write-ahead logs in the backup.\n\nf\nfetch\nThe write-ahead log files are collected at the end of the backup. Therefore, it is\nnecessary for the source server's walkeepsize parameter to be set high enough that\nthe required log data is not removed before the end of the backup. If the required\nlog data has been recycled before it's time to transfer it, the backup will fail and\nbe unusable.\n\nWhen tar format is used, the write-ahead log files will be included in the base.tar\nfile.\n\ns\nstream\nStream write-ahead log data while the backup is being taken. This method will open a\nsecond connection to the server and start streaming the write-ahead log in parallel\nwhile running the backup. Therefore, it will require two replication connections not\njust one. As long as the client can keep up with the write-ahead log data, using this\nmethod requires no extra write-ahead logs to be saved on the source server.\n\nWhen tar format is used, the write-ahead log files will be written to a separate file\nnamed pgwal.tar (if the server is a version earlier than 10, the file will be named\npgxlog.tar).\n\nThis value is the default.\n",
                        "flag": "-X"
                    },
                    {
                        "name": "-z",
                        "content": "",
                        "flag": "-z"
                    },
                    {
                        "name": "--gzip",
                        "content": "Enables gzip compression of tar file output, with the default compression level.\nCompression is only available when using the tar format, and the suffix .gz will\nautomatically be added to all tar filenames.\n",
                        "long": "--gzip"
                    },
                    {
                        "name": "-Z",
                        "content": "--compress=level\nEnables gzip compression of tar file output, and specifies the compression level (0\nthrough 9, 0 being no compression and 9 being best compression). Compression is only\navailable when using the tar format, and the suffix .gz will automatically be added to\nall tar filenames.\n\nThe following command-line options control the generation of the backup and the invocation of\nthe program:\n",
                        "flag": "-Z"
                    },
                    {
                        "name": "-c",
                        "content": "--checkpoint=fast|spread\nSets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3).\n",
                        "flag": "-c"
                    },
                    {
                        "name": "-C",
                        "content": "",
                        "flag": "-C"
                    },
                    {
                        "name": "--create-slot",
                        "content": "Specifies that the replication slot named by the --slot option should be created before\nstarting the backup. An error is raised if the slot already exists.\n",
                        "long": "--create-slot"
                    },
                    {
                        "name": "-l",
                        "content": "--label=label\nSets the label for the backup. If none is specified, a default value of “pgbasebackup\nbase backup” will be used.\n",
                        "flag": "-l"
                    },
                    {
                        "name": "-n",
                        "content": "",
                        "flag": "-n"
                    },
                    {
                        "name": "--no-clean",
                        "content": "By default, when pgbasebackup aborts with an error, it removes any directories it might\nhave created before discovering that it cannot finish the job (for example, the target\ndirectory and write-ahead log directory). This option inhibits tidying-up and is thus\nuseful for debugging.\n\nNote that tablespace directories are not cleaned up either way.\n",
                        "long": "--no-clean"
                    },
                    {
                        "name": "-N",
                        "content": "",
                        "flag": "-N"
                    },
                    {
                        "name": "--no-sync",
                        "content": "By default, pgbasebackup will wait for all files to be written safely to disk. This\noption causes pgbasebackup to return without waiting, which is faster, but means that a\nsubsequent operating system crash can leave the base backup corrupt. Generally, this\noption is useful for testing but should not be used when creating a production\ninstallation.\n",
                        "long": "--no-sync"
                    },
                    {
                        "name": "-P",
                        "content": "",
                        "flag": "-P"
                    },
                    {
                        "name": "--progress",
                        "content": "Enables progress reporting. Turning this on will deliver an approximate progress report\nduring the backup. Since the database may change during the backup, this is only an\napproximation and may not end at exactly 100%. In particular, when WAL log is included in\nthe backup, the total amount of data cannot be estimated in advance, and in this case the\nestimated target size will increase once it passes the total estimate without WAL.\n",
                        "long": "--progress"
                    },
                    {
                        "name": "-r",
                        "content": "--max-rate=rate\nSets the maximum transfer rate at which data is collected from the source server. This\ncan be useful to limit the impact of pgbasebackup on the server. Values are in kilobytes\nper second. Use a suffix of M to indicate megabytes per second. A suffix of k is also\naccepted, and has no effect. Valid values are between 32 kilobytes per second and 1024\nmegabytes per second.\n\nThis option always affects transfer of the data directory. Transfer of WAL files is only\naffected if the collection method is fetch.\n",
                        "flag": "-r"
                    },
                    {
                        "name": "-S",
                        "content": "--slot=slotname\nThis option can only be used together with -X stream. It causes WAL streaming to use the\nspecified replication slot. If the base backup is intended to be used as a\nstreaming-replication standby using a replication slot, the standby should then use the\nsame replication slot name as primaryslotname. This ensures that the primary server\ndoes not remove any necessary WAL data in the time between the end of the base backup and\nthe start of streaming replication on the new standby.\n\nThe specified replication slot has to exist unless the option -C is also used.\n\nIf this option is not specified and the server supports temporary replication slots\n(version 10 and later), then a temporary replication slot is automatically used for WAL\nstreaming.\n",
                        "flag": "-S"
                    },
                    {
                        "name": "-v",
                        "content": "",
                        "flag": "-v"
                    },
                    {
                        "name": "--verbose",
                        "content": "Enables verbose mode. Will output some extra steps during startup and shutdown, as well\nas show the exact file name that is currently being processed if progress reporting is\nalso enabled.\n\n--manifest-checksums=algorithm\nSpecifies the checksum algorithm that should be applied to each file included in the\nbackup manifest. Currently, the available algorithms are NONE, CRC32C, SHA224, SHA256,\nSHA384, and SHA512. The default is CRC32C.\n\nIf NONE is selected, the backup manifest will not contain any checksums. Otherwise, it\nwill contain a checksum of each file in the backup using the specified algorithm. In\naddition, the manifest will always contain a SHA256 checksum of its own contents. The SHA\nalgorithms are significantly more CPU-intensive than CRC32C, so selecting one of them may\nincrease the time required to complete the backup.\n\nUsing a SHA hash function provides a cryptographically secure digest of each file for\nusers who wish to verify that the backup has not been tampered with, while the CRC32C\nalgorithm provides a checksum that is much faster to calculate; it is good at catching\nerrors due to accidental changes but is not resistant to malicious modifications. Note\nthat, to be useful against an adversary who has access to the backup, the backup manifest\nwould need to be stored securely elsewhere or otherwise verified not to have been\nmodified since the backup was taken.\n\npgverifybackup(1) can be used to check the integrity of a backup against the backup\nmanifest.\n",
                        "long": "--verbose"
                    },
                    {
                        "name": "--manifest-force-encode",
                        "content": "Forces all filenames in the backup manifest to be hex-encoded. If this option is not\nspecified, only non-UTF8 filenames are hex-encoded. This option is mostly intended to\ntest that tools which read a backup manifest file properly handle this case.\n",
                        "long": "--manifest-force-encode"
                    },
                    {
                        "name": "--no-estimate-size",
                        "content": "Prevents the server from estimating the total amount of backup data that will be\nstreamed, resulting in the backuptotal column in the pgstatprogressbasebackup view\nalways being NULL.\n\nWithout this option, the backup will start by enumerating the size of the entire\ndatabase, and then go back and send the actual contents. This may make the backup take\nslightly longer, and in particular it will take longer before the first data is sent.\nThis option is useful to avoid such estimation time if it's too long.\n\nThis option is not allowed when using --progress.\n",
                        "long": "--no-estimate-size"
                    },
                    {
                        "name": "--no-manifest",
                        "content": "Disables generation of a backup manifest. If this option is not specified, the server\nwill generate and send a backup manifest which can be verified using pgverifybackup(1).\nThe manifest is a list of every file present in the backup with the exception of any WAL\nfiles that may be included. It also stores the size, last modification time, and an\noptional checksum for each file.\n",
                        "long": "--no-manifest"
                    },
                    {
                        "name": "--no-slot",
                        "content": "Prevents the creation of a temporary replication slot for the backup.\n\nBy default, if log streaming is selected but no slot name is given with the -S option,\nthen a temporary replication slot is created (if supported by the source server).\n\nThe main purpose of this option is to allow taking a base backup when the server has no\nfree replication slots. Using a replication slot is almost always preferred, because it\nprevents needed WAL from being removed by the server during the backup.\n",
                        "long": "--no-slot"
                    },
                    {
                        "name": "--no-verify-checksums",
                        "content": "Disables verification of checksums, if they are enabled on the server the base backup is\ntaken from.\n\nBy default, checksums are verified and checksum failures will result in a non-zero exit\nstatus. However, the base backup will not be removed in such a case, as if the --no-clean\noption had been used. Checksum verification failures will also be reported in the\npgstatdatabase view.\n\nThe following command-line options control the connection to the source server:\n",
                        "long": "--no-verify-checksums"
                    },
                    {
                        "name": "-d",
                        "content": "--dbname=connstr\nSpecifies parameters used to connect to the server, as a connection string; these will\noverride any conflicting command line options.\n\nThe option is called --dbname for consistency with other client applications, but because\npgbasebackup doesn't connect to any particular database in the cluster, any database\nname in the connection string will be ignored.\n",
                        "flag": "-d"
                    },
                    {
                        "name": "-h",
                        "content": "--host=host\nSpecifies the host name of the machine on which the server is running. If the value\nbegins with a slash, it is used as the directory for a Unix domain socket. The default is\ntaken from the PGHOST environment variable, if set, else a Unix domain socket connection\nis attempted.\n",
                        "flag": "-h"
                    },
                    {
                        "name": "-p",
                        "content": "--port=port\nSpecifies the TCP port or local Unix domain socket file extension on which the server is\nlistening for connections. Defaults to the PGPORT environment variable, if set, or a\ncompiled-in default.\n",
                        "flag": "-p"
                    },
                    {
                        "name": "-s",
                        "content": "--status-interval=interval\nSpecifies the number of seconds between status packets sent back to the source server.\nSmaller values allow more accurate monitoring of backup progress from the server. A value\nof zero disables periodic status updates completely, although an update will still be\nsent when requested by the server, to avoid timeout-based disconnects. The default value\nis 10 seconds.\n",
                        "flag": "-s"
                    },
                    {
                        "name": "-U",
                        "content": "--username=username\nSpecifies the user name to connect as.\n",
                        "flag": "-U"
                    },
                    {
                        "name": "-w",
                        "content": "",
                        "flag": "-w"
                    },
                    {
                        "name": "--no-password",
                        "content": "Prevents issuing a password prompt. If the server requires password authentication and a\npassword is not available by other means such as a .pgpass file, the connection attempt\nwill fail. This option can be useful in batch jobs and scripts where no user is present\nto enter a password.\n",
                        "long": "--no-password"
                    },
                    {
                        "name": "-W",
                        "content": "",
                        "flag": "-W"
                    },
                    {
                        "name": "--password",
                        "content": "Forces pgbasebackup to prompt for a password before connecting to the source server.\n\nThis option is never essential, since pgbasebackup will automatically prompt for a\npassword if the server demands password authentication. However, pgbasebackup will waste\na connection attempt finding out that the server wants a password. In some cases it is\nworth typing -W to avoid the extra connection attempt.\n\nOther options are also available:\n",
                        "long": "--password"
                    },
                    {
                        "name": "-V",
                        "content": "",
                        "flag": "-V"
                    },
                    {
                        "name": "--version",
                        "content": "Prints the pgbasebackup version and exits.\n\n-?",
                        "long": "--version"
                    },
                    {
                        "name": "--help",
                        "content": "Shows help about pgbasebackup command line arguments, and exits.\n",
                        "long": "--help"
                    }
                ]
            },
            "ENVIRONMENT": {
                "content": "This utility, like most other PostgreSQL utilities, uses the environment variables supported\nby libpq (see Section 34.15).\n\nThe environment variable PGCOLOR specifies whether to use color in diagnostic messages.\nPossible values are always, auto and never.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "At the beginning of the backup, a checkpoint needs to be performed on the source server. This\ncan take some time (especially if the option --checkpoint=fast is not used), during which\npgbasebackup will appear to be idle.\n\nThe backup will include all files in the data directory and tablespaces, including the\nconfiguration files and any additional files placed in the directory by third parties, except\ncertain temporary files managed by PostgreSQL. But only regular files and directories are\ncopied, except that symbolic links used for tablespaces are preserved. Symbolic links\npointing to certain directories known to PostgreSQL are copied as empty directories. Other\nsymbolic links and special device files are skipped. See Section 53.4 for the precise\ndetails.\n\nIn plain format, tablespaces will be backed up to the same path they have on the source\nserver, unless the option --tablespace-mapping is used. Without this option, running a plain\nformat base backup on the same host as the server will not work if tablespaces are in use,\nbecause the backup would have to be written to the same directory locations as the original\ntablespaces.\n\nWhen tar format is used, it is the user's responsibility to unpack each tar file before\nstarting a PostgreSQL server that uses the data. If there are additional tablespaces, the tar\nfiles for them need to be unpacked in the correct locations. In this case the symbolic links\nfor those tablespaces will be created by the server according to the contents of the\ntablespacemap file that is included in the base.tar file.\n\npgbasebackup works with servers of the same or an older major version, down to 9.1. However,\nWAL streaming mode (-X stream) only works with server version 9.3 and later, and tar format\n(--format=tar) only works with server version 9.5 and later.\n\npgbasebackup will preserve group permissions for data files if group permissions are enabled\non the source cluster.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "To create a base backup of the server at mydbserver and store it in the local directory\n/usr/local/pgsql/data:\n\n$ pgbasebackup -h mydbserver -D /usr/local/pgsql/data\n\nTo create a backup of the local server with one compressed tar file for each tablespace, and\nstore it in the directory backup, showing a progress report while running:\n\n$ pgbasebackup -D backup -Ft -z -P\n\nTo create a backup of a single-tablespace local database and compress this with bzip2:\n\n$ pgbasebackup -D - -Ft -X fetch | bzip2 > backup.tar.bz2\n\n(This command will fail if there are multiple tablespaces in the database.)\n\nTo create a backup of a local database where the tablespace in /opt/ts is relocated to\n./backup/ts:\n\n$ pgbasebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "pgdump(1), Section 28.4.5\n\n\n\nPostgreSQL 14.23                                2026                                PGBASEBACKUP(1)",
                "subsections": []
            }
        }
    }
}