7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.89 1998/09/01 04:32:13 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.90 1998/10/02 01:14:14 tgl Exp $
11
11
*
12
12
* NOTES
13
13
* this is the "main" module of the postgres backend and
@@ -223,6 +223,7 @@ InteractiveBackend(char *inBuf)
223
223
* ----------------
224
224
*/
225
225
printf ("> " );
226
+ fflush (stdout );
226
227
227
228
for (;;)
228
229
{
@@ -295,6 +296,7 @@ InteractiveBackend(char *inBuf)
295
296
*/
296
297
if (EchoQuery )
297
298
printf ("query: %s\n" , inBuf );
299
+ fflush (stdout );
298
300
299
301
return 'Q' ;
300
302
}
@@ -1398,7 +1400,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
1398
1400
{
1399
1401
PS_INIT_STATUS (real_argc , real_argv , argv [0 ],
1400
1402
remote_info , userName , DBName );
1401
- PS_SET_STATUS ("idle " );
1403
+ PS_SET_STATUS ("startup " );
1402
1404
}
1403
1405
1404
1406
/* ----------------
@@ -1465,18 +1467,33 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
1465
1467
puts ("\treset_client_encoding() done." );
1466
1468
#endif
1467
1469
1470
+ /* ----------------
1471
+ * if stable main memory is assumed (-S(old) flag is set), it is necessary
1472
+ * to flush all dirty shared buffers before exit
1473
+ * plai 8/7/90
1474
+ * this used to be done further down, causing an additional entry in
1475
+ * the shmem exit list for every error :-( ... tgl 10/1/98
1476
+ * ----------------
1477
+ */
1478
+ if (!TransactionFlushEnabled ())
1479
+ on_shmem_exit (FlushBufferPool , NULL );
1480
+
1468
1481
/* ----------------
1469
1482
* Set up handler for cancel-request signal, and
1470
1483
* send this backend's cancellation info to the frontend.
1471
1484
* This should not be done until we are sure startup is successful.
1472
1485
* ----------------
1473
1486
*/
1474
1487
1475
- pqsignal (SIGHUP , read_pg_options ); /* upate pg_options from file */
1488
+ pqsignal (SIGHUP , read_pg_options ); /* update pg_options from file */
1476
1489
pqsignal (SIGINT , QueryCancelHandler ); /* cancel current query */
1477
1490
pqsignal (SIGQUIT , handle_warn ); /* handle error */
1478
1491
pqsignal (SIGTERM , die );
1479
- pqsignal (SIGPIPE , die );
1492
+ pqsignal (SIGPIPE , SIG_IGN ); /* ignore failure to write to frontend */
1493
+ /* Note: if frontend closes connection, we will notice it and exit cleanly
1494
+ * when control next returns to outer loop. This seems safer than forcing
1495
+ * exit in the midst of output during who-knows-what operation...
1496
+ */
1480
1497
pqsignal (SIGUSR1 , quickdie );
1481
1498
pqsignal (SIGUSR2 , Async_NotifyHandler ); /* flush also sinval cache */
1482
1499
pqsignal (SIGCHLD , SIG_IGN ); /* ignored, sent by LockOwners */
@@ -1491,7 +1508,15 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
1491
1508
/* Need not flush since ReadyForQuery will do it. */
1492
1509
}
1493
1510
1511
+ if (!IsUnderPostmaster )
1512
+ {
1513
+ puts ("\nPOSTGRES backend interactive interface " );
1514
+ puts ("$Revision: 1.90 $ $Date: 1998/10/02 01:14:14 $\n" );
1515
+ }
1516
+
1494
1517
/* ----------------
1518
+ * POSTGRES main processing loop begins here
1519
+ *
1495
1520
* if an exception is encountered, processing resumes here
1496
1521
* so we abort the current transaction and start a new one.
1497
1522
* This must be done after we initialize the slave backends
@@ -1512,52 +1537,41 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
1512
1537
if (Verbose )
1513
1538
TPRINTF (TRACE_VERBOSE , "AbortCurrentTransaction" );
1514
1539
1515
- MemSet (parser_input , 0 , MAX_PARSE_BUFFER );
1516
-
1517
1540
AbortCurrentTransaction ();
1518
-
1519
1541
}
1520
1542
1521
1543
InError = false;
1522
1544
1523
- /* ----------------
1524
- * POSTGRES main processing loop begins here
1525
- * ----------------
1526
- */
1527
- if (!IsUnderPostmaster )
1528
- {
1529
- puts ("\nPOSTGRES backend interactive interface" );
1530
- puts ("$Revision: 1.89 $ $Date: 1998/09/01 04:32:13 $" );
1531
- }
1532
-
1533
- /* ----------------
1534
- * if stable main memory is assumed (-S(old) flag is set), it is necessary
1535
- * to flush all dirty shared buffers before exit
1536
- * plai 8/7/90
1537
- * ----------------
1545
+ /*
1546
+ * Non-error queries loop here.
1538
1547
*/
1539
- if (!TransactionFlushEnabled ())
1540
- on_shmem_exit (FlushBufferPool , NULL );
1541
1548
1542
1549
for (;;)
1543
1550
{
1551
+ PS_SET_STATUS ("idle" );
1552
+
1544
1553
/* ----------------
1545
- * (0) tell the frontend we're ready for a new query.
1554
+ * (1) tell the frontend we're ready for a new query.
1555
+ *
1556
+ * Note: this includes fflush()'ing the last of the prior output.
1546
1557
* ----------------
1547
1558
*/
1548
1559
ReadyForQuery (whereToSendOutput );
1549
1560
1550
1561
/* ----------------
1551
- * (1 ) read a command.
1562
+ * (2 ) read a command.
1552
1563
* ----------------
1553
1564
*/
1554
1565
MemSet (parser_input , 0 , MAX_PARSE_BUFFER );
1555
1566
1556
1567
firstchar = ReadCommand (parser_input );
1557
1568
1558
- QueryCancel = false;
1569
+ QueryCancel = false; /* forget any earlier CANCEL signal */
1559
1570
1560
- /* process the command */
1571
+ /* ----------------
1572
+ * (3) process the command.
1573
+ * ----------------
1574
+ */
1561
1575
switch (firstchar )
1562
1576
{
1563
1577
/* ----------------
@@ -1571,19 +1585,16 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
1571
1585
/* start an xact for this function invocation */
1572
1586
if (Verbose )
1573
1587
TPRINTF (TRACE_VERBOSE , "StartTransactionCommand" );
1574
-
1575
1588
StartTransactionCommand ();
1589
+
1576
1590
HandleFunctionRequest ();
1577
- PS_SET_STATUS ("idle" );
1578
1591
break ;
1579
1592
1580
1593
/* ----------------
1581
1594
* 'Q' indicates a user query
1582
1595
* ----------------
1583
1596
*/
1584
1597
case 'Q' :
1585
- fflush (stdout );
1586
-
1587
1598
if (strspn (parser_input , " \t\n" ) == strlen (parser_input ))
1588
1599
{
1589
1600
/* ----------------
@@ -1610,8 +1621,6 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
1610
1621
1611
1622
pg_exec_query (parser_input );
1612
1623
1613
- PS_SET_STATUS ("idle" );
1614
-
1615
1624
if (ShowStats )
1616
1625
ShowUsage ();
1617
1626
}
@@ -1631,7 +1640,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
1631
1640
}
1632
1641
1633
1642
/* ----------------
1634
- * (3 ) commit the current transaction
1643
+ * (4 ) commit the current transaction
1635
1644
*
1636
1645
* Note: if we had an empty input buffer, then we didn't
1637
1646
* call pg_exec_query, so we don't bother to commit this transaction.
@@ -1643,17 +1652,15 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
1643
1652
TPRINTF (TRACE_VERBOSE , "CommitTransactionCommand" );
1644
1653
PS_SET_STATUS ("commit" );
1645
1654
CommitTransactionCommand ();
1646
- PS_SET_STATUS ("idle" );
1647
-
1648
1655
}
1649
1656
else
1650
1657
{
1651
1658
if (IsUnderPostmaster )
1652
1659
NullCommand (Remote );
1653
1660
}
1654
-
1655
1661
} /* infinite for-loop */
1656
- proc_exit (0 );
1662
+
1663
+ proc_exit (0 ); /* shouldn't get here... */
1657
1664
return 1 ;
1658
1665
}
1659
1666
0 commit comments