Reputation: 170628
I know two methods of copying a postgres database, but both of them require you to have exclusive access to the database, something you do not have while trying to copy a database from production in order to use it for testing something, like a software upgrade/migration.
psql>create database mydb_test with template mydb owner dbuser;
ERROR: source database "mydb" is being accessed by other users
>createdb -O dbuser -T mydb mydb_test
createdb: database creation failed: ERROR: source database "mydb" is being accessed by other users
Upvotes: 4
Views: 2722
Reputation: 170628
That worked:
psql
create database mydb_test owner dbuser;
\q
pg_dump mydb|psql -d mydb_test
Upvotes: 6