Postgresql – High Postgres-RDS CPU usage after migration

amazon-web-servicesmigrationpostgresqlrds

We deployed an update of our software today (3 EC2 instances) and made a migration to our RDS (db.t2.medium, Postgres) which added one column to a table with ~15 rows. Before migrating, we had a CPU usage of around "2". After the migration the CPU usage increased to "60". After a db reboot, it dropped, but went up again.

As a sidenote: After migration we tried to connect using a GUI and it hanged while SSL-verification. We restartet the GUI and it worked again.

Any advice on this? Here is a screenshot with current metrics. You can clearly see the increase in usage.

Current metrics from the RDS dashboard

We currently use PostgreSQL 9.6.2!

Best Answer

We fixed this ourselves:

The problem was, we didn't shut down our background service, which made several transactions while updating our software and the db. These transactions polluted the database. We found these transactions using this snippet:

SELECT pid, age(query_start, clock_timestamp()), usename, query,state 
FROM pg_stat_activity 
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' 
ORDER BY query_start desc;

After flushing our redis queue and restarting the background services, the CPU went down to 2% again.