Skip to content

Instantly share code, notes, and snippets.

@ledongthuc
Last active June 29, 2020 17:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ledongthuc/4a343ae930028b113e0db08febd3bad6 to your computer and use it in GitHub Desktop.
Save ledongthuc/4a343ae930028b113e0db08febd3bad6 to your computer and use it in GitHub Desktop.
Docker postgres actions
# Docker postgres backup data
docker exec -t -e PGPASSWORD={password} {container_name} pg_dump -U {username} --column-inserts --data-only --schema={schema} {database_name} > /path/to/exported/file.sql
# Docker postgres run script from outside
docker cp /host_path.sql captrondb:/container_inside.sql
docker exec -u {login_user} {container_name} psql {database_name} {db_username} -f /container_inside.sql # with continer username
docker exec {container_name} psql {database_name} {db_username} -f /container_inside.sql # without continer username
-- Run this SQL to see postgresql max connections allowed:
show max_connections;
-- Take a look at exactly who/what/when/where is holding open your connections:
SELECT * FROM pg_stat_activity;
-- The number of connections currently used is:
SELECT COUNT(*) from pg_stat_activity;
-- What's the maximum max_connections?
select min_val, max_val from pg_settings where name='max_connections';
-- Size of database
SELECT pg_size_pretty( pg_total_relation_size('database_name') );
-- Size of table
SELECT pg_size_pretty( pg_total_relation_size('table_name') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment