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
https://dba.stackexchange.com/questions/11893/force-drop-db-while-others-may-be-connected

then issue:

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
admin