Created
June 8, 2020 07:34
-
-
Save germanow/ba574059fd59c63838f8856e69cb5625 to your computer and use it in GitHub Desktop.
Duplicate database in postgresql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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