The following is approaching:
pg_dump --schema-only --format c dbName | \ pg_restore --schema-only --clean --dbname=dbNameTest
Except that it does not work if dbNameTest does not exist yet. The following does the job (although she complains that dbNameTest already exists. I can live with this)
createdb dbNameTest pg_dump --schema-only --format c dbName | \ pg_restore --schema-only --clean --dbname=dbNameTest
Oneliner with short options will be:
createdb dbNameTest ; pg_dump -s -F c dbName | pg_restore -s -c -d dbNameTest
A sh script pg_copy_schema will look something like this:
#!/bin/sh if [ -z "$2" ] ; then echo "Usage: `basename $0` original-db new-db" ; exit 1 ; fi echo "Copying schema of $1 to $2" createdb "$2" 2> /dev/null pg_dump --schema-only --format c "$1" | pg_restore --schema-only --clean --dbname="$2"
source share