CPU 100% usage caused by unknown postgres query

非 Y 不嫁゛ 提交于 2019-12-13 02:59:14

问题


I installed timescaledb extension (v.5.0) for PostgreSQL (v9.6) on 16.04 Linux box and observes that Postgres process occupies 100% CPU:

here is result of top command:

PID   USER      PR  NI    VIRT    RES    SHR S %CPU %MEM   TIME+   COMMAND
19885 postgres  20   0  192684   3916   1420 S 98.3  0.1   5689:04 x3606027128                                     

I run query SELECT pid, datname, usename, query FROM pg_stat_activity and find two weird queries

pid   datname   username  query
19882 postgres  postgres  select Fun013301 ('./x3606027128 &')
19901 postgres  postgres  select Fun013301 ('./ps3597605779 &')

function Fun013301 is not existed in postgres database. I cannot figure out what ./x3606027128 command is!?


回答1:


I had a similar issue. It was due to - some transactions was getting stuck and running for long time. Thus, CPU utilization was at 100% all the time. Following command helped to find out the connections running for the longest time:

SELECT max(now() - xact_start) FROM pg_stat_activity
                           WHERE state IN ('idle in transaction', 'active');

This command shows the time since when a connection is running. This time should not be greater than an hour. So killing the connection which was running from long time or stuck at any point, worked for me. I followed this post for monitoring and solving my issue. Post includes lots of useful commands to monitor this situation.



来源:https://stackoverflow.com/questions/46617329/cpu-100-usage-caused-by-unknown-postgres-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!