Make a copy of the postgres database while other users are connected to it

I know two methods of copying postgres database, but both require you to have exclusive access to the database, which you don't, trying to copy a database from production to use it to test something like software upgrade / migration provision.

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

      

+3


source to share


1 answer


This worked:



psql
create database mydb_test owner dbuser;
\q
pg_dump mydb|psql -d mydb_test

      

+5


source







All Articles