Postgresql – AWS RDS Postgres performance issue

amazon-web-servicesdjangopostgresqlpython

We are using rds(postgres) with instance type as db.m4.2xlarge.

Usually most of the time number of connections are 8-10. But on some occasion as the number of connections increases to 100-200. DB becomes non-responsive. DB non-responsiveness we have seen many time in cases of sudden spike in number or read connections(so even in cases where connections have increases from 10 to 100).

Queries which are being executed at max takes 2sec to execute.

My application server is running on django/python stack(with Gunicorn). Latency of these servers go high when DB server response time increases.

Any changes in configuration of postgres rds we should do to improve performance(currently most of the settings are default) ?

Best Answer

I was having the same issue. The postgresql is setup on AWS RDS and it was having 100% cpu utilisation even after increasing the instance. I debugged with the method shown here and one of the method worked for me.

I checked for the query running for the longest time and came to know that certain queries was stuck and was running since more than 3-4 hours. To check since how much time the query is running, run the following command:

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

If this is more than an hour, than this is the issue. Kill the long running connection and limit the max age of the connection from application side.