Created
August 7, 2019 07:24
-
-
Save soiqualang/56bca4efc144f38a5d5a52c70f9516a4 to your computer and use it in GitHub Desktop.
Clone Database in PostgreSQL #clone #database #sql #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
/* KILL ALL EXISTING CONNECTION FROM ORIGINAL DB (sourcedb)*/ | |
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = 'SOURCE_DB' AND pid <> pg_backend_pid(); | |
/* CLONE DATABASE TO NEW ONE(TARGET_DB) */ | |
CREATE DATABASE TARGET_DB WITH TEMPLATE SOURCE_DB OWNER USER_DB; | |
--https://stackoverflow.com/questions/876522/creating-a-copy-of-a-database-in-postgresql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment