Bobort
Bobort

Reputation: 3218

Restore PostgreSQL data into existing database

Of course, the situation is such that I need a solution as soon as possible.

I have database in production in which I accidentally ran a script that deleted records that I did not want deleted. Thankfully, I have a backup of the data before doing so as an *.sql file. As such, I can manipulate it on my development environment to obtain only the data or even a dump file from pg_dump.

Whenever I try to use pg_restore or psql to import the file, it does not seem to import the missing rows. It throws many errors, which I expect since it has duplicate data. But I don't care about the duplicate data; I want the non-duplicated data back into the database.

Does anyone have any idea how to about doing this?

Upvotes: 2

Views: 789

Answers (1)

teppic
teppic

Reputation: 7286

pg_dump with --inserts. This will get you a script with individual inserts for the rows instead of single COPY statements.

Run the script with AUTOCOMMIT on (the default).

Upvotes: 2

Related Questions