0

I have two Postgres databases, one old and one new.

How do I move the data from old to new while keeping the existing data that's in new (and of course the data that's being migrated from old) in tact? Also, what if I want to add mappings from old table names to new table names?

Taking both databases offline is a possibility, if truly necessary.

1 Answer 1

1

Check out the --data option to pg_dump. This should produce a dump that won't drop or recreate tables or overwrite existing data.

Something like:

pg_dump --data database_name > dump.sql

This can be restored to the database using something like:

psql database_name << dump.sql

I'd be very careful using this if you have important data in "new", and I'd make sure I had a dump of the new database (with schema included, not just data) in case I messed it up.

NOTE: you tagged this with rails, so be aware that this approach will bypass any ActiveRecord validations you have (including validations for uniqueness, etc.

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

2 Comments

Thanks! What if I want to add mappings from old table names to new table names? Editing original question to reflect this requirement.
The easiest way to do that would be to load your original dump in a text editor and edit the table names by hand. It depends on how much mapping of column names you need to do -- at some point, you'll want to actually use a script to transfer the data.

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.