# Postgres cpu hitting higher cpu

**URL:** <https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502>\
**Category:** Get Help\
**Created:** [March 21, 2024, 8:10pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502 "2024-03-21T20:10:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narender](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Narender](https://forum.ansible.com/u/Narender)\
**Post date:** [March 21, 2024, 8:10pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/1 "2024-03-21T20:10:56Z")

</div>

We are using external database and we are having an issue where we are hitting higher cpu. We see below query is executing every 2 secs. Why is this query running this frequent and how can we stop this query from executing if it is not needed

```auto
   SELECT
                c.relname,
                CASE
                    WHEN c.relispartition THEN 'p'
                    WHEN c.relkind IN ('m', 'v') THEN 'v'
                    ELSE 't'
                END,
                obj_description(c.oid, 'pg_class')
            FROM pg_catalog.pg_class c
            LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
            WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                AND pg_catalog.pg_table_is_visible(c.oid)

```

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 22, 2024, 7:43pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/2 "2024-03-22T19:43:55Z")

</div>

What version of Postgres are you using? What version of AWX are you using? Did this start happening after an upgrade? If so, what version were you using before you noticed high CPU usage on the PG side? Has the high CPU persisted, or has it relaxed since? Upgrading AWX does perform some initialization/migration steps on the DB, but that only occurs once each upgrade.

Unfortunately, I don’t know enough about the backend of AWX to really help much further, but those who do would probably like a lot more information than you initially provided.

Maybe @TheRealHaoLiu or @rooftopcellist or someone else on the AWX team might be able to help more.

---

<div class="post-metadata">

**Author:** ![TheRealHaoLiu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/therealhaoliu/32/100_2.png) [@TheRealHaoLiu](https://forum.ansible.com/u/TheRealHaoLiu)\
**Post date:** [March 24, 2024, 11:30pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/3 "2024-03-24T23:30:04Z")

</div>

From first look it doesn’t seem to be from AWX. Ping Jeff Bradberry to confirm

---

<div class="post-metadata">

**Author:** ![TheRealHaoLiu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/therealhaoliu/32/100_2.png) [@TheRealHaoLiu](https://forum.ansible.com/u/TheRealHaoLiu)\
**Post date:** [March 25, 2024, 1:31pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/4 "2024-03-25T13:31:45Z")

</div>

From Jeff the query seems to be coming from

> <https://github.com/django/django/blob/ae10146793dca0e0594c7acdee20ca3810983f39/django/db/backends/postgresql/introspection.py#L56-L79>

---

<div class="post-metadata">

**Author:** ![TheRealHaoLiu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/therealhaoliu/32/100_2.png) [@TheRealHaoLiu](https://forum.ansible.com/u/TheRealHaoLiu)\
**Post date:** [March 25, 2024, 1:57pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/5 "2024-03-25T13:57:37Z")

</div>

@Narender what version of AWX and AWX-operator do you have?

---

<div class="post-metadata">

**Author:** ![Narender](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Narender](https://forum.ansible.com/u/Narender)\
**Post date:** [March 25, 2024, 2:04pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/6 "2024-03-25T14:04:59Z")

</div>

@TheRealHaoLiu Thank you for your response AWX 23.3.1

Awx operator: [quay.io/ansible/awx-operator:2.7.1](http://quay.io/ansible/awx-operator:2.7.1)

---

<div class="post-metadata">

**Author:** ![TheRealHaoLiu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/therealhaoliu/32/100_2.png) [@TheRealHaoLiu](https://forum.ansible.com/u/TheRealHaoLiu)\
**Post date:** [March 25, 2024, 2:12pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/7 "2024-03-25T14:12:37Z")

</div>

Ok so it’s most likely not due to any of the big awx-operator change we made recently…or any change we made related to PG15 (AWX 24.0.0)

---

<div class="post-metadata">

**Author:** ![chrismeyersfsu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chrismeyersfsu/32/1016_2.png) [@chrismeyersfsu](https://forum.ansible.com/u/chrismeyersfsu)\
**Post date:** [March 25, 2024, 2:23pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/8 "2024-03-25T14:23:58Z")

</div>

@Narender

For each django db connection we set `application_name` to be the AWX service + the process ID. This is helpful to trace back which process is using which query.

can you run `SELECT application_name, query FROM pg_stat_activity;` until you find the problematic query and post the results here?

Below is an example set of results

```auto
awx-manage dbshell
awx=> SELECT application_name, query FROM pg_stat_activity;

```

```auto
         application_name | >
----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------->
                                  | <insufficient privilege>
                                  | <insufficient privilege>
 awx-272-cache_clear-awx_1 | LISTEN "tower_settings_change";
                                  | LISTEN web_ws_heartbeat
 awx-270-ws_heartbeat-awx_1 | SELECT pg_notify('web_ws_heartbeat', '{"hostname": "awx_1", "ip": null, "action": "online"}');
 awx-271-rsyslog_configurer-awx_1 | SELECT "conf_setting"."id", "conf_setting"."created", "conf_setting"."modified", "conf_setting"."key", "conf_setting"."value", "conf_setting"."user_id" FROM "conf>
                                  | LISTEN "awx_1";
 awx-250-dispatcher-awx_1 | SELECT "conf_setting"."id", "conf_setting"."created", "conf_setting"."modified", "conf_setting"."key", "conf_setting"."value", "conf_setting"."user_id" FROM "conf>
 awx-470-dispatcher_worker-awx_1 | SELECT pg_advisory_unlock(503423469)
 awx-474-dispatcher_worker-awx_1 | SELECT pg_advisory_unlock(-756382330)
 awx-472-dispatcher_worker-awx_1 | SELECT pg_advisory_unlock(1226251610)
 psql | SELECT application_name, query FROM pg_stat_activity;
                                  | <insufficient privilege>
                                  | <insufficient privilege>
                                  | <insufficient privilege>

```

---

<div class="post-metadata">

**Author:** ![Narender](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Narender](https://forum.ansible.com/u/Narender)\
**Post date:** [March 25, 2024, 3:47pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/9 "2024-03-25T15:47:18Z")

</div>

@chrismeyersfsu Please find the attached screenshot

 ![Screenshot 2024-03-25 at 9.46.05 AM](https://us1.discourse-cdn.com/ansible/original/2X/f/fde9ee7b224db7d1423c9cc9e11d565b1662edbf.png)

---

<div class="post-metadata">

**Author:** ![chrismeyersfsu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chrismeyersfsu/32/1016_2.png) [@chrismeyersfsu](https://forum.ansible.com/u/chrismeyersfsu)\
**Post date:** [March 25, 2024, 5:17pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/10 "2024-03-25T17:17:41Z")

</div>

I can’t find the query in question in that screenshot.

Please find the query in question for me. Circle it if it’s in the screenshot. Otherwise please paste the text so I can search for it.

I need you to do some grunt work here.

---

<div class="post-metadata">

**Author:** ![Stephen\_Brile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/stephen_brile/32/8167_2.png) [@Stephen\_Brile](https://forum.ansible.com/u/Stephen_Brile)\
**Post date:** [April 17, 2025, 8:10pm UTC](https://forum.ansible.com/t/postgres-cpu-hitting-higher-cpu/4502/11 "2025-04-17T20:10:51Z")

</div>

Did you guys ever find a resolution to this? Experiencing same issue with that query.  
AWX Operator 2.10  
AWX 23.6 (Azure AKS) with external postgres 15.12
