Commit 68528d37 authored by Tom Lane's avatar Tom Lane

Support a --no-tablespaces option in pg_dump/pg_dumpall/pg_restore, so that

dumps can be loaded into databases without the same tablespaces that the
source had.  The option acts by suppressing all "SET default_tablespace"
commands, and also CREATE TABLESPACE commands in pg_dumpall's case.

Gavin Roy, with documentation and minor fixes by me.
parent f9e083fd
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.98 2007/12/11 19:57:32 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.99 2008/03/20 17:36:57 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -427,6 +427,23 @@ PostgreSQL documentation ...@@ -427,6 +427,23 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--no-tablespaces</option></term>
<listitem>
<para>
Do not output commands to select tablespaces.
With this option, all objects will be created in whichever
tablespace is the default during restore.
</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>
<varlistentry> <varlistentry>
<term><option>-s</option></term> <term><option>-s</option></term>
<term><option>--schema-only</option></term> <term><option>--schema-only</option></term>
......
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.69 2007/12/11 19:57:32 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.70 2008/03/20 17:36:57 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -40,7 +40,8 @@ PostgreSQL documentation ...@@ -40,7 +40,8 @@ PostgreSQL documentation
that are common to all databases. that are common to all databases.
(<application>pg_dump</application> does not save these objects.) (<application>pg_dump</application> does not save these objects.)
This currently includes information about database users and This currently includes information about database users and
groups, and access permissions that apply to databases as a whole. groups, tablespaces, and properties such as access permissions
that apply to databases as a whole.
</para> </para>
<para> <para>
...@@ -204,6 +205,18 @@ PostgreSQL documentation ...@@ -204,6 +205,18 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--no-tablespaces</option></term>
<listitem>
<para>
Do not output commands to create tablespaces nor select tablespaces
for objects.
With this option, all objects will be created in whichever
tablespace is the default during restore.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>-r</option></term> <term><option>-r</option></term>
<term><option>--roles-only</option></term> <term><option>--roles-only</option></term>
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.72 2007/12/11 19:57:32 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.73 2008/03/20 17:36:57 tgl Exp $ -->
<refentry id="APP-PGRESTORE"> <refentry id="APP-PGRESTORE">
<refmeta> <refmeta>
...@@ -273,6 +273,17 @@ ...@@ -273,6 +273,17 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--no-tablespaces</option></term>
<listitem>
<para>
Do not output commands to select tablespaces.
With this option, all objects will be created in whichever
tablespace is the default during restore.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>-P <replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term> <term><option>-P <replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term>
<term><option>--function=<replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term> <term><option>--function=<replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.45 2007/01/25 03:30:43 momjian Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.46 2008/03/20 17:36:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -83,6 +83,7 @@ typedef struct _restoreOptions ...@@ -83,6 +83,7 @@ typedef struct _restoreOptions
{ {
int create; /* Issue commands to create the database */ int create; /* Issue commands to create the database */
int noOwner; /* Don't try to match original object owner */ int noOwner; /* Don't try to match original object owner */
int noTablespace; /* Don't issue tablespace-related commands */
int disable_triggers; /* disable triggers during data-only int disable_triggers; /* disable triggers during data-only
* restore */ * restore */
int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.152 2008/01/14 19:27:41 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.153 2008/03/20 17:36:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2378,6 +2378,10 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace) ...@@ -2378,6 +2378,10 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace)
const char *want, const char *want,
*have; *have;
/* do nothing in --no-tablespaces mode */
if (AH->ropt->noTablespace)
return;
have = AH->currTablespace; have = AH->currTablespace;
want = tablespace; want = tablespace;
...@@ -2578,7 +2582,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat ...@@ -2578,7 +2582,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
pfx, te->tag, te->desc, pfx, te->tag, te->desc,
te->namespace ? te->namespace : "-", te->namespace ? te->namespace : "-",
ropt->noOwner ? "-" : te->owner); ropt->noOwner ? "-" : te->owner);
if (te->tablespace) if (te->tablespace && !ropt->noTablespace)
ahprintf(AH, "; Tablespace: %s", te->tablespace); ahprintf(AH, "; Tablespace: %s", te->tablespace);
ahprintf(AH, "\n"); ahprintf(AH, "\n");
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* by PostgreSQL * by PostgreSQL
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.482 2008/01/30 18:35:55 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.483 2008/03/20 17:36:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -223,9 +223,10 @@ main(int argc, char **argv) ...@@ -223,9 +223,10 @@ main(int argc, char **argv)
int outputCreate = 0; int outputCreate = 0;
bool outputBlobs = false; bool outputBlobs = false;
int outputNoOwner = 0; int outputNoOwner = 0;
static int use_setsessauth = 0;
static int disable_triggers = 0;
char *outputSuperuser = NULL; char *outputSuperuser = NULL;
static int disable_triggers = 0;
static int outputNoTablespaces = 0;
static int use_setsessauth = 0;
RestoreOptions *ropt; RestoreOptions *ropt;
...@@ -266,6 +267,7 @@ main(int argc, char **argv) ...@@ -266,6 +267,7 @@ main(int argc, char **argv)
*/ */
{"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1}, {"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
{"disable-triggers", no_argument, &disable_triggers, 1}, {"disable-triggers", no_argument, &disable_triggers, 1},
{"no-tablespaces", no_argument, &outputNoTablespaces, 1},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1}, {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
...@@ -417,6 +419,8 @@ main(int argc, char **argv) ...@@ -417,6 +419,8 @@ main(int argc, char **argv)
disable_dollar_quoting = 1; disable_dollar_quoting = 1;
else if (strcmp(optarg, "disable-triggers") == 0) else if (strcmp(optarg, "disable-triggers") == 0)
disable_triggers = 1; disable_triggers = 1;
else if (strcmp(optarg, "no-tablespaces") == 0)
outputNoTablespaces = 1;
else if (strcmp(optarg, "use-set-session-authorization") == 0) else if (strcmp(optarg, "use-set-session-authorization") == 0)
use_setsessauth = 1; use_setsessauth = 1;
else else
...@@ -708,6 +712,7 @@ main(int argc, char **argv) ...@@ -708,6 +712,7 @@ main(int argc, char **argv)
ropt->superuser = outputSuperuser; ropt->superuser = outputSuperuser;
ropt->create = outputCreate; ropt->create = outputCreate;
ropt->noOwner = outputNoOwner; ropt->noOwner = outputNoOwner;
ropt->noTablespace = outputNoTablespaces;
ropt->disable_triggers = disable_triggers; ropt->disable_triggers = disable_triggers;
ropt->use_setsessauth = use_setsessauth; ropt->use_setsessauth = use_setsessauth;
ropt->dataOnly = dataOnly; ropt->dataOnly = dataOnly;
...@@ -768,6 +773,7 @@ help(const char *progname) ...@@ -768,6 +773,7 @@ help(const char *progname)
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n")); printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n")); printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
printf(_(" --disable-triggers disable triggers during data-only restore\n")); printf(_(" --disable-triggers disable triggers during data-only restore\n"));
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
printf(_(" --use-set-session-authorization\n" printf(_(" --use-set-session-authorization\n"
" use SESSION AUTHORIZATION commands instead of\n" " use SESSION AUTHORIZATION commands instead of\n"
" ALTER OWNER commands to set ownership\n")); " ALTER OWNER commands to set ownership\n"));
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* *
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.100 2008/01/01 19:45:55 momjian Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.101 2008/03/20 17:36:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -64,6 +64,7 @@ static bool ignoreVersion = false; ...@@ -64,6 +64,7 @@ static bool ignoreVersion = false;
static int disable_dollar_quoting = 0; static int disable_dollar_quoting = 0;
static int disable_triggers = 0; static int disable_triggers = 0;
static int no_tablespaces = 0;
static int use_setsessauth = 0; static int use_setsessauth = 0;
static int server_version; static int server_version;
...@@ -118,6 +119,7 @@ main(int argc, char *argv[]) ...@@ -118,6 +119,7 @@ main(int argc, char *argv[])
*/ */
{"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1}, {"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
{"disable-triggers", no_argument, &disable_triggers, 1}, {"disable-triggers", no_argument, &disable_triggers, 1},
{"no-tablespaces", no_argument, &no_tablespaces, 1},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1}, {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
...@@ -285,11 +287,13 @@ main(int argc, char *argv[]) ...@@ -285,11 +287,13 @@ main(int argc, char *argv[])
case 'X': case 'X':
/* -X is a deprecated alternative to long options */ /* -X is a deprecated alternative to long options */
if (strcmp(optarg, "disable-dollar-quoting") == 0) if (strcmp(optarg, "disable-dollar-quoting") == 0)
appendPQExpBuffer(pgdumpopts, " --disable-dollar-quoting"); disable_dollar_quoting = 1;
else if (strcmp(optarg, "disable-triggers") == 0) else if (strcmp(optarg, "disable-triggers") == 0)
appendPQExpBuffer(pgdumpopts, " --disable-triggers"); disable_triggers = 1;
else if (strcmp(optarg, "no-tablespaces") == 0)
no_tablespaces = 1;
else if (strcmp(optarg, "use-set-session-authorization") == 0) else if (strcmp(optarg, "use-set-session-authorization") == 0)
/* no-op, still allowed for compatibility */ ; use_setsessauth = 1;
else else
{ {
fprintf(stderr, fprintf(stderr,
...@@ -314,6 +318,8 @@ main(int argc, char *argv[]) ...@@ -314,6 +318,8 @@ main(int argc, char *argv[])
appendPQExpBuffer(pgdumpopts, " --disable-dollar-quoting"); appendPQExpBuffer(pgdumpopts, " --disable-dollar-quoting");
if (disable_triggers) if (disable_triggers)
appendPQExpBuffer(pgdumpopts, " --disable-triggers"); appendPQExpBuffer(pgdumpopts, " --disable-triggers");
if (no_tablespaces)
appendPQExpBuffer(pgdumpopts, " --no-tablespaces");
if (use_setsessauth) if (use_setsessauth)
appendPQExpBuffer(pgdumpopts, " --use-set-session-authorization"); appendPQExpBuffer(pgdumpopts, " --use-set-session-authorization");
...@@ -444,7 +450,7 @@ main(int argc, char *argv[]) ...@@ -444,7 +450,7 @@ main(int argc, char *argv[])
dumpGroups(conn); dumpGroups(conn);
} }
if (!roles_only) if (!roles_only && !no_tablespaces)
{ {
/* Dump tablespaces */ /* Dump tablespaces */
if (server_version >= 80000) if (server_version >= 80000)
...@@ -502,6 +508,7 @@ help(void) ...@@ -502,6 +508,7 @@ help(void)
printf(_(" --disable-dollar-quoting\n" printf(_(" --disable-dollar-quoting\n"
" disable dollar quoting, use SQL standard quoting\n")); " disable dollar quoting, use SQL standard quoting\n"));
printf(_(" --disable-triggers disable triggers during data-only restore\n")); printf(_(" --disable-triggers disable triggers during data-only restore\n"));
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
printf(_(" --use-set-session-authorization\n" printf(_(" --use-set-session-authorization\n"
" use SESSION AUTHORIZATION commands instead of\n" " use SESSION AUTHORIZATION commands instead of\n"
" OWNER TO commands\n")); " OWNER TO commands\n"));
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.85 2007/12/11 19:01:06 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.86 2008/03/20 17:36:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -74,9 +74,10 @@ main(int argc, char **argv) ...@@ -74,9 +74,10 @@ main(int argc, char **argv)
char *inputFileSpec; char *inputFileSpec;
extern int optind; extern int optind;
extern char *optarg; extern char *optarg;
static int use_setsessauth = 0;
static int disable_triggers = 0; static int disable_triggers = 0;
static int no_data_for_failed_tables = 0; static int no_data_for_failed_tables = 0;
static int outputNoTablespaces = 0;
static int use_setsessauth = 0;
struct option cmdopts[] = { struct option cmdopts[] = {
{"clean", 0, NULL, 'c'}, {"clean", 0, NULL, 'c'},
...@@ -110,9 +111,10 @@ main(int argc, char **argv) ...@@ -110,9 +111,10 @@ main(int argc, char **argv)
/* /*
* the following options don't have an equivalent short option letter * the following options don't have an equivalent short option letter
*/ */
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
{"disable-triggers", no_argument, &disable_triggers, 1}, {"disable-triggers", no_argument, &disable_triggers, 1},
{"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1}, {"no-data-for-failed-tables", no_argument, &no_data_for_failed_tables, 1},
{"no-tablespaces", no_argument, &outputNoTablespaces, 1},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
...@@ -241,10 +243,14 @@ main(int argc, char **argv) ...@@ -241,10 +243,14 @@ main(int argc, char **argv)
case 'X': case 'X':
/* -X is a deprecated alternative to long options */ /* -X is a deprecated alternative to long options */
if (strcmp(optarg, "use-set-session-authorization") == 0) if (strcmp(optarg, "disable-triggers") == 0)
use_setsessauth = 1;
else if (strcmp(optarg, "disable-triggers") == 0)
disable_triggers = 1; disable_triggers = 1;
else if (strcmp(optarg, "no-data-for-failed-tables") == 0)
no_data_for_failed_tables = 1;
else if (strcmp(optarg, "no-tablespaces") == 0)
outputNoTablespaces = 1;
else if (strcmp(optarg, "use-set-session-authorization") == 0)
use_setsessauth = 1;
else else
{ {
fprintf(stderr, fprintf(stderr,
...@@ -290,8 +296,9 @@ main(int argc, char **argv) ...@@ -290,8 +296,9 @@ main(int argc, char **argv)
} }
opts->disable_triggers = disable_triggers; opts->disable_triggers = disable_triggers;
opts->use_setsessauth = use_setsessauth;
opts->noDataForFailedTables = no_data_for_failed_tables; opts->noDataForFailedTables = no_data_for_failed_tables;
opts->noTablespace = outputNoTablespaces;
opts->use_setsessauth = use_setsessauth;
if (opts->formatName) if (opts->formatName)
{ {
...@@ -395,12 +402,13 @@ usage(const char *progname) ...@@ -395,12 +402,13 @@ usage(const char *progname)
printf(_(" -T, --trigger=NAME restore named trigger\n")); printf(_(" -T, --trigger=NAME restore named trigger\n"));
printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n")); printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
printf(_(" --disable-triggers disable triggers during data-only restore\n")); printf(_(" --disable-triggers disable triggers during data-only restore\n"));
printf(_(" --use-set-session-authorization\n"
" use SESSION AUTHORIZATION commands instead of\n"
" OWNER TO commands\n"));
printf(_(" --no-data-for-failed-tables\n" printf(_(" --no-data-for-failed-tables\n"
" do not restore data of tables that could not be\n" " do not restore data of tables that could not be\n"
" created\n")); " created\n"));
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
printf(_(" --use-set-session-authorization\n"
" use SESSION AUTHORIZATION commands instead of\n"
" OWNER TO commands\n"));
printf(_(" -1, --single-transaction\n" printf(_(" -1, --single-transaction\n"
" restore as a single transaction\n")); " restore as a single transaction\n"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment