Re: Getting pg_stat_database data takes significant time

From: Vijaykumar Jain <vijaykumarjain(dot)github(at)gmail(dot)com>
To: depesz(at)depesz(dot)com
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Getting pg_stat_database data takes significant time
Date: 2021-08-11 13:56:26
Message-ID: CAM+6J96UZO3o1DTQN0eyF=EPTrJwWtonNq7QZBF68tpjeCOC2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 11 Aug 2021 at 19:12, Vijaykumar Jain <
vijaykumarjain(dot)github(at)gmail(dot)com> wrote:

>
>> ok my guess here was, since pg_class is updated every now and then with
> stats, it might require some lock while adding the data.
> so if it were bloated, that would block the planner to get the estimates ,
> and hence delay the query at whole.
> but that was a wild guess.
>

> --pg_class not locked
> postgres(at)db:~$ time psql -c 'select * from pg_stat_database;' >/dev/null
>
> real 0m0.016s
> user 0m0.003s
> sys 0m0.000s
>
> -- pg_class locked and the query completed when tx it unlocks
> postgres(at)db:~$ time psql -c 'select * from pg_stat_database;' >/dev/null
>
> real 0m7.269s
> user 0m0.003s
> sys 0m0.000s
>
>
ok pls ignore, i think this was wrong.
the delay while pg_class was locked on psql connection, not
pg_stat_database query.

strace -r psql -c 'select * from pg_stat_database;' >/dev/null
....
0.000612 poll([{fd=3, events=POLLIN|POLLERR}], 1, -1) = 1 ([{fd=3,
revents=POLLIN}])
4.819832 recvfrom(3,
"R\0\0\0\10\0\0\0\0S\0\0\0\32application_name\0p"..., 16384, 0, NULL, NULL)
= 396 -- the time till table was locked

I think i'll back off here, do some gdb tracing myself before i make
assumptions.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2021-08-11 14:09:55 Re: php connection failure
Previous Message Tom Lane 2021-08-11 13:54:16 Re: php connection failure