Created
February 19, 2019 09:17
-
-
Save alexandr-parkhomenko/e89deb634bb811b6a162039b1ea307ef to your computer and use it in GitHub Desktop.
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
Postgres allows the use of any existing database on the server as a template when creating a new database. I'm not sure whether pgAdmin gives you the option on the create database dialog but you should be able to execute the following in a query window if it doesn't: | |
CREATE DATABASE newdb WITH TEMPLATE originaldb OWNER dbuser; | |
Still, you may get: | |
ERROR: source database "originaldb" is being accessed by other users | |
To fix it 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment