Skip to content

Instantly share code, notes, and snippets.

@germanow
Created June 8, 2020 07:34
Show Gist options
  • Save germanow/ba574059fd59c63838f8856e69cb5625 to your computer and use it in GitHub Desktop.
Save germanow/ba574059fd59c63838f8856e69cb5625 to your computer and use it in GitHub Desktop.
Duplicate database in postgresql
-- To disconnect all other users from the database, you can use this query:
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'originaldb' AND pid <> pg_backend_pid();
CREATE DATABASE newdb WITH TEMPLATE originaldb OWNER dbuser;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment