public inbox for [email protected]  
help / color / mirror / Atom feed
From: Sheryl Prabhu David <[email protected]>
To: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: Nested loop behaviour with pg_stat_activity
Date: Thu, 14 Mar 2024 12:59:03 +0530
Message-ID: <CAKxBfWEq9GoMxmtyoFnjwnAFbTLHFZK5G+57Cu2Oek67F_1X0Q@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAKxBfWFZZO7MnvFVrJeX7bCJoXbVeeDY0Q2dJkKS8hs4ucYvXA@mail.gmail.com>
	<[email protected]>

Thanks a lot Tom, Postgres community truly is impressive, I never thought I
will get a response this soon if at all.

In Oracle with v$session being the inner table of a nested loop for each
scan we get different copies of it even as the data changes under us, thats
the hack someone figured out, and it gives us tons of samples - in the
order of ~500 per second with a single SQL run.

In Postgres the reason I mention the behaviour is different is that the
count I get with the outer group by for each connected client is one record
with a count of 2000 if I use 2000 records from generate_series. Oracles
behaviour would be multiple records each with a different wait event adding
up to 2000.

As you describe this may not be possible with Postgres. I will try SELECT
pg_stat_clear_snapshot() but not sure if that can be done is a single SQL
statement. Will let you know if it works.

Thanks a lot again.

Regards
Prabhu David

On Wed, Mar 13, 2024 at 8:00 PM Tom Lane <[email protected]> wrote:

> Sheryl Prabhu David <[email protected]> writes:
> > In an Oracle database using a SQL like the one below, we have the ability
> > to use, a series along the lines of Postgresqls generate_series() as seen
> > in the 'connect by' line as outer table of a forced nested loop, and
> > v$session(Oracles equivalent of pg_stat_activity) as the inner table, to
> > get many samples of v$session each second.
>
> That's ... impressively ill-defined.  How do you know you are getting
> consistent "samples" at all?
>
> > Trying something similar in Postgres does not produce an equivalent
> result.
> > Instead of 'Number of sample' times *DIFFERENT* copies of
> pg_stat_activity,
> > we are seeing 'Number of sample' times *SAME* copy of pg_stat_activity,
> > unlike Oracle. MVCC and Isolation guarantees for regular tables is
> expected
> > to produce this kind of a result, but I was hoping pg_stat_activity
> being a
> > portal into internal data structures will act similar to Oracles
> v$session
> > bypassing MVCC+Isolation. I am hoping to find out if there is anyway to
> > force Oracle type behaviour for pg_stat_activity, please help.
>
> A Postgres session captures a snapshot of pg_stat_activity on first
> reference, and holds it until end of transaction or you call
> pg_stat_clear_snapshot().  Without this behavior you would get total
> garbage from queries as the data changes under you, especially so
> from join queries which may require multiple scans of the input.
>
> I don't think there's any way to precisely duplicate what you describe
> doing in Postgres, but you can easily get a similar result by
> alternating "SELECT pg_stat_clear_snapshot()" with selects from
> pg_stat_activity.
>
>                         regards, tom lane
>


view thread (3+ messages)

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Nested loop behaviour with pg_stat_activity
  In-Reply-To: <CAKxBfWEq9GoMxmtyoFnjwnAFbTLHFZK5G+57Cu2Oek67F_1X0Q@mail.gmail.com>

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

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