Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No per process wait stats #17

Open
jamessewell opened this issue Feb 24, 2020 · 5 comments
Open

No per process wait stats #17

jamessewell opened this issue Feb 24, 2020 · 5 comments

Comments

@jamessewell
Copy link

jamessewell commented Feb 24, 2020

Hi,

I have pg_stat_statements and pg_wait_sampling loaded on PostgreSQL 11.5

postgres=# show shared_preload_libraries
;
             shared_preload_libraries
---------------------------------------------------
 timescaledb, pg_stat_statements, pg_wait_sampling
(1 row)

postgres=# \dx
                                         List of installed extensions
        Name        | Version |   Schema   |                            Description
--------------------+---------+------------+-------------------------------------------------------------------
 pg_stat_statements | 1.6     | public     | track execution statistics of all SQL statements executed
 pg_wait_sampling   | 1.1     | public     | sampling based statistics of wait events
 plpgsql            | 1.0     | pg_catalog | PL/pgSQL procedural language
 timescaledb        | 1.5.0   | public     | Enables scalable inserts and complex queries for time-series data
(4 rows)

postgres=# show pg_wait_sampling.profile_queries ;
 pg_wait_sampling.profile_queries
----------------------------------
 on
(1 row)

I am forcing a lock like this:

session 1:

begin;
truncate a;

session 2:

insert into a values (1)

This shows up as so:

postgres=# select * from pg_wait_sampling_current where event = 'relation';
 pid | event_type |  event   | queryid
-----+------------+----------+---------
 634 | Lock       | relation |       0
(1 row)

Why is queryid not populated?

@jamessewell
Copy link
Author

jamessewell commented Feb 24, 2020 via email

@maksm90
Copy link
Collaborator

maksm90 commented Feb 26, 2020

Hi @jamessewell !

It is set

Yes, I saw later so removed my last post

I occasionally get a queryid listed. For example the SELECT from the wait sampling tables has one associated

OK, I'll try to reproduce your case and get to the bottom of it .

@maksm90
Copy link
Collaborator

maksm90 commented Mar 29, 2022

Hi @jamessewell ! Sorry for so delayed answer.

The core issue here is that the lock acquiring on relations happens on parse-analyze stage when database objects in query is transformed from test representation to internal one. But computing of queryId in pg_stat_statements extension occurs immediately after this stage (by calling post_parse_analyze_hook). And pg_wait_sampling captures queryId on further step - before planning (by calling planner_hook). For these reasons the sample collector process cannot find out the queryId of locked insert operation and eventually it detects running process as one without queryId value.

@maksm90
Copy link
Collaborator

maksm90 commented Mar 29, 2022

In general, due to much of locks on relations and other db objects are acquired in parse-analyze routine there is no ability to assign queryId values to the waits on transactional locks, i.e., monitoring by queryId is not applicable to lock waits in most cases. And unfortunately we are not able to amend this situation because queryId is attached to Query structure that is initialized after completion of parse-anlayze stage, i.e., after primary locks acquiring on db objects in query text.

In a certain sense this issue might be solved after segregation of analyze and lock expansion stages in postgres core.

@maksm90
Copy link
Collaborator

maksm90 commented Aug 16, 2022

In general, with current state of lock acquiring mechanics it's possible to assign queryId value to the waiting on heavyweight locks. But this assignment will be deferred. And it would require some investigation to make it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants