PostgreSQL, update existing rows with pg_restore

Posted by woky on Server Fault See other posts from Server Fault or by woky
Published on 2009-11-27T09:40:39Z Indexed on 2010/03/28 8:03 UTC
Read the original article Hit count: 211

Filed under:
|
|

Hello.

I need to sync two PostgreSQL databases (some tables from development db to production db) sometimes.

So I came up with this script:

[...]
pg_dump -a -F tar -t table1 -t table2 -U user1 dbname1 | \
pg_restore -a -U user2 -d dbname2
[...]

The problem is that this works just for newly added rows. When I edit non-PK column I get constraint error and row isn't updated. For each dumped row I need to check if it exists in destination database (by PK) and if so delete it before INSERT/COPY.

Thanks for your advice.

(Previously posted on stackoverflow.com, but IMHO this is better place for this question).

© Server Fault or respective owner

Related posts about postgresql

Related posts about dump

  • systemstate dump ??

    as seen on Oracle Blogs - Search for 'Oracle Blogs'
            ???????????????hang????,????????systemstate dump?????????,?????,????????,???????????????,????systemstate dump?????????????       ??????,????????systemstate dump, ?????“WAITED TOO LONG FOR A ROW CACHE ENQUEUE LOCK”?       … >>> More

  • Heap Dump Root Classes

    as seen on Stack Overflow - Search for 'Stack Overflow'
    We have production system going into infinite loop of full gc and memory drops form 8 gigs to like 1 MB in just 2 minutes. After taking heap dump it tells me there an is an array of java.lang.Object ([Ljava.lang.Object) with millions of java.lang.String objects having same String taking 99% of heap… >>> More

  • vbscript calling svnadmin dump

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hi, Running the following vbscript to call svnadmin dump fails (i.e. no dump is being created) Set objShell = CreateObject("WScript.Shell") Set objShellExec = objShell.Exec("svnadmin dump C:\svn_repos > C:\fullbackup") I discovered from another post, http://stackoverflow.com/questions/445121/svn-dump-fails-with-wscript-shell/2400011#2400011… >>> More

  • Know more about shared pool subpool

    as seen on Oracle Blogs - Search for 'Oracle Blogs'
    ????T.askmaclean.com???Shared Pool?SubPool?????,????????_kghdsidx_count ? subpool ??subpool????( ???duration)???: SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi PL/SQL… >>> More

  • Hex Dump using LINQ (in 7 lines of code)

    as seen on ASP.net Weblogs - Search for 'ASP.net Weblogs'
    Eric White has posted an interesting LINQ query on his blog that shows how to create a Hex Dump in something like 7 lines of code.Of course, this is not production grade code, but it's another good example that demonstrates the expressiveness of LINQ.Here is the code:byte[] ba = File.ReadAllBytes("test… >>> More