1.链接数据库

1
2
psql -h localhost postgres postgres
# /Library/PostgreSQL/9.4/bin/psql -h localhost postgres postgres

2.强制断开连接到该数据库的所有客户端的连接

1
2
3
4
5
UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'mydb';

SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'mydb';

3.删除数据库

1
DROP DATABASE mydb;