Re: Inconsistency between pg_stat_activity and log_duration - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: Inconsistency between pg_stat_activity and log_duration
Date
Msg-id CAA4eK1+qUEYs921W912+q_W=3RhK+verBvE2q0r6R34YwPr3zQ@mail.gmail.com
Whole thread Raw
In response to Re: Inconsistency between pg_stat_activity and log_duration  (Tatsuo Ishii <ishii@postgresql.org>)
List pgsql-hackers
On Fri, Feb 7, 2014 at 2:44 PM, Tatsuo Ishii <ishii@postgresql.org> wrote:
>>> One idea is, calling pgstat_report_activity(STATE_IDLE) in
>>> exec_execute_message() of postgres.c. The function has already called
>>> pgstat_report_activity(STATE_RUNNING) which shows "active" state in
>>> pg_stat_actviity view. So why cann't we call
>>> pgstat_report_activity(STATE_IDLE) here.
>>>
>>> Somebody might claim that "idle" is a transaction state term.
>>
>> Idle means "The backend is waiting for a new client command.", which
>> is certainly not true especially in case of 'E' message as still sync
>> message processing is left.
>>
>>> In the
>>> case, I propose to add new state name, say "finished". So above
>>> proposal would calling pgstat_report_activity(STATE_FINISHED) instead.
>>
>> Okay, so by state finish, it can mean "The backend has finished execution
>> of a query.". In that case I think this might need to be called at end
>> of exec_simple_query() as well, but then there will be very less difference
>> between idle and finish for simple query.
>
> Of course.
>
>> The argument here could be do we really need a new state for such a short
>> window between completion of 'E' message and processing of 'S' sync
>> message considering updation of state is not a very light call which can
>> be called between processing of 2 messages. It might make sense for cases
>> where sync message processing can take longer time.
>>
>> Would it be not sufficient, If we just explain this in docs. Do users really
>> face any inconvenience or it's a matter of clear understanding for users?
>
> Well... maybe it's a matter of doc.
>
> Pgpool-II issues such SELECTs intenally to retrieve system catalog
> info.
>
> The query is piggy backed on the same connection to PostgreSQL opend
> by user (pgpool-II cannot issue "sync" because it closes the
> transaction, which in turn closes user's unnamed portal).
>
> If user's query is SELECT, it can be sent to standbys because of load
> balance. After such internal queries are sent to master, which will
> remain "active" for long time because "sync" is not issued.

In that case, will it not be better if pgpool-II start a transaction explicitly
(BEGIN/START TRANSACTION) rather than relying on automatic commit
mode?

> If you're issuing a flush instead, maybe we could consider whether it's
> reasonable to do an extra pgstat_report_activity() upon receipt of a
> flush message.

I think it might be reasonable to call pgstat_report_activity(), as sending
Flush message indicates user got the complete response of the command
sent to backend, but I am not sure if it is good idea to set
send_ready_for_query = true; and sending ReadyForQuery() message to
FE (Frontend), as it is expected that FE can send more messages like
'B', 'E', so we might need to set the status bases on current state of
backend.

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Craig Ringer
Date:
Subject: Re: narwhal and PGDLLIMPORT
Next
From: Haribabu Kommi
Date:
Subject: Re: New option for pg_basebackup, to specify a different directory for pg_xlog