diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index 8730c5ea914c29765a5e969eb1c93053140acb0f..532eacc066edf39cfacfa399654c2e2bdec0cc86 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -379,8 +379,18 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
 	}
 	else
 	{
+		int			old_umask;
+
 		tm = pg_malloc0(sizeof(TAR_MEMBER));
 
+		/*
+		 * POSIX does not require, but permits, tmpfile() to restrict file
+		 * permissions.  Given an OS crash after we write data, the filesystem
+		 * might retain the data but forget tmpfile()'s unlink().  If so, the
+		 * file mode protects confidentiality of the data written.
+		 */
+		old_umask = umask(S_IRWXG | S_IRWXO);
+
 #ifndef WIN32
 		tm->tmpFH = tmpfile();
 #else
@@ -415,6 +425,8 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
 		if (tm->tmpFH == NULL)
 			exit_horribly(modulename, "could not generate temporary file name: %s\n", strerror(errno));
 
+		umask(old_umask);
+
 #ifdef HAVE_LIBZ
 
 		if (AH->compression != 0)