Skip to content

Instantly share code, notes, and snippets.

@clodal
Created August 15, 2018 15:09
Show Gist options
  • Save clodal/2053e947dc733a6964231d8e3ca3050f to your computer and use it in GitHub Desktop.
Save clodal/2053e947dc733a6964231d8e3ca3050f to your computer and use it in GitHub Desktop.
Debug notes on sequelize max-connections issue

Debug Notes for Sequelize + PG max connections issue

The following are commands useful for debugging pool connections in a sequelize + pg setup:


Connect to local psql shell psql -d <DB_NAME>

Connect to remote psql shell psql --host=<DB_HOST> --port=5432 --username=<DB_USER> --dbname=<DB_NAME>

List max connections SHOW max_connections;

Get pg connections SELECT * FROM pg_stat_activity;

Count pg connections SELECT COUNT(*) from pg_stat_activity;

Display pg connections in a table

SELECT max_conn,used,res_for_super,max_conn-used-res_for_super res_for_normal 
FROM 
  (select count(*) used from pg_stat_activity) t1,
  (select setting::int res_for_super from pg_settings where name=$$superuser_reserved_connections$$) t2,
  (select setting::int max_conn from pg_settings where name=$$max_connections$$) t3;

Reboot sequelize dropdb <DB_NAME>; createdb <DB_NAME>; yarn sequelize db:migrate; yarn sequelize db:seed:all; yarn start-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment