postgres duplicate database in same server while other session is using source database

Solutions on MaxInterview for postgres duplicate database in same server while other session is using source database by the best coders in the world

showing results for - "postgres duplicate database in same server while other session is using source database"
Emely
16 Nov 2019
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