From aae078198dd4b9cbb3590262dcb65d0b735c80d7 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Wed, 28 May 2003 17:25:02 +0000
Subject: [PATCH] In bootstrap and standalone-backend modes, do not sort LOG
 elevel out of order; the 'server log' output is actually client output in
 these scenarios and we ought to treat elevels the same way as in the client
 case.  This allows initdb to not send backend stderr to /dev/null anymore,
 which makes it much more likely that people will notice problems during
 initdb.

---
 src/backend/postmaster/postmaster.c |  4 ++-
 src/backend/utils/error/elog.c      | 40 +++++++++++++++++------------
 src/backend/utils/init/globals.c    |  4 ++-
 src/bin/initdb/initdb.sh            |  8 +++---
 src/include/miscadmin.h             |  3 ++-
 5 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 77aff02b150..e860fe129c6 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.329 2003/05/27 17:49:46 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.330 2003/05/28 17:25:02 tgl Exp $
  *
  * NOTES
  *
@@ -379,6 +379,8 @@ PostmasterMain(int argc, char *argv[])
 
 	progname = argv[0];
 
+	IsPostmasterEnvironment = true;
+
 	/*
 	 * Catch standard options before doing much else.  This even works on
 	 * systems without getopt_long.
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6ca9f384017..fd6d35bb5ad 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.109 2003/04/24 21:16:44 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.110 2003/05/28 17:25:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -189,25 +189,33 @@ errstart(int elevel, const char *filename, int lineno,
 	}
 
 	/* Determine whether message is enabled for server log output */
-	/* Complicated because LOG is sorted out-of-order for this purpose */
-	if (elevel == LOG || elevel == COMMERROR)
+	if (IsPostmasterEnvironment)
 	{
-		if (log_min_messages == LOG)
-			output_to_server = true;
-		else if (log_min_messages < FATAL)
-			output_to_server = true;
-	}
-	else
-	{
-		/* elevel != LOG */
-		if (log_min_messages == LOG)
+		/* Complicated because LOG is sorted out-of-order for this purpose */
+		if (elevel == LOG || elevel == COMMERROR)
 		{
-			if (elevel >= FATAL)
+			if (log_min_messages == LOG)
+				output_to_server = true;
+			else if (log_min_messages < FATAL)
 				output_to_server = true;
 		}
-		/* Neither is LOG */
-		else if (elevel >= log_min_messages)
-			output_to_server = true;
+		else
+		{
+			/* elevel != LOG */
+			if (log_min_messages == LOG)
+			{
+				if (elevel >= FATAL)
+					output_to_server = true;
+			}
+			/* Neither is LOG */
+			else if (elevel >= log_min_messages)
+				output_to_server = true;
+		}
+	}
+	else
+	{
+		/* In bootstrap/standalone case, do not sort LOG out-of-order */
+		output_to_server = (elevel >= log_min_messages);
 	}
 
 	/* Determine whether message is enabled for client output */
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 8a707165ec5..a4b0889e4fa 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.69 2003/02/22 05:57:45 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.70 2003/05/28 17:25:02 tgl Exp $
  *
  * NOTES
  *	  Globals used all over the place should be declared here and not
@@ -57,6 +57,8 @@ char	   *DatabasePath = NULL;
 
 Oid			MyDatabaseId = InvalidOid;
 
+/* these are initialized for the bootstrap/standalone case: */
+bool		IsPostmasterEnvironment = false;
 bool		IsUnderPostmaster = false;
 
 int			DateStyle = USE_ISO_DATES;
diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh
index 47290529dfb..67ae4b00052 100644
--- a/src/bin/initdb/initdb.sh
+++ b/src/bin/initdb/initdb.sh
@@ -27,7 +27,7 @@
 # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
 # Portions Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.189 2003/05/15 15:50:19 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.190 2003/05/28 17:25:02 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -546,9 +546,7 @@ PGSQL_OPT="-F -D$PGDATA"
 
 if [ "$debug" = yes ]
 then
-    BACKEND_TALK_ARG="-d 5"
-else
-    PGSQL_OPT="$PGSQL_OPT -o /dev/null"
+    BOOTSTRAP_TALK_ARG="-d 5"
 fi
 
 
@@ -570,7 +568,7 @@ cat "$POSTGRES_BKI" \
   export LC_COLLATE
   export LC_CTYPE
   unset LC_ALL
-  "$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BACKEND_TALK_ARG template1
+  "$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BOOTSTRAP_TALK_ARG template1
 ) \
 || exit_nicely
 
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 18781c5dc52..8621722bad2 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: miscadmin.h,v 1.121 2003/05/03 03:52:07 momjian Exp $
+ * $Id: miscadmin.h,v 1.122 2003/05/28 17:25:02 tgl Exp $
  *
  * NOTES
  *	  some of the information in this file should be moved to
@@ -104,6 +104,7 @@ extern void ProcessInterrupts(void);
 /*
  * from postmaster/postmaster.c
  */
+extern bool IsPostmasterEnvironment;
 extern bool IsUnderPostmaster;
 extern bool ClientAuthInProgress;
 extern const bool ExecBackend;
-- 
GitLab