pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Robert Treat <rob@xzilla.net>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Nikolay Samokhvalov <samokhvalov@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Bruce Momjian <bruce@momjian.us>
Cc: Alexey Kondratov <a.kondratov@postgrespro.ru>
Cc: v.makarov@postgrespro.ru
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: [PATCH] Increase the maximum value track_activity_query_size
Date: Mon, 30 Dec 2019 18:08:42 -0500
Message-ID: <20733.1577747322@sss.pgh.pa.us> (raw)
In-Reply-To: <20191230213342.jmtvp2kmqdtt55sp@development>
References: <20191219154110.GL30116@momjian.us>
	<556.1576771167@sss.pgh.pa.us>
	<CA+Tgmobjp+cqjNW+397Ejbo=M8XNzykQPspfhbd39DVc8Wd7Wg@mail.gmail.com>
	<7a4ecea0-949e-efa7-865f-0ef2ddce52c3@postgrespro.ru>
	<20191220135704.GC29807@momjian.us>
	<20191221024757.GF15758@paquier.xyz>
	<CANNMO+LrCCMTJBgETVyWdRGmwkT8hO9utF1RtdpsO=w765z6PQ@mail.gmail.com>
	<25274.1576963505@sss.pgh.pa.us>
	<CA+TgmoZSs4BZ+CQ6x0Vswxhc8A6r78iCNLcJKWLazGWCqKHnYw@mail.gmail.com>
	<CABV9wwOXrWH2qdPvjzjUTMB1WKF=3NuUguLXnwEkQmZHt5AyiA@mail.gmail.com>
	<20191230213342.jmtvp2kmqdtt55sp@development>

Tomas Vondra <tomas.vondra@2ndquadrant.com> writes:
> 2) What's the overhead for increasing the value for short/long queries?

> My assumption is that for short queries, it's going to be negligible.
> For longer queries it may be measurable, but I'd expect longer queries
> to be more expensive in general, so maybe it's still negligible.

The thing that has been bothering me is the idea that backends reading
st_activity_raw might palloc the max possible length and/or memcpy the
whole buffer rather than just the valid part.  Having now rooted through
pgstat.c, that appears to be half true: the local allocation made by
pgstat_read_current_status() will be just as large as the shared-memory
arena, but we use strcpy() or equivalent so that each query copy should
stop upon hitting a '\0'.  So the run-time cost should be negligible, but
you might be eating a lot of memory if multiple sessions are inspecting
pg_stat_activity and you cranked the setting up imprudently high.

This doesn't seem like a reason not to allow a higher limit, like a
megabyte or so, but I'm not sure that pushing it to the moon would be
wise.

Meanwhile, I noted what seems like a pretty obvious bug in
pg_stat_get_backend_activity():

	clipped_activity = pgstat_clip_activity(activity);
	ret = cstring_to_text(activity);
	pfree(clipped_activity);

We're not actually applying the intended clip to the returned
value, so that an invalidly-encoded result is possible.

(Of course, since we also don't seem to be making any attempt
to translate from the source backend's encoding to our own,
there's more problems here than just that.)

			regards, tom lane





view thread (29+ messages)  latest in thread

Message-ID: <20733.1577747322@sss.pgh.pa.us>
Permalink:  ../20733.1577747322@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20733.1577747322@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, tomas.vondra@2ndquadrant.com, rob@xzilla.net, robertmhaas@gmail.com, samokhvalov@gmail.com, michael@paquier.xyz, bruce@momjian.us, a.kondratov@postgrespro.ru, v.makarov@postgrespro.ru
  Subject: Re: [PATCH] Increase the maximum value track_activity_query_size
  In-Reply-To: <20733.1577747322@sss.pgh.pa.us>
  References: <20191219154110.GL30116@momjian.us> <556.1576771167@sss.pgh.pa.us> <CA+Tgmobjp+cqjNW+397Ejbo=M8XNzykQPspfhbd39DVc8Wd7Wg@mail.gmail.com> <7a4ecea0-949e-efa7-865f-0ef2ddce52c3@postgrespro.ru> <20191220135704.GC29807@momjian.us> <20191221024757.GF15758@paquier.xyz> <CANNMO+LrCCMTJBgETVyWdRGmwkT8hO9utF1RtdpsO=w765z6PQ@mail.gmail.com> <25274.1576963505@sss.pgh.pa.us> <CA+TgmoZSs4BZ+CQ6x0Vswxhc8A6r78iCNLcJKWLazGWCqKHnYw@mail.gmail.com> <CABV9wwOXrWH2qdPvjzjUTMB1WKF=3NuUguLXnwEkQmZHt5AyiA@mail.gmail.com> <20191230213342.jmtvp2kmqdtt55sp@development> <20733.1577747322@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox