From 5fc2d7e45148b92ea082356b425562c3cb971954 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 21 Nov 2006 22:19:46 +0000
Subject: [PATCH] Suppress timezone (%Z) part of timestamp display when running
 on Windows, because on that platform strftime produces localized zone names
 in varying encodings.  Even though it's only in a comment, this can cause
 encoding errors when reloading the dump script.  Per suggestion from Andreas
 Seltenreich.  Also, suppress %Z on Windows in the %s escape of
 log_line_prefix ... not sure why this one is different from the other two,
 but it shouldn't be.

---
 src/backend/utils/error/elog.c       |  9 +++++++--
 src/bin/pg_dump/pg_backup_archiver.c | 16 ++++++++++++++--
 src/bin/pg_dump/pg_dumpall.c         | 16 ++++++++++++++--
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6b6a9c51cf7..714fb9d0ca2 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -42,7 +42,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.176 2006/11/21 00:49:55 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.177 2006/11/21 22:19:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1471,7 +1471,7 @@ log_line_prefix(StringInfo buf)
 					char		strfbuf[128];
 
 					strftime(strfbuf, sizeof(strfbuf),
-					/* Win32 timezone names are too long so don't print them. */
+					/* Win32 timezone names are too long so don't print them */
 #ifndef WIN32
 							 "%Y-%m-%d %H:%M:%S %Z",
 #else
@@ -1487,7 +1487,12 @@ log_line_prefix(StringInfo buf)
 					char		strfbuf[128];
 
 					strftime(strfbuf, sizeof(strfbuf),
+					/* Win32 timezone names are too long so don't print them */
+#ifndef WIN32
 							 "%Y-%m-%d %H:%M:%S %Z",
+#else
+							 "%Y-%m-%d %H:%M:%S",
+#endif
 							 localtime(&MyProcPort->session_start));
 					appendStringInfoString(buf, strfbuf);
 				}
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 272ff5fb9d9..9b99cb8826f 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *		$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.137 2006/10/14 23:07:22 tgl Exp $
+ *		$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.138 2006/11/21 22:19:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2780,6 +2780,18 @@ dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim)
 {
 	char		buf[256];
 
-	if (strftime(buf, 256, "%Y-%m-%d %H:%M:%S %Z", localtime(&tim)) != 0)
+	/*
+	 * We don't print the timezone on Win32, because the names are long and
+	 * localized, which means they may contain characters in various random
+	 * encodings; this has been seen to cause encoding errors when reading
+	 * the dump script.
+	 */
+	if (strftime(buf, sizeof(buf),
+#ifndef WIN32
+				 "%Y-%m-%d %H:%M:%S %Z",
+#else
+				 "%Y-%m-%d %H:%M:%S",
+#endif
+				 localtime(&tim)) != 0)
 		ahprintf(AH, "-- %s %s\n\n", msg, buf);
 }
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index d4181839fe9..26b873dafde 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.84 2006/10/07 20:59:05 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.85 2006/11/21 22:19:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1320,6 +1320,18 @@ dumpTimestamp(char *msg)
 	char		buf[256];
 	time_t		now = time(NULL);
 
-	if (strftime(buf, 256, "%Y-%m-%d %H:%M:%S %Z", localtime(&now)) != 0)
+	/*
+	 * We don't print the timezone on Win32, because the names are long and
+	 * localized, which means they may contain characters in various random
+	 * encodings; this has been seen to cause encoding errors when reading
+	 * the dump script.
+	 */
+	if (strftime(buf, sizeof(buf),
+#ifndef WIN32
+				 "%Y-%m-%d %H:%M:%S %Z",
+#else
+				 "%Y-%m-%d %H:%M:%S",
+#endif
+				 localtime(&now)) != 0)
 		printf("-- %s %s\n\n", msg, buf);
 }
-- 
GitLab