# PMM3 Postgresql custom queries

**URL:** <https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065>\
**Category:** Percona Monitoring and Management (PMM)\
**Tags:** pmm, postgres\
**Created:** [January 19, 2026, 1:58pm UTC](https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065 "2026-01-19T13:58:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![makuartur](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@makuartur](https://forums.percona.com/u/makuartur)\
**Post date:** [January 19, 2026, 1:58pm UTC](https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065/1 "2026-01-19T13:58:02Z")

</div>

## Description:

I am trying to configure the execution of a PostgreSQL query using **pmm-agent** (via its built-in `postgresql_exporter`). The problem is that database auto-discovery is enabled and works as expected, but my query must be executed only in one specific database, because the required relations do not exist in the others.

Is it possible to achieve this in any way? Should I register an additional PostgreSQL service via `pmm-admin`? If so, how can I override the path to custom queries specifically for that service, so that only it executes this query? Or is there another way to achieve the desired result?

## Steps to Reproduce:

1. Enable PostgreSQL database auto-discovery.

2. Add the YAML file with the query to the custom queries directory path.

## Version:

pmm-client:3.5.0-7.noble

## Logs:

## Expected Result:

## Actual Result:

## Additional Information:

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [January 19, 2026, 3:37pm UTC](https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065/2 "2026-01-19T15:37:36Z")

</div>

> [@makuartur](#):
>
> Should I register an additional PostgreSQL service via `pmm-admin`?

No, you don’t need to do that.

> [@makuartur](#):
>
> must be executed only in one specific database, because the required relations do not exist in the others

Add the custom query anyways. The query will fail to execute for the other databases, but that’s OK, as custom query failure will not impact anything else.

---

<div class="post-metadata">

**Author:** ![makuartur](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@makuartur](https://forums.percona.com/u/makuartur)\
**Post date:** [January 19, 2026, 4:12pm UTC](https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065/3 "2026-01-19T16:12:14Z")

</div>

If the query fails, there will be a large number of query execution errors. I have a PostgreSQL instance with 40+ databases, so every minute I will get approximately 40 errors in the PostgreSQL logs and in the pmm-agent logs. Is there any way to avoid this?

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [January 19, 2026, 4:48pm UTC](https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065/4 "2026-01-19T16:48:37Z")

</div>

Unfortunately, I don’t see an option in the custom queries yaml that allows filtering on a per-database level:

> <https://github.com/percona/postgres_exporter/blob/main/cmd/postgres_exporter/queries.go#L27>

I suggest opening a feature request on our [https://jira.percona.com/](https://jira.percona.com/)

---

<div class="post-metadata">

**Author:** ![makuartur](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@makuartur](https://forums.percona.com/u/makuartur)\
**Post date:** [January 20, 2026, 9:38am UTC](https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065/5 "2026-01-20T09:38:32Z")

</div>

Unfortunately, I was not able to create it in Jira, so I created it on GitHub instead. Thank you for the response. [The ability to execute custom queries in a specific database. · Issue #4949 · percona/pmm · GitHub](https://github.com/percona/pmm/issues/4949)

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [January 20, 2026, 3:48pm UTC](https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065/6 "2026-01-20T15:48:40Z")

</div>

Our JIRA is public. What error did you run into when trying to create the issue?

---

<div class="post-metadata">

**Author:** ![makuartur](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@makuartur](https://forums.percona.com/u/makuartur)\
**Post date:** [January 20, 2026, 5:00pm UTC](https://forums.percona.com/t/pmm3-postgresql-custom-queries/40065/7 "2026-01-20T17:00:32Z")

</div>

The **Create** button simply isn’t clickable, unfortunately. I checked it in **Google Chrome** and **Safari** , both with AdBlock enabled and disabled.
