diff --git a/doc/src/sgml/backup.sgml b/doc/src/sgml/backup.sgml
index 5f7489afbd1..168444eccc5 100644
--- a/doc/src/sgml/backup.sgml
+++ b/doc/src/sgml/backup.sgml
@@ -627,7 +627,7 @@ tar -cf backup.tar /usr/local/pgsql/data
character in the command. The simplest useful command is something
like:
-archive_command = 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f' # Unix
+archive_command = 'test ! -f "/mnt/server/archivedir/%f" && cp "%p" "/mnt/server/archivedir/%f"' # Unix
archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows
which will copy archivable WAL segments to the directory
@@ -1294,7 +1294,7 @@ SELECT * FROM pg_backup_stop(wait_for_archive => true);
character in the command. The simplest useful command is
something like:
-restore_command = 'cp /mnt/server/archivedir/%f %p'
+restore_command = 'cp "/mnt/server/archivedir/%f" "%p"'
which will copy previously archived WAL segments from the directory
/mnt/server/archivedir. Of course, you can use something
@@ -1493,11 +1493,11 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
If archive storage size is a concern, you can use
gzip to compress the archive files:
-archive_command = 'gzip < %p > /mnt/server/archivedir/%f.gz'
+archive_command = 'gzip < "%p" > "/mnt/server/archivedir/%f.gz"'
You will then need to use gunzip during recovery:
-restore_command = 'gunzip < /mnt/server/archivedir/%f.gz > %p'
+restore_command = 'gunzip < "/mnt/server/archivedir/%f.gz" > "%p"'
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index d7e48f61905..df1c3eaaa58 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -4059,7 +4059,7 @@ include_dir 'conf.d'
names that are not present in the archive; it must return nonzero
when so asked. Examples:
-restore_command = 'cp /mnt/server/archivedir/%f "%p"'
+restore_command = 'cp "/mnt/server/archivedir/%f" "%p"'
restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
An exception is that if the command was terminated by a signal (other
@@ -4098,7 +4098,7 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
The module
is often used in archive_cleanup_command for
single-standby configurations, for example:
-archive_cleanup_command = 'pg_archivecleanup /mnt/server/archivedir %r'
+archive_cleanup_command = 'pg_archivecleanup /mnt/server/archivedir "%r"'
Note however that if multiple standby servers are restoring from the
same archive directory, you will need to ensure that you do not delete
WAL files until they are no longer needed by any of the servers.
diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml
index 340c4622221..81eeadd6c47 100644
--- a/doc/src/sgml/high-availability.sgml
+++ b/doc/src/sgml/high-availability.sgml
@@ -745,8 +745,8 @@ protocol to make nodes agree on a serializable transactional order.
A simple example of configuration is:
primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass options=''-c wal_sender_timeout=5000'''
-restore_command = 'cp /path/to/archive/%f %p'
-archive_cleanup_command = 'pg_archivecleanup /path/to/archive %r'
+restore_command = 'cp "/path/to/archive/%f" "%p"'
+archive_cleanup_command = 'pg_archivecleanup /path/to/archive "%r"'
diff --git a/doc/src/sgml/ref/pgarchivecleanup.sgml b/doc/src/sgml/ref/pgarchivecleanup.sgml
index cd8f49b1c5b..79e751381ac 100644
--- a/doc/src/sgml/ref/pgarchivecleanup.sgml
+++ b/doc/src/sgml/ref/pgarchivecleanup.sgml
@@ -44,7 +44,7 @@ PostgreSQL documentation
server to use pg_archivecleanup, put this into its
postgresql.conf configuration file:
-archive_cleanup_command = 'pg_archivecleanup archivelocation %r'
+archive_cleanup_command = 'pg_archivecleanup archivelocation "%r"'
where archivelocation is the directory from which WAL segment
files should be removed.
@@ -198,7 +198,7 @@ pg_archivecleanup: removing file "archive/00000001000000370000000E"
On Linux or Unix systems, you might use:
-archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>cleanup.log'
+archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive "%r" 2>>cleanup.log'
where the archive directory is physically located on the standby server,
so that the archive_command is accessing it across NFS,
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 08bcef50c19..fdb37e927de 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -283,7 +283,7 @@
#archive_command = '' # command to use to archive a WAL file
# placeholders: %p = path of file to archive
# %f = file name only
- # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
+ # e.g. 'test ! -f "/mnt/server/archivedir/%f" && cp "%p" "/mnt/server/archivedir/%f"'
#archive_timeout = 0 # force a WAL file switch after this
# number of seconds; 0 disables
@@ -294,7 +294,7 @@
#restore_command = '' # command to use to restore an archived WAL file
# placeholders: %p = path of file to restore
# %f = file name only
- # e.g. 'cp /mnt/server/archivedir/%f %p'
+ # e.g. 'cp "/mnt/server/archivedir/%f" "%p"'
#archive_cleanup_command = '' # command to execute at every restartpoint
#recovery_end_command = '' # command to execute at completion of recovery