1

I have a PostgreSQL Database, with one table. Each day, I want to export the data WHERE date='whatever' so it ONLY dump the data I've managed TODAY.

Then, I go to another Database, and import that DUMP file, but instead of overwrite what I already had, I want to append to it...

I'm trying to do this on a C# Console APP... Any suggestion?

Thank you.

5
  • why don't you use something more robust? Commented Jun 12, 2013 at 15:19
  • It is necessary for the client to use PostgreSQL, he doesn't want MSSQL, MySQL, etc.. just PostgreSQL... What a shame.. Commented Jun 12, 2013 at 15:30
  • i mean why do you have to write your own backup solution. Commented Jun 12, 2013 at 15:34
  • 2
    Daniel is correct. It seems like you are trying to write your own replication system. If you need to modify/tweak the data then I suggest you make sure you have a trigger on the desired tables to timestamp them and you take a look at dblink. I often use it to query one db, and pull data into another db after making some changes. Worse case, take a look at copy to and copy from. No need to use a dump file. Commented Jun 12, 2013 at 16:00
  • 4
    And by the way, saying that using PostgreSQL is a "shame" is not going to make you many friends or encourage people to help you. Given the fact that you don't know anything about dblink or "copy", it seems unlikely that you have enough experience with PostgreSQL to make such a statement. Commented Jun 12, 2013 at 16:04

1 Answer 1

2

Don't do it this way. Use one of the existing well-maintained solutions for the purpose, like Bucardo, Londiste, Slony-I, etc.

See replication on the Pg wiki.

Londiste at least can cope with being stopped, then resumed when you want it to catch up, so you can run it as a daily batch if you want.

If all you're dealing with is an insert-only table then you can avoid the need for full-fledged replication; all you need is something like

psql -h host1 db1 -c \
    "\copy (SELECT * FROM the_table WHERE the_date = '2012-01-01') TO stdout" \
| psql -h host2 db2 -c \
    "\copy the_table FROM STDIN"

See the manual on COPY

You can do the same thing within your C# app by making two PostgreSQL connections, doing a COPY FROM on one, and a COPY TO on the other, then copying the rows between them. You'll find nPgSQL's support for COPY useful for this.

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

Comments

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.