# Why was the query not captured in PMM?

**URL:** <https://forums.percona.com/t/why-was-the-query-not-captured-in-pmm/39922>\
**Category:** PMM 3.x\
**Created:** [December 19, 2025, 3:24pm UTC](https://forums.percona.com/t/why-was-the-query-not-captured-in-pmm/39922 "2025-12-19T15:24:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ANDiv1976](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/andiv1976/32/20170_2.png) [@ANDiv1976](https://forums.percona.com/u/ANDiv1976)\
**Post date:** [December 19, 2025, 3:24pm UTC](https://forums.percona.com/t/why-was-the-query-not-captured-in-pmm/39922/1 "2025-12-19T15:24:47Z")

</div>

The server is running PostgreSQL version 14 with the pg\_stat\_statements and pg\_profile extensions installed.  
Pg\_profile snapshots are created hourly at minute 00.  
A query was started at 00:05 and completed at 04:23.  
This query is not present in PMM but appears in the pg\_profile report for 05:00.  
PMM is configured in medium mode for metric collection.  
What could be the reason the query was not captured in PMM?

PMM version 3.4.1

---

<div class="post-metadata">

**Author:** ![ANDiv1976](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/andiv1976/32/20170_2.png) [@ANDiv1976](https://forums.percona.com/u/ANDiv1976)\
**Post date:** [December 20, 2025, 1:55am UTC](https://forums.percona.com/t/why-was-the-query-not-captured-in-pmm/39922/2 "2025-12-20T01:55:18Z")

</div>

Disabled pg\_profile snapshot. Waited for the long query to complete. Its execution took 3 hours and 40 minutes. After 30 minutes, checked PMM QAN — this query is not there. Maybe single queries are being filtered somewhere on your side?

I suspect the problem is that after the query execution is complete and the data is retrieved, the client closes the connection. This creates a situation where the query exists in `pg_stat_statements`, but since the corresponding PID is no longer in `pg_stat_activity`, this information does not make it into PMM.

Why does a request from session 69462779.3f3725 from a single IP address appear in the pg\_stat\_statement log and in PMM, while a request from session 6945c41b.2922ac is only present in pg\_stat\_statement?

session\_id=69462779.3f3725, user=[unknown], db=[unknown], app=[unknown], client=[local]LOG: connection received: host=[local]  
session\_id=69462779.3f3725, user=postgres, db=database, app=[unknown], client=[local]LOG: connection authorized: user=postgres database=database application\_name=psql  
session\_id=69462779.3f3725, user=postgres, db=database, app=psql, client=[local]LOG: duration: 3919303.234 ms statement: — query\_text —

session\_id=6945c41b.2922ac, user=[unknown], db=[unknown], app=[unknown], client=ip\_clientLOG: connection received: host=ip\_client port=44852  
session\_id=6945c41b.2922ac, user=id\_client, db=database, app=[unknown], client=ip\_clientLOG: connection authenticated: identity=“id\_client” method=md5 (/pgsql/14/data/pg\_hba.conf:122)  
session\_id=6945c41b.2922ac, user=id\_client, db=database, app=[unknown], client=ip\_clientLOG: connection authorized: user=id\_client database=database  
session\_id=6945c41b.2922ac, user=id\_client, db=database, app=PostgreSQL JDBC Driver, client=ip\_clientLOG: duration: 11260136.968 ms execute : — query\_text —  
session\_id=6945c41b.2922ac, user=id\_client, db=database, app=PostgreSQL JDBC Driver, client=ip\_clientDETAIL: parameters: $1 = ‘2025-10-01’, $2 = ‘2025-10-01’, $3 = ‘2025-10-01’, $4 = ‘2025-12-19 00:05:00.182’, $5 = ‘1000000’  
session\_id=6945c41b.2922ac, user=id\_client, db=database, app=PostgreSQL JDBC Driver, client=ip\_clientLOG: duration: 103180.453 ms execute : — query\_text —  
session\_id=6945c41b.2922ac, user=id\_client, db=database, app=PostgreSQL JDBC Driver, client=ip\_clientDETAIL: parameters: $1 = ‘2025-10-01’, $2 = ‘2025-10-01’, $3 = ‘2025-10-01’, $4 = ‘2025-12-19 00:05:00.182’

---

<div class="post-metadata">

**Author:** ![ANDiv1976](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/andiv1976/32/20170_2.png) [@ANDiv1976](https://forums.percona.com/u/ANDiv1976)\
**Post date:** [December 20, 2025, 11:21am UTC](https://forums.percona.com/t/why-was-the-query-not-captured-in-pmm/39922/3 "2025-12-20T11:21:57Z")

</div>

I conducted testing. When using pg\_stat\_statements, we lose the query chain. We also lose queries for which the connection is terminated immediately after execution.

I created a file named 1.sql and wrote something similar to this in it:

sql

```auto
select * from schemas.tables limit 10000000;
SELECT pg_sleep(600);
\q

```

After executing the script via psql, only the query `SELECT pg_sleep(600);` with an execution time of 600 seconds appeared in PMM’s QAN. The first SELECT query is not present in PMM’s history.

Then, in the 1.sql file, I removed `SELECT pg_sleep(600);` and ran the execution via psql again.  
This time, no queries appeared in QAN. All of them are present in pg\_stat\_statements, but pg\_stat\_activity is empty.

Perhaps we should give administrators the option to choose how necessary it is to bind queries to the hosts they originated from? When using pg\_stat\_statements…

---

<div class="post-metadata">

**Author:** ![Jiri\_Ctvrtka1](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/jiri_ctvrtka1/32/10716_2.png) [@Jiri\_Ctvrtka1](https://forums.percona.com/u/Jiri_Ctvrtka1)\
**Post date:** [December 23, 2025, 4:08pm UTC](https://forums.percona.com/t/why-was-the-query-not-captured-in-pmm/39922/4 "2025-12-23T16:08:41Z")

</div>

Hi @ANDiv1976,

First of all, PMM using `pg_stat_statements` (PGSS) does not use `pg_stat_activity` in any way. So if something is captured by `pg_stat_activity` but not by PGSS, it will be missing in PMM, because PMM only consumes the output from PGSS.

I tried your example, but I’m seeing the opposite behavior. The query `SELECT * FROM schemas.tables LIMIT 10000000;` shows up in QAN, but `SELECT pg_sleep(600);` does not - because it was cancelled before it finished.

You wrote:

> “After executing the script via psql, only the query `SELECT pg_sleep(600);` with an execution time of 600 seconds appeared in PMM’s QAN. The first SELECT query is not present in PMM’s history.”

I’m not sure how `SELECT pg_sleep(600);` could appear in PGSS output, because PGSS records only finished queries, not running or cancelled ones. So it shouldn’t be present at all, because you cancelled it. It may be left over from a previous execution if PGSS wasn’t reset in the meantime. Could you please verify (e.g., reset PGSS and rerun)?

I’ll also take another look at the long-running query case (where it’s missing in QAN even though you say it was present in PGSS). I haven’t been able to reproduce that yet - maybe it requires running the query for hours. I’ll follow up once I have an update.

Thank you.

---

<div class="post-metadata">

**Author:** ![ANDiv1976](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/andiv1976/32/20170_2.png) [@ANDiv1976](https://forums.percona.com/u/ANDiv1976)\
**Post date:** [December 25, 2025, 9:33am UTC](https://forums.percona.com/t/why-was-the-query-not-captured-in-pmm/39922/5 "2025-12-25T09:33:11Z")

</div>

which versions have you tested on?  
I’m losing queries for PostgreSQL version 14.17 and PMM 3.4.1  
I’ll run similar tests on version 16 of PostgreSQL.

---

<div class="post-metadata">

**Author:** ![Jiri\_Ctvrtka1](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/jiri_ctvrtka1/32/10716_2.png) [@Jiri\_Ctvrtka1](https://forums.percona.com/u/Jiri_Ctvrtka1)\
**Post date:** [December 29, 2025, 9:37am UTC](https://forums.percona.com/t/why-was-the-query-not-captured-in-pmm/39922/6 "2025-12-29T09:37:55Z")

</div>

I’m using the same versions as you (PostgreSQL 14.17 and PMM 3.4.1). Regardless of the version, canceled queries are not being captured. That’s why I’m surprised that you had `SELECT pg_sleep(600);` appear in QAN.

Could you please run the same test you mentioned and share the results? Thank you.
