Reputation: 5044
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.
Upvotes: 0
Views: 195
Reputation: 561
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.
Upvotes: 1