0

We are creating a Dockerfile that can spin up a Postgres database container, using this image as a basis

https://hub.docker.com/_/postgres/

Every time we test we want to create a fresh database with the production database as a template - we want to copy the database structures without copying the data in tables etc.

Can someone provide an example of doing this? I need something concrete with database urls etc.

There are some good examples here, but some are a bit nebulous to a Postgres newb.

I see examples like this:

pg_dump production-db | psql test-db

I don't know what "production-db" / "test-db" refer to (are they URL strings?), so I am lost. Also, I believe this copies over all the data in the DB, and we really just want to copy the database structures (tables, views, etc).

8
  • 5
    Probably the intended command was pg_dump prod-db | psql local-db which means: run pg_dump on prod-db and pipe the output into test-db. For only the structures you possibly mean pg_dump --schema-only .... See the manual or pg_dump --help for usage hints. NB: prod-db and test-db are the names of the old and new databases. Commented Oct 24, 2016 at 17:20
  • 1
    thanks! --schema-only might be useful info! Commented Oct 24, 2016 at 17:21
  • but do you know what "prod-db" and "local-db" are? are they URLs? Commented Oct 24, 2016 at 17:21
  • Well, it could be metasyntactic names; just substitute them by your actual database names. Commented Oct 24, 2016 at 17:22
  • 2
    database names are local to the machine. But you can invoke pg_dump from a remote machine, if you use the -h <IP-address_or_hostname_here> flag. You probably need to specify a username, too. And a password. And URLs are useless here. Commented Oct 24, 2016 at 17:27

0

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.