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
That worked: