88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.231 2001/09/07 16:12:48 wieck Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.232 2001/09/08 01:10:20 tgl Exp $
1212 *
1313 * NOTES
1414 * this is the "main" module of the postgres backend and
@@ -85,6 +85,7 @@ boolShowPortNumber;
8585
8686bool Log_connections = false;
8787
88+ /* Note: whereToSendOutput is initialized for the bootstrap/standalone case */
8889CommandDest whereToSendOutput = Debug ;
8990
9091static bool dontExecute = false;
@@ -536,7 +537,7 @@ pg_plan_query(Query *querytree)
536537
537538if (Show_planner_stats )
538539{
539- fprintf (stderr ,"PLANNER STATISTICS\n" );
540+ fprintf (StatFp ,"PLANNER STATISTICS\n" );
540541ShowUsage ();
541542}
542543
@@ -813,7 +814,7 @@ pg_exec_query_string(char *query_string,/* string to execute */
813814
814815if (Show_executor_stats )
815816{
816- fprintf (stderr ,"EXECUTOR STATISTICS\n" );
817+ fprintf (StatFp ,"EXECUTOR STATISTICS\n" );
817818ShowUsage ();
818819}
819820}
@@ -910,9 +911,9 @@ quickdie(SIGNAL_ARGS)
910911PG_SETMASK (& BlockSig );
911912elog (NOTICE ,"Message from PostgreSQL backend:"
912913"\n\tThe Postmaster has informed me that some other backend"
913- "\tdied abnormally and possibly corrupted shared memory."
914+ "\n\ tdied abnormally and possibly corrupted shared memory."
914915"\n\tI have rolled back the current transaction and am"
915- "\tgoing to terminate your database system connection and exit."
916+ "\n\ tgoing to terminate your database system connection and exit."
916917"\n\tPlease reconnect to the database system and repeat your query." );
917918
918919/*
@@ -968,6 +969,10 @@ die(SIGNAL_ARGS)
968969/*
969970 * Shutdown signal from postmaster during client authentication.
970971 * Simply exit(0).
972+ *
973+ * XXX: possible future improvement: try to send a message indicating
974+ * why we are disconnecting. Problem is to be sure we don't block while
975+ * doing so nor mess up the authentication message exchange.
971976 */
972977void
973978authdie (SIGNAL_ARGS )
@@ -1163,6 +1168,16 @@ PostgresMain(int argc, char *argv[],
11631168
11641169SetProcessingMode (InitProcessing );
11651170
1171+ /*
1172+ * If under postmaster, initialize libpq and enable reporting of
1173+ * elog errors to the client.
1174+ */
1175+ if (IsUnderPostmaster )
1176+ {
1177+ pq_init ();/* initialize libpq at backend startup */
1178+ whereToSendOutput = Remote ;/* now safe to elog to client */
1179+ }
1180+
11661181/*
11671182 * Set default values for command-line options.
11681183 */
@@ -1209,7 +1224,7 @@ PostgresMain(int argc, char *argv[],
12091224#ifdef USE_ASSERT_CHECKING
12101225SetConfigOption ("debug_assertions" ,optarg ,ctx , true);
12111226#else
1212- fprintf ( stderr ,"Assert checking is not compiled in\n " );
1227+ elog ( NOTICE ,"Assert checking is not compiled in" );
12131228#endif
12141229break ;
12151230
@@ -1439,7 +1454,7 @@ PostgresMain(int argc, char *argv[],
14391454 */
14401455if (XfuncMode != 0 )
14411456{
1442- fprintf ( stderr ,"only one -x flag is allowed\n " );
1457+ elog ( NOTICE ,"only one -x flag is allowed" );
14431458errs ++ ;
14441459break ;
14451460}
@@ -1457,7 +1472,7 @@ PostgresMain(int argc, char *argv[],
14571472XfuncMode = XFUNC_WAIT ;
14581473else
14591474{
1460- fprintf ( stderr ,"use -x {off,nor,nopull,nopm,pullall,wait}\n " );
1475+ elog ( NOTICE ,"use -x {off,nor,nopull,nopm,pullall,wait}" );
14611476errs ++ ;
14621477}
14631478#endif
@@ -1492,14 +1507,11 @@ PostgresMain(int argc, char *argv[],
14921507
14931508/*
14941509 * Post-processing for command line options.
1495- *
1496- * XXX It'd be nice if libpq were already running here, so we could do
1497- * elog(NOTICE) instead of just writing on stderr...
14981510 */
14991511if (Show_query_stats &&
15001512(Show_parser_stats || Show_planner_stats || Show_executor_stats ))
15011513{
1502- fprintf ( stderr ,"Query statistics are disabled because parser, planner, or executor statistics are on.\n " );
1514+ elog ( NOTICE ,"Query statistics are disabled because parser, planner, or executor statistics are on." );
15031515SetConfigOption ("show_query_stats" ,"false" ,ctx , true);
15041516}
15051517
@@ -1508,9 +1520,9 @@ PostgresMain(int argc, char *argv[],
15081520if (!potential_DataDir )
15091521{
15101522fprintf (stderr ,"%s does not know where to find the database system "
1511- "data. You must specify the directory that contains the "
1512- "database system either by specifying the -D invocation "
1513- "option or by setting the PGDATA environment variable.\n\n" ,
1523+ "data. You must specify the directory that contains the "
1524+ "database system either by specifying the -D invocation "
1525+ "option or by setting the PGDATA environment variable.\n\n" ,
15141526argv [0 ]);
15151527proc_exit (1 );
15161528}
@@ -1578,27 +1590,28 @@ PostgresMain(int argc, char *argv[],
15781590/* noninteractive case: nothing should be left after switches */
15791591if (errs || argc != optind || DBName == NULL )
15801592{
1581- fprintf (stderr ,"%s: invalid command line arguments\nTry -? for help.\n" ,argv [0 ]);
1593+ elog (NOTICE ,"%s: invalid command line arguments\nTry -? for help." ,
1594+ argv [0 ]);
15821595proc_exit (0 );/* not 1, that causes system-wide
15831596 * restart... */
15841597}
1585- pq_init ();/* initialize libpq at backend startup */
15861598BaseInit ();
15871599}
15881600else
15891601{
15901602/* interactive case: database name can be last arg on command line */
15911603if (errs || argc - optind > 1 )
15921604{
1593- fprintf (stderr ,"%s: invalid command line arguments\nTry -? for help.\n" ,argv [0 ]);
1605+ elog (NOTICE ,"%s: invalid command line arguments\nTry -? for help." ,
1606+ argv [0 ]);
15941607proc_exit (1 );
15951608}
15961609else if (argc - optind == 1 )
15971610DBName = argv [optind ];
15981611else if ((DBName = username )== NULL )
15991612{
1600- fprintf ( stderr ,"%s: user name undefined and no database specified\n" ,
1601- argv [0 ]);
1613+ elog ( NOTICE ,"%s: user name undefined and no database specified\n" ,
1614+ argv [0 ]);
16021615proc_exit (1 );
16031616}
16041617
@@ -1723,7 +1736,7 @@ PostgresMain(int argc, char *argv[],
17231736if (!IsUnderPostmaster )
17241737{
17251738puts ("\nPOSTGRES backend interactive interface " );
1726- puts ("$Revision: 1.231 $ $Date: 2001/09/07 16:12:48 $\n" );
1739+ puts ("$Revision: 1.232 $ $Date: 2001/09/08 01:10:20 $\n" );
17271740}
17281741
17291742/*