diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml
index fdd3d051483..ea314d279ac 100644
--- a/doc/src/sgml/protocol.sgml
+++ b/doc/src/sgml/protocol.sgml
@@ -3062,7 +3062,7 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
Files other than regular files and directories, such as symbolic
links (other than for the directories listed above) and special
- device files, are skipped. (Symbolic links
+ device and operating system files, are skipped. (Symbolic links
in pg_tblspc are maintained.)
diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_basebackup.sgml
index a5f63bd6609..04323af0b35 100644
--- a/doc/src/sgml/ref/pg_basebackup.sgml
+++ b/doc/src/sgml/ref/pg_basebackup.sgml
@@ -905,7 +905,8 @@ PostgreSQL documentation
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
+ 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.
diff --git a/doc/src/sgml/ref/pg_rewind.sgml b/doc/src/sgml/ref/pg_rewind.sgml
index 69d6924b3a2..dffb1b12f72 100644
--- a/doc/src/sgml/ref/pg_rewind.sgml
+++ b/doc/src/sgml/ref/pg_rewind.sgml
@@ -389,8 +389,9 @@ GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, b
backup_label,
tablespace_map,
pg_internal.init,
- postmaster.opts, and
- postmaster.pid, as well as any file or directory
+ postmaster.opts,
+ postmaster.pid and
+ .DS_Store as well as any file or directory
beginning with pgsql_tmp, are omitted.
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 078a3fe99c2..847a52f599b 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -1185,6 +1185,10 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
strlen(PG_TEMP_FILE_PREFIX)) == 0)
continue;
+ /* Skip macOS system files */
+ if (strcmp(de->d_name, ".DS_Store") == 0)
+ continue;
+
/*
* Check if the postmaster has signaled us to exit, and abort with an
* error in that case. The error handler further up will call
diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
index ec72282aae5..e0f34e16f92 100644
--- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl
+++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
@@ -3,6 +3,7 @@
use strict;
use warnings;
+use Config;
use File::Basename qw(basename dirname);
use File::Path qw(rmtree);
use PostgreSQL::Test::Cluster;
@@ -173,6 +174,16 @@ foreach my $filename (
close $file;
}
+# Test that macOS system files are skipped. Only test on non-macOS systems
+# however since creating incorrect .DS_Store files on a macOS system may have
+# unintended side effects.
+if ($Config{osname} ne 'darwin')
+{
+ open my $file, '>>', "$pgdata/.DS_Store";
+ print $file "DONOTCOPY";
+ close $file;
+}
+
# Connect to a database to create global/pg_internal.init. If this is removed
# the test to ensure global/pg_internal.init is not copied will return a false
# positive.
@@ -242,6 +253,12 @@ foreach my $filename (
ok(!-f "$tempdir/backup/$filename", "$filename not copied");
}
+# We only test .DS_Store files being skipped on non-macOS systems
+if ($Config{osname} ne 'darwin')
+{
+ ok(!-f "$tempdir/backup/.DS_Store", ".DS_Store not copied");
+}
+
# Unlogged relation forks other than init should not be copied
ok(-f "$tempdir/backup/${baseUnloggedPath}_init",
'unlogged init fork in backup');
diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
index 21dfe1b6ee5..1af65cd2de8 100644
--- a/src/bin/pg_checksums/pg_checksums.c
+++ b/src/bin/pg_checksums/pg_checksums.c
@@ -337,6 +337,10 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
strlen(PG_TEMP_FILES_DIR)) == 0)
continue;
+ /* Skip macOS system files */
+ if (strcmp(de->d_name, ".DS_Store") == 0)
+ continue;
+
snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name);
if (lstat(fn, &st) < 0)
pg_fatal("could not stat file \"%s\": %m", fn);
diff --git a/src/bin/pg_checksums/t/002_actions.pl b/src/bin/pg_checksums/t/002_actions.pl
index 0309cbbaa33..792ac4823d3 100644
--- a/src/bin/pg_checksums/t/002_actions.pl
+++ b/src/bin/pg_checksums/t/002_actions.pl
@@ -6,6 +6,7 @@
use strict;
use warnings;
+use Config;
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
@@ -114,6 +115,12 @@ append_to_file "$pgdata/global/pgsql_tmp/1.1", "foo";
append_to_file "$pgdata/global/pg_internal.init", "foo";
append_to_file "$pgdata/global/pg_internal.init.123", "foo";
+# These are non-postgres macOS files, which should be ignored by the scan.
+# Only perform this test on non-macOS systems though as creating incorrect
+# system files may have side effects on macOS.
+append_to_file "$pgdata/global/.DS_Store", "foo"
+ unless ($Config{osname} eq 'darwin');
+
# Enable checksums.
command_ok([ 'pg_checksums', '--enable', '--no-sync', '-D', $pgdata ],
"checksums successfully enabled in cluster");
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index 62529310415..24f508c6efa 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -647,6 +647,10 @@ decide_file_action(file_entry_t *entry)
if (strcmp(path, "global/pg_control") == 0)
return FILE_ACTION_NONE;
+ /* Skip macOS system files */
+ if (strstr(path, ".DS_Store") != NULL)
+ return FILE_ACTION_NONE;
+
/*
* Remove all files matching the exclusion filters in the target.
*/
diff --git a/src/bin/pg_rewind/t/003_extrafiles.pl b/src/bin/pg_rewind/t/003_extrafiles.pl
index 100c212a4db..54bb63ccec2 100644
--- a/src/bin/pg_rewind/t/003_extrafiles.pl
+++ b/src/bin/pg_rewind/t/003_extrafiles.pl
@@ -5,6 +5,7 @@
use strict;
use warnings;
+use Config;
use PostgreSQL::Test::Utils;
use Test::More;
@@ -53,6 +54,10 @@ sub run_test
append_to_file
"$test_standby_datadir/tst_standby_dir/standby_subdir/standby_file4",
"in standby4";
+ # Skip testing .DS_Store files on macOS to avoid risk of side effects
+ append_to_file
+ "$test_standby_datadir/tst_standby_dir/.DS_Store",
+ "macOS system file" unless ($Config{osname} eq 'darwin');
mkdir "$test_primary_datadir/tst_primary_dir";
append_to_file "$test_primary_datadir/tst_primary_dir/primary_file1",