8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
* NOTES
14
14
* this is the "main" module of the postgres backend and
@@ -85,6 +85,7 @@ bool ShowPortNumber;
85
85
86
86
bool Log_connections = false;
87
87
88
+ /* Note: whereToSendOutput is initialized for the bootstrap/standalone case */
88
89
CommandDest whereToSendOutput = Debug ;
89
90
90
91
static bool dontExecute = false;
@@ -536,7 +537,7 @@ pg_plan_query(Query *querytree)
536
537
537
538
if (Show_planner_stats )
538
539
{
539
- fprintf (stderr , "PLANNER STATISTICS\n" );
540
+ fprintf (StatFp , "PLANNER STATISTICS\n" );
540
541
ShowUsage ();
541
542
}
542
543
@@ -813,7 +814,7 @@ pg_exec_query_string(char *query_string, /* string to execute */
813
814
814
815
if (Show_executor_stats )
815
816
{
816
- fprintf (stderr , "EXECUTOR STATISTICS\n" );
817
+ fprintf (StatFp , "EXECUTOR STATISTICS\n" );
817
818
ShowUsage ();
818
819
}
819
820
}
@@ -910,9 +911,9 @@ quickdie(SIGNAL_ARGS)
910
911
PG_SETMASK (& BlockSig );
911
912
elog (NOTICE , "Message from PostgreSQL backend:"
912
913
"\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."
914
915
"\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."
916
917
"\n\tPlease reconnect to the database system and repeat your query." );
917
918
918
919
/*
@@ -968,6 +969,10 @@ die(SIGNAL_ARGS)
968
969
/*
969
970
* Shutdown signal from postmaster during client authentication.
970
971
* 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.
971
976
*/
972
977
void
973
978
authdie (SIGNAL_ARGS )
@@ -1163,6 +1168,16 @@ PostgresMain(int argc, char *argv[],
1163
1168
1164
1169
SetProcessingMode (InitProcessing );
1165
1170
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
+
1166
1181
/*
1167
1182
* Set default values for command-line options.
1168
1183
*/
@@ -1209,7 +1224,7 @@ PostgresMain(int argc, char *argv[],
1209
1224
#ifdef USE_ASSERT_CHECKING
1210
1225
SetConfigOption ("debug_assertions" , optarg , ctx , true);
1211
1226
#else
1212
- fprintf ( stderr , "Assert checking is not compiled in\n " );
1227
+ elog ( NOTICE , "Assert checking is not compiled in" );
1213
1228
#endif
1214
1229
break ;
1215
1230
@@ -1439,7 +1454,7 @@ PostgresMain(int argc, char *argv[],
1439
1454
*/
1440
1455
if (XfuncMode != 0 )
1441
1456
{
1442
- fprintf ( stderr , "only one -x flag is allowed\n " );
1457
+ elog ( NOTICE , "only one -x flag is allowed" );
1443
1458
errs ++ ;
1444
1459
break ;
1445
1460
}
@@ -1457,7 +1472,7 @@ PostgresMain(int argc, char *argv[],
1457
1472
XfuncMode = XFUNC_WAIT ;
1458
1473
else
1459
1474
{
1460
- fprintf ( stderr , "use -x {off,nor,nopull,nopm,pullall,wait}\n " );
1475
+ elog ( NOTICE , "use -x {off,nor,nopull,nopm,pullall,wait}" );
1461
1476
errs ++ ;
1462
1477
}
1463
1478
#endif
@@ -1492,14 +1507,11 @@ PostgresMain(int argc, char *argv[],
1492
1507
1493
1508
/*
1494
1509
* 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...
1498
1510
*/
1499
1511
if (Show_query_stats &&
1500
1512
(Show_parser_stats || Show_planner_stats || Show_executor_stats ))
1501
1513
{
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." );
1503
1515
SetConfigOption ("show_query_stats" , "false" , ctx , true);
1504
1516
}
1505
1517
@@ -1508,9 +1520,9 @@ PostgresMain(int argc, char *argv[],
1508
1520
if (!potential_DataDir )
1509
1521
{
1510
1522
fprintf (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" ,
1514
1526
argv [0 ]);
1515
1527
proc_exit (1 );
1516
1528
}
@@ -1578,27 +1590,28 @@ PostgresMain(int argc, char *argv[],
1578
1590
/* noninteractive case: nothing should be left after switches */
1579
1591
if (errs || argc != optind || DBName == NULL )
1580
1592
{
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 ]);
1582
1595
proc_exit (0 ); /* not 1, that causes system-wide
1583
1596
* restart... */
1584
1597
}
1585
- pq_init (); /* initialize libpq at backend startup */
1586
1598
BaseInit ();
1587
1599
}
1588
1600
else
1589
1601
{
1590
1602
/* interactive case: database name can be last arg on command line */
1591
1603
if (errs || argc - optind > 1 )
1592
1604
{
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 ]);
1594
1607
proc_exit (1 );
1595
1608
}
1596
1609
else if (argc - optind == 1 )
1597
1610
DBName = argv [optind ];
1598
1611
else if ((DBName = username ) == NULL )
1599
1612
{
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 ]);
1602
1615
proc_exit (1 );
1603
1616
}
1604
1617
@@ -1723,7 +1736,7 @@ PostgresMain(int argc, char *argv[],
1723
1736
if (!IsUnderPostmaster )
1724
1737
{
1725
1738
puts ("\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" );
1727
1740
}
1728
1741
1729
1742
/*
0 commit comments