Last active
January 5, 2018 15:32
-
-
Save ddrscott/8eed79573192d982486d7e43e3f01211 to your computer and use it in GitHub Desktop.
Export specific records from Postgres and import into another DB in a different docker host.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # export source data to file | |
| psql anon -c "copy (SELECT * FROM assets WHERE color='red') to stdout csv header" > assets.csv | |
| # create new database instance (without password) | |
| docker run --name postgres-9.6 -e POSTGRES_PASSWORD='' -d -p 65436:5432 postgres:9.6 | |
| # copy table screma | |
| pg_dump --schema-only --table=assets anon > schema.sql | |
| # might need to remove foreign keys | |
| $EDITOR schema.sql | |
| # create new schema | |
| psql -h localhost -p 65436 -U postgres < schema.sql | |
| # insert into destination DB | |
| psql -h localhost -p 65436 -U postgres -c 'copy assets from stdin with (format csv, header)' < assets.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment