pg_restore -1 vs -C and -c - Mailing list pgsql-hackers

From Magnus Hagander
Subject pg_restore -1 vs -C and -c
Date
Msg-id 496B6B40.1010909@hagander.net
Whole thread Raw
Responses Re: pg_restore -1 vs -C and -c
List pgsql-hackers
Hi!

As I think has been previously noted, using pg_restore with -1 (single
transaction) is fundamentally incompatible with -C (we can't CREATE
DATABASE inside a transaction) and often incompatible with -c (we don't
do DROP IF EXISTS, so if the objects don't exist the entire restore will
fail). It does work with -c *sometimes*.


It should be possible to make it compatible with -C by moving the CREATE
DATABASE command to outside of the transaction. I have only had a quick
look at the code wrt how much work this would be. One thing that hit me
quickly: do we support multiple CREATE DATABASE statements in a single
dump file? I think not, but the format seems to allow it? If not, it
should be "fairly simple" to do.

As for -c, the solution would be to issue DROP IF EXISTS statements. Is
there any particular reason why we don't?

Finally, attached is a patch that throws a nicer error message when -C
and -1 is used together, since they're fundamentally incompatible. This
one would also be backpatchable even if we fix the above.


Comments?

//Magnus

*** a/src/bin/pg_dump/pg_backup_archiver.c
--- b/src/bin/pg_dump/pg_backup_archiver.c
***************
*** 146,151 **** RestoreArchive(Archive *AHX, RestoreOptions *ropt)
--- 146,157 ----
       */
      if (ropt->create && ropt->dropSchema)
          die_horribly(AH, modulename, "-C and -c are incompatible options\n");
+     /*
+      * -1 is not compatible with -C, because we can't create a database
+      *  inside a transaction block.
+      */
+     if (ropt->create && ropt->single_txn)
+         die_horribly(AH, modulename, "-C and -1 are incompatible options\n");

      /*
       * If we're using a DB connection, then connect it.


pgsql-hackers by date:

Previous
From: "Guillaume Smet"
Date:
Subject: Re: Recovery Test Framework
Next
From: "Greg Stark"
Date:
Subject: Re: Recovery Test Framework