I am using the following query on the pg_stat_activity to look for the queries that are currently running:
SELECT pid, age(clock_timestamp(), query_start), usename, query, *
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' and usename='<db_user>'
ORDER BY query_start desc;
I have set a satement_timeout to 30s for this user using below query:
ALTER ROLE <db_user> set statement_timeout = 30000
I verifiy that this is set by opening a new session for db_user:
show statement_timeout;
statement_timeout|
-----------------|
30s |
I run this query which times out after 30 seconds as expected.
SELECT pg_sleep(31);
SQL Error [57014]: ERROR: canceling statement due to statement timeout
However after this when I run the first query to see what queries are running, it shows me the timed out query as well
pid | age | usename | query |
---|---|---|---|
9133 | 00:00:54.366638 | <db_user> | COMMIT |
31551 | 00:01:49.70594 | <db_user> | ¶SELECT pg_sleep(31) |
Why is the timeout query still showing when querying the pg_stat_activity. I expect that since this query has terminated, it must not show up in the pg_stat_activity.