Last active
June 29, 2020 17:02
-
-
Save ledongthuc/4a343ae930028b113e0db08febd3bad6 to your computer and use it in GitHub Desktop.
Docker postgres actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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