mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Rewrite --section option to decouple it from --schema-only/--data-only.
The initial implementation of pg_dump's --section option supposed that the existing --schema-only and --data-only options could be made equivalent to --section settings. This is wrong, though, due to dubious but long since set-in-stone decisions about where to dump SEQUENCE SET items, as seen in bug report from Martin Pitt. (And I'm not totally convinced there weren't other bugs, either.) Undo that coupling and instead drive --section filtering off current-section state tracked as we scan through the TOC list to call _tocEntryRequired(). To make sure those decisions don't shift around and hopefully save a few cycles, run _tocEntryRequired() only once per TOC entry and save the result in a new TOC field. This required minor rejiggering of ACL handling but also allows a far cleaner implementation of inhibit_data_for_failed_table. Also, to ensure that pg_dump and pg_restore have the same behavior with respect to the --section switches, add _tocEntryRequired() filtering to WriteToc() and WriteDataChunks(), rather than trying to implement section filtering in an entirely orthogonal way in dumpDumpableObject(). This required adjusting the handling of the special ENCODING and STDSTRINGS items, but they were pretty weird before anyway. Minor other code review for the patch, too.
This commit is contained in:
@ -17,7 +17,6 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include "dumputils.h"
|
||||
#include "pg_backup.h"
|
||||
|
||||
#include "parser/keywords.h"
|
||||
|
||||
@ -1230,6 +1229,37 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Parse a --section=foo command line argument.
|
||||
*
|
||||
* Set or update the bitmask in *dumpSections according to arg.
|
||||
* dumpSections is initialised as DUMP_UNSECTIONED by pg_dump and
|
||||
* pg_restore so they can know if this has even been called.
|
||||
*/
|
||||
void
|
||||
set_dump_section(const char *arg, int *dumpSections)
|
||||
{
|
||||
/* if this is the first call, 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_nicely(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write a printf-style message to stderr.
|
||||
*
|
||||
@ -1279,35 +1309,6 @@ exit_horribly(const char *modulename, const char *fmt,...)
|
||||
exit_nicely(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the bitmask in dumpSections according to the first argument.
|
||||
* dumpSections is initialised as DUMP_UNSECTIONED by pg_dump and
|
||||
* pg_restore so they can know if this has even been called.
|
||||
*/
|
||||
|
||||
void
|
||||
set_section (const char *arg, int *dumpSections)
|
||||
{
|
||||
/* 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_nicely(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Register a callback to be run when exit_nicely is invoked. */
|
||||
void
|
||||
on_exit_nicely(on_exit_nicely_callback function, void *arg)
|
||||
|
Reference in New Issue
Block a user