codekingpro/portable-devtools
115k
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>pg_basebackup</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="app-pgamcheck.html" title="pg_amcheck" /><link rel="next" href="pgbench.html" title="pgbench" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span class="application">pg_basebackup</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pgamcheck.html" title="pg_amcheck">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><th width="60%" align="center">PostgreSQL Client Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="pgbench.html" title="pgbench">Next</a></td></tr></table><hr /></div><div class="refentry" id="APP-PGBASEBACKUP"><div class="titlepage"></div><a id="id-1.9.4.10.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">pg_basebackup</span></span></h2><p>pg_basebackup — take a base backup of a <span class="productname">PostgreSQL</span> cluster</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.10.4.1"><code class="command">pg_basebackup</code> [<em class="replaceable"><code>option</code></em>...]</p></div></div><div class="refsect1" id="id-1.9.4.10.5"><h2>Description</h2><p>3 <span class="application">pg_basebackup</span> is used to take a base backup of4 a running <span class="productname">PostgreSQL</span> database cluster. The backup5 is taken without affecting other clients of the database, and can be used6 both for point-in-time recovery (see <a class="xref" href="continuous-archiving.html" title="26.3. Continuous Archiving and Point-in-Time Recovery (PITR)">Section 26.3</a>)7 and as the starting point for a log-shipping or streaming-replication standby8 server (see <a class="xref" href="warm-standby.html" title="27.2. Log-Shipping Standby Servers">Section 27.2</a>).9 </p><p>10 <span class="application">pg_basebackup</span> makes an exact copy of the database11 cluster's files, while making sure the server is put into and12 out of backup mode automatically. Backups are always taken of the entire13 database cluster; it is not possible to back up individual databases or14 database objects. For selective backups, another tool such as15 <a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle"><span class="application">pg_dump</span></span></a> must be used.16 </p><p>17 The backup is made over a regular <span class="productname">PostgreSQL</span>18 connection that uses the replication protocol. The connection must be made19 with a user ID that has <code class="literal">REPLICATION</code> permissions20 (see <a class="xref" href="role-attributes.html" title="22.2. Role Attributes">Section 22.2</a>) or is a superuser,21 and <a class="link" href="auth-pg-hba-conf.html" title="21.1. The pg_hba.conf File"><code class="filename">pg_hba.conf</code></a>22 must permit the replication connection. The server must also be configured23 with <a class="xref" href="runtime-config-replication.html#GUC-MAX-WAL-SENDERS">max_wal_senders</a> set high enough to provide at24 least one walsender for the backup plus one for WAL streaming (if used).25 </p><p>26 There can be multiple <code class="command">pg_basebackup</code>s running at the same time, but it is usually27 better from a performance point of view to take only one backup, and copy28 the result.29 </p><p>30 <span class="application">pg_basebackup</span> can make a base backup from31 not only a primary server but also a standby. To take a backup from a standby,32 set up the standby so that it can accept replication connections (that is, set33 <code class="varname">max_wal_senders</code> and <a class="xref" href="runtime-config-replication.html#GUC-HOT-STANDBY">hot_standby</a>,34 and configure its <code class="filename">pg_hba.conf</code> appropriately).35 You will also need to enable <a class="xref" href="runtime-config-wal.html#GUC-FULL-PAGE-WRITES">full_page_writes</a> on the primary.36 </p><p>37 Note that there are some limitations in taking a backup from a standby:38 39 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>40 The backup history file is not created in the database cluster backed up.41 </p></li><li class="listitem"><p>42 <span class="application">pg_basebackup</span> cannot force the standby43 to switch to a new WAL file at the end of backup.44 When you are using <code class="literal">-X none</code>, if write activity on45 the primary is low, <span class="application">pg_basebackup</span> may46 need to wait a long time for the last WAL file required for the backup47 to be switched and archived. In this case, it may be useful to run48 <code class="function">pg_switch_wal</code> on the primary in order to49 trigger an immediate WAL file switch.50 </p></li><li class="listitem"><p>51 If the standby is promoted to be primary during backup, the backup fails.52 </p></li><li class="listitem"><p>53 All WAL records required for the backup must contain sufficient full-page writes,54 which requires you to enable <code class="varname">full_page_writes</code> on the primary.55 </p></li></ul></div><p>56 </p><p>57 Whenever <span class="application">pg_basebackup</span> is taking a base58 backup, the server's <code class="structname">pg_stat_progress_basebackup</code>59 view will report the progress of the backup.60 See <a class="xref" href="progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING" title="28.4.6. Base Backup Progress Reporting">Section 28.4.6</a> for details.61 </p></div><div class="refsect1" id="id-1.9.4.10.6"><h2>Options</h2><p>62 The following command-line options control the location and format of the63 output:64 65 </p><div class="variablelist"><dl class="variablelist"><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><dd><p>66 Sets the target directory to write the output to.67 <span class="application">pg_basebackup</span> will create this directory68 (and any missing parent directories) if it does not exist. If it69 already exists, it must be empty.70 </p><p>71 When the backup is in tar format, the target directory may be72 specified as <code class="literal">-</code> (dash), causing the tar file to be73 written to <code class="literal">stdout</code>.74 </p><p>75 This option is required.76 </p></dd><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><dd><p>77 Selects the format for the output. <em class="replaceable"><code>format</code></em>78 can be one of the following:79 80 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">p</code><br /></span><span class="term"><code class="literal">plain</code></span></dt><dd><p>81 Write the output as plain files, with the same layout as the82 source server's data directory and tablespaces. When the cluster has83 no additional tablespaces, the whole database will be placed in84 the target directory. If the cluster contains additional85 tablespaces, the main data directory will be placed in the86 target directory, but all other tablespaces will be placed87 in the same absolute path as they have on the source server.88 (See <code class="option">--tablespace-mapping</code> to change that.)89 </p><p>90 This is the default format.91 </p></dd><dt><span class="term"><code class="literal">t</code><br /></span><span class="term"><code class="literal">tar</code></span></dt><dd><p>92 Write the output as tar files in the target directory. The main93 data directory's contents will be written to a file named94 <code class="filename">base.tar</code>, and each other tablespace will be95 written to a separate tar file named after that tablespace's OID.96 </p><p>97 If the target directory is specified as <code class="literal">-</code>98 (dash), the tar contents will be written to99 standard output, suitable for piping to (for example)100 <span class="productname">gzip</span>. This is only allowed if101 the cluster has no additional tablespaces and WAL102 streaming is not used.103 </p></dd></dl></div></dd><dt><span class="term"><code class="option">-R</code><br /></span><span class="term"><code class="option">--write-recovery-conf</code></span></dt><dd><p>104 Creates a105 <a class="link" href="warm-standby.html#FILE-STANDBY-SIGNAL"><code class="filename">standby.signal</code></a>106 <a id="id-1.9.4.10.6.2.1.3.3.1.2" class="indexterm"></a>107 file and appends108 connection settings to the <code class="filename">postgresql.auto.conf</code>109 file in the target directory (or within the base archive file when110 using tar format). This eases setting up a standby server using the111 results of the backup.112 </p><p>113 The <code class="filename">postgresql.auto.conf</code> file will record the connection114 settings and, if specified, the replication slot115 that <span class="application">pg_basebackup</span> is using, so that116 streaming replication will use the same settings later on.117 </p></dd><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><dd><p>118 Instructs the server where to place the base backup. The default target119 is <code class="literal">client</code>, which specifies that the backup should120 be sent to the machine where <span class="application">pg_basebackup</span>121 is running. If the target is instead set to122 <code class="literal">server:/some/path</code>, the backup will be stored on123 the machine where the server is running in the124 <code class="literal">/some/path</code> directory. Storing a backup on the125 server requires superuser privileges or having privileges of the126 <code class="literal">pg_write_server_files</code> role. If the target is set to127 <code class="literal">blackhole</code>, the contents are discarded and not128 stored anywhere. This should only be used for testing purposes, as you129 will not end up with an actual backup.130 </p><p>131 Since WAL streaming is implemented by132 <span class="application">pg_basebackup</span> rather than by the server,133 this option cannot be used together with <code class="literal">-Xstream</code>.134 Since that is the default, when this option is specified, you must also135 specify either <code class="literal">-Xfetch</code> or <code class="literal">-Xnone</code>.136 </p></dd><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><dd><p>137 Relocates the tablespace in directory <em class="replaceable"><code>olddir</code></em>138 to <em class="replaceable"><code>newdir</code></em> during the backup. To be139 effective, <em class="replaceable"><code>olddir</code></em> must exactly match the140 path specification of the tablespace as it is defined on the source141 server. (But it is not an error if there is no tablespace142 in <em class="replaceable"><code>olddir</code></em> on the source server.)143 Meanwhile <em class="replaceable"><code>newdir</code></em> is a directory in the144 receiving host's filesystem. As with the main target directory,145 <em class="replaceable"><code>newdir</code></em> need not exist already, but if146 it does exist it must be empty.147 Both <em class="replaceable"><code>olddir</code></em>148 and <em class="replaceable"><code>newdir</code></em> must be absolute paths. If149 either path needs to contain an equal sign (<code class="literal">=</code>),150 precede that with a backslash. This option can be specified multiple151 times for multiple tablespaces.152 </p><p>153 If a tablespace is relocated in this way, the symbolic links inside154 the main data directory are updated to point to the new location. So155 the new data directory is ready to be used for a new server instance156 with all tablespaces in the updated locations.157 </p><p>158 Currently, this option only works with plain output format; it is159 ignored if tar format is selected.160 </p></dd><dt><span class="term"><code class="option">--waldir=<em class="replaceable"><code>waldir</code></em></code></span></dt><dd><p>161 Sets the directory to write WAL (write-ahead log) files to.162 By default WAL files will be placed in163 the <code class="filename">pg_wal</code> subdirectory of the target164 directory, but this option can be used to place them elsewhere.165 <em class="replaceable"><code>waldir</code></em> must be an absolute path.166 As with the main target directory,167 <em class="replaceable"><code>waldir</code></em> need not exist already, but if168 it does exist it must be empty.169 This option can only be specified when170 the backup is in plain format.171 </p></dd><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><dd><p>172 Includes the required WAL (write-ahead log) files in the173 backup. This will include all write-ahead logs generated during174 the backup. Unless the method <code class="literal">none</code> is specified,175 it is possible to start a postmaster in the target176 directory without the need to consult the WAL archive, thus177 making the output a completely standalone backup.178 </p><p>179 The following <em class="replaceable"><code>method</code></em>s for collecting the180 write-ahead logs are supported:181 182 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">n</code><br /></span><span class="term"><code class="literal">none</code></span></dt><dd><p>183 Don't include write-ahead logs in the backup.184 </p></dd><dt><span class="term"><code class="literal">f</code><br /></span><span class="term"><code class="literal">fetch</code></span></dt><dd><p>185 The write-ahead log files are collected at the end of the backup.186 Therefore, it is necessary for the source server's187 <a class="xref" href="runtime-config-replication.html#GUC-WAL-KEEP-SIZE">wal_keep_size</a> parameter to be set high188 enough that the required log data is not removed before the end189 of the backup. If the required log data has been recycled190 before it's time to transfer it, the backup will fail and be191 unusable.192 </p><p>193 When tar format is used, the write-ahead log files will be194 included in the <code class="filename">base.tar</code> file.195 </p></dd><dt><span class="term"><code class="literal">s</code><br /></span><span class="term"><code class="literal">stream</code></span></dt><dd><p>196 Stream write-ahead log data while the backup is being taken.197 This method will open a second connection to the server and198 start streaming the write-ahead log in parallel while running199 the backup. Therefore, it will require two replication200 connections not just one. As long as the client can keep up201 with the write-ahead log data, using this method requires no202 extra write-ahead logs to be saved on the source server.203 </p><p>204 When tar format is used, the write-ahead log files will be205 written to a separate file named <code class="filename">pg_wal.tar</code>206 (if the server is a version earlier than 10, the file will be named207 <code class="filename">pg_xlog.tar</code>).208 </p><p>209 This value is the default.210 </p></dd></dl></div></dd><dt><span class="term"><code class="option">-z</code><br /></span><span class="term"><code class="option">--gzip</code></span></dt><dd><p>211 Enables gzip compression of tar file output, with the default212 compression level. Compression is only available when using213 the tar format, and the suffix <code class="filename">.gz</code> will214 automatically be added to all tar filenames.215 </p></dd><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><dd><p>216 Requests compression of the backup. If <code class="literal">client</code> or217 <code class="literal">server</code> is included, it specifies where the218 compression is to be performed. Compressing on the server will reduce219 transfer bandwidth but will increase server CPU consumption. The220 default is <code class="literal">client</code> except when221 <code class="literal">--target</code> is used. In that case, the backup is not222 being sent to the client, so only server compression is sensible.223 When <code class="literal">-Xstream</code>, which is the default, is used,224 server-side compression will not be applied to the WAL. To compress225 the WAL, use client-side compression, or226 specify <code class="literal">-Xfetch</code>.227 </p><p>228 The compression method can be set to <code class="literal">gzip</code>,229 <code class="literal">lz4</code>, <code class="literal">zstd</code>,230 <code class="literal">none</code> for no compression or an integer (no231 compression if 0, <code class="literal">gzip</code> if greater than 0).232 A compression detail string can optionally be specified.233 If the detail string is an integer, it specifies the compression234 level. Otherwise, it should be a comma-separated list of items,235 each of the form <code class="literal">keyword</code> or236 <code class="literal">keyword=value</code>.237 Currently, the supported keywords are <code class="literal">level</code>,238 <code class="literal">long</code>, and <code class="literal">workers</code>.239 The detail string cannot be used when the compression method240 is specified as a plain integer.241 </p><p>242 If no compression level is specified, the default compression level243 will be used. If only a level is specified without mentioning an244 algorithm, <code class="literal">gzip</code> compression will be used if the245 level is greater than 0, and no compression will be used if the level246 is 0.247 </p><p>248 When the tar format is used with <code class="literal">gzip</code>,249 <code class="literal">lz4</code>, or <code class="literal">zstd</code>, the suffix250 <code class="filename">.gz</code>, <code class="filename">.lz4</code>, or251 <code class="filename">.zst</code>, respectively, will be automatically added to252 all tar filenames. When the plain format is used, client-side253 compression may not be specified, but it is still possible to request254 server-side compression. If this is done, the server will compress the255 backup for transmission, and the client will decompress and extract it.256 </p><p>257 When this option is used in combination with258 <code class="literal">-Xstream</code>, <code class="literal">pg_wal.tar</code> will259 be compressed using <code class="literal">gzip</code> if client-side gzip260 compression is selected, but will not be compressed if any other261 compression algorithm is selected, or if server-side compression262 is selected.263 </p></dd></dl></div><p>264 </p><p>265 The following command-line options control the generation of the266 backup and the invocation of the program:267 268 </p><div class="variablelist"><dl class="variablelist"><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><dd><p>269 Sets checkpoint mode to fast (immediate) or spread (the default)270 (see <a class="xref" href="continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP" title="26.3.3. Making a Base Backup Using the Low Level API">Section 26.3.3</a>).271 </p></dd><dt><span class="term"><code class="option">-C</code><br /></span><span class="term"><code class="option">--create-slot</code></span></dt><dd><p>272 Specifies that the replication slot named by the273 <code class="literal">--slot</code> option should be created before starting274 the backup. An error is raised if the slot already exists.275 </p></dd><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><dd><p>276 Sets the label for the backup. If none is specified, a default value of277 <span class="quote">“<span class="quote"><code class="literal">pg_basebackup base backup</code></span>”</span> will be used.278 </p></dd><dt><span class="term"><code class="option">-n</code><br /></span><span class="term"><code class="option">--no-clean</code></span></dt><dd><p>279 By default, when <code class="command">pg_basebackup</code> aborts with an280 error, it removes any directories it might have created before281 discovering that it cannot finish the job (for example, the target282 directory and write-ahead log directory). This option inhibits283 tidying-up and is thus useful for debugging.284 </p><p>285 Note that tablespace directories are not cleaned up either way.286 </p></dd><dt><span class="term"><code class="option">-N</code><br /></span><span class="term"><code class="option">--no-sync</code></span></dt><dd><p>287 By default, <code class="command">pg_basebackup</code> will wait for all files288 to be written safely to disk. This option causes289 <code class="command">pg_basebackup</code> to return without waiting, which is290 faster, but means that a subsequent operating system crash can leave291 the base backup corrupt. Generally, this option is useful for testing292 but should not be used when creating a production installation.293 </p></dd><dt><span class="term"><code class="option">-P</code><br /></span><span class="term"><code class="option">--progress</code></span></dt><dd><p>294 Enables progress reporting. Turning this on will deliver an approximate295 progress report during the backup. Since the database may change during296 the backup, this is only an approximation and may not end at exactly297 <code class="literal">100%</code>. In particular, when WAL log is included in the298 backup, the total amount of data cannot be estimated in advance, and299 in this case the estimated target size will increase once it passes the300 total estimate without WAL.301 </p></dd><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><dd><p>302 Sets the maximum transfer rate at which data is collected from the303 source server. This can be useful to limit the impact304 of <span class="application">pg_basebackup</span> on the server. Values305 are in kilobytes per second. Use a suffix of <code class="literal">M</code>306 to indicate megabytes per second. A suffix of <code class="literal">k</code>307 is also accepted, and has no effect. Valid values are between 32308 kilobytes per second and 1024 megabytes per second.309 </p><p>310 This option always affects transfer of the data directory. Transfer of311 WAL files is only affected if the collection method312 is <code class="literal">fetch</code>.313 </p></dd><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><dd><p>314 This option can only be used together with <code class="literal">-X315 stream</code>. It causes WAL streaming to use the specified316 replication slot. If the base backup is intended to be used as a317 streaming-replication standby using a replication slot, the standby318 should then use the same replication slot name as319 <a class="xref" href="runtime-config-replication.html#GUC-PRIMARY-SLOT-NAME">primary_slot_name</a>. This ensures that the320 primary server does not remove any necessary WAL data in the time321 between the end of the base backup and the start of streaming322 replication on the new standby.323 </p><p>324 The specified replication slot has to exist unless the325 option <code class="option">-C</code> is also used.326 </p><p>327 If this option is not specified and the server supports temporary328 replication slots (version 10 and later), then a temporary replication329 slot is automatically used for WAL streaming.330 </p></dd><dt><span class="term"><code class="option">-v</code><br /></span><span class="term"><code class="option">--verbose</code></span></dt><dd><p>331 Enables verbose mode. Will output some extra steps during startup and332 shutdown, as well as show the exact file name that is currently being333 processed if progress reporting is also enabled.334 </p></dd><dt><span class="term"><code class="option">--manifest-checksums=<em class="replaceable"><code>algorithm</code></em></code></span></dt><dd><p>335 Specifies the checksum algorithm that should be applied to each file336 included in the backup manifest. Currently, the available337 algorithms are <code class="literal">NONE</code>, <code class="literal">CRC32C</code>,338 <code class="literal">SHA224</code>, <code class="literal">SHA256</code>,339 <code class="literal">SHA384</code>, and <code class="literal">SHA512</code>.340 The default is <code class="literal">CRC32C</code>.341 </p><p>342 If <code class="literal">NONE</code> is selected, the backup manifest will343 not contain any checksums. Otherwise, it will contain a checksum344 of each file in the backup using the specified algorithm. In addition,345 the manifest will always contain a <code class="literal">SHA256</code>346 checksum of its own contents. The <code class="literal">SHA</code> algorithms347 are significantly more CPU-intensive than <code class="literal">CRC32C</code>,348 so selecting one of them may increase the time required to complete349 the backup.350 </p><p>351 Using a SHA hash function provides a cryptographically secure digest352 of each file for users who wish to verify that the backup has not been353 tampered with, while the CRC32C algorithm provides a checksum that is354 much faster to calculate; it is good at catching errors due to accidental355 changes but is not resistant to malicious modifications. Note that, to356 be useful against an adversary who has access to the backup, the backup357 manifest would need to be stored securely elsewhere or otherwise358 verified not to have been modified since the backup was taken.359 </p><p>360 <a class="xref" href="app-pgverifybackup.html" title="pg_verifybackup"><span class="refentrytitle"><span class="application">pg_verifybackup</span></span></a> can be used to check the361 integrity of a backup against the backup manifest.362 </p></dd><dt><span class="term"><code class="option">--manifest-force-encode</code></span></dt><dd><p>363 Forces all filenames in the backup manifest to be hex-encoded.364 If this option is not specified, only non-UTF8 filenames are365 hex-encoded. This option is mostly intended to test that tools which366 read a backup manifest file properly handle this case.367 </p></dd><dt><span class="term"><code class="option">--no-estimate-size</code></span></dt><dd><p>368 Prevents the server from estimating the total369 amount of backup data that will be streamed, resulting in the370 <code class="structfield">backup_total</code> column in the371 <code class="structname">pg_stat_progress_basebackup</code> view372 always being <code class="literal">NULL</code>.373 </p><p>374 Without this option, the backup will start by enumerating375 the size of the entire database, and then go back and send376 the actual contents. This may make the backup take slightly377 longer, and in particular it will take longer before the first378 data is sent. This option is useful to avoid such estimation379 time if it's too long.380 </p><p>381 This option is not allowed when using <code class="option">--progress</code>.382 </p></dd><dt><span class="term"><code class="option">--no-manifest</code></span></dt><dd><p>383 Disables generation of a backup manifest. If this option is not384 specified, the server will generate and send a backup manifest385 which can be verified using <a class="xref" href="app-pgverifybackup.html" title="pg_verifybackup"><span class="refentrytitle"><span class="application">pg_verifybackup</span></span></a>.386 The manifest is a list of every file present in the backup with the387 exception of any WAL files that may be included. It also stores the388 size, last modification time, and an optional checksum for each file.389 </p></dd><dt><span class="term"><code class="option">--no-slot</code></span></dt><dd><p>390 Prevents the creation of a temporary replication slot391 for the backup.392 </p><p>393 By default, if log streaming is selected but no slot name is given394 with the <code class="option">-S</code> option, then a temporary replication395 slot is created (if supported by the source server).396 </p><p>397 The main purpose of this option is to allow taking a base backup when398 the server has no free replication slots. Using a replication slot399 is almost always preferred, because it prevents needed WAL from being400 removed by the server during the backup.401 </p></dd><dt><span class="term"><code class="option">--no-verify-checksums</code></span></dt><dd><p>402 Disables verification of checksums, if they are enabled on the server403 the base backup is taken from.404 </p><p>405 By default, checksums are verified and checksum failures will result406 in a non-zero exit status. However, the base backup will not be407 removed in such a case, as if the <code class="option">--no-clean</code> option408 had been used. Checksum verification failures will also be reported409 in the <a class="link" href="monitoring-stats.html#MONITORING-PG-STAT-DATABASE-VIEW" title="28.2.16. pg_stat_database">410 <code class="structname">pg_stat_database</code></a> view.411 </p></dd></dl></div><p>412 </p><p>413 The following command-line options control the connection to the source414 server:415 416 </p><div class="variablelist"><dl class="variablelist"><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><dd><p>417 Specifies parameters used to connect to the server, as a <a class="link" href="libpq-connect.html#LIBPQ-CONNSTRING" title="34.1.1. Connection Strings">connection string</a>; these418 will override any conflicting command line options.419 </p><p>420 The option is called <code class="literal">--dbname</code> for consistency with other421 client applications, but because <span class="application">pg_basebackup</span>422 doesn't connect to any particular database in the cluster, any database423 name in the connection string will be ignored.424 </p></dd><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><dd><p>425 Specifies the host name of the machine on which the server is426 running. If the value begins with a slash, it is used as the427 directory for a Unix domain socket. The default is taken428 from the <code class="envar">PGHOST</code> environment variable, if set,429 else a Unix domain socket connection is attempted.430 </p></dd><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><dd><p>431 Specifies the TCP port or local Unix domain socket file432 extension on which the server is listening for connections.433 Defaults to the <code class="envar">PGPORT</code> environment variable, if434 set, or a compiled-in default.435 </p></dd><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><dd><p>436 Specifies the number of seconds between status packets sent back to437 the source server. Smaller values allow more accurate monitoring of438 backup progress from the server.439 A value of zero disables periodic status updates completely,440 although an update will still be sent when requested by the server, to441 avoid timeout-based disconnects. The default value is 10 seconds.442 </p></dd><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><dd><p>443 Specifies the user name to connect as.444 </p></dd><dt><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span></dt><dd><p>445 Prevents issuing a password prompt. If the server requires446 password authentication and a password is not available by447 other means such as a <code class="filename">.pgpass</code> file, the448 connection attempt will fail. This option can be useful in449 batch jobs and scripts where no user is present to enter a450 password.451 </p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span></dt><dd><p>452 Forces <span class="application">pg_basebackup</span> to prompt for a453 password before connecting to the source server.454 </p><p>455 This option is never essential, since456 <span class="application">pg_basebackup</span> will automatically prompt457 for a password if the server demands password authentication.458 However, <span class="application">pg_basebackup</span> will waste a459 connection attempt finding out that the server wants a password.460 In some cases it is worth typing <code class="option">-W</code> to avoid the extra461 connection attempt.462 </p></dd></dl></div><p>463 </p><p>464 Other options are also available:465 466 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>467 Prints the <span class="application">pg_basebackup</span> version and exits.468 </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>469 Shows help about <span class="application">pg_basebackup</span> command line470 arguments, and exits.471 </p></dd></dl></div><p>472 </p></div><div class="refsect1" id="id-1.9.4.10.7"><h2>Environment</h2><p>473 This utility, like most other <span class="productname">PostgreSQL</span> utilities,474 uses the environment variables supported by <span class="application">libpq</span>475 (see <a class="xref" href="libpq-envars.html" title="34.15. Environment Variables">Section 34.15</a>).476 </p><p>477 The environment variable <code class="envar">PG_COLOR</code> specifies whether to use478 color in diagnostic messages. Possible values are479 <code class="literal">always</code>, <code class="literal">auto</code> and480 <code class="literal">never</code>.481 </p></div><div class="refsect1" id="id-1.9.4.10.8"><h2>Notes</h2><p>482 At the beginning of the backup, a checkpoint needs to be performed on the483 source server. This can take some time (especially if the option484 <code class="literal">--checkpoint=fast</code> is not used), during485 which <span class="application">pg_basebackup</span> will appear to be idle.486 </p><p>487 The backup will include all files in the data directory and tablespaces,488 including the configuration files and any additional files placed in the489 directory by third parties, except certain temporary files managed by490 PostgreSQL and operating system files. But only regular files and491 directories are copied, except that492 symbolic links used for tablespaces are preserved. Symbolic links pointing493 to certain directories known to PostgreSQL are copied as empty directories.494 Other symbolic links and special device files are skipped.495 See <a class="xref" href="protocol-replication.html" title="55.4. Streaming Replication Protocol">Section 55.4</a> for the precise details.496 </p><p>497 In plain format, tablespaces will be backed up to the same path498 they have on the source server, unless the499 option <code class="literal">--tablespace-mapping</code> is used. Without500 this option, running a plain format base backup on the same host as the501 server will not work if tablespaces are in use, because the backup would502 have to be written to the same directory locations as the original503 tablespaces.504 </p><p>505 When tar format is used, it is the user's responsibility to unpack each506 tar file before starting a PostgreSQL server that uses the data. If there507 are additional tablespaces, the508 tar files for them need to be unpacked in the correct locations. In this509 case the symbolic links for those tablespaces will be created by the server510 according to the contents of the <code class="filename">tablespace_map</code> file that is511 included in the <code class="filename">base.tar</code> file.512 </p><p>513 <span class="application">pg_basebackup</span> works with servers of the same514 or an older major version, down to 9.1. However, WAL streaming mode (<code class="literal">-X515 stream</code>) only works with server version 9.3 and later, and tar format516 (<code class="literal">--format=tar</code>) only works with server version 9.5517 and later.518 </p><p>519 <span class="application">pg_basebackup</span> will preserve group permissions520 for data files if group permissions are enabled on the source cluster.521 </p></div><div class="refsect1" id="id-1.9.4.10.9"><h2>Examples</h2><p>522 To create a base backup of the server at <code class="literal">mydbserver</code>523 and store it in the local directory524 <code class="filename">/usr/local/pgsql/data</code>:525</p><pre class="screen">526<code class="prompt">$</code> <strong class="userinput"><code>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</code></strong>527</pre><p>528 </p><p>529 To create a backup of the local server with one compressed530 tar file for each tablespace, and store it in the directory531 <code class="filename">backup</code>, showing a progress report while running:532</p><pre class="screen">533<code class="prompt">$</code> <strong class="userinput"><code>pg_basebackup -D backup -Ft -z -P</code></strong>534</pre><p>535 </p><p>536 To create a backup of a single-tablespace local database and compress537 this with <span class="productname">bzip2</span>:538</p><pre class="screen">539<code class="prompt">$</code> <strong class="userinput"><code>pg_basebackup -D - -Ft -X fetch | bzip2 > backup.tar.bz2</code></strong>540</pre><p>541 (This command will fail if there are multiple tablespaces in the542 database.)543 </p><p>544 To create a backup of a local database where the tablespace in545 <code class="filename">/opt/ts</code> is relocated546 to <code class="filename">./backup/ts</code>:547</p><pre class="screen">548<code class="prompt">$</code> <strong class="userinput"><code>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</code></strong>549</pre><p>550 To create a backup of a local server with one tar file for each tablespace551 compressed with <span class="application">gzip</span> at level 9, stored in the552 directory <code class="filename">backup</code>:553</p><pre class="screen">554<code class="prompt">$</code> <strong class="userinput"><code>pg_basebackup -D backup -Ft --compress=gzip:9</code></strong>555</pre></div><div class="refsect1" id="id-1.9.4.10.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle"><span class="application">pg_dump</span></span></a>, <a class="xref" href="progress-reporting.html#BASEBACKUP-PROGRESS-REPORTING" title="28.4.6. Base Backup Progress Reporting">Section 28.4.6</a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-pgamcheck.html" title="pg_amcheck">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pgbench.html" title="pgbench">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_amcheck</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">pgbench</span></td></tr></table></div></body></html>