On 08/26/2011 05:11 PM, Tom Lane wrote:
Alvaro Herrera<alvhe...@commandprompt.com> writes:
The "--section=data --section=indexes" proposal seems very reasonable to
me -- more so than "--sections='data indexes'".
+1 ... not only easier to code and less squishily defined, but more like
the existing precedent for other pg_dump switches, such as --table.
Here is a patch for that for pg_dump. The sections provided for are
pre-data, data and post-data, as discussed elsewhere. I still feel that
anything finer grained should be handled via pg_restore's --use-list
functionality. I'll provide a patch to do the same switch for pg_restore
shortly.
Adding to the commitfest.
cheers
andrew
*** a/doc/src/sgml/ref/pg_dump.sgml
--- b/doc/src/sgml/ref/pg_dump.sgml
***************
*** 116,124 **** PostgreSQL documentation
</para>
<para>
! This option is only meaningful for the plain-text format. For
! the archive formats, you can specify the option when you
! call <command>pg_restore</command>.
</para>
</listitem>
</varlistentry>
--- 116,122 ----
</para>
<para>
! This option is equivalent to specifying <option>--section=data</>.
</para>
</listitem>
</varlistentry>
***************
*** 404,413 **** PostgreSQL documentation
--- 402,431 ----
<para>
Dump only the object definitions (schema), not data.
</para>
+ <para>
+ This option is equivalent to specifying
+ <option>--section=pre-data --section=post-data</>.
+ </para>
</listitem>
</varlistentry>
<varlistentry>
+ <term><option>--section=<replaceable class="parameter">sectionname</replaceable></option></term>
+ <listitem>
+ <para>
+ Only dump the named section. The name can be one of <option>pre-data</>, <option>data</>
+ and <option>post-data</>.
+ This option can be specified more than once. The default is to dump all sections.
+ </para>
+ <para>
+ Post-data items consist of definitions of indexes, triggers, rules
+ and constraints other than check constraints.
+ Pre-data items consist of all other data definition items.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>-S <replaceable class="parameter">username</replaceable></option></term>
<term><option>--superuser=<replaceable class="parameter">username</replaceable></option></term>
<listitem>
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
***************
*** 82,87 **** typedef struct
--- 82,96 ----
int objsubid; /* subobject (table column #) */
} SecLabelItem;
+ typedef enum
+ {
+ DUMP_PRE_DATA = 0x01,
+ DUMP_DATA = 0x02,
+ DUMP_POST_DATA = 0x04,
+ DUMP_UNSECTIONED = 0xff
+ } DumpSections;
+
+
/* global decls */
bool g_verbose; /* User wants verbose narration of our
* activities. */
***************
*** 91,96 **** PGconn *g_conn; /* the database connection */
--- 100,106 ----
/* various user-settable parameters */
bool schemaOnly;
bool dataOnly;
+ int dumpSections; /* bitmask of chosen sections */
bool aclsSkip;
const char *lockWaitTimeout;
***************
*** 247,253 **** static const char *fmtCopyColumnList(const TableInfo *ti);
static void do_sql_command(PGconn *conn, const char *query);
static void check_sql_result(PGresult *res, PGconn *conn, const char *query,
ExecStatusType expected);
!
int
main(int argc, char **argv)
--- 257,263 ----
static void do_sql_command(PGconn *conn, const char *query);
static void check_sql_result(PGresult *res, PGconn *conn, const char *query,
ExecStatusType expected);
! static void set_section(const char *arg);
int
main(int argc, char **argv)
***************
*** 330,335 **** main(int argc, char **argv)
--- 340,346 ----
{"quote-all-identifiers", no_argument, "e_all_identifiers, 1},
{"role", required_argument, NULL, 3},
{"serializable-deferrable", no_argument, &serializable_deferrable, 1},
+ {"section", required_argument, NULL, 5},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
{"no-security-labels", no_argument, &no_security_labels, 1},
{"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1},
***************
*** 346,351 **** main(int argc, char **argv)
--- 357,363 ----
strcpy(g_opaque_type, "opaque");
dataOnly = schemaOnly = false;
+ dumpSections = DUMP_UNSECTIONED;
lockWaitTimeout = NULL;
progname = get_progname(argv[0]);
***************
*** 487,492 **** main(int argc, char **argv)
--- 499,508 ----
use_role = optarg;
break;
+ case 5: /* section */
+ set_section(optarg);
+ break;
+
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
***************
*** 517,522 **** main(int argc, char **argv)
--- 533,554 ----
exit(1);
}
+ if ((dataOnly || schemaOnly) && dumpSections != DUMP_UNSECTIONED)
+ {
+ write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used with --section\n");
+ exit(1);
+ }
+
+ if (dataOnly)
+ dumpSections = DUMP_DATA;
+ else if (schemaOnly)
+ dumpSections = DUMP_PRE_DATA | DUMP_POST_DATA;
+ else if ( dumpSections != DUMP_UNSECTIONED)
+ {
+ dataOnly = dumpSections == DUMP_DATA;
+ schemaOnly = !(dumpSections & DUMP_DATA);
+ }
+
if (dataOnly && outputClean)
{
write_msg(NULL, "options -c/--clean and -a/--data-only cannot be used together\n");
***************
*** 859,864 **** help(const char *progname)
--- 891,897 ----
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
printf(_(" --no-unlogged-table-data do not dump unlogged table data\n"));
printf(_(" --quote-all-identifiers quote all identifiers, even if not key words\n"));
+ printf(_(" --section=SECTION dump named section (pre-data, data or post-data\n"));
printf(_(" --serializable-deferrable wait until the dump can run without anomalies\n"));
printf(_(" --use-set-session-authorization\n"
" use SET SESSION AUTHORIZATION commands instead of\n"
***************
*** 7038,7043 **** collectComments(Archive *fout, CommentItem **items)
--- 7071,7098 ----
static void
dumpDumpableObject(Archive *fout, DumpableObject *dobj)
{
+
+ int skip = 0;
+
+ switch (dobj->objType)
+ {
+ case DO_INDEX:
+ case DO_TRIGGER:
+ case DO_CONSTRAINT:
+ case DO_FK_CONSTRAINT:
+ case DO_RULE:
+ skip = !(dumpSections & DUMP_POST_DATA);
+ break;
+ case DO_TABLE_DATA:
+ skip = !(dumpSections & DUMP_DATA);
+ break;
+ default:
+ skip = !(dumpSections & DUMP_PRE_DATA);
+ }
+
+ if (skip)
+ return;
+
switch (dobj->objType)
{
case DO_NAMESPACE:
***************
*** 14402,14404 **** check_sql_result(PGresult *res, PGconn *conn, const char *query,
--- 14457,14481 ----
write_msg(NULL, "The command was: %s\n", query);
exit_nicely();
}
+
+ static void set_section (const char *arg)
+ {
+ /* if this is the first, clear all the bits */
+ if (dumpSections == DUMP_UNSECTIONED)
+ dumpSections = 0;
+
+ if (strcmp(arg,"pre-data") == 0)
+ dumpSections |= DUMP_PRE_DATA;
+ else if (strcmp(arg,"data") == 0)
+ dumpSections |= DUMP_DATA;
+ else if (strcmp(arg,"post-data") == 0)
+ dumpSections |= DUMP_POST_DATA;
+ else
+ {
+ fprintf(stderr, _("%s: unknown section name \"%s\")\n"),
+ progname, arg);
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+ progname);
+ exit(1);
+ }
+ }
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers