1SELECT pg_terminate_backend(pg_stat_activity.pid)
2FROM pg_stat_activity
3WHERE pg_stat_activity.datname = '[Database to copy]'
4AND pid <> pg_backend_pid();
5CREATE DATABASE [Database to create]
6WITH TEMPLATE [Database to copy]
7OWNER [Your username];
8