@@ -67,16 +67,7 @@ List*QueryDescStack = NIL;
6767static ProcSignalReason UserIdPollReason = INVALID_PROCSIGNAL ;
6868static ProcSignalReason QueryStatePollReason = INVALID_PROCSIGNAL ;
6969static ProcSignalReason WorkerPollReason = INVALID_PROCSIGNAL ;
70- static bool module_initialized = false;
71- static const char * be_state_str []= {/* BackendState -> string repr */
72- "undefined" ,/* STATE_UNDEFINED */
73- "idle" ,/* STATE_IDLE */
74- "active" ,/* STATE_RUNNING */
75- "idle in transaction" ,/* STATE_IDLEINTRANSACTION */
76- "fastpath function call" ,/* STATE_FASTPATH */
77- "idle in transaction (aborted)" ,/* STATE_IDLEINTRANSACTION_ABORTED */
78- "disabled" ,/* STATE_DISABLED */
79- };
70+ static bool module_initialized = false;
8071static int reqid = 0 ;
8172
8273typedef struct
@@ -352,6 +343,37 @@ qs_ExecutorFinish(QueryDesc *queryDesc)
352343PG_END_TRY ();
353344}
354345
346+ /*
347+ *Convert BackendState to string description
348+ */
349+ static const char *
350+ be_state_str (BackendState be_state )
351+ {
352+ switch (be_state )
353+ {
354+ case STATE_UNDEFINED :
355+ return "undefined" ;
356+ #if PG_VERSION_NUM >=180000
357+ case STATE_STARTING :
358+ return "starting" ;
359+ #endif
360+ case STATE_IDLE :
361+ return "idle" ;
362+ case STATE_RUNNING :
363+ return "active" ;
364+ case STATE_IDLEINTRANSACTION :
365+ return "idle in transaction" ;
366+ case STATE_FASTPATH :
367+ return "fastpath function call" ;
368+ case STATE_IDLEINTRANSACTION_ABORTED :
369+ return "idle in transaction (aborted)" ;
370+ case STATE_DISABLED :
371+ return "disabled" ;
372+ default :
373+ return "unknown" ;
374+ }
375+ }
376+
355377/*
356378 * Find PgBackendStatus entry
357379 */
@@ -598,7 +620,7 @@ pg_query_state(PG_FUNCTION_ARGS)
598620
599621if (be_status )
600622elog (INFO ,"state of backend is %s" ,
601- be_state_str [ be_status -> st_state - STATE_UNDEFINED ] );
623+ be_state_str ( be_status -> st_state ) );
602624else
603625elog (INFO ,"backend is not running query" );
604626