Re: Patch: show xid and xmin in pg_stat_activity and pg_stat_replication

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Christian Kruse <christian(at)2ndquadrant(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Subject: Re: Patch: show xid and xmin in pg_stat_activity and pg_stat_replication
Date: 2014-02-15 04:03:43
Message-ID: CA+TgmoaXQ+0fX9A2w2MF2JcDaNAcawOYg1cjP_dyYN4g_HMLBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Feb 12, 2014 at 8:00 AM, Christian Kruse
<christian(at)2ndquadrant(dot)com> wrote:
> On Wednesday 12 February 2014 11:14:56 Andres Freund wrote:
>> But they do take up shared memory without really needing to. I
>> personally don't find that too bad, it's not much memory. If we want to
>> avoid it we could have a LocalPgBackendStatus that includes the normal
>> PgBackendStatus. Since pgstat_read_current_status() copies all the data
>> locally, that'd be a sensible point to fill it. While that will cause a
>> bit of churn, I'd guess we can use the infrastructure in the not too far
>> away future for other parts.
>
> That's a good idea. Attached you will find a patch implementing it
> that way; is this how you pictured it?
>
> Although I'm not sure if this shouldn't be done in two patches, one
> for the changes needed for LocalPgBackendStatus and one for the
> xid/xmin changes.

Well, this version of the patch reveals a mighty interesting point: a
lot of the people who are calling pgstat_fetch_stat_beentry() don't
need this additional information and might prefer not to pay the cost
of fetching it. None of pg_stat_get_backend_pid,
pg_stat_get_backend_dbid, pg_stat_get_backend_userid,
pg_stat_get_backend_activity, pg_stat_get_backend_activity,
pg_stat_get_backend_waiting, pg_stat_get_backend_activity_start,
pg_stat_get_backend_xact_start, pg_stat_get_backend_start,
pg_stat_get_backend_client_addr, pg_stat_get_backend_client_port,
pg_stat_get_backend_client_port, and pg_stat_get_db_numbackends
actually need this new information; it's only ever used in one place.
So it seems like it might be wise to have pgstat_fetch_stat_beentry
continue to return the PgBackendStatus * and add a new function
pgstat_fetch_stat_local_beentry to fetch the LocalPgBackendStatus *;
then most of these call sites wouldn't need to change.

It would still be the case that pgstat_read_current_status() pays the
price of fetching this information even if pg_stat_get_activity is
never called. But since that's probably by far the most commonly-used
API for this information, that's probably OK.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-02-15 04:28:49 Re: Small psql memory fix
Previous Message Bruce Momjian 2014-02-15 03:51:45 Small psql memory fix