88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.358 2003/08/12 18:23:21 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.359 2003/08/12 18:52:38 tgl Exp $
1212 *
1313 * NOTES
1414 * this is the "main" module of the postgres backend and
@@ -2023,7 +2023,7 @@ PostgresMain(int argc, char *argv[], const char *username)
20232023GucSource gucsource ;
20242024char * tmp ;
20252025int firstchar ;
2026- StringInfo input_message ;
2026+ StringInfoData input_message ;
20272027volatile bool send_rfq = true;
20282028
20292029/*
@@ -2646,7 +2646,7 @@ PostgresMain(int argc, char *argv[], const char *username)
26462646if (!IsUnderPostmaster )
26472647{
26482648puts ("\nPOSTGRES backend interactive interface " );
2649- puts ("$Revision: 1.358 $ $Date: 2003/08/12 18:23:21 $\n" );
2649+ puts ("$Revision: 1.359 $ $Date: 2003/08/12 18:52:38 $\n" );
26502650}
26512651
26522652/*
@@ -2765,35 +2765,36 @@ PostgresMain(int argc, char *argv[], const char *username)
27652765MemoryContextSwitchTo (MessageContext );
27662766MemoryContextResetAndDeleteChildren (MessageContext );
27672767
2768- input_message = makeStringInfo ( );
2768+ initStringInfo ( & input_message );
27692769
27702770/*
2771- * (1) tell the frontend we're ready for a new query.
2771+ * (1) If we've reached idle state, tell the frontend we're ready
2772+ * for a new query.
27722773 *
27732774 * Note: this includes fflush()'ing the last of the prior output.
2775+ *
2776+ * This is also a good time to send collected statistics to the
2777+ * collector, and to update the PS stats display. We avoid doing
2778+ * those every time through the message loop because it'd slow down
2779+ * processing of batched messages.
27742780 */
27752781if (send_rfq )
27762782{
2777- ReadyForQuery (whereToSendOutput );
2778- send_rfq = false;
2779- }
2783+ pgstat_report_tabstat ();
27802784
2781- /* ----------
2782- * Tell the statistics collector what we've collected
2783- * so far.
2784- * ----------
2785- */
2786- pgstat_report_tabstat ();
2785+ if (IsTransactionBlock ())
2786+ {
2787+ set_ps_display ("idle in transaction" );
2788+ pgstat_report_activity ("<IDLE> in transaction" );
2789+ }
2790+ else
2791+ {
2792+ set_ps_display ("idle" );
2793+ pgstat_report_activity ("<IDLE>" );
2794+ }
27872795
2788- if (IsTransactionBlock ())
2789- {
2790- set_ps_display ("idle in transaction" );
2791- pgstat_report_activity ("<IDLE> in transaction" );
2792- }
2793- else
2794- {
2795- set_ps_display ("idle" );
2796- pgstat_report_activity ("<IDLE>" );
2796+ ReadyForQuery (whereToSendOutput );
2797+ send_rfq = false;
27972798}
27982799
27992800/*
@@ -2815,7 +2816,7 @@ PostgresMain(int argc, char *argv[], const char *username)
28152816/*
28162817 * (3) read a command (loop blocks here)
28172818 */
2818- firstchar = ReadCommand (input_message );
2819+ firstchar = ReadCommand (& input_message );
28192820
28202821/*
28212822 * (4) disable async signal conditions again.
@@ -2848,8 +2849,8 @@ PostgresMain(int argc, char *argv[], const char *username)
28482849{
28492850const char * query_string ;
28502851
2851- query_string = pq_getmsgstring (input_message );
2852- pq_getmsgend (input_message );
2852+ query_string = pq_getmsgstring (& input_message );
2853+ pq_getmsgend (& input_message );
28532854
28542855exec_simple_query (query_string );
28552856
@@ -2864,18 +2865,18 @@ PostgresMain(int argc, char *argv[], const char *username)
28642865int numParams ;
28652866Oid * paramTypes = NULL ;
28662867
2867- stmt_name = pq_getmsgstring (input_message );
2868- query_string = pq_getmsgstring (input_message );
2869- numParams = pq_getmsgint (input_message ,2 );
2868+ stmt_name = pq_getmsgstring (& input_message );
2869+ query_string = pq_getmsgstring (& input_message );
2870+ numParams = pq_getmsgint (& input_message ,2 );
28702871if (numParams > 0 )
28712872{
28722873int i ;
28732874
28742875paramTypes = (Oid * )palloc (numParams * sizeof (Oid ));
28752876for (i = 0 ;i < numParams ;i ++ )
2876- paramTypes [i ]= pq_getmsgint (input_message ,4 );
2877+ paramTypes [i ]= pq_getmsgint (& input_message ,4 );
28772878}
2878- pq_getmsgend (input_message );
2879+ pq_getmsgend (& input_message );
28792880
28802881exec_parse_message (query_string ,stmt_name ,
28812882paramTypes ,numParams );
@@ -2888,17 +2889,17 @@ PostgresMain(int argc, char *argv[], const char *username)
28882889 * this message is complex enough that it seems best to
28892890 * put the field extraction out-of-line
28902891 */
2891- exec_bind_message (input_message );
2892+ exec_bind_message (& input_message );
28922893break ;
28932894
28942895case 'E' :/* execute */
28952896{
28962897const char * portal_name ;
28972898int max_rows ;
28982899
2899- portal_name = pq_getmsgstring (input_message );
2900- max_rows = pq_getmsgint (input_message ,4 );
2901- pq_getmsgend (input_message );
2900+ portal_name = pq_getmsgstring (& input_message );
2901+ max_rows = pq_getmsgint (& input_message ,4 );
2902+ pq_getmsgend (& input_message );
29022903
29032904exec_execute_message (portal_name ,max_rows );
29042905}
@@ -2914,7 +2915,7 @@ PostgresMain(int argc, char *argv[], const char *username)
29142915/* switch back to message context */
29152916MemoryContextSwitchTo (MessageContext );
29162917
2917- if (HandleFunctionRequest (input_message )== EOF )
2918+ if (HandleFunctionRequest (& input_message )== EOF )
29182919{
29192920/* lost frontend connection during F message input */
29202921
@@ -2939,9 +2940,9 @@ PostgresMain(int argc, char *argv[], const char *username)
29392940int close_type ;
29402941const char * close_target ;
29412942
2942- close_type = pq_getmsgbyte (input_message );
2943- close_target = pq_getmsgstring (input_message );
2944- pq_getmsgend (input_message );
2943+ close_type = pq_getmsgbyte (& input_message );
2944+ close_target = pq_getmsgstring (& input_message );
2945+ pq_getmsgend (& input_message );
29452946
29462947switch (close_type )
29472948{
@@ -2987,9 +2988,9 @@ PostgresMain(int argc, char *argv[], const char *username)
29872988int describe_type ;
29882989const char * describe_target ;
29892990
2990- describe_type = pq_getmsgbyte (input_message );
2991- describe_target = pq_getmsgstring (input_message );
2992- pq_getmsgend (input_message );
2991+ describe_type = pq_getmsgbyte (& input_message );
2992+ describe_target = pq_getmsgstring (& input_message );
2993+ pq_getmsgend (& input_message );
29932994
29942995switch (describe_type )
29952996{
@@ -3010,13 +3011,13 @@ PostgresMain(int argc, char *argv[], const char *username)
30103011break ;
30113012
30123013case 'H' :/* flush */
3013- pq_getmsgend (input_message );
3014+ pq_getmsgend (& input_message );
30143015if (whereToSendOutput == Remote )
30153016pq_flush ();
30163017break ;
30173018
30183019case 'S' :/* sync */
3019- pq_getmsgend (input_message );
3020+ pq_getmsgend (& input_message );
30203021finish_xact_command ();
30213022send_rfq = true;
30223023break ;