Link to home
Start Free TrialLog in
Avatar of Gerhardpet
GerhardpetFlag for Canada

asked on

Postgres constantly at 50% CPU utilization

I have a Windows server where the CPU utilization is constantly at 50% which is mostly made up of the PostgreSQL server service. Even if I reboot the server as soon as it is up the CPU usage is at 50% +

It does not matter whether people are logged in and using the Application that is using the PostgreSQL server. Also, the application using the PostgreSQL server makes very light use of it

Here is a screenshot and one as well below from an CPU monitor external to the server. The CPU monitor is from the last 3 hours which was night time with no one on the server or using the application

Avatar of Apurva Bhandari
Apurva Bhandari
Flag of India image

check  the query running for the longest time by
SELECT max(now() - xact_start) FROM pg_stat_activity WHERE state IN ('idle in transaction', 'active');

Kill the long running connection and limit the max age of the connection from application side.

pls check the link https://stackoverflow.com/questions/8208310/postgresql-how-to-see-which-queries-have-run
Avatar of Gerhardpet

ASKER

When I run that I get max interval = 00:00:00

Does that mean anything?
When I run that I get max interval = 00:00:00

Does that mean anything?

That means that the oldest transaction in the active or 'idle in transaction' state is you running that select statement.

Are there any connections if you just do the following as an admin?

select * from pg_stat_activity;

Open in new window


That should list every connection along with the query they were running and the states they are in.  Check out some of the documentation for the pg_stat_activity table here if you're not familiar with it: https://www.postgresql.org/docs/current/static/monitoring-stats.html

You can also check the log file, maybe the postgres process is doing something behind the scenes.  If you have WAL logging enabled, maybe the frequency is too high and it's constantly writing log files.
ASKER CERTIFIED SOLUTION
Avatar of Gerhardpet
Gerhardpet
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial