Seed data from existing DB to a new DB in Rails

330 Views Asked by At

I'm supposed to seed the partial data from existing Postgres DB residing on Server A into another Postgres DB residing on Server B. Is there any efficient way to do so apart from creating the API and executing in a Rake Task or using seeds.rb?

More Details

I tried the approach suggested by @Siim Liiser, but it creates the dump of all the data in the table instead of selected records. Is there any way to add a where clause in dump option?

1

There are 1 best solutions below

3
Siim Liiser On

Use pg_dump to store data from Server A into a file. There's plenty of options to choose which partial data you want to export. Most useful is probably to specify which tables you want.

Move that file over to Server B (scp or whatever other tool you wish to use) and then pg_restore it into the database on Server B.

This is the best solution for a simple one time action in my opinion. Of course building an api for this would also work, but would be more work and slower to execute.