1

I have a users-production database on 157.157.35.333

I would like to clone it to another host as users-sandbox

here is what I tried:

    PRODUCTION_HOST=111.111.11.111
    SANDBOX_HOST=222.222.22.222

    echo "creating db on sanbox"
    psql -h ${SANDBOX_HOST} -U postgres  -c "CREATE DATABASE \"users-sandbox\";"

    pg_dump -h ${PRODUCTION_HOST} -U postgres  -d users-production -F c -b -v  | \
       pg_restore -C -c -h ${SANDBOX_HOST} -U postgres  -d users-sandbox -v

but this creates the database with the old name

how do I create with a new name?

1
  • unfortunately it doesnt.. Commented May 9, 2018 at 7:57

1 Answer 1

2

https://www.postgresql.org/docs/current/static/app-pgrestore.html

-d dbname

Connect to database dbname and restore directly into the database.

but!

-C

--create

Create the database before restoring into it. If --clean is also specified, drop and recreate the target database before connecting to it.

When this option is used, the database named with -d is used only to issue the initial DROP DATABASE and CREATE DATABASE commands. All data is restored into the database name that appears in the archive.

so remove -C from pg_restore arguments...

(formatting of quotes mine)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.