{"kind": "tool", "major": "18", "item": {"slug": "pg-basebackup", "name": "pg_basebackup", "name_zh": "", "category": "Client applications", "summary": "pg_basebackup \u2014 take a base backup of a PostgreSQL cluster", "aliases": ["pg_basebackup"], "content_hash": "302d5a82cb86d2c4839b7b05bdcc88d2f2057edbdaadca3380e19b05448da725", "versions": {"10": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "10.23"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "26"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "Write a minimal recovery.conf in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The recovery.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "This option can only be used together with -X stream . It causes the 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 recovery.conf . 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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Relocate 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.) 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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-Z level --compress= level"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 ).", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-c fast|spread --checkpoint= fast|spread"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "User name to connect as.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "Never issue 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.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Force pg_basebackup to prompt for a password before connecting to a database.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Print the pg_basebackup version and exit.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Show help about pg_basebackup command line arguments, and exit.", "signature": {"url": "/docs/10/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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. When the backup is in tar mode, and the directory is specified as - (dash), the tar file will be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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 current 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 will be written to a file named base.tar , and all other tablespaces will be named after the tablespace 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 the cluster has no additional tablespaces and WAL streaming is not used."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-R", "--write-recovery-conf"], "summary": "Write a minimal recovery.conf in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The recovery.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on.", "signature": "-R --write-recovery-conf", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Write a minimal recovery.conf in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The recovery.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "This option can only be used together with -X stream . It causes the 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 recovery.conf . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/10/app-pgbasebackup.html", "description": "This option can only be used together with -X stream . It causes the 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 recovery.conf . 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. 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."}, {"names": ["--no-slot"], "summary": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.", "signature": "--no-slot", "source_url": "/docs/10/app-pgbasebackup.html", "description": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server. Temporary replication slots are created by default if no slot name is given with the option -S when using log streaming. 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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "Relocate 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.) 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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Relocate 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.) 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. 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."}, {"names": ["--waldir= waldir"], "summary": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.", "signature": "--waldir= waldir", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode."}, {"names": ["-X method", "--wal-method= method"], "summary": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup. The following methods for collecting the write-ahead logs are supported: n none Don't include write-ahead log in the backup. f fetch The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the wal_keep_segments 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. When tar format mode is used, the write-ahead log files will be written to the base.tar file. s 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 max_wal_senders 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. When tar format mode 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 ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/10/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "--compress= level"], "summary": "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.", "signature": "-Z level --compress= level", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "summary": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 ).", "signature": "-c fast|spread --checkpoint= fast|spread", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 )."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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.", "signature": "-n --no-clean", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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. Note that tablespace directories are not cleaned up either way."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/10/app-pgbasebackup.html", "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. When this is enabled, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/10/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/10/app-pgbasebackup.html", "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."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "summary": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted.", "signature": "-h host --host= host", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/10/app-pgbasebackup.html", "description": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds."}, {"names": ["-U username", "--username= username"], "summary": "User name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/10/app-pgbasebackup.html", "description": "User name to connect as."}, {"names": ["-w", "--no-password"], "summary": "Never issue 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.", "signature": "-w --no-password", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Never issue 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."}, {"names": ["-W", "--password"], "summary": "Force pg_basebackup to prompt for a password before connecting to a database.", "signature": "-W --password", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Force pg_basebackup to prompt for a password before connecting to a database. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Print the pg_basebackup version and exit.", "signature": "-V --version", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Print the pg_basebackup version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pg_basebackup command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/10/app-pgbasebackup.html", "description": "Show help about pg_basebackup command line arguments, and exit."}], "related": [{"url": "/wiki/conn/?v=10", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "label": "10.23", "major": "10", "channel": "historical", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/10/postgresql-10-A4.pdf", "bytes": 12631706, "pages": 2591, "sha256": "34497ab9efb45c5bdf1bd11b9016b5451354feb462fa029cf74557a5fa5fbbc1", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/10/postgresql-10-US.pdf", "bytes": 12531684, "pages": 2724, "sha256": "429cc7133ddf4f97c560aa466dc9caea4b718721a8321e293357037cf0af4733", "built_at": "2026-09-26"}}, "tree": "10", "index": "index.html", "major": "10", "pages": 1085, "release": "10.23", "source_url": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "svg_assets": 0, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9"}, "revision": "f9301feba91e2e2566038a36b8cee0e4402db68989538f88670fddd20b1f78ea", "evidence_kind": "English manual and source declarations", "source_sha256": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9"}, "sources": [{"url": "/docs/10/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "10.23 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "78d415a7754d35812c98554f42b369c4da6bfd3d369cb250a4d5b5c9f70ab0f1"}, {"url": "/docs/10/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "e4330732b6acd6c025a1fbdce45574b23d964de847a1b849ea88b98ab628d2e2"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\">pg_basebackup</span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.9.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take base backups of a running <span class=\"productname\">PostgreSQL</span> database cluster. These are taken without affecting other clients to the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/10/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log shipping or streaming replication standby servers (see <a class=\"xref\" href=\"/docs/10/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> makes a binary copy of the database cluster files, while making sure the system is put in 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 <a class=\"xref\" href=\"/docs/10/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\">pg_dump</span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection, and uses the replication protocol. The connection must be made with a superuser or a user having <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/10/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>), and <code class=\"filename\">pg_hba.conf</code> must explicitly permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/10/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to leave at least one session available for the backup and one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s running at the same time, but it is better from a performance point of view to take only one backup, and copy the result.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from not only the master but also the standby. To take a backup from the standby, set up the standby so that it can accept replication connections (that is, set <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/10/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure <a class=\"link\" href=\"/docs/10/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\">host-based authentication</a>). You will also need to enable <a class=\"xref\" href=\"/docs/10/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the master.</p>\n<p>Note that there are some limitations in an online backup from the standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to the master during online backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the master and not to use a tool like <span class=\"application\">pg_compresslog</span> as <code class=\"varname\">archive_command</code> to remove full-page writes from WAL files.</p>\n</li>\n</ul>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Directory to write the output to. <span class=\"application\">pg_basebackup</span> 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.</p>\n<p>When the backup is in tar mode, and the directory is specified as <code class=\"literal\">-</code> (dash), the tar file will be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>Write the output as plain files, with the same layout as the current 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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory will be written to a file named <code class=\"filename\">base.tar</code>, and all other tablespaces will be named after the tablespace OID.</p>\n<p>If the value <code class=\"literal\">-</code> (dash) is specified as target directory, the tar contents will be written to standard output, suitable for piping to for example <span class=\"productname\">gzip</span>. This is only possible if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>The maximum transfer rate of data transferred from the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>The purpose is to limit the impact of <span class=\"application\">pg_basebackup</span> on the running server.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Write a minimal <code class=\"filename\">recovery.conf</code> in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The <code class=\"filename\">recovery.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that the streaming replication will use the same settings later on.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. It causes the 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 <code class=\"filename\">recovery.conf</code>. 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.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.</p>\n<p>Temporary replication slots are created by default if no slot name is given with the option <code class=\"option\">-S</code> when using log streaming.</p>\n<p>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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocate the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> contained in the backup.) Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If a path happens to contain a <code class=\"literal\">=</code> sign, escape it with a backslash. This option can be specified multiple times for multiple tablespaces. See examples below.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Specifies the location for the write-ahead log directory. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>Includes the required write-ahead log files (WAL files) in the backup. This will include all write-ahead logs generated during the backup. Unless the method <code class=\"literal\">none</code> is specified, it is possible to start a postmaster directly in the extracted directory without the need to consult the log archive, thus making this a completely standalone backup.</p>\n<p>The following methods for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead log in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the <a class=\"xref\" href=\"/docs/10/runtime-config-replication.html#GUC-WAL-KEEP-SEGMENTS\">wal_keep_segments</a> 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.</p>\n<p>When tar format mode is used, the write-ahead log files will be written to the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/10/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> 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.</p>\n<p>When tar format mode is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the running of the program.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c <em class=\"replaceable\"><code>fast|spread</code></em></code><br></span><span class=\"term\"><code class=\"option\">--checkpoint=<em class=\"replaceable\"><code>fast|spread</code></em></code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (default) (see <a class=\"xref\" href=\"/docs/10/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.3.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.3</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n<p>When this is enabled, 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the database connection parameters.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/10/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"33.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>The option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, database name in the connection string will be ignored.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 from the <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>User name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Force <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to a database.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pg_basebackup</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pg_basebackup</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/10/libpq-envars.html\" title=\"33.14.\u00a0Environment Variables\">Section\u00a033.14</a>).</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.8\">\n<h2>Notes</h2>\n<p>At the beginning of the backup, a checkpoint needs to be written on the server the backup is taken from. Especially if the option <code class=\"literal\">--checkpoint=fast</code> is not used, this can take some time during which <span class=\"application\">pg_basebackup</span> will be appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/10/protocol-replication.html\" title=\"52.4.\u00a0Streaming Replication Protocol\">Section\u00a052.4</a> for the precise details.</p>\n<p>Tablespaces will in plain format by default be backed up to the same path they have on the server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, and tar format mode (<code class=\"literal\">--format=tar</code>) of the current version only works with server version 9.5 or later.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre></div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.10\">\n<h2>See Also</h2>\n<span class=\"simplelist\"><a class=\"xref\" href=\"/docs/10/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\">pg_dump</span></a></span></div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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. When the backup is in tar mode, and the directory is specified as - (dash), the tar file will be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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 current 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 will be written to a file named base.tar , and all other tablespaces will be named after the tablespace 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 the cluster has no additional tablespaces and WAL streaming is not used."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "description": "Write a minimal recovery.conf in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The recovery.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "This option can only be used together with -X stream . It causes the 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 recovery.conf . 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. 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "description": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server. Temporary replication slots are created by default if no slot name is given with the option -S when using log streaming. 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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "Relocate 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.) 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. 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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup. The following methods for collecting the write-ahead logs are supported: n none Don't include write-ahead log in the backup. f fetch The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the wal_keep_segments 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. When tar format mode is used, the write-ahead log files will be written to the base.tar file. s 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 max_wal_senders 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. When tar format mode 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 ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "--compress= level"], "signature": "-Z level --compress= level", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "signature": "-c fast|spread --checkpoint= fast|spread", "description": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 )."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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. Note that tablespace directories are not cleaned up either way."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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. When this is enabled, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "User name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "description": "Never issue 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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Force pg_basebackup to prompt for a password before connecting to a database. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pg_basebackup version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pg_basebackup command line arguments, and exit."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "a58cdfebc241478acd58f0ca9cd95c9af3b5abb5a8d9ef8e1b16670207b0acb9"}, "11": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "11.22"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "28"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "Write a minimal recovery.conf in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The recovery.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Relocate 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.) 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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-Z level --compress= level"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 ).", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-c fast|spread --checkpoint= fast|spread"}}, {"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "This option can only be used together with -X stream . It causes the 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 recovery.conf . 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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "User name to connect as.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "Never issue 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.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Force pg_basebackup to prompt for a password before connecting to a database.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Print the pg_basebackup version and exit.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Show help about pg_basebackup command line arguments, and exit.", "signature": {"url": "/docs/11/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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. When the backup is in tar mode, and the directory is specified as - (dash), the tar file will be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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 current 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 will be written to a file named base.tar , and all other tablespaces will be named after the tablespace 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 the cluster has no additional tablespaces and WAL streaming is not used."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-R", "--write-recovery-conf"], "summary": "Write a minimal recovery.conf in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The recovery.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on.", "signature": "-R --write-recovery-conf", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Write a minimal recovery.conf in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The recovery.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "Relocate 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.) 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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Relocate 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.) 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. 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."}, {"names": ["--waldir= waldir"], "summary": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.", "signature": "--waldir= waldir", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode."}, {"names": ["-X method", "--wal-method= method"], "summary": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup. The following methods for collecting the write-ahead logs are supported: n none Don't include write-ahead log in the backup. f fetch The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the wal_keep_segments 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. When tar format mode is used, the write-ahead log files will be written to the base.tar file. s 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 max_wal_senders 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. When tar format mode 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 ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/11/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "--compress= level"], "summary": "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.", "signature": "-Z level --compress= level", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "summary": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 ).", "signature": "-c fast|spread --checkpoint= fast|spread", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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.", "signature": "-n --no-clean", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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. Note that tablespace directories are not cleaned up either way."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/11/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/11/app-pgbasebackup.html", "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. When this is enabled, 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."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "This option can only be used together with -X stream . It causes the 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 recovery.conf . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/11/app-pgbasebackup.html", "description": "This option can only be used together with -X stream . It causes the 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 recovery.conf . 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. 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."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/11/app-pgbasebackup.html", "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."}, {"names": ["--no-slot"], "summary": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.", "signature": "--no-slot", "source_url": "/docs/11/app-pgbasebackup.html", "description": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server. Temporary replication slots are created by default if no slot name is given with the option -S when using log streaming. 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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/11/app-pgbasebackup.html", "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."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "summary": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted.", "signature": "-h host --host= host", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/11/app-pgbasebackup.html", "description": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds."}, {"names": ["-U username", "--username= username"], "summary": "User name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/11/app-pgbasebackup.html", "description": "User name to connect as."}, {"names": ["-w", "--no-password"], "summary": "Never issue 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.", "signature": "-w --no-password", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Never issue 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."}, {"names": ["-W", "--password"], "summary": "Force pg_basebackup to prompt for a password before connecting to a database.", "signature": "-W --password", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Force pg_basebackup to prompt for a password before connecting to a database. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Print the pg_basebackup version and exit.", "signature": "-V --version", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Print the pg_basebackup version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pg_basebackup command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/11/app-pgbasebackup.html", "description": "Show help about pg_basebackup command line arguments, and exit."}], "related": [{"url": "/wiki/conn/?v=11", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "label": "11.22", "major": "11", "channel": "historical", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/11/postgresql-11-A4.pdf", "bytes": 13057499, "pages": 2732, "sha256": "41d75855e610d0d9b8802b87dc5b080bef8d7e91c7cf69401fbf8d3cf801b4b5", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/11/postgresql-11-US.pdf", "bytes": 12961189, "pages": 2883, "sha256": "6a8899ef36935a5b7ed2b436207564a567a4ef1eb1c2200195876b8de4d4fa30", "built_at": "2026-09-26"}}, "tree": "11", "index": "index.html", "major": "11", "pages": 1125, "release": "11.22", "source_url": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "svg_assets": 0, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0"}, "revision": "53315ddaf3b3f9e6669fd1edc096bbb2cd4a65ea3e836c89e542b43af9ba3a7f", "evidence_kind": "English manual and source declarations", "source_sha256": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0"}, "sources": [{"url": "/docs/11/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "11.22 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "a1fe2815bbf7e45e5898613140825a53f784037cbb6dcf9459c8a18b558b0df3"}, {"url": "/docs/11/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "3a30e696058b118a55cc42892c39671d9bae86f77e1024d5ebcc4688ad9ab4c3"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\">pg_basebackup</span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.9.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take base backups of a running <span class=\"productname\">PostgreSQL</span> database cluster. These are taken without affecting other clients to the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/11/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log shipping or streaming replication standby servers (see <a class=\"xref\" href=\"/docs/11/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> makes a binary copy of the database cluster files, while making sure the system is put in 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 <a class=\"xref\" href=\"/docs/11/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\">pg_dump</span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection, and uses the replication protocol. The connection must be made with a superuser or a user having <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/11/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>), and <code class=\"filename\">pg_hba.conf</code> must explicitly permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/11/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to leave at least one session available for the backup and one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s running at the same time, but it is better from a performance point of view to take only one backup, and copy the result.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from not only the master but also the standby. To take a backup from the standby, set up the standby so that it can accept replication connections (that is, set <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/11/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure <a class=\"link\" href=\"/docs/11/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\">host-based authentication</a>). You will also need to enable <a class=\"xref\" href=\"/docs/11/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the master.</p>\n<p>Note that there are some limitations in an online backup from the standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to the master during online backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the master and not to use a tool like <span class=\"application\">pg_compresslog</span> as <code class=\"varname\">archive_command</code> to remove full-page writes from WAL files.</p>\n</li>\n</ul>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Directory to write the output to. <span class=\"application\">pg_basebackup</span> 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.</p>\n<p>When the backup is in tar mode, and the directory is specified as <code class=\"literal\">-</code> (dash), the tar file will be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>Write the output as plain files, with the same layout as the current 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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory will be written to a file named <code class=\"filename\">base.tar</code>, and all other tablespaces will be named after the tablespace OID.</p>\n<p>If the value <code class=\"literal\">-</code> (dash) is specified as target directory, the tar contents will be written to standard output, suitable for piping to for example <span class=\"productname\">gzip</span>. This is only possible if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>The maximum transfer rate of data transferred from the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>The purpose is to limit the impact of <span class=\"application\">pg_basebackup</span> on the running server.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Write a minimal <code class=\"filename\">recovery.conf</code> in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The <code class=\"filename\">recovery.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that the streaming replication will use the same settings later on.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocate the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> contained in the backup.) Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If a path happens to contain a <code class=\"literal\">=</code> sign, escape it with a backslash. This option can be specified multiple times for multiple tablespaces. See examples below.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Specifies the location for the write-ahead log directory. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>Includes the required write-ahead log files (WAL files) in the backup. This will include all write-ahead logs generated during the backup. Unless the method <code class=\"literal\">none</code> is specified, it is possible to start a postmaster directly in the extracted directory without the need to consult the log archive, thus making this a completely standalone backup.</p>\n<p>The following methods for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead log in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the <a class=\"xref\" href=\"/docs/11/runtime-config-replication.html#GUC-WAL-KEEP-SEGMENTS\">wal_keep_segments</a> 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.</p>\n<p>When tar format mode is used, the write-ahead log files will be written to the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/11/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> 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.</p>\n<p>When tar format mode is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the running of the program.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c <em class=\"replaceable\"><code>fast|spread</code></em></code><br></span><span class=\"term\"><code class=\"option\">--checkpoint=<em class=\"replaceable\"><code>fast|spread</code></em></code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (default) (see <a class=\"xref\" href=\"/docs/11/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.3.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.3</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>This option causes creation of a replication slot named by the <code class=\"literal\">--slot</code> option before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n<p>When this is enabled, 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. It causes the 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 <code class=\"filename\">recovery.conf</code>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.</p>\n<p>Temporary replication slots are created by default if no slot name is given with the option <code class=\"option\">-S</code> when using log streaming.</p>\n<p>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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the database connection parameters.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/11/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"34.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>The option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, database name in the connection string will be ignored.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 from the <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>User name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Force <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to a database.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pg_basebackup</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pg_basebackup</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/11/libpq-envars.html\" title=\"34.14.\u00a0Environment Variables\">Section\u00a034.14</a>).</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.8\">\n<h2>Notes</h2>\n<p>At the beginning of the backup, a checkpoint needs to be written on the server the backup is taken from. Especially if the option <code class=\"literal\">--checkpoint=fast</code> is not used, this can take some time during which <span class=\"application\">pg_basebackup</span> will be appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/11/protocol-replication.html\" title=\"53.4.\u00a0Streaming Replication Protocol\">Section\u00a053.4</a> for the precise details.</p>\n<p>Tablespaces will in plain format by default be backed up to the same path they have on the server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, and tar format mode (<code class=\"literal\">--format=tar</code>) of the current version only works with server version 9.5 or later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions in both the <code class=\"literal\">plain</code> and <code class=\"literal\">tar</code> formats if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/11/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\">pg_dump</span></a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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. When the backup is in tar mode, and the directory is specified as - (dash), the tar file will be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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 current 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 will be written to a file named base.tar , and all other tablespaces will be named after the tablespace 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 the cluster has no additional tablespaces and WAL streaming is not used."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "description": "Write a minimal recovery.conf in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The recovery.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "Relocate 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.) 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. 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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup. The following methods for collecting the write-ahead logs are supported: n none Don't include write-ahead log in the backup. f fetch The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the wal_keep_segments 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. When tar format mode is used, the write-ahead log files will be written to the base.tar file. s 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 max_wal_senders 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. When tar format mode 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 ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "--compress= level"], "signature": "-Z level --compress= level", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "signature": "-c fast|spread --checkpoint= fast|spread", "description": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "description": "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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. Note that tablespace directories are not cleaned up either way."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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. When this is enabled, 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."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "This option can only be used together with -X stream . It causes the 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 recovery.conf . 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. 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."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--no-slot"], "signature": "--no-slot", "description": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server. Temporary replication slots are created by default if no slot name is given with the option -S when using log streaming. 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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "User name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "description": "Never issue 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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Force pg_basebackup to prompt for a password before connecting to a database. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pg_basebackup version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pg_basebackup command line arguments, and exit."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "1403f5873b409f8efceee8a869f9b98dde4f16f6d573555a3946a2770fac07fd"}, "12": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "12.22"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "28"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "Create standby.signal file 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. The postgresql.auto.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Relocate 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.) 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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-Z level --compress= level"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 ).", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-c fast|spread --checkpoint= fast|spread"}}, {"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "This option can only be used together with -X stream . It causes the 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 primary_slot_name . 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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "User name to connect as.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "Never issue 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.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Force pg_basebackup to prompt for a password before connecting to a database.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Print the pg_basebackup version and exit.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Show help about pg_basebackup command line arguments, and exit.", "signature": {"url": "/docs/12/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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. When the backup is in tar mode, and the directory is specified as - (dash), the tar file will be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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 current 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 will be written to a file named base.tar , and all other tablespaces will be named after the tablespace 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 the cluster has no additional tablespaces and WAL streaming is not used."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-R", "--write-recovery-conf"], "summary": "Create standby.signal file 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. The postgresql.auto.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on.", "signature": "-R --write-recovery-conf", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Create standby.signal file 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. The postgresql.auto.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "Relocate 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.) 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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Relocate 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.) 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. 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."}, {"names": ["--waldir= waldir"], "summary": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.", "signature": "--waldir= waldir", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode."}, {"names": ["-X method", "--wal-method= method"], "summary": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup. The following methods for collecting the write-ahead logs are supported: n none Don't include write-ahead log in the backup. f fetch The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the wal_keep_segments 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. When tar format mode is used, the write-ahead log files will be written to the base.tar file. s 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 max_wal_senders 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. When tar format mode 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 ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/12/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "--compress= level"], "summary": "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.", "signature": "-Z level --compress= level", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "summary": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 ).", "signature": "-c fast|spread --checkpoint= fast|spread", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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.", "signature": "-n --no-clean", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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. Note that tablespace directories are not cleaned up either way."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/12/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/12/app-pgbasebackup.html", "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. When this is enabled, 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."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "This option can only be used together with -X stream . It causes the 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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/12/app-pgbasebackup.html", "description": "This option can only be used together with -X stream . It causes the 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 primary_slot_name . 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. 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."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/12/app-pgbasebackup.html", "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."}, {"names": ["--no-slot"], "summary": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.", "signature": "--no-slot", "source_url": "/docs/12/app-pgbasebackup.html", "description": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server. Temporary replication slots are created by default if no slot name is given with the option -S when using log streaming. 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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/12/app-pgbasebackup.html", "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 verifications failures will also be reported in the pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "summary": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted.", "signature": "-h host --host= host", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/12/app-pgbasebackup.html", "description": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds."}, {"names": ["-U username", "--username= username"], "summary": "User name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/12/app-pgbasebackup.html", "description": "User name to connect as."}, {"names": ["-w", "--no-password"], "summary": "Never issue 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.", "signature": "-w --no-password", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Never issue 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."}, {"names": ["-W", "--password"], "summary": "Force pg_basebackup to prompt for a password before connecting to a database.", "signature": "-W --password", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Force pg_basebackup to prompt for a password before connecting to a database. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Print the pg_basebackup version and exit.", "signature": "-V --version", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Print the pg_basebackup version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pg_basebackup command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/12/app-pgbasebackup.html", "description": "Show help about pg_basebackup command line arguments, and exit."}], "related": [{"url": "/wiki/conn/?v=12", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "label": "12.22", "major": "12", "channel": "historical", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/12/postgresql-12-A4.pdf", "bytes": 13424351, "pages": 2803, "sha256": "7422cf53fd1939e7a3d2925231a88b0330e468afa5393627cac0ff86158a0621", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/12/postgresql-12-US.pdf", "bytes": 13322565, "pages": 2958, "sha256": "51f3b04e72907fc38512685946223452ea65f84419c60c66241dfa3396035e77", "built_at": "2026-09-26"}}, "tree": "12", "index": "index.html", "major": "12", "pages": 1131, "release": "12.22", "source_url": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "svg_assets": 2, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b"}, "revision": "7a827e97cbfacd7febff75f34443e2043e40723de5b6d8c9d81a9430b65a37e4", "evidence_kind": "English manual and source declarations", "source_sha256": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b"}, "sources": [{"url": "/docs/12/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "12.22 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "d787f26a12af978ff302a05a3ff490a2f9068935e6b833649aa0f85bd7e7bee9"}, {"url": "/docs/12/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "089624dd131f52eea682b304f87a1acb03392ee7bcf78b000699c9b17c7ca22d"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\">pg_basebackup</span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.9.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take base backups of a running <span class=\"productname\">PostgreSQL</span> database cluster. These are taken without affecting other clients to the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/12/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log shipping or streaming replication standby servers (see <a class=\"xref\" href=\"/docs/12/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> makes a binary copy of the database cluster files, while making sure the system is put in 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 <a class=\"xref\" href=\"/docs/12/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\">pg_dump</span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection, and uses the replication protocol. The connection must be made with a superuser or a user having <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/12/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>), and <code class=\"filename\">pg_hba.conf</code> must explicitly permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/12/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to leave at least one session available for the backup and one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s running at the same time, but it is better from a performance point of view to take only one backup, and copy the result.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from not only the master but also the standby. To take a backup from the standby, set up the standby so that it can accept replication connections (that is, set <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/12/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure <a class=\"link\" href=\"/docs/12/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\">host-based authentication</a>). You will also need to enable <a class=\"xref\" href=\"/docs/12/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the master.</p>\n<p>Note that there are some limitations in an online backup from the standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to the master during online backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the master and not to use a tool like <span class=\"application\">pg_compresslog</span> as <code class=\"varname\">archive_command</code> to remove full-page writes from WAL files.</p>\n</li>\n</ul>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Directory to write the output to. <span class=\"application\">pg_basebackup</span> 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.</p>\n<p>When the backup is in tar mode, and the directory is specified as <code class=\"literal\">-</code> (dash), the tar file will be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>Write the output as plain files, with the same layout as the current 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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory will be written to a file named <code class=\"filename\">base.tar</code>, and all other tablespaces will be named after the tablespace OID.</p>\n<p>If the value <code class=\"literal\">-</code> (dash) is specified as target directory, the tar contents will be written to standard output, suitable for piping to for example <span class=\"productname\">gzip</span>. This is only possible if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>The maximum transfer rate of data transferred from the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>The purpose is to limit the impact of <span class=\"application\">pg_basebackup</span> on the running server.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Create <a class=\"link\" href=\"/docs/12/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and append connection settings to <code class=\"filename\">postgresql.auto.conf</code> in the output directory (or into the base archive file when using tar format) to ease setting up a standby server. The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that the streaming replication will use the same settings later on.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocate the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> contained in the backup.) Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If a path happens to contain a <code class=\"literal\">=</code> sign, escape it with a backslash. This option can be specified multiple times for multiple tablespaces. See examples below.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Specifies the location for the write-ahead log directory. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>Includes the required write-ahead log files (WAL files) in the backup. This will include all write-ahead logs generated during the backup. Unless the method <code class=\"literal\">none</code> is specified, it is possible to start a postmaster directly in the extracted directory without the need to consult the log archive, thus making this a completely standalone backup.</p>\n<p>The following methods for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead log in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the <a class=\"xref\" href=\"/docs/12/runtime-config-replication.html#GUC-WAL-KEEP-SEGMENTS\">wal_keep_segments</a> 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.</p>\n<p>When tar format mode is used, the write-ahead log files will be written to the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/12/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> 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.</p>\n<p>When tar format mode is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the running of the program.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c <em class=\"replaceable\"><code>fast|spread</code></em></code><br></span><span class=\"term\"><code class=\"option\">--checkpoint=<em class=\"replaceable\"><code>fast|spread</code></em></code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (default) (see <a class=\"xref\" href=\"/docs/12/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.3.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.3</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>This option causes creation of a replication slot named by the <code class=\"literal\">--slot</code> option before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n<p>When this is enabled, 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. It causes the 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 <a class=\"xref\" href=\"/docs/12/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server.</p>\n<p>Temporary replication slots are created by default if no slot name is given with the option <code class=\"option\">-S</code> when using log streaming.</p>\n<p>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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verifications failures will also be reported in the <a class=\"xref\" href=\"/docs/12/monitoring-stats.html#PG-STAT-DATABASE-VIEW\" title=\"Table\u00a027.12.\u00a0pg_stat_database View\">pg_stat_database</a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the database connection parameters.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/12/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"33.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>The option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, database name in the connection string will be ignored.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 from the <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>User name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Force <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to a database.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pg_basebackup</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pg_basebackup</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/12/libpq-envars.html\" title=\"33.14.\u00a0Environment Variables\">Section\u00a033.14</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.8\">\n<h2>Notes</h2>\n<p>At the beginning of the backup, a checkpoint needs to be written on the server the backup is taken from. Especially if the option <code class=\"literal\">--checkpoint=fast</code> is not used, this can take some time during which <span class=\"application\">pg_basebackup</span> will be appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/12/protocol-replication.html\" title=\"52.4.\u00a0Streaming Replication Protocol\">Section\u00a052.4</a> for the precise details.</p>\n<p>Tablespaces will in plain format by default be backed up to the same path they have on the server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, and tar format mode (<code class=\"literal\">--format=tar</code>) of the current version only works with server version 9.5 or later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions in both the <code class=\"literal\">plain</code> and <code class=\"literal\">tar</code> formats if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/12/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\">pg_dump</span></a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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. When the backup is in tar mode, and the directory is specified as - (dash), the tar file will be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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 current 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 will be written to a file named base.tar , and all other tablespaces will be named after the tablespace 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 the cluster has no additional tablespaces and WAL streaming is not used."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "description": "Create standby.signal file 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. The postgresql.auto.conf file will record the connection settings and, if specified, the replication slot that pg_basebackup is using, so that the streaming replication will use the same settings later on."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "Relocate 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.) 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. 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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "Specifies the location for the write-ahead log directory. waldir must be an absolute path. The write-ahead log directory can only be specified when the backup is in plain mode."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "Includes the required write-ahead log files (WAL 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 directory without the need to consult the log archive, thus making this a completely standalone backup. The following methods for collecting the write-ahead logs are supported: n none Don't include write-ahead log in the backup. f fetch The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the wal_keep_segments 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. When tar format mode is used, the write-ahead log files will be written to the base.tar file. s 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 max_wal_senders 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. When tar format mode 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 ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "--compress= level"], "signature": "-Z level --compress= level", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "signature": "-c fast|spread --checkpoint= fast|spread", "description": "Sets checkpoint mode to fast (immediate) or spread (default) (see Section 25.3.3 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "description": "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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. Note that tablespace directories are not cleaned up either way."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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. When this is enabled, 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."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "This option can only be used together with -X stream . It causes the 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 primary_slot_name . 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. 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."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--no-slot"], "signature": "--no-slot", "description": "This option prevents the creation of a temporary replication slot during the backup even if it's supported by the server. Temporary replication slots are created by default if no slot name is given with the option -S when using log streaming. 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 is almost always preferred, because it prevents needed WAL from being removed by the server during the backup."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 verifications failures will also be reported in the pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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 from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "User name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "description": "Never issue 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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Force pg_basebackup to prompt for a password before connecting to a database. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pg_basebackup version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pg_basebackup command line arguments, and exit."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "868d1ae75f45701e289105395b94ef352a567a94afa3f59c1bf78ef2a152287d"}, "13": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "13.23"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "32"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-Z level --compress= level"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.3 ).", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-c fast|spread --checkpoint= fast|spread"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/13/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/13/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication will use the same settings later on."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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.", "signature": "-X method --wal-method= method", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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 method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/13/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "--compress= level"], "summary": "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.", "signature": "-Z level --compress= level", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.3 ).", "signature": "-c fast|spread --checkpoint= fast|spread", "source_url": "/docs/13/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.3 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/13/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/13/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/13/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/13/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/13/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/13/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/13/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/13/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/13/app-pgbasebackup.html", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/13/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/13/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/13/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/13/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/13/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/13/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=13", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "label": "13.23", "major": "13", "channel": "historical", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/13/postgresql-13-A4.pdf", "bytes": 13843239, "pages": 2826, "sha256": "171cc09f90936dbc1cbd503a98ff07ae72ea58ab9771ff051313f1217737799c", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/13/postgresql-13-US.pdf", "bytes": 13739572, "pages": 2984, "sha256": "48d09c6e197d9db4220f41afe83efe848a8661b1b168d3b89419751ecaf6c24d", "built_at": "2026-09-26"}}, "tree": "13", "index": "index.html", "major": "13", "pages": 1139, "release": "13.23", "source_url": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "svg_assets": 3, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6"}, "revision": "614ee3133270254e476c118cdf6f72af78d4e4b8bbd9b28ed9ab1e14e4e9c0f6", "evidence_kind": "English manual and source declarations", "source_sha256": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6"}, "sources": [{"url": "/docs/13/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "13.23 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "d40492f13076160c53bad4d173932e8c79587e4baeb700d385ac4c70d6d439c7"}, {"url": "/docs/13/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "2a16c2982d9803edd4bd6920f76b66083e7f2959182d6a3bcec7ccfbac0a9ad8"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.9.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/13/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/13/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/13/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\">pg_dump</span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/13/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/13/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/13/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/13/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/13/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary and not to use a tool like <span class=\"application\">pg_compresslog</span> as <code class=\"varname\">archive_command</code> to remove full-page writes from WAL files.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/13/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.5.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.5</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/13/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication will use the same settings later on.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> 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.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/13/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c <em class=\"replaceable\"><code>fast|spread</code></em></code><br></span><span class=\"term\"><code class=\"option\">--checkpoint=<em class=\"replaceable\"><code>fast|spread</code></em></code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (the default) (see <a class=\"xref\" href=\"/docs/13/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.3.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.3</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/13/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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.</p>\n<p><a class=\"xref\" href=\"/docs/13/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\">pg_verifybackup</span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/13/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\">pg_verifybackup</span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/13/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"27.2.11.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/13/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"33.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>The option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/13/libpq-envars.html\" title=\"33.14.\u00a0Environment Variables\">Section\u00a033.14</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/13/protocol-replication.html\" title=\"52.4.\u00a0Streaming Replication Protocol\">Section\u00a052.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, and tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.9.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/13/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\">pg_dump</span></a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication will use the same settings later on."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "--compress= level"], "signature": "-Z level --compress= level", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "signature": "-c fast|spread --checkpoint= fast|spread", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.3 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "c154724f0b16d9ef0a0d4d9c9ee8c4f296e591c1cc19a77b9a5e0a93ad3a3adb"}, "14": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "14.24"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "32"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-Z level --compress= level"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 ).", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-c fast|spread --checkpoint= fast|spread"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/14/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/14/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication will use the same settings later on."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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.", "signature": "-X method --wal-method= method", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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 method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/14/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "--compress= level"], "summary": "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.", "signature": "-Z level --compress= level", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 ).", "signature": "-c fast|spread --checkpoint= fast|spread", "source_url": "/docs/14/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/14/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/14/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/14/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/14/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/14/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/14/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/14/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/14/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/14/app-pgbasebackup.html", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/14/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/14/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/14/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/14/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/14/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/14/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=14", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "label": "14.24", "major": "14", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/14/postgresql-14-A4.pdf", "bytes": 14354704, "pages": 2944, "sha256": "8bc6b9dd7b246888bb77f0a5e8c39a2eae52e9926569832669c7d1600becb27c", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/14/postgresql-14-US.pdf", "bytes": 14242178, "pages": 3102, "sha256": "b7ecb5a5f62d8b9f73a69e25a7d26ba285373bc53168a553bff7b77955506db4", "built_at": "2026-09-26"}}, "tree": "14", "index": "index.html", "major": "14", "pages": 1158, "release": "14.24", "source_url": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "svg_assets": 3, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897"}, "revision": "588700d46356d8837c77c7c0a4e71e645fe6535983b8f1830aa8f2e4e41c40ae", "evidence_kind": "English manual and source declarations", "source_sha256": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897"}, "sources": [{"url": "/docs/14/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "14.24 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "4951b5a64ee637d73e383c5c5c0f4135363311b71bbf1022f3b741b1d2798c1c"}, {"url": "/docs/14/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "5a13567a052954dfe494dfaab9f50919faa1ae56023930fdbb78d45e53feccde"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/14/continuous-archiving.html\" title=\"26.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a026.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/14/warm-standby.html\" title=\"27.2.\u00a0Log-Shipping Standby Servers\">Section\u00a027.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/14/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/14/role-attributes.html\" title=\"22.2.\u00a0Role Attributes\">Section\u00a022.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/14/auth-pg-hba-conf.html\" title=\"21.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/14/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/14/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/14/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary and not to use a tool like <span class=\"application\">pg_compresslog</span> as <code class=\"varname\">archive_command</code> to remove full-page writes from WAL files.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/14/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"28.4.5.\u00a0Base Backup Progress Reporting\">Section\u00a028.4.5</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/14/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication will use the same settings later on.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> 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.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/14/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c <em class=\"replaceable\"><code>fast|spread</code></em></code><br></span><span class=\"term\"><code class=\"option\">--checkpoint=<em class=\"replaceable\"><code>fast|spread</code></em></code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (the default) (see <a class=\"xref\" href=\"/docs/14/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"26.3.3.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a026.3.3</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/14/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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.</p>\n<p><a class=\"xref\" href=\"/docs/14/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/14/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/14/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"28.2.13.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/14/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"34.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>The option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/14/libpq-envars.html\" title=\"34.15.\u00a0Environment Variables\">Section\u00a034.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/14/protocol-replication.html\" title=\"53.4.\u00a0Streaming Replication Protocol\">Section\u00a053.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, and tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/14/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a>, <a class=\"xref\" href=\"/docs/14/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"28.4.5.\u00a0Base Backup Progress Reporting\">Section\u00a028.4.5</a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication will use the same settings later on."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "--compress= level"], "signature": "-Z level --compress= level", "description": "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."}, {"names": ["-c fast|spread", "--checkpoint= fast|spread"], "signature": "-c fast|spread --checkpoint= fast|spread", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "5e35443c9d7bf4da4f5379ce1dd021f75d1351076791f58aa9f545a2fe0cba95"}, "15": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "15.19"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "33"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-t target --target= target"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 ).", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-c {fast|spread} --checkpoint={fast|spread}"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/15/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/15/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication will use the same settings later on."}, {"names": ["-t target", "--target= target"], "summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": "-t target --target= target", "source_url": "/docs/15/app-pgbasebackup.html", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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.", "signature": "-X method --wal-method= method", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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 method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/15/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "source_url": "/docs/15/app-pgbasebackup.html", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , or none for no compression. A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level and workers . If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 ).", "signature": "-c {fast|spread} --checkpoint={fast|spread}", "source_url": "/docs/15/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/15/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/15/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/15/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/15/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/15/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/15/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/15/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/15/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/15/app-pgbasebackup.html", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/15/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/15/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/15/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/15/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/15/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/15/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=15", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "label": "15.19", "major": "15", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/15/postgresql-15-A4.pdf", "bytes": 14609140, "pages": 2987, "sha256": "66228564a4d16efb47d6a914085716ecfe22ca1566db56bc7c3d82f790646d72", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/15/postgresql-15-US.pdf", "bytes": 14495690, "pages": 3153, "sha256": "645a498c2390d47a6223ec74770631185807a19c484edb0fc5a295d9f460bc02", "built_at": "2026-09-26"}}, "tree": "15", "index": "index.html", "major": "15", "pages": 1168, "release": "15.19", "source_url": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "svg_assets": 3, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89"}, "revision": "6af958c6520151fc7697d56e0616b03fb00522c4568158674d452ae0644ba545", "evidence_kind": "English manual and source declarations", "source_sha256": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89"}, "sources": [{"url": "/docs/15/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "15.19 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "0363f172e413c5ea3f20ba9ae3420e514ace28021d3c3cd67297e348b20b107f"}, {"url": "/docs/15/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "015b2ea2bd205946a55a1b837e735570631bac831c92074a6bf58444f9a3cb98"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/15/continuous-archiving.html\" title=\"26.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a026.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/15/warm-standby.html\" title=\"27.2.\u00a0Log-Shipping Standby Servers\">Section\u00a027.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/15/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/15/role-attributes.html\" title=\"22.2.\u00a0Role Attributes\">Section\u00a022.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/15/auth-pg-hba-conf.html\" title=\"21.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/15/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/15/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/15/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/15/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"28.4.5.\u00a0Base Backup Progress Reporting\">Section\u00a028.4.5</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/15/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication will use the same settings later on.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>target</code></em></code><br></span><span class=\"term\"><code class=\"option\">--target=<em class=\"replaceable\"><code>target</code></em></code></span></dt>\n<dd>\n<p>Instructs the server where to place the base backup. The default target is <code class=\"literal\">client</code>, which specifies that the backup should be sent to the machine where <span class=\"application\">pg_basebackup</span> is running. If the target is instead set to <code class=\"literal\">server:/some/path</code>, the backup will be stored on the machine where the server is running in the <code class=\"literal\">/some/path</code> directory. Storing a backup on the server requires superuser privileges or having privileges of the <code class=\"literal\">pg_write_server_files</code> role. If the target is set to <code class=\"literal\">blackhole</code>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.</p>\n<p>Since WAL streaming is implemented by <span class=\"application\">pg_basebackup</span> rather than by the server, this option cannot be used together with <code class=\"literal\">-Xstream</code>. Since that is the default, when this option is specified, you must also specify either <code class=\"literal\">-Xfetch</code> or <code class=\"literal\">-Xnone</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> 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.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/15/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">-Z [{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=[{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code></span></dt>\n<dd>\n<p>Requests compression of the backup. If <code class=\"literal\">client</code> or <code class=\"literal\">server</code> is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is <code class=\"literal\">client</code> except when <code class=\"literal\">--target</code> is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When <code class=\"literal\">-Xstream</code>, which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify <code class=\"literal\">-Xfetch</code>.</p>\n<p>The compression method can be set to <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, <code class=\"literal\">zstd</code>, or <code class=\"literal\">none</code> for no compression. A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <code class=\"literal\">keyword</code> or <code class=\"literal\">keyword=value</code>. Currently, the supported keywords are <code class=\"literal\">level</code> and <code class=\"literal\">workers</code>.</p>\n<p>If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <code class=\"literal\">gzip</code> compression will be used if the level is greater than 0, and no compression will be used if the level is 0.</p>\n<p>When the tar format is used with <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, or <code class=\"literal\">zstd</code>, the suffix <code class=\"filename\">.gz</code>, <code class=\"filename\">.lz4</code>, or <code class=\"filename\">.zst</code>, respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it.</p>\n<p>When this option is used in combination with <code class=\"literal\">-Xstream</code>, <code class=\"literal\">pg_wal.tar</code> will be compressed using <code class=\"literal\">gzip</code> if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c {fast|spread}</code><br></span><span class=\"term\"><code class=\"option\">--checkpoint={fast|spread}</code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (the default) (see <a class=\"xref\" href=\"/docs/15/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"26.3.3.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a026.3.3</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/15/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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.</p>\n<p><a class=\"xref\" href=\"/docs/15/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/15/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/15/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"28.2.15.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/15/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"34.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>The option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/15/libpq-envars.html\" title=\"34.15.\u00a0Environment Variables\">Section\u00a034.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL and operating system files. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/15/protocol-replication.html\" title=\"55.4.\u00a0Streaming Replication Protocol\">Section\u00a055.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, and tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n<p>To create a backup of a local server with one tar file for each tablespace compressed with <span class=\"application\">gzip</span> at level 9, stored in the directory <code class=\"filename\">backup</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft --compress=gzip:9</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/15/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a>, <a class=\"xref\" href=\"/docs/15/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"28.4.5.\u00a0Base Backup Progress Reporting\">Section\u00a028.4.5</a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication will use the same settings later on."}, {"names": ["-t target", "--target= target"], "signature": "-t target --target= target", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , or none for no compression. A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level and workers . If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "signature": "-c {fast|spread} --checkpoint={fast|spread}", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "52a98f3fe5e39d56f4448675cf6e77682c6a4edec033f5c0a381ffb6f6081ad5"}, "16": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "16.15"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "33"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-t target --target= target"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 ).", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-c {fast|spread} --checkpoint={fast|spread}"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/16/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/16/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication will use the same settings later on."}, {"names": ["-t target", "--target= target"], "summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": "-t target --target= target", "source_url": "/docs/16/app-pgbasebackup.html", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/16/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "source_url": "/docs/16/app-pgbasebackup.html", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 ).", "signature": "-c {fast|spread} --checkpoint={fast|spread}", "source_url": "/docs/16/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/16/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/16/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/16/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/16/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/16/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/16/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/16/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/16/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/16/app-pgbasebackup.html", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/16/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/16/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/16/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/16/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/16/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/16/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=16", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "label": "16.15", "major": "16", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/16/postgresql-16-A4.pdf", "bytes": 15282337, "pages": 3055, "sha256": "4bb6c1f63deedac98736d8c4c7bc0fad0ac24e85b07e21ee10411872f06afd06", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/16/postgresql-16-US.pdf", "bytes": 15164148, "pages": 3220, "sha256": "5b6b6166c89991199e144bb0ae34c17a5f29826251dbf19db1abc0df3a3e771b", "built_at": "2026-09-26"}}, "tree": "16", "index": "index.html", "major": "16", "pages": 1169, "release": "16.15", "source_url": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "svg_assets": 3, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed"}, "revision": "3c21e58b35318021716440e67bb8bafd392b6a2b965a244d90e9e33c99e0bdef", "evidence_kind": "English manual and source declarations", "source_sha256": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed"}, "sources": [{"url": "/docs/16/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "16.15 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "f0c6588fe61e7332b22709fdc10ff5adc191c06ddfc3cc620ccd57fcba3972a6"}, {"url": "/docs/16/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "a28c30c3c0f8783e16d56413a0b6fd39487e336da1683b29b60abf1c229cef26"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/16/continuous-archiving.html\" title=\"26.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a026.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/16/warm-standby.html\" title=\"27.2.\u00a0Log-Shipping Standby Servers\">Section\u00a027.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/16/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/16/role-attributes.html\" title=\"22.2.\u00a0Role Attributes\">Section\u00a022.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/16/auth-pg-hba-conf.html\" title=\"21.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/16/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/16/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/16/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/16/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"28.4.6.\u00a0Base Backup Progress Reporting\">Section\u00a028.4.6</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/16/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication will use the same settings later on.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>target</code></em></code><br></span><span class=\"term\"><code class=\"option\">--target=<em class=\"replaceable\"><code>target</code></em></code></span></dt>\n<dd>\n<p>Instructs the server where to place the base backup. The default target is <code class=\"literal\">client</code>, which specifies that the backup should be sent to the machine where <span class=\"application\">pg_basebackup</span> is running. If the target is instead set to <code class=\"literal\">server:/some/path</code>, the backup will be stored on the machine where the server is running in the <code class=\"literal\">/some/path</code> directory. Storing a backup on the server requires superuser privileges or having privileges of the <code class=\"literal\">pg_write_server_files</code> role. If the target is set to <code class=\"literal\">blackhole</code>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.</p>\n<p>Since WAL streaming is implemented by <span class=\"application\">pg_basebackup</span> rather than by the server, this option cannot be used together with <code class=\"literal\">-Xstream</code>. Since that is the default, when this option is specified, you must also specify either <code class=\"literal\">-Xfetch</code> or <code class=\"literal\">-Xnone</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> is specified, it is possible to start a postmaster in the target directory without the need to consult the WAL archive, thus making the output a completely standalone backup.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/16/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">-Z [{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=[{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code></span></dt>\n<dd>\n<p>Requests compression of the backup. If <code class=\"literal\">client</code> or <code class=\"literal\">server</code> is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is <code class=\"literal\">client</code> except when <code class=\"literal\">--target</code> is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When <code class=\"literal\">-Xstream</code>, which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify <code class=\"literal\">-Xfetch</code>.</p>\n<p>The compression method can be set to <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, <code class=\"literal\">zstd</code>, <code class=\"literal\">none</code> for no compression or an integer (no compression if 0, <code class=\"literal\">gzip</code> if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <code class=\"literal\">keyword</code> or <code class=\"literal\">keyword=value</code>. Currently, the supported keywords are <code class=\"literal\">level</code>, <code class=\"literal\">long</code>, and <code class=\"literal\">workers</code>. The detail string cannot be used when the compression method is specified as a plain integer.</p>\n<p>If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <code class=\"literal\">gzip</code> compression will be used if the level is greater than 0, and no compression will be used if the level is 0.</p>\n<p>When the tar format is used with <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, or <code class=\"literal\">zstd</code>, the suffix <code class=\"filename\">.gz</code>, <code class=\"filename\">.lz4</code>, or <code class=\"filename\">.zst</code>, respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it.</p>\n<p>When this option is used in combination with <code class=\"literal\">-Xstream</code>, <code class=\"literal\">pg_wal.tar</code> will be compressed using <code class=\"literal\">gzip</code> if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c {fast|spread}</code><br></span><span class=\"term\"><code class=\"option\">--checkpoint={fast|spread}</code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (the default) (see <a class=\"xref\" href=\"/docs/16/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"26.3.3.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a026.3.3</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/16/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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.</p>\n<p><a class=\"xref\" href=\"/docs/16/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/16/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/16/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"28.2.16.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/16/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"34.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>The option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/16/libpq-envars.html\" title=\"34.15.\u00a0Environment Variables\">Section\u00a034.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL and operating system files. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/16/protocol-replication.html\" title=\"55.4.\u00a0Streaming Replication Protocol\">Section\u00a055.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or an older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, and tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n<p>To create a backup of a local server with one tar file for each tablespace compressed with <span class=\"application\">gzip</span> at level 9, stored in the directory <code class=\"filename\">backup</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft --compress=gzip:9</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/16/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a>, <a class=\"xref\" href=\"/docs/16/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"28.4.6.\u00a0Base Backup Progress Reporting\">Section\u00a028.4.6</a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication will use the same settings later on."}, {"names": ["-t target", "--target= target"], "signature": "-t target --target= target", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "signature": "-c {fast|spread} --checkpoint={fast|spread}", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "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 pg_basebackup doesn't connect to any particular database in the cluster, any database name in the connection string will be ignored."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "4c8ffc9b3c2690b878daa7b25f98eacb3779e8aef24f602543e86f43fa4fb027"}, "17": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "17.11"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "35"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-i old_manifest_file --incremental= old_manifest_file"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-t target --target= target"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 ).", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-c {fast|spread} --checkpoint={fast|spread}"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "--sync-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/17/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": "-i old_manifest_file --incremental= old_manifest_file", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/17/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": "-t target --target= target", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/17/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 ).", "signature": "-c {fast|spread} --checkpoint={fast|spread}", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/17/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/17/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/17/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": "--sync-method= method", "source_url": "/docs/17/app-pgbasebackup.html", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/17/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/17/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/17/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/17/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/17/app-pgbasebackup.html", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/17/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/17/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/17/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=17", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "label": "17.11", "major": "17", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/17/postgresql-17-A4.pdf", "bytes": 15521293, "pages": 3099, "sha256": "1991354df0dc89e70ec39328c28988ef8b19c6a93671dab3893650b63e9f4e36", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/17/postgresql-17-US.pdf", "bytes": 15398150, "pages": 3270, "sha256": "07696c8f38abf31babf22d2db337093936e7c472d2af36d050b000c49bbcf52c", "built_at": "2026-09-26"}}, "tree": "17", "index": "index.html", "major": "17", "pages": 1143, "release": "17.11", "source_url": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}, "revision": "58419c9b0dd42cb34c8d53695bb025a7e582edf55ccd4c5bcb1c2c7c71a37487", "evidence_kind": "English manual and source declarations", "source_sha256": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}, "sources": [{"url": "/docs/17/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "17.11 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "1b224ac91af880c3a70def02a70217c438c95be576b5a92648f6de9cbce5f1c2"}, {"url": "/docs/17/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "3194fc72ddad8e2fcba55f8e007f83413cb352146cb65aaa9457a18d0314ee1b"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/17/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/17/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> can take a full or incremental base backup of the database. When used to take a full backup, it makes an exact copy of the database cluster's files. When used to take an incremental backup, some files that would have been part of a full backup may be replaced with incremental versions of the same files, containing only those blocks that have been modified since the reference backup. An incremental backup cannot be used directly; instead, <a class=\"xref\" href=\"/docs/17/app-pgcombinebackup.html\" title=\"pg_combinebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_combinebackup</span></span></a> must first be used to combine it with the previous backups upon which it depends. See <a class=\"xref\" href=\"/docs/17/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">Section\u00a025.3.3</a> for more information about incremental backups, and <a class=\"xref\" href=\"/docs/17/continuous-archiving.html#BACKUP-PITR-RECOVERY\" title=\"25.3.5.\u00a0Recovering Using a Continuous Archive Backup\">Section\u00a025.3.5</a> for steps to recover from a backup.</p>\n<p>In any mode, <span class=\"application\">pg_basebackup</span> makes 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/17/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/17/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/17/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/17/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/17/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.6.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.6</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i <em class=\"replaceable\"><code>old_manifest_file</code></em></code><br></span><span class=\"term\"><code class=\"option\">--incremental=<em class=\"replaceable\"><code>old_manifest_file</code></em></code></span></dt>\n<dd>\n<p>Performs an <a class=\"link\" href=\"/docs/17/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">incremental backup</a>. The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/17/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication and <a class=\"link\" href=\"/docs/17/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a> will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or <a class=\"link\" href=\"/docs/17/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">environment variable</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>target</code></em></code><br></span><span class=\"term\"><code class=\"option\">--target=<em class=\"replaceable\"><code>target</code></em></code></span></dt>\n<dd>\n<p>Instructs the server where to place the base backup. The default target is <code class=\"literal\">client</code>, which specifies that the backup should be sent to the machine where <span class=\"application\">pg_basebackup</span> is running. If the target is instead set to <code class=\"literal\">server:/some/path</code>, the backup will be stored on the machine where the server is running in the <code class=\"literal\">/some/path</code> directory. Storing a backup on the server requires superuser privileges or having privileges of the <code class=\"literal\">pg_write_server_files</code> role. If the target is set to <code class=\"literal\">blackhole</code>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.</p>\n<p>Since WAL streaming is implemented by <span class=\"application\">pg_basebackup</span> rather than by the server, this option cannot be used together with <code class=\"literal\">-Xstream</code>. Since that is the default, when this option is specified, you must also specify either <code class=\"literal\">-Xfetch</code> or <code class=\"literal\">-Xnone</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> is specified, it is possible to start a postmaster in the target directory without the need to consult the WAL archive, thus making the output a completely standalone backup.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">-Z [{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=[{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code></span></dt>\n<dd>\n<p>Requests compression of the backup. If <code class=\"literal\">client</code> or <code class=\"literal\">server</code> is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is <code class=\"literal\">client</code> except when <code class=\"literal\">--target</code> is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When <code class=\"literal\">-Xstream</code>, which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify <code class=\"literal\">-Xfetch</code>.</p>\n<p>The compression method can be set to <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, <code class=\"literal\">zstd</code>, <code class=\"literal\">none</code> for no compression or an integer (no compression if 0, <code class=\"literal\">gzip</code> if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <em class=\"replaceable\"><code>keyword</code></em> or <em class=\"replaceable\"><code>keyword=value</code></em>. Currently, the supported keywords are <code class=\"literal\">level</code>, <code class=\"literal\">long</code>, and <code class=\"literal\">workers</code>. The detail string cannot be used when the compression method is specified as a plain integer.</p>\n<p>If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <code class=\"literal\">gzip</code> compression will be used if the level is greater than 0, and no compression will be used if the level is 0.</p>\n<p>When the tar format is used with <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, or <code class=\"literal\">zstd</code>, the suffix <code class=\"filename\">.gz</code>, <code class=\"filename\">.lz4</code>, or <code class=\"filename\">.zst</code>, respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it.</p>\n<p>When this option is used in combination with <code class=\"literal\">-Xstream</code>, <code class=\"literal\">pg_wal.tar</code> will be compressed using <code class=\"literal\">gzip</code> if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c {fast|spread}</code><br></span><span class=\"term\"><code class=\"option\">--checkpoint={fast|spread}</code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (the default) (see <a class=\"xref\" href=\"/docs/17/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.4.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.4</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/17/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sync-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>When set to <code class=\"literal\">fsync</code>, which is the default, <code class=\"command\">pg_basebackup</code> will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.</p>\n<p>On Linux, <code class=\"literal\">syncfs</code> may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, <code class=\"command\">pg_basebackup</code> will also synchronize the file systems that contain the WAL files and each tablespace. See <a class=\"xref\" href=\"/docs/17/runtime-config-error-handling.html#GUC-RECOVERY-INIT-SYNC-METHOD\">recovery_init_sync_method</a> for information about the caveats to be aware of when using <code class=\"literal\">syncfs</code>.</p>\n<p>This option has no effect when <code class=\"option\">--no-sync</code> is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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.</p>\n<p><a class=\"xref\" href=\"/docs/17/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/17/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/17/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"27.2.17.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/17/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>This option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name (<code class=\"literal\">replication</code>) for purposes of looking up the replication connection's password in <code class=\"filename\">~/.pgpass</code>. Similarly, middleware or proxies used in connecting to <span class=\"productname\">PostgreSQL</span> might utilize the name for purposes such as connection routing. The database name can also be used by <a class=\"link\" href=\"/docs/17/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/17/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">Section\u00a032.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL and operating system files. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/17/protocol-replication.html\" title=\"53.4.\u00a0Streaming Replication Protocol\">Section\u00a053.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, the tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later, and incremental backup (<code class=\"literal\">--incremental</code>) only works with server version 17 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n<p>To create a backup of the local server with one tar file for each tablespace compressed with <span class=\"application\">gzip</span> at level 9, stored in the directory <code class=\"filename\">backup</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft --compress=gzip:9</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/17/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a>, <a class=\"xref\" href=\"/docs/17/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.6.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.6</a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "signature": "-i old_manifest_file --incremental= old_manifest_file", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "signature": "-t target --target= target", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "signature": "-c {fast|spread} --checkpoint={fast|spread}", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "signature": "--sync-method= method", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "17915f265ed4206a2736150575c5ca2e314265548d96f44f6ffdda3f809ba830"}, "18": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "18.6"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "35"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-i old_manifest_file --incremental= old_manifest_file"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-t target --target= target"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 ).", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-c {fast|spread} --checkpoint={fast|spread}"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--sync-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": "-i old_manifest_file --incremental= old_manifest_file", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/18/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": "-t target --target= target", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 ).", "signature": "-c {fast|spread} --checkpoint={fast|spread}", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/18/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": "--sync-method= method", "source_url": "/docs/18/app-pgbasebackup.html", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 CRC-32C 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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/18/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/18/app-pgbasebackup.html", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=18", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "label": "18.6", "major": "18", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/18/postgresql-18-A4.pdf", "bytes": 15865106, "pages": 3154, "sha256": "19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/18/postgresql-18-US.pdf", "bytes": 15748059, "pages": 3328, "sha256": "facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319", "built_at": "2026-09-26"}}, "tree": "18", "index": "index.html", "major": "18", "pages": 1148, "release": "18.6", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "revision": "ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8", "evidence_kind": "English manual and source declarations", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "sources": [{"url": "/docs/18/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "18.6 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "76780bc785b5bf8a7b20cdc1678b3e8d1de6aafb9cc46df9e578012d4f71546b"}, {"url": "/docs/18/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "68f726af77272fe73a827be2b7b5958d0f2239a6f8ed44264e9d42496bfa4fd0"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/18/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/18/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> can take a full or incremental base backup of the database. When used to take a full backup, it makes an exact copy of the database cluster's files. When used to take an incremental backup, some files that would have been part of a full backup may be replaced with incremental versions of the same files, containing only those blocks that have been modified since the reference backup. An incremental backup cannot be used directly; instead, <a class=\"xref\" href=\"/docs/18/app-pgcombinebackup.html\" title=\"pg_combinebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_combinebackup</span></span></a> must first be used to combine it with the previous backups upon which it depends. See <a class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">Section\u00a025.3.3</a> for more information about incremental backups, and <a class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-PITR-RECOVERY\" title=\"25.3.5.\u00a0Recovering Using a Continuous Archive Backup\">Section\u00a025.3.5</a> for steps to recover from a backup.</p>\n<p>In any mode, <span class=\"application\">pg_basebackup</span> makes 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/18/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/18/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/18/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/18/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.6.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.6</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i <em class=\"replaceable\"><code>old_manifest_file</code></em></code><br></span><span class=\"term\"><code class=\"option\">--incremental=<em class=\"replaceable\"><code>old_manifest_file</code></em></code></span></dt>\n<dd>\n<p>Performs an <a class=\"link\" href=\"/docs/18/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">incremental backup</a>. The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/18/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication and <a class=\"link\" href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a> will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or <a class=\"link\" href=\"/docs/18/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">environment variable</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>target</code></em></code><br></span><span class=\"term\"><code class=\"option\">--target=<em class=\"replaceable\"><code>target</code></em></code></span></dt>\n<dd>\n<p>Instructs the server where to place the base backup. The default target is <code class=\"literal\">client</code>, which specifies that the backup should be sent to the machine where <span class=\"application\">pg_basebackup</span> is running. If the target is instead set to <code class=\"literal\">server:/some/path</code>, the backup will be stored on the machine where the server is running in the <code class=\"literal\">/some/path</code> directory. Storing a backup on the server requires superuser privileges or having privileges of the <code class=\"literal\">pg_write_server_files</code> role. If the target is set to <code class=\"literal\">blackhole</code>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.</p>\n<p>Since WAL streaming is implemented by <span class=\"application\">pg_basebackup</span> rather than by the server, this option cannot be used together with <code class=\"literal\">-Xstream</code>. Since that is the default, when this option is specified, you must also specify either <code class=\"literal\">-Xfetch</code> or <code class=\"literal\">-Xnone</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> is specified, it is possible to start a postmaster in the target directory without the need to consult the WAL archive, thus making the output a completely standalone backup.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">-Z [{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=[{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code></span></dt>\n<dd>\n<p>Requests compression of the backup. If <code class=\"literal\">client</code> or <code class=\"literal\">server</code> is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is <code class=\"literal\">client</code> except when <code class=\"literal\">--target</code> is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When <code class=\"literal\">-Xstream</code>, which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify <code class=\"literal\">-Xfetch</code>.</p>\n<p>The compression method can be set to <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, <code class=\"literal\">zstd</code>, <code class=\"literal\">none</code> for no compression or an integer (no compression if 0, <code class=\"literal\">gzip</code> if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <em class=\"replaceable\"><code>keyword</code></em> or <em class=\"replaceable\"><code>keyword=value</code></em>. Currently, the supported keywords are <code class=\"literal\">level</code>, <code class=\"literal\">long</code>, and <code class=\"literal\">workers</code>. The detail string cannot be used when the compression method is specified as a plain integer.</p>\n<p>If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <code class=\"literal\">gzip</code> compression will be used if the level is greater than 0, and no compression will be used if the level is 0.</p>\n<p>When the tar format is used with <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, or <code class=\"literal\">zstd</code>, the suffix <code class=\"filename\">.gz</code>, <code class=\"filename\">.lz4</code>, or <code class=\"filename\">.zst</code>, respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it.</p>\n<p>When this option is used in combination with <code class=\"literal\">-Xstream</code>, <code class=\"literal\">pg_wal.tar</code> will be compressed using <code class=\"literal\">gzip</code> if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c {fast|spread}</code><br></span><span class=\"term\"><code class=\"option\">--checkpoint={fast|spread}</code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (the default) (see <a class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.4.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.4</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sync-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>When set to <code class=\"literal\">fsync</code>, which is the default, <code class=\"command\">pg_basebackup</code> will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.</p>\n<p>On Linux, <code class=\"literal\">syncfs</code> may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, <code class=\"command\">pg_basebackup</code> will also synchronize the file systems that contain the WAL files and each tablespace. See <a class=\"xref\" href=\"/docs/18/runtime-config-error-handling.html#GUC-RECOVERY-INIT-SYNC-METHOD\">recovery_init_sync_method</a> for information about the caveats to be aware of when using <code class=\"literal\">syncfs</code>.</p>\n<p>This option has no effect when <code class=\"option\">--no-sync</code> is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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 CRC-32C 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.</p>\n<p><a class=\"xref\" href=\"/docs/18/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/18/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/18/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"27.2.17.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>This option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name (<code class=\"literal\">replication</code>) for purposes of looking up the replication connection's password in <code class=\"filename\">~/.pgpass</code>. Similarly, middleware or proxies used in connecting to <span class=\"productname\">PostgreSQL</span> might utilize the name for purposes such as connection routing. The database name can also be used by <a class=\"link\" href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/18/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">Section\u00a032.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL and operating system files. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/18/protocol-replication.html\" title=\"54.4.\u00a0Streaming Replication Protocol\">Section\u00a054.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, the tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later, and incremental backup (<code class=\"literal\">--incremental</code>) only works with server version 17 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n<p>To create a backup of the local server with one tar file for each tablespace compressed with <span class=\"application\">gzip</span> at level 9, stored in the directory <code class=\"filename\">backup</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft --compress=gzip:9</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/18/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a>, <a class=\"xref\" href=\"/docs/18/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.6.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.6</a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "signature": "-i old_manifest_file --incremental= old_manifest_file", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "signature": "-t target --target= target", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "signature": "-c {fast|spread} --checkpoint={fast|spread}", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "signature": "--sync-method= method", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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 CRC-32C 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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "1355c21a25dc07b130a2e139c0430698018dbc37b620dff3f0f565fbaec56228"}, "19": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "19beta4"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "35"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-i old_manifest_file --incremental= old_manifest_file"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-t target --target= target"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]"}}, {"summary": "Sets checkpoint mode to fast or spread (see Section 25.3.4 ). The default is spread.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-c {fast|spread} --checkpoint={fast|spread}"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "--sync-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/19/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": "-i old_manifest_file --incremental= old_manifest_file", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/19/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": "-t target --target= target", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/19/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "summary": "Sets checkpoint mode to fast or spread (see Section 25.3.4 ). The default is spread.", "signature": "-c {fast|spread} --checkpoint={fast|spread}", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast or spread (see Section 25.3.4 ). The default is spread."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/19/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/19/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/19/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": "--sync-method= method", "source_url": "/docs/19/app-pgbasebackup.html", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/19/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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 CRC-32C 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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/19/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/19/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/19/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/19/app-pgbasebackup.html", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/19/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/19/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/19/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=19", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "label": "19beta4", "major": "19", "channel": "preview", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/19/postgresql-19-A4.pdf", "bytes": 16064841, "pages": 3052, "sha256": "4dd099e4125c591128fc5f3ebd02178dc24781f9e5ae629f96d67c4c8547427b", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/19/postgresql-19-US.pdf", "bytes": 15974616, "pages": 3225, "sha256": "61971fa857f0956d47341a0388fa6af9ae10acf691d4b2fc009007d384b0342b", "built_at": "2026-09-26"}}, "tree": "19", "index": "index.html", "major": "19", "pages": 1155, "release": "19beta4", "source_url": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "svg_assets": 5, "source_mode": "en SGML built with pinned official archive", "source_sha256": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}, "revision": "1bbbbf4133d426f0e4304010688d2984c30fb67df0cc3a61b3e37eb3f6f37833", "evidence_kind": "English manual and source declarations", "source_sha256": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}, "sources": [{"url": "/docs/19/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "19beta4 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "9658c982553138ec05473353c33103fff14760c65ac9ea0291e44ee8d185763b"}, {"url": "/docs/19/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "c827f460db781b39da305303c88e73729a419cd2b2b9dedb126d8ad5cbf02c95"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/19/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/19/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> can take a full or incremental base backup of the database. When used to take a full backup, it makes an exact copy of the database cluster's files. When used to take an incremental backup, some files that would have been part of a full backup may be replaced with incremental versions of the same files, containing only those blocks that have been modified since the reference backup. An incremental backup cannot be used directly; instead, <a class=\"xref\" href=\"/docs/19/app-pgcombinebackup.html\" title=\"pg_combinebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_combinebackup</span></span></a> must first be used to combine it with the previous backups upon which it depends. See <a class=\"xref\" href=\"/docs/19/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">Section\u00a025.3.3</a> for more information about incremental backups, and <a class=\"xref\" href=\"/docs/19/continuous-archiving.html#BACKUP-PITR-RECOVERY\" title=\"25.3.5.\u00a0Recovering Using a Continuous Archive Backup\">Section\u00a025.3.5</a> for steps to recover from a backup.</p>\n<p>In any mode, <span class=\"application\">pg_basebackup</span> makes 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/19/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/19/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/19/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/19/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/19/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.7.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.7</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i <em class=\"replaceable\"><code>old_manifest_file</code></em></code><br></span><span class=\"term\"><code class=\"option\">--incremental=<em class=\"replaceable\"><code>old_manifest_file</code></em></code></span></dt>\n<dd>\n<p>Performs an <a class=\"link\" href=\"/docs/19/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">incremental backup</a>. The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/19/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication and <a class=\"link\" href=\"/docs/19/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a> will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or <a class=\"link\" href=\"/docs/19/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">environment variable</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>target</code></em></code><br></span><span class=\"term\"><code class=\"option\">--target=<em class=\"replaceable\"><code>target</code></em></code></span></dt>\n<dd>\n<p>Instructs the server where to place the base backup. The default target is <code class=\"literal\">client</code>, which specifies that the backup should be sent to the machine where <span class=\"application\">pg_basebackup</span> is running. If the target is instead set to <code class=\"literal\">server:/some/path</code>, the backup will be stored on the machine where the server is running in the <code class=\"literal\">/some/path</code> directory. Storing a backup on the server requires superuser privileges or having privileges of the <code class=\"literal\">pg_write_server_files</code> role. If the target is set to <code class=\"literal\">blackhole</code>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.</p>\n<p>Since WAL streaming is implemented by <span class=\"application\">pg_basebackup</span> rather than by the server, this option cannot be used together with <code class=\"literal\">-Xstream</code>. Since that is the default, when this option is specified, you must also specify either <code class=\"literal\">-Xfetch</code> or <code class=\"literal\">-Xnone</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> is specified, it is possible to start a postmaster in the target directory without the need to consult the WAL archive, thus making the output a completely standalone backup.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">-Z [{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=[{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code></span></dt>\n<dd>\n<p>Requests compression of the backup. If <code class=\"literal\">client</code> or <code class=\"literal\">server</code> is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is <code class=\"literal\">client</code> except when <code class=\"literal\">--target</code> is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When <code class=\"literal\">-Xstream</code>, which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify <code class=\"literal\">-Xfetch</code>.</p>\n<p>The compression method can be set to <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, <code class=\"literal\">zstd</code>, <code class=\"literal\">none</code> for no compression or an integer (no compression if 0, <code class=\"literal\">gzip</code> if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <em class=\"replaceable\"><code>keyword</code></em> or <em class=\"replaceable\"><code>keyword=value</code></em>. Currently, the supported keywords are <code class=\"literal\">level</code>, <code class=\"literal\">long</code>, and <code class=\"literal\">workers</code>. The detail string cannot be used when the compression method is specified as a plain integer.</p>\n<p>If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <code class=\"literal\">gzip</code> compression will be used if the level is greater than 0, and no compression will be used if the level is 0.</p>\n<p>When the tar format is used with <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, or <code class=\"literal\">zstd</code>, the suffix <code class=\"filename\">.gz</code>, <code class=\"filename\">.lz4</code>, or <code class=\"filename\">.zst</code>, respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it.</p>\n<p>When this option is used in combination with <code class=\"literal\">-Xstream</code>, <code class=\"literal\">pg_wal.tar</code> will be compressed using <code class=\"literal\">gzip</code> if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c {fast|spread}</code><br></span><span class=\"term\"><code class=\"option\">--checkpoint={fast|spread}</code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast or spread (see <a class=\"xref\" href=\"/docs/19/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.4.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.4</a>). The default is spread.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/19/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sync-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>When set to <code class=\"literal\">fsync</code>, which is the default, <code class=\"command\">pg_basebackup</code> will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.</p>\n<p>On Linux, <code class=\"literal\">syncfs</code> may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, <code class=\"command\">pg_basebackup</code> will also synchronize the file systems that contain the WAL files and each tablespace. See <a class=\"xref\" href=\"/docs/19/runtime-config-error-handling.html#GUC-RECOVERY-INIT-SYNC-METHOD\">recovery_init_sync_method</a> for information about the caveats to be aware of when using <code class=\"literal\">syncfs</code>.</p>\n<p>This option has no effect when <code class=\"option\">--no-sync</code> is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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 CRC-32C 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.</p>\n<p><a class=\"xref\" href=\"/docs/19/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/19/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/19/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"27.2.19.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/19/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>This option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name (<code class=\"literal\">replication</code>) for purposes of looking up the replication connection's password in <code class=\"filename\">~/.pgpass</code>. Similarly, middleware or proxies used in connecting to <span class=\"productname\">PostgreSQL</span> might utilize the name for purposes such as connection routing. The database name can also be used by <a class=\"link\" href=\"/docs/19/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/19/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">Section\u00a032.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL and operating system files. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/19/protocol-replication.html\" title=\"54.4.\u00a0Streaming Replication Protocol\">Section\u00a054.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, the tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later, and incremental backup (<code class=\"literal\">--incremental</code>) only works with server version 17 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n<p>To create a backup of the local server with one tar file for each tablespace compressed with <span class=\"application\">gzip</span> at level 9, stored in the directory <code class=\"filename\">backup</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft --compress=gzip:9</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/19/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a>, <a class=\"xref\" href=\"/docs/19/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.7.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.7</a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "signature": "-i old_manifest_file --incremental= old_manifest_file", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "signature": "-t target --target= target", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "signature": "-c {fast|spread} --checkpoint={fast|spread}", "description": "Sets checkpoint mode to fast or spread (see Section 25.3.4 ). The default is spread."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "signature": "--sync-method= method", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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 CRC-32C 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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "0b9d45700823d646b3b9768e4659fe4e693f0bd75c42184c1e47a39fdde2b788"}, "20": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "20devel"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "35"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-i old_manifest_file --incremental= old_manifest_file"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-t target --target= target"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]"}}, {"summary": "Sets checkpoint mode to fast or spread (see Section 25.3.4 ). The default is spread.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-c {fast|spread} --checkpoint={fast|spread}"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "--sync-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/devel/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": "-i old_manifest_file --incremental= old_manifest_file", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/devel/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": "-t target --target= target", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/devel/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "summary": "Sets checkpoint mode to fast or spread (see Section 25.3.4 ). The default is spread.", "signature": "-c {fast|spread} --checkpoint={fast|spread}", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast or spread (see Section 25.3.4 ). The default is spread."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/devel/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/devel/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": "--sync-method= method", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/devel/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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 CRC-32C 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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/devel/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/devel/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/devel/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/devel/app-pgbasebackup.html", "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 pg_stat_database view. Checksums must be enabled on the server for the duration of the base backup in order to be verified. If checksums are in the process of being enabled when the base backup starts then checksum verification is disabled for the base backup."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/devel/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/devel/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=20", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "label": "20devel", "major": "20", "channel": "devel", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/20/postgresql-20-A4.pdf", "bytes": 16030631, "pages": 3052, "sha256": "bd5d82c0ce38fc18f92a0447818a91a193a261776bca1c37564bf9a683e177d0", "built_at": "2026-09-28"}, "US": {"url": "/files/documentation/pdf/20/postgresql-20-US.pdf", "bytes": 15936613, "pages": 3223, "sha256": "d97d9e0db479a02f4234b175f50fcad70c3661619afc8d6df9b9437882e3c299", "built_at": "2026-09-28"}}, "tree": "0", "index": "index.html", "major": "20", "pages": 1156, "release": "20devel", "source_url": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "svg_assets": 6, "source_mode": "en SGML built with pinned official archive", "source_sha256": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41", "source_snapshot_utc": "26-Sep-2026 20:22"}, "revision": "2eba5e0fd4c3bffb2803247b6cd537878e9d6ee5a6dfbe3c50ece8b421b80918", "evidence_kind": "English manual and source declarations", "source_sha256": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41"}, "sources": [{"url": "/docs/devel/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "20devel English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "8e8e29426743c0dc0a2c14166d80fb67f95bf1c3536f3fd8de25fe091dab5c8b"}, {"url": "/docs/devel/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "a6c7ba748fa1d9feac5bb7cde41d1d36a1f4c26d5963e07fb103d02918b2a8ca"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/devel/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/devel/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> can take a full or incremental base backup of the database. When used to take a full backup, it makes an exact copy of the database cluster's files. When used to take an incremental backup, some files that would have been part of a full backup may be replaced with incremental versions of the same files, containing only those blocks that have been modified since the reference backup. An incremental backup cannot be used directly; instead, <a class=\"xref\" href=\"/docs/devel/app-pgcombinebackup.html\" title=\"pg_combinebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_combinebackup</span></span></a> must first be used to combine it with the previous backups upon which it depends. See <a class=\"xref\" href=\"/docs/devel/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">Section\u00a025.3.3</a> for more information about incremental backups, and <a class=\"xref\" href=\"/docs/devel/continuous-archiving.html#BACKUP-PITR-RECOVERY\" title=\"25.3.5.\u00a0Recovering Using a Continuous Archive Backup\">Section\u00a025.3.5</a> for steps to recover from a backup.</p>\n<p>In any mode, <span class=\"application\">pg_basebackup</span> makes 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/devel/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/devel/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/devel/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/devel/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/devel/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.7.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.7</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i <em class=\"replaceable\"><code>old_manifest_file</code></em></code><br></span><span class=\"term\"><code class=\"option\">--incremental=<em class=\"replaceable\"><code>old_manifest_file</code></em></code></span></dt>\n<dd>\n<p>Performs an <a class=\"link\" href=\"/docs/devel/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">incremental backup</a>. The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/devel/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication and <a class=\"link\" href=\"/docs/devel/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a> will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or <a class=\"link\" href=\"/docs/devel/libpq-envars.html\" title=\"32.14.\u00a0Environment Variables\">environment variable</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>target</code></em></code><br></span><span class=\"term\"><code class=\"option\">--target=<em class=\"replaceable\"><code>target</code></em></code></span></dt>\n<dd>\n<p>Instructs the server where to place the base backup. The default target is <code class=\"literal\">client</code>, which specifies that the backup should be sent to the machine where <span class=\"application\">pg_basebackup</span> is running. If the target is instead set to <code class=\"literal\">server:/some/path</code>, the backup will be stored on the machine where the server is running in the <code class=\"literal\">/some/path</code> directory. Storing a backup on the server requires superuser privileges or having privileges of the <code class=\"literal\">pg_write_server_files</code> role. If the target is set to <code class=\"literal\">blackhole</code>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.</p>\n<p>Since WAL streaming is implemented by <span class=\"application\">pg_basebackup</span> rather than by the server, this option cannot be used together with <code class=\"literal\">-Xstream</code>. Since that is the default, when this option is specified, you must also specify either <code class=\"literal\">-Xfetch</code> or <code class=\"literal\">-Xnone</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> is specified, it is possible to start a postmaster in the target directory without the need to consult the WAL archive, thus making the output a completely standalone backup.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">-Z [{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=[{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code></span></dt>\n<dd>\n<p>Requests compression of the backup. If <code class=\"literal\">client</code> or <code class=\"literal\">server</code> is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is <code class=\"literal\">client</code> except when <code class=\"literal\">--target</code> is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When <code class=\"literal\">-Xstream</code>, which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify <code class=\"literal\">-Xfetch</code>.</p>\n<p>The compression method can be set to <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, <code class=\"literal\">zstd</code>, <code class=\"literal\">none</code> for no compression or an integer (no compression if 0, <code class=\"literal\">gzip</code> if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <em class=\"replaceable\"><code>keyword</code></em> or <em class=\"replaceable\"><code>keyword=value</code></em>. Currently, the supported keywords are <code class=\"literal\">level</code>, <code class=\"literal\">long</code>, and <code class=\"literal\">workers</code>. The detail string cannot be used when the compression method is specified as a plain integer.</p>\n<p>If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <code class=\"literal\">gzip</code> compression will be used if the level is greater than 0, and no compression will be used if the level is 0.</p>\n<p>When the tar format is used with <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, or <code class=\"literal\">zstd</code>, the suffix <code class=\"filename\">.gz</code>, <code class=\"filename\">.lz4</code>, or <code class=\"filename\">.zst</code>, respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it.</p>\n<p>When this option is used in combination with <code class=\"literal\">-Xstream</code>, <code class=\"literal\">pg_wal.tar</code> will be compressed using <code class=\"literal\">gzip</code> if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c {fast|spread}</code><br></span><span class=\"term\"><code class=\"option\">--checkpoint={fast|spread}</code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast or spread (see <a class=\"xref\" href=\"/docs/devel/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.4.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.4</a>). The default is spread.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/devel/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sync-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>When set to <code class=\"literal\">fsync</code>, which is the default, <code class=\"command\">pg_basebackup</code> will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.</p>\n<p>On Linux, <code class=\"literal\">syncfs</code> may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, <code class=\"command\">pg_basebackup</code> will also synchronize the file systems that contain the WAL files and each tablespace. See <a class=\"xref\" href=\"/docs/devel/runtime-config-error-handling.html#GUC-RECOVERY-INIT-SYNC-METHOD\">recovery_init_sync_method</a> for information about the caveats to be aware of when using <code class=\"literal\">syncfs</code>.</p>\n<p>This option has no effect when <code class=\"option\">--no-sync</code> is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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 CRC-32C 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.</p>\n<p><a class=\"xref\" href=\"/docs/devel/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/devel/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/devel/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"27.2.20.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n<p>Checksums must be enabled on the server for the duration of the base backup in order to be verified. If checksums are in the process of being enabled when the base backup starts then checksum verification is disabled for the base backup.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/devel/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>This option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name (<code class=\"literal\">replication</code>) for purposes of looking up the replication connection's password in <code class=\"filename\">~/.pgpass</code>. Similarly, middleware or proxies used in connecting to <span class=\"productname\">PostgreSQL</span> might utilize the name for purposes such as connection routing. The database name can also be used by <a class=\"link\" href=\"/docs/devel/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/devel/libpq-envars.html\" title=\"32.14.\u00a0Environment Variables\">Section\u00a032.14</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL and operating system files. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/devel/protocol-replication.html\" title=\"54.4.\u00a0Streaming Replication Protocol\">Section\u00a054.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, the tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later, and incremental backup (<code class=\"literal\">--incremental</code>) only works with server version 17 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n<p>To create a backup of the local server with one tar file for each tablespace compressed with <span class=\"application\">gzip</span> at level 9, stored in the directory <code class=\"filename\">backup</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft --compress=gzip:9</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/devel/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a>, <a class=\"xref\" href=\"/docs/devel/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.7.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.7</a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "signature": "-i old_manifest_file --incremental= old_manifest_file", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "signature": "-t target --target= target", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "signature": "-c {fast|spread} --checkpoint={fast|spread}", "description": "Sets checkpoint mode to fast or spread (see Section 25.3.4 ). The default is spread."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "signature": "--sync-method= method", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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 CRC-32C 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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view. Checksums must be enabled on the server for the duration of the base backup in order to be verified. If checksums are in the process of being enabled when the base backup starts then checksum verification is disabled for the base backup."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "5fca952ed471e4df86add9ceb6b9e1a78175dd501662ede0aebe83562b504eb4"}}}, "snapshot": {"facts": [{"label": "Documented executable", "value": "pg_basebackup"}, {"label": "Executable version", "value": "18.6"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "35"}], "tables": [{"key": "options", "rows": [{"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-D directory --pgdata= directory"}}, {"summary": "Selects the format for the output. format can be one of the following:", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-F format --format= format"}}, {"summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-i old_manifest_file --incremental= old_manifest_file"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-R --write-recovery-conf"}}, {"summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-t target --target= target"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-T olddir = newdir --tablespace-mapping= olddir = newdir"}}, {"summary": "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. 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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--waldir= waldir"}}, {"summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-X method --wal-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-z --gzip"}}, {"summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]"}}, {"summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 ).", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-c {fast|spread} --checkpoint={fast|spread}"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-C --create-slot"}}, {"summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-l label --label= label"}}, {"summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-n --no-clean"}}, {"summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-N --no-sync"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-P --progress"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-r rate --max-rate= rate"}}, {"summary": "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 primary_slot_name . 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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-S slotname --slot= slotname"}}, {"summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--sync-method= method"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-v --verbose"}}, {"summary": "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 .", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--manifest-checksums= algorithm"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--manifest-force-encode"}}, {"summary": "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 view always being NULL .", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--no-estimate-size"}}, {"summary": "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 pg_verifybackup . 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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--no-manifest"}}, {"summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--no-slot"}}, {"summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "--no-verify-checksums"}}, {"summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-d connstr --dbname= connstr"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-h host --host= host"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-p port --port= port"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-s interval --status-interval= interval"}}, {"summary": "Specifies the user name to connect as.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-U username --username= username"}}, {"summary": "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.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-w --no-password"}}, {"summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-W --password"}}, {"summary": "Prints the pg_basebackup version and exits.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-V --version"}}, {"summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": {"url": "/docs/18/app-pgbasebackup.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-D directory", "--pgdata= directory"], "summary": "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.", "signature": "-D directory --pgdata= directory", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "summary": "Selects the format for the output. format can be one of the following:", "signature": "-F format --format= format", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "summary": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.", "signature": "-i old_manifest_file --incremental= old_manifest_file", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "summary": "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.", "signature": "-R --write-recovery-conf", "source_url": "/docs/18/app-pgbasebackup.html", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "summary": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.", "signature": "-t target --target= target", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "summary": "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.", "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["--waldir= waldir"], "summary": "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. 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.", "signature": "--waldir= waldir", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "summary": "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 WAL archive, thus making the output a completely standalone backup.", "signature": "-X method --wal-method= method", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "summary": "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.", "signature": "-z --gzip", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "summary": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch .", "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "summary": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 ).", "signature": "-c {fast|spread} --checkpoint={fast|spread}", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 )."}, {"names": ["-C", "--create-slot"], "summary": "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.", "signature": "-C --create-slot", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["-l label", "--label= label"], "summary": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used.", "signature": "-l label --label= label", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "summary": "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, the target directory and write-ahead log directory). This option inhibits tidying-up and is thus useful for debugging.", "signature": "-n --no-clean", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "summary": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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.", "signature": "-N --no-sync", "source_url": "/docs/18/app-pgbasebackup.html", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "summary": "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.", "signature": "-P --progress", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["-r rate", "--max-rate= rate"], "summary": "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.", "signature": "-r rate --max-rate= rate", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "summary": "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 primary_slot_name . 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.", "signature": "-S slotname --slot= slotname", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "summary": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.", "signature": "--sync-method= method", "source_url": "/docs/18/app-pgbasebackup.html", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "summary": "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.", "signature": "-v --verbose", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["--manifest-checksums= algorithm"], "summary": "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 .", "signature": "--manifest-checksums= algorithm", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 CRC-32C 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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "summary": "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.", "signature": "--manifest-force-encode", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["--no-estimate-size"], "summary": "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 view always being NULL .", "signature": "--no-estimate-size", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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 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 ."}, {"names": ["--no-manifest"], "summary": "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 pg_verifybackup . 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.", "signature": "--no-manifest", "source_url": "/docs/18/app-pgbasebackup.html", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "summary": "Prevents the creation of a temporary replication slot for the backup.", "signature": "--no-slot", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["--no-verify-checksums"], "summary": "Disables verification of checksums, if they are enabled on the server the base backup is taken from.", "signature": "--no-verify-checksums", "source_url": "/docs/18/app-pgbasebackup.html", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "summary": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options.", "signature": "-d connstr --dbname= connstr", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "summary": "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.", "signature": "-h host --host= host", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["-p port", "--port= port"], "summary": "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.", "signature": "-p port --port= port", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "summary": "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.", "signature": "-s interval --status-interval= interval", "source_url": "/docs/18/app-pgbasebackup.html", "description": "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."}, {"names": ["-U username", "--username= username"], "summary": "Specifies the user name to connect as.", "signature": "-U username --username= username", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "summary": "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.", "signature": "-w --no-password", "source_url": "/docs/18/app-pgbasebackup.html", "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."}, {"names": ["-W", "--password"], "summary": "Forces pg_basebackup to prompt for a password before connecting to the source server.", "signature": "-W --password", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "summary": "Prints the pg_basebackup version and exits.", "signature": "-V --version", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "summary": "Shows help about pg_basebackup command line arguments, and exits.", "signature": "-? --help", "source_url": "/docs/18/app-pgbasebackup.html", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "related": [{"url": "/wiki/conn/?v=18", "label": "libpq connection parameters"}], "release": {"ref": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "label": "18.6", "major": "18", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/18/postgresql-18-A4.pdf", "bytes": 15865106, "pages": 3154, "sha256": "19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/18/postgresql-18-US.pdf", "bytes": 15748059, "pages": 3328, "sha256": "facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319", "built_at": "2026-09-26"}}, "tree": "18", "index": "index.html", "major": "18", "pages": 1148, "release": "18.6", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "revision": "ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8", "evidence_kind": "English manual and source declarations", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "sources": [{"url": "/docs/18/app-pgbasebackup.html", "file": "app-pgbasebackup.html", "label": "18.6 English manual \u00b7 app-pgbasebackup.html", "anchor": "", "sha256": "76780bc785b5bf8a7b20cdc1678b3e8d1de6aafb9cc46df9e578012d4f71546b"}, {"url": "/docs/18/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "68f726af77272fe73a827be2b7b5958d0f2239a6f8ed44264e9d42496bfa4fd0"}], "sections": [], "synopsis": ["pg_basebackup [ option ...]"], "signature": "pg_basebackup [ option ...]", "description": ["pg_basebackup \u2014 take a base backup of a PostgreSQL cluster"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"APP-PGBASEBACKUP\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pg_basebackup</span></span></h2>\n<p>pg_basebackup \u2014 take a base backup of a <span class=\"productname\">PostgreSQL</span> cluster</p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pg_basebackup</code> [<em class=\"replaceable\"><code>option</code></em>...]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pg_basebackup</span> is used to take a base backup of a running <span class=\"productname\">PostgreSQL</span> database cluster. The backup is taken without affecting other clients of the database, and can be used both for point-in-time recovery (see <a class=\"xref\" href=\"/docs/18/continuous-archiving.html\" title=\"25.3.\u00a0Continuous Archiving and Point-in-Time Recovery (PITR)\">Section\u00a025.3</a>) and as the starting point for a log-shipping or streaming-replication standby server (see <a class=\"xref\" href=\"/docs/18/warm-standby.html\" title=\"26.2.\u00a0Log-Shipping Standby Servers\">Section\u00a026.2</a>).</p>\n<p><span class=\"application\">pg_basebackup</span> can take a full or incremental base backup of the database. When used to take a full backup, it makes an exact copy of the database cluster's files. When used to take an incremental backup, some files that would have been part of a full backup may be replaced with incremental versions of the same files, containing only those blocks that have been modified since the reference backup. An incremental backup cannot be used directly; instead, <a class=\"xref\" href=\"/docs/18/app-pgcombinebackup.html\" title=\"pg_combinebackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_combinebackup</span></span></a> must first be used to combine it with the previous backups upon which it depends. See <a class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">Section\u00a025.3.3</a> for more information about incremental backups, and <a class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-PITR-RECOVERY\" title=\"25.3.5.\u00a0Recovering Using a Continuous Archive Backup\">Section\u00a025.3.5</a> for steps to recover from a backup.</p>\n<p>In any mode, <span class=\"application\">pg_basebackup</span> makes 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 selective backups, another tool such as <a class=\"xref\" href=\"/docs/18/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a> must be used.</p>\n<p>The backup is made over a regular <span class=\"productname\">PostgreSQL</span> connection that uses the replication protocol. The connection must be made with a user ID that has <code class=\"literal\">REPLICATION</code> permissions (see <a class=\"xref\" href=\"/docs/18/role-attributes.html\" title=\"21.2.\u00a0Role Attributes\">Section\u00a021.2</a>) or is a superuser, and <a class=\"link\" href=\"/docs/18/auth-pg-hba-conf.html\" title=\"20.1.\u00a0The pg_hba.conf File\"><code class=\"filename\">pg_hba.conf</code></a> must permit the replication connection. The server must also be configured with <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-MAX-WAL-SENDERS\">max_wal_senders</a> set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used).</p>\n<p>There can be multiple <code class=\"command\">pg_basebackup</code>s 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.</p>\n<p><span class=\"application\">pg_basebackup</span> can make a base backup from 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 <code class=\"varname\">max_wal_senders</code> and <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-HOT-STANDBY\">hot_standby</a>, and configure its <code class=\"filename\">pg_hba.conf</code> appropriately). You will also need to enable <a class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-FULL-PAGE-WRITES\">full_page_writes</a> on the primary.</p>\n<p>Note that there are some limitations in taking a backup from a standby:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The backup history file is not created in the database cluster backed up.</p>\n</li>\n<li class=\"listitem\">\n<p><span class=\"application\">pg_basebackup</span> cannot force the standby to switch to a new WAL file at the end of backup. When you are using <code class=\"literal\">-X none</code>, if write activity on the primary is low, <span class=\"application\">pg_basebackup</span> may need to wait a long time for the last WAL file required for the backup to be switched and archived. In this case, it may be useful to run <code class=\"function\">pg_switch_wal</code> on the primary in order to trigger an immediate WAL file switch.</p>\n</li>\n<li class=\"listitem\">\n<p>If the standby is promoted to be primary during backup, the backup fails.</p>\n</li>\n<li class=\"listitem\">\n<p>All WAL records required for the backup must contain sufficient full-page writes, which requires you to enable <code class=\"varname\">full_page_writes</code> on the primary.</p>\n</li>\n</ul>\n</div>\n<p>Whenever <span class=\"application\">pg_basebackup</span> is taking a base backup, the server's <code class=\"structname\">pg_stat_progress_basebackup</code> view will report the progress of the backup. See <a class=\"xref\" href=\"/docs/18/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.6.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.6</a> for details.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following command-line options control the location and format of the output:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-D <em class=\"replaceable\"><code>directory</code></em></code><br></span><span class=\"term\"><code class=\"option\">--pgdata=<em class=\"replaceable\"><code>directory</code></em></code></span></dt>\n<dd>\n<p>Sets the target directory to write the output to. <span class=\"application\">pg_basebackup</span> will create this directory (and any missing parent directories) if it does not exist. If it already exists, it must be empty.</p>\n<p>When the backup is in tar format, the target directory may be specified as <code class=\"literal\">-</code> (dash), causing the tar file to be written to <code class=\"literal\">stdout</code>.</p>\n<p>This option is required.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F <em class=\"replaceable\"><code>format</code></em></code><br></span><span class=\"term\"><code class=\"option\">--format=<em class=\"replaceable\"><code>format</code></em></code></span></dt>\n<dd>\n<p>Selects the format for the output. <em class=\"replaceable\"><code>format</code></em> can be one of the following:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">p</code><br></span><span class=\"term\"><code class=\"literal\">plain</code></span></dt>\n<dd>\n<p>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 <code class=\"option\">--tablespace-mapping</code> to change that.)</p>\n<p>This is the default format.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code><br></span><span class=\"term\"><code class=\"literal\">tar</code></span></dt>\n<dd>\n<p>Write the output as tar files in the target directory. The main data directory's contents will be written to a file named <code class=\"filename\">base.tar</code>, and each other tablespace will be written to a separate tar file named after that tablespace's OID.</p>\n<p>If the target directory is specified as <code class=\"literal\">-</code> (dash), the tar contents will be written to standard output, suitable for piping to (for example) <span class=\"productname\">gzip</span>. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i <em class=\"replaceable\"><code>old_manifest_file</code></em></code><br></span><span class=\"term\"><code class=\"option\">--incremental=<em class=\"replaceable\"><code>old_manifest_file</code></em></code></span></dt>\n<dd>\n<p>Performs an <a class=\"link\" href=\"/docs/18/continuous-archiving.html#BACKUP-INCREMENTAL-BACKUP\" title=\"25.3.3.\u00a0Making an Incremental Backup\">incremental backup</a>. The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code><br></span><span class=\"term\"><code class=\"option\">--write-recovery-conf</code></span></dt>\n<dd>\n<p>Creates a <a class=\"link\" href=\"/docs/18/warm-standby.html#FILE-STANDBY-SIGNAL\"><code class=\"filename\">standby.signal</code></a>  file and appends connection settings to the <code class=\"filename\">postgresql.auto.conf</code> 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.</p>\n<p>The <code class=\"filename\">postgresql.auto.conf</code> file will record the connection settings and, if specified, the replication slot that <span class=\"application\">pg_basebackup</span> is using, so that streaming replication and <a class=\"link\" href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a> will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or <a class=\"link\" href=\"/docs/18/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">environment variable</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t <em class=\"replaceable\"><code>target</code></em></code><br></span><span class=\"term\"><code class=\"option\">--target=<em class=\"replaceable\"><code>target</code></em></code></span></dt>\n<dd>\n<p>Instructs the server where to place the base backup. The default target is <code class=\"literal\">client</code>, which specifies that the backup should be sent to the machine where <span class=\"application\">pg_basebackup</span> is running. If the target is instead set to <code class=\"literal\">server:/some/path</code>, the backup will be stored on the machine where the server is running in the <code class=\"literal\">/some/path</code> directory. Storing a backup on the server requires superuser privileges or having privileges of the <code class=\"literal\">pg_write_server_files</code> role. If the target is set to <code class=\"literal\">blackhole</code>, the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup.</p>\n<p>Since WAL streaming is implemented by <span class=\"application\">pg_basebackup</span> rather than by the server, this option cannot be used together with <code class=\"literal\">-Xstream</code>. Since that is the default, when this option is specified, you must also specify either <code class=\"literal\">-Xfetch</code> or <code class=\"literal\">-Xnone</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T <em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code><br></span><span class=\"term\"><code class=\"option\">--tablespace-mapping=<em class=\"replaceable\"><code>olddir</code></em>=<em class=\"replaceable\"><code>newdir</code></em></code></span></dt>\n<dd>\n<p>Relocates the tablespace in directory <em class=\"replaceable\"><code>olddir</code></em> to <em class=\"replaceable\"><code>newdir</code></em> during the backup. To be effective, <em class=\"replaceable\"><code>olddir</code></em> 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 <em class=\"replaceable\"><code>olddir</code></em> on the source server.) Meanwhile <em class=\"replaceable\"><code>newdir</code></em> is a directory in the receiving host's filesystem. As with the main target directory, <em class=\"replaceable\"><code>newdir</code></em> need not exist already, but if it does exist it must be empty. Both <em class=\"replaceable\"><code>olddir</code></em> and <em class=\"replaceable\"><code>newdir</code></em> must be absolute paths. If either path needs to contain an equal sign (<code class=\"literal\">=</code>), precede that with a backslash. This option can be specified multiple times for multiple tablespaces.</p>\n<p>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.</p>\n<p>Currently, this option only works with plain output format; it is ignored if tar format is selected.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--waldir=<em class=\"replaceable\"><code>waldir</code></em></code></span></dt>\n<dd>\n<p>Sets the directory to write WAL (write-ahead log) files to. By default WAL files will be placed in the <code class=\"filename\">pg_wal</code> subdirectory of the target directory, but this option can be used to place them elsewhere. <em class=\"replaceable\"><code>waldir</code></em> must be an absolute path. As with the main target directory, <em class=\"replaceable\"><code>waldir</code></em> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-X <em class=\"replaceable\"><code>method</code></em></code><br></span><span class=\"term\"><code class=\"option\">--wal-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">none</code> is specified, it is possible to start a postmaster in the target directory without the need to consult the WAL archive, thus making the output a completely standalone backup.</p>\n<p>The following <em class=\"replaceable\"><code>method</code></em>s for collecting the write-ahead logs are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">n</code><br></span><span class=\"term\"><code class=\"literal\">none</code></span></dt>\n<dd>\n<p>Don't include write-ahead logs in the backup.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code><br></span><span class=\"term\"><code class=\"literal\">fetch</code></span></dt>\n<dd>\n<p>The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the source server's <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-WAL-KEEP-SIZE\">wal_keep_size</a> 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.</p>\n<p>When tar format is used, the write-ahead log files will be included in the <code class=\"filename\">base.tar</code> file.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">s</code><br></span><span class=\"term\"><code class=\"literal\">stream</code></span></dt>\n<dd>\n<p>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.</p>\n<p>When tar format is used, the write-ahead log files will be written to a separate file named <code class=\"filename\">pg_wal.tar</code> (if the server is a version earlier than 10, the file will be named <code class=\"filename\">pg_xlog.tar</code>).</p>\n<p>This value is the default.</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-z</code><br></span><span class=\"term\"><code class=\"option\">--gzip</code></span></dt>\n<dd>\n<p>Enables gzip compression of tar file output, with the default compression level. Compression is only available when using the tar format, and the suffix <code class=\"filename\">.gz</code> will automatically be added to all tar filenames.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-Z <em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">-Z [{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code><br></span><span class=\"term\"><code class=\"option\">--compress=<em class=\"replaceable\"><code>level</code></em></code><br></span><span class=\"term\"><code class=\"option\">--compress=[{client|server}-]<em class=\"replaceable\"><code>method</code></em>[:<em class=\"replaceable\"><code>detail</code></em>]</code></span></dt>\n<dd>\n<p>Requests compression of the backup. If <code class=\"literal\">client</code> or <code class=\"literal\">server</code> is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is <code class=\"literal\">client</code> except when <code class=\"literal\">--target</code> is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When <code class=\"literal\">-Xstream</code>, which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify <code class=\"literal\">-Xfetch</code>.</p>\n<p>The compression method can be set to <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, <code class=\"literal\">zstd</code>, <code class=\"literal\">none</code> for no compression or an integer (no compression if 0, <code class=\"literal\">gzip</code> if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form <em class=\"replaceable\"><code>keyword</code></em> or <em class=\"replaceable\"><code>keyword=value</code></em>. Currently, the supported keywords are <code class=\"literal\">level</code>, <code class=\"literal\">long</code>, and <code class=\"literal\">workers</code>. The detail string cannot be used when the compression method is specified as a plain integer.</p>\n<p>If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, <code class=\"literal\">gzip</code> compression will be used if the level is greater than 0, and no compression will be used if the level is 0.</p>\n<p>When the tar format is used with <code class=\"literal\">gzip</code>, <code class=\"literal\">lz4</code>, or <code class=\"literal\">zstd</code>, the suffix <code class=\"filename\">.gz</code>, <code class=\"filename\">.lz4</code>, or <code class=\"filename\">.zst</code>, respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it.</p>\n<p>When this option is used in combination with <code class=\"literal\">-Xstream</code>, <code class=\"literal\">pg_wal.tar</code> will be compressed using <code class=\"literal\">gzip</code> if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the generation of the backup and the invocation of the program:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-c {fast|spread}</code><br></span><span class=\"term\"><code class=\"option\">--checkpoint={fast|spread}</code></span></dt>\n<dd>\n<p>Sets checkpoint mode to fast (immediate) or spread (the default) (see <a class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP\" title=\"25.3.4.\u00a0Making a Base Backup Using the Low Level API\">Section\u00a025.3.4</a>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--create-slot</code></span></dt>\n<dd>\n<p>Specifies that the replication slot named by the <code class=\"literal\">--slot</code> option should be created before starting the backup. An error is raised if the slot already exists.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l <em class=\"replaceable\"><code>label</code></em></code><br></span><span class=\"term\"><code class=\"option\">--label=<em class=\"replaceable\"><code>label</code></em></code></span></dt>\n<dd>\n<p>Sets the label for the backup. If none is specified, a default value of <span class=\"quote\">\u201c<span class=\"quote\"><code class=\"literal\">pg_basebackup base backup</code></span>\u201d</span> will be used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-clean</code></span></dt>\n<dd>\n<p>By default, when <code class=\"command\">pg_basebackup</code> 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.</p>\n<p>Note that tablespace directories are not cleaned up either way.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--no-sync</code></span></dt>\n<dd>\n<p>By default, <code class=\"command\">pg_basebackup</code> will wait for all files to be written safely to disk. This option causes <code class=\"command\">pg_basebackup</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code><br></span><span class=\"term\"><code class=\"option\">--progress</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100%</code>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r <em class=\"replaceable\"><code>rate</code></em></code><br></span><span class=\"term\"><code class=\"option\">--max-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sets the maximum transfer rate at which data is collected from the source server. This can be useful to limit the impact of <span class=\"application\">pg_basebackup</span> on the server. Values are in kilobytes per second. Use a suffix of <code class=\"literal\">M</code> to indicate megabytes per second. A suffix of <code class=\"literal\">k</code> is also accepted, and has no effect. Valid values are between 32 kilobytes per second and 1024 megabytes per second.</p>\n<p>This option always affects transfer of the data directory. Transfer of WAL files is only affected if the collection method is <code class=\"literal\">fetch</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S <em class=\"replaceable\"><code>slotname</code></em></code><br></span><span class=\"term\"><code class=\"option\">--slot=<em class=\"replaceable\"><code>slotname</code></em></code></span></dt>\n<dd>\n<p>This option can only be used together with <code class=\"literal\">-X stream</code>. 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 <a class=\"xref\" href=\"/docs/18/runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME\">primary_slot_name</a>. 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.</p>\n<p>The specified replication slot has to exist unless the option <code class=\"option\">-C</code> is also used.</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sync-method=<em class=\"replaceable\"><code>method</code></em></code></span></dt>\n<dd>\n<p>When set to <code class=\"literal\">fsync</code>, which is the default, <code class=\"command\">pg_basebackup</code> will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace.</p>\n<p>On Linux, <code class=\"literal\">syncfs</code> may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, <code class=\"command\">pg_basebackup</code> will also synchronize the file systems that contain the WAL files and each tablespace. See <a class=\"xref\" href=\"/docs/18/runtime-config-error-handling.html#GUC-RECOVERY-INIT-SYNC-METHOD\">recovery_init_sync_method</a> for information about the caveats to be aware of when using <code class=\"literal\">syncfs</code>.</p>\n<p>This option has no effect when <code class=\"option\">--no-sync</code> is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--verbose</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-checksums=<em class=\"replaceable\"><code>algorithm</code></em></code></span></dt>\n<dd>\n<p>Specifies the checksum algorithm that should be applied to each file included in the backup manifest. Currently, the available algorithms are <code class=\"literal\">NONE</code>, <code class=\"literal\">CRC32C</code>, <code class=\"literal\">SHA224</code>, <code class=\"literal\">SHA256</code>, <code class=\"literal\">SHA384</code>, and <code class=\"literal\">SHA512</code>. The default is <code class=\"literal\">CRC32C</code>.</p>\n<p>If <code class=\"literal\">NONE</code> 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 <code class=\"literal\">SHA256</code> checksum of its own contents. The <code class=\"literal\">SHA</code> algorithms are significantly more CPU-intensive than <code class=\"literal\">CRC32C</code>, so selecting one of them may increase the time required to complete the backup.</p>\n<p>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 CRC-32C 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.</p>\n<p><a class=\"xref\" href=\"/docs/18/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a> can be used to check the integrity of a backup against the backup manifest.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--manifest-force-encode</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-estimate-size</code></span></dt>\n<dd>\n<p>Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the <code class=\"structfield\">backup_total</code> column in the <code class=\"structname\">pg_stat_progress_basebackup</code> view always being <code class=\"literal\">NULL</code>.</p>\n<p>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.</p>\n<p>This option is not allowed when using <code class=\"option\">--progress</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-manifest</code></span></dt>\n<dd>\n<p>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 <a class=\"xref\" href=\"/docs/18/app-pgverifybackup.html\" title=\"pg_verifybackup\"><span class=\"refentrytitle\"><span class=\"application\">pg_verifybackup</span></span></a>. 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-slot</code></span></dt>\n<dd>\n<p>Prevents the creation of a temporary replication slot for the backup.</p>\n<p>By default, if log streaming is selected but no slot name is given with the <code class=\"option\">-S</code> option, then a temporary replication slot is created (if supported by the source server).</p>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--no-verify-checksums</code></span></dt>\n<dd>\n<p>Disables verification of checksums, if they are enabled on the server the base backup is taken from.</p>\n<p>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 <code class=\"option\">--no-clean</code> option had been used. Checksum verification failures will also be reported in the <a class=\"link\" href=\"/docs/18/monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW\" title=\"27.2.17.\u00a0pg_stat_database\"><code class=\"structname\">pg_stat_database</code></a> view.</p>\n</dd>\n</dl>\n</div>\n<p>The following command-line options control the connection to the source server:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-d <em class=\"replaceable\"><code>connstr</code></em></code><br></span><span class=\"term\"><code class=\"option\">--dbname=<em class=\"replaceable\"><code>connstr</code></em></code></span></dt>\n<dd>\n<p>Specifies parameters used to connect to the server, as a <a class=\"link\" href=\"/docs/18/libpq-connect.html#LIBPQ-CONNSTRING\" title=\"32.1.1.\u00a0Connection Strings\">connection string</a>; these will override any conflicting command line options.</p>\n<p>This option is called <code class=\"literal\">--dbname</code> for consistency with other client applications, but because <span class=\"application\">pg_basebackup</span> doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name (<code class=\"literal\">replication</code>) for purposes of looking up the replication connection's password in <code class=\"filename\">~/.pgpass</code>. Similarly, middleware or proxies used in connecting to <span class=\"productname\">PostgreSQL</span> might utilize the name for purposes such as connection routing. The database name can also be used by <a class=\"link\" href=\"/docs/18/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION\" title=\"47.2.3.\u00a0Replication Slot Synchronization\">logical replication slot synchronization</a>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-h <em class=\"replaceable\"><code>host</code></em></code><br></span><span class=\"term\"><code class=\"option\">--host=<em class=\"replaceable\"><code>host</code></em></code></span></dt>\n<dd>\n<p>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 <code class=\"envar\">PGHOST</code> environment variable, if set, else a Unix domain socket connection is attempted.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p <em class=\"replaceable\"><code>port</code></em></code><br></span><span class=\"term\"><code class=\"option\">--port=<em class=\"replaceable\"><code>port</code></em></code></span></dt>\n<dd>\n<p>Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the <code class=\"envar\">PGPORT</code> environment variable, if set, or a compiled-in default.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s <em class=\"replaceable\"><code>interval</code></em></code><br></span><span class=\"term\"><code class=\"option\">--status-interval=<em class=\"replaceable\"><code>interval</code></em></code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U <em class=\"replaceable\"><code>username</code></em></code><br></span><span class=\"term\"><code class=\"option\">--username=<em class=\"replaceable\"><code>username</code></em></code></span></dt>\n<dd>\n<p>Specifies the user name to connect as.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-w</code><br></span><span class=\"term\"><code class=\"option\">--no-password</code></span></dt>\n<dd>\n<p>Prevents issuing a password prompt. If the server requires password authentication and a password is not available by other means such as a <code class=\"filename\">.pgpass</code> 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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-W</code><br></span><span class=\"term\"><code class=\"option\">--password</code></span></dt>\n<dd>\n<p>Forces <span class=\"application\">pg_basebackup</span> to prompt for a password before connecting to the source server.</p>\n<p>This option is never essential, since <span class=\"application\">pg_basebackup</span> will automatically prompt for a password if the server demands password authentication. However, <span class=\"application\">pg_basebackup</span> will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing <code class=\"option\">-W</code> to avoid the extra connection attempt.</p>\n</dd>\n</dl>\n</div>\n<p>Other options are also available:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Prints the <span class=\"application\">pg_basebackup</span> version and exits.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Shows help about <span class=\"application\">pg_basebackup</span> command line arguments, and exits.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Environment</h2>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/18/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">Section\u00a032.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Notes</h2>\n<p>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 <code class=\"literal\">--checkpoint=fast</code> is not used), during which <span class=\"application\">pg_basebackup</span> will appear to be idle.</p>\n<p>The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL and operating system files. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories. Other symbolic links and special device files are skipped. See <a class=\"xref\" href=\"/docs/18/protocol-replication.html\" title=\"54.4.\u00a0Streaming Replication Protocol\">Section\u00a054.4</a> for the precise details.</p>\n<p>In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option <code class=\"literal\">--tablespace-mapping</code> 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 have to be written to the same directory locations as the original tablespaces.</p>\n<p>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 <code class=\"filename\">tablespace_map</code> file that is included in the <code class=\"filename\">base.tar</code> file.</p>\n<p><span class=\"application\">pg_basebackup</span> works with servers of the same or older major version, down to 9.1. However, WAL streaming mode (<code class=\"literal\">-X stream</code>) only works with server version 9.3 and later, the tar format (<code class=\"literal\">--format=tar</code>) only works with server version 9.5 and later, and incremental backup (<code class=\"literal\">--incremental</code>) only works with server version 17 and later.</p>\n<p><span class=\"application\">pg_basebackup</span> will preserve group permissions for data files if group permissions are enabled on the source cluster.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Examples</h2>\n<p>To create a base backup of the server at <code class=\"literal\">mydbserver</code> and store it in the local directory <code class=\"filename\">/usr/local/pgsql/data</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>\n</pre>\n<p>To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory <code class=\"filename\">backup</code>, showing a progress report while running:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft -z -P</code></strong>\n</pre>\n<p>To create a backup of a single-tablespace local database and compress this with <span class=\"productname\">bzip2</span>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D - -Ft -X fetch | bzip2 &gt; backup.tar.bz2</code></strong>\n</pre>\n<p>(This command will fail if there are multiple tablespaces in the database.)</p>\n<p>To create a backup of a local database where the tablespace in <code class=\"filename\">/opt/ts</code> is relocated to <code class=\"filename\">./backup/ts</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>\n</pre>\n<p>To create a backup of the local server with one tar file for each tablespace compressed with <span class=\"application\">gzip</span> at level 9, stored in the directory <code class=\"filename\">backup</code>:</p>\n<pre class=\"screen\"><code class=\"prompt\">$</code> <strong class=\"userinput\"><code>pg_basebackup -D backup -Ft --compress=gzip:9</code></strong>\n</pre>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.10\">\n<h2>See Also</h2><span class=\"simplelist\"><a class=\"xref\" href=\"/docs/18/app-pgdump.html\" title=\"pg_dump\"><span class=\"refentrytitle\"><span class=\"application\">pg_dump</span></span></a>, <a class=\"xref\" href=\"/docs/18/progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING\" title=\"27.4.6.\u00a0Base Backup Progress Reporting\">Section\u00a027.4.6</a></span>\n</div>\n</div></div>", "manual_path": "app-pgbasebackup.html", "comparison_data": {"options": [{"names": ["-D directory", "--pgdata= directory"], "signature": "-D directory --pgdata= directory", "description": "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 format, the target directory may be specified as - (dash), causing the tar file to be written to stdout . This option is required."}, {"names": ["-F format", "--format= format"], "signature": "-F format --format= format", "description": "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."}, {"names": ["-i old_manifest_file", "--incremental= old_manifest_file"], "signature": "-i old_manifest_file --incremental= old_manifest_file", "description": "Performs an incremental backup . The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup."}, {"names": ["-R", "--write-recovery-conf"], "signature": "-R --write-recovery-conf", "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 pg_basebackup is using, so that streaming replication and logical replication slot synchronization will use the same settings later on. The dbname will be recorded only if the dbname was specified explicitly in the connection string or environment variable ."}, {"names": ["-t target", "--target= target"], "signature": "-t target --target= target", "description": "Instructs the server where to place the base backup. The default target is client , which specifies that the backup should be sent to the machine where pg_basebackup is running. If the target is instead set to server:/some/path , the backup will be stored on the machine where the server is running in the /some/path directory. Storing a backup on the server requires superuser privileges or having privileges of the pg_write_server_files role. If the target is set to blackhole , the contents are discarded and not stored anywhere. This should only be used for testing purposes, as you will not end up with an actual backup. Since WAL streaming is implemented by pg_basebackup rather than by the server, this option cannot be used together with -Xstream . Since that is the default, when this option is specified, you must also specify either -Xfetch or -Xnone ."}, {"names": ["-T olddir = newdir", "--tablespace-mapping= olddir = newdir"], "signature": "-T olddir = newdir --tablespace-mapping= olddir = newdir", "description": "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."}, {"names": ["--waldir= waldir"], "signature": "--waldir= waldir", "description": "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. 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."}, {"names": ["-X method", "--wal-method= method"], "signature": "-X method --wal-method= method", "description": "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 WAL archive, thus making the output a completely standalone backup. The following method s 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 wal_keep_size 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 pg_wal.tar (if the server is a version earlier than 10, the file will be named pg_xlog.tar ). This value is the default."}, {"names": ["-z", "--gzip"], "signature": "-z --gzip", "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."}, {"names": ["-Z level", "-Z [{client|server}-] method [: detail ]", "--compress= level", "--compress=[{client|server}-] method [: detail ]"], "signature": "-Z level -Z [{client|server}-] method [: detail ] --compress= level --compress=[{client|server}-] method [: detail ]", "description": "Requests compression of the backup. If client or server is included, it specifies where the compression is to be performed. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption. The default is client except when --target is used. In that case, the backup is not being sent to the client, so only server compression is sensible. When -Xstream , which is the default, is used, server-side compression will not be applied to the WAL. To compress the WAL, use client-side compression, or specify -Xfetch . The compression method can be set to gzip , lz4 , zstd , none for no compression or an integer (no compression if 0, gzip if greater than 0). A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the form keyword or keyword=value . Currently, the supported keywords are level , long , and workers . The detail string cannot be used when the compression method is specified as a plain integer. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0. When the tar format is used with gzip , lz4 , or zstd , the suffix .gz , .lz4 , or .zst , respectively, will be automatically added to all tar filenames. When the plain format is used, client-side compression may not be specified, but it is still possible to request server-side compression. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it. When this option is used in combination with -Xstream , pg_wal.tar will be compressed using gzip if client-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server-side compression is selected."}, {"names": ["-c {fast|spread}", "--checkpoint={fast|spread}"], "signature": "-c {fast|spread} --checkpoint={fast|spread}", "description": "Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.4 )."}, {"names": ["-C", "--create-slot"], "signature": "-C --create-slot", "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."}, {"names": ["-l label", "--label= label"], "signature": "-l label --label= label", "description": "Sets the label for the backup. If none is specified, a default value of \u201c pg_basebackup base backup \u201d will be used."}, {"names": ["-n", "--no-clean"], "signature": "-n --no-clean", "description": "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, 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."}, {"names": ["-N", "--no-sync"], "signature": "-N --no-sync", "description": "By default, pg_basebackup will wait for all files to be written safely to disk. This option causes pg_basebackup 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."}, {"names": ["-P", "--progress"], "signature": "-P --progress", "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."}, {"names": ["-r rate", "--max-rate= rate"], "signature": "-r rate --max-rate= rate", "description": "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 ."}, {"names": ["-S slotname", "--slot= slotname"], "signature": "-S slotname --slot= slotname", "description": "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 primary_slot_name . 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."}, {"names": ["--sync-method= method"], "signature": "--sync-method= method", "description": "When set to fsync , which is the default, pg_basebackup will recursively open and synchronize all files in the backup directory. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace. On Linux, syncfs may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory. When the plain format is used, pg_basebackup will also synchronize the file systems that contain the WAL files and each tablespace. See recovery_init_sync_method for information about the caveats to be aware of when using syncfs . This option has no effect when --no-sync is used."}, {"names": ["-v", "--verbose"], "signature": "-v --verbose", "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."}, {"names": ["--manifest-checksums= algorithm"], "signature": "--manifest-checksums= algorithm", "description": "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 CRC-32C 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. pg_verifybackup can be used to check the integrity of a backup against the backup manifest."}, {"names": ["--manifest-force-encode"], "signature": "--manifest-force-encode", "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."}, {"names": ["--no-estimate-size"], "signature": "--no-estimate-size", "description": "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 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 ."}, {"names": ["--no-manifest"], "signature": "--no-manifest", "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 pg_verifybackup . 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."}, {"names": ["--no-slot"], "signature": "--no-slot", "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."}, {"names": ["--no-verify-checksums"], "signature": "--no-verify-checksums", "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 pg_stat_database view."}, {"names": ["-d connstr", "--dbname= connstr"], "signature": "-d connstr --dbname= connstr", "description": "Specifies parameters used to connect to the server, as a connection string ; these will override any conflicting command line options. This option is called --dbname for consistency with other client applications, but because pg_basebackup doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name ( replication ) for purposes of looking up the replication connection's password in ~/.pgpass . Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. The database name can also be used by logical replication slot synchronization ."}, {"names": ["-h host", "--host= host"], "signature": "-h host --host= host", "description": "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."}, {"names": ["-p port", "--port= port"], "signature": "-p port --port= port", "description": "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."}, {"names": ["-s interval", "--status-interval= interval"], "signature": "-s interval --status-interval= interval", "description": "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."}, {"names": ["-U username", "--username= username"], "signature": "-U username --username= username", "description": "Specifies the user name to connect as."}, {"names": ["-w", "--no-password"], "signature": "-w --no-password", "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."}, {"names": ["-W", "--password"], "signature": "-W --password", "description": "Forces pg_basebackup to prompt for a password before connecting to the source server. This option is never essential, since pg_basebackup will automatically prompt for a password if the server demands password authentication. However, pg_basebackup 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."}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Prints the pg_basebackup version and exits."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Shows help about pg_basebackup command line arguments, and exits."}], "synopsis": ["pg_basebackup [ option ...]"], "environment": []}, "comparison_hash": "1355c21a25dc07b130a2e139c0430698018dbc37b620dff3f0f565fbaec56228"}, "comparison": {"left": "13", "right": "14", "status": "changed", "diff": "--- PostgreSQL 13\n+++ PostgreSQL 14\n@@ -65,7 +65,7 @@\n       \"signature\": \"-Z level --compress= level\"\n     },\n     {\n-      \"description\": \"Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 25.3.3 ).\",\n+      \"description\": \"Sets checkpoint mode to fast (immediate) or spread (the default) (see Section 26.3.3 ).\",\n       \"names\": [\n         \"-c fast|spread\",\n         \"--checkpoint= fast|spread\""}}