Created
July 6, 2018 14:45
-
-
Save nara-l/cda22b6f7928bf8695b888cabe9c92c5 to your computer and use it in GitHub Desktop.
How to create copy of local postgres db
This file contains hidden or 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
| CREATE DATABASE newdb WITH TEMPLATE originaldb OWNER dbuser; # newdb and originaldb are names of the new database and old database | |
| # getting an error ? | |
| ERROR: source database "originaldb" is being accessed by other users | |
| # run this query to stop error before running create data base query | |
| SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity | |
| WHERE pg_stat_activity.datname = 'originaldb' AND pid <> pg_backend_pid(); # change originaldb with name of old database | |
| # ref https://stackoverflow.com/a/876565/851056 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment