docker exec -it -u postgres example-db psql; # login interactively SELECT * FROM pg_stat_activity WHERE datname = 'example'; # check open connections to database example # (there shall be none, otherwise you can not drop the database) SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'example';
ERROR: cannot drop the currently open database
-> try to restart database, disconnect all clients
psql -U postgres -c "drop database example"
and pray that it works
now if you want to import a database dump you can recreate the database like this:
docker exec -it -u postgres example-db psql; # login interactively CREATE DATABASE example; \q # disconnect # import backup docker exec -i -u postgres example-db psql --user example example < /backups/2018-02-02-example-dump.sql
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!