Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit68528d3

Browse files
committed
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 thesource 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.
1 parentf9e083f commit68528d3

File tree

8 files changed

+92
-25
lines changed

8 files changed

+92
-25
lines changed

‎doc/src/sgml/ref/pg_dump.sgml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.98 2007/12/11 19:57:32 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.99 2008/03/20 17:36:57 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -427,6 +427,23 @@ PostgreSQL documentation
427427
</listitem>
428428
</varlistentry>
429429

430+
<varlistentry>
431+
<term><option>--no-tablespaces</option></term>
432+
<listitem>
433+
<para>
434+
Do not output commands to select tablespaces.
435+
With this option, all objects will be created in whichever
436+
tablespace is the default during restore.
437+
</para>
438+
439+
<para>
440+
This option is only meaningful for the plain-text format. For
441+
the archive formats, you can specify the option when you
442+
call <command>pg_restore</command>.
443+
</para>
444+
</listitem>
445+
</varlistentry>
446+
430447
<varlistentry>
431448
<term><option>-s</option></term>
432449
<term><option>--schema-only</option></term>

‎doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.69 2007/12/11 19:57:32 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.70 2008/03/20 17:36:57 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -40,7 +40,8 @@ PostgreSQL documentation
4040
that are common to all databases.
4141
(<application>pg_dump</application> does not save these objects.)
4242
This currently includes information about database users and
43-
groups, and access permissions that apply to databases as a whole.
43+
groups, tablespaces, and properties such as access permissions
44+
that apply to databases as a whole.
4445
</para>
4546

4647
<para>
@@ -204,6 +205,18 @@ PostgreSQL documentation
204205
</listitem>
205206
</varlistentry>
206207

208+
<varlistentry>
209+
<term><option>--no-tablespaces</option></term>
210+
<listitem>
211+
<para>
212+
Do not output commands to create tablespaces nor select tablespaces
213+
for objects.
214+
With this option, all objects will be created in whichever
215+
tablespace is the default during restore.
216+
</para>
217+
</listitem>
218+
</varlistentry>
219+
207220
<varlistentry>
208221
<term><option>-r</option></term>
209222
<term><option>--roles-only</option></term>

‎doc/src/sgml/ref/pg_restore.sgml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.72 2007/12/11 19:57:32 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.73 2008/03/20 17:36:57 tgl Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<refmeta>
@@ -273,6 +273,17 @@
273273
</listitem>
274274
</varlistentry>
275275

276+
<varlistentry>
277+
<term><option>--no-tablespaces</option></term>
278+
<listitem>
279+
<para>
280+
Do not output commands to select tablespaces.
281+
With this option, all objects will be created in whichever
282+
tablespace is the default during restore.
283+
</para>
284+
</listitem>
285+
</varlistentry>
286+
276287
<varlistentry>
277288
<term><option>-P <replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term>
278289
<term><option>--function=<replaceable class="parameter">function-name(argtype [, ...])</replaceable></option></term>

‎src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.45 2007/01/25 03:30:43 momjian Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.46 2008/03/20 17:36:57 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -83,6 +83,7 @@ typedef struct _restoreOptions
8383
{
8484
intcreate;/* Issue commands to create the database */
8585
intnoOwner;/* Don't try to match original object owner */
86+
intnoTablespace;/* Don't issue tablespace-related commands */
8687
intdisable_triggers;/* disable triggers during data-only
8788
* restore */
8889
intuse_setsessauth;/* Use SET SESSION AUTHORIZATION commands

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.152 2008/01/14 19:27:41 tgl Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.153 2008/03/20 17:36:57 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2378,6 +2378,10 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace)
23782378
constchar*want,
23792379
*have;
23802380

2381+
/* do nothing in --no-tablespaces mode */
2382+
if (AH->ropt->noTablespace)
2383+
return;
2384+
23812385
have=AH->currTablespace;
23822386
want=tablespace;
23832387

@@ -2578,7 +2582,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
25782582
pfx,te->tag,te->desc,
25792583
te->namespace ?te->namespace :"-",
25802584
ropt->noOwner ?"-" :te->owner);
2581-
if (te->tablespace)
2585+
if (te->tablespace&& !ropt->noTablespace)
25822586
ahprintf(AH,"; Tablespace: %s",te->tablespace);
25832587
ahprintf(AH,"\n");
25842588

‎src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.482 2008/01/30 18:35:55 tgl Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.483 2008/03/20 17:36:57 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -223,9 +223,10 @@ main(int argc, char **argv)
223223
intoutputCreate=0;
224224
booloutputBlobs= false;
225225
intoutputNoOwner=0;
226-
staticintuse_setsessauth=0;
227-
staticintdisable_triggers=0;
228226
char*outputSuperuser=NULL;
227+
staticintdisable_triggers=0;
228+
staticintoutputNoTablespaces=0;
229+
staticintuse_setsessauth=0;
229230

230231
RestoreOptions*ropt;
231232

@@ -266,6 +267,7 @@ main(int argc, char **argv)
266267
*/
267268
{"disable-dollar-quoting",no_argument,&disable_dollar_quoting,1},
268269
{"disable-triggers",no_argument,&disable_triggers,1},
270+
{"no-tablespaces",no_argument,&outputNoTablespaces,1},
269271
{"use-set-session-authorization",no_argument,&use_setsessauth,1},
270272

271273
{NULL,0,NULL,0}
@@ -417,6 +419,8 @@ main(int argc, char **argv)
417419
disable_dollar_quoting=1;
418420
elseif (strcmp(optarg,"disable-triggers")==0)
419421
disable_triggers=1;
422+
elseif (strcmp(optarg,"no-tablespaces")==0)
423+
outputNoTablespaces=1;
420424
elseif (strcmp(optarg,"use-set-session-authorization")==0)
421425
use_setsessauth=1;
422426
else
@@ -708,6 +712,7 @@ main(int argc, char **argv)
708712
ropt->superuser=outputSuperuser;
709713
ropt->create=outputCreate;
710714
ropt->noOwner=outputNoOwner;
715+
ropt->noTablespace=outputNoTablespaces;
711716
ropt->disable_triggers=disable_triggers;
712717
ropt->use_setsessauth=use_setsessauth;
713718
ropt->dataOnly=dataOnly;
@@ -768,6 +773,7 @@ help(const char *progname)
768773
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
769774
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
770775
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
776+
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
771777
printf(_(" --use-set-session-authorization\n"
772778
" use SESSION AUTHORIZATION commands instead of\n"
773779
" ALTER OWNER commands to set ownership\n"));

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.100 2008/01/01 19:45:55 momjian Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.101 2008/03/20 17:36:57 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -64,6 +64,7 @@ static bool ignoreVersion = false;
6464

6565
staticintdisable_dollar_quoting=0;
6666
staticintdisable_triggers=0;
67+
staticintno_tablespaces=0;
6768
staticintuse_setsessauth=0;
6869
staticintserver_version;
6970

@@ -118,6 +119,7 @@ main(int argc, char *argv[])
118119
*/
119120
{"disable-dollar-quoting",no_argument,&disable_dollar_quoting,1},
120121
{"disable-triggers",no_argument,&disable_triggers,1},
122+
{"no-tablespaces",no_argument,&no_tablespaces,1},
121123
{"use-set-session-authorization",no_argument,&use_setsessauth,1},
122124

123125
{NULL,0,NULL,0}
@@ -285,11 +287,13 @@ main(int argc, char *argv[])
285287
case'X':
286288
/* -X is a deprecated alternative to long options */
287289
if (strcmp(optarg,"disable-dollar-quoting")==0)
288-
appendPQExpBuffer(pgdumpopts," --disable-dollar-quoting");
290+
disable_dollar_quoting=1;
289291
elseif (strcmp(optarg,"disable-triggers")==0)
290-
appendPQExpBuffer(pgdumpopts," --disable-triggers");
292+
disable_triggers=1;
293+
elseif (strcmp(optarg,"no-tablespaces")==0)
294+
no_tablespaces=1;
291295
elseif (strcmp(optarg,"use-set-session-authorization")==0)
292-
/* no-op, still allowed for compatibility */;
296+
use_setsessauth=1;
293297
else
294298
{
295299
fprintf(stderr,
@@ -314,6 +318,8 @@ main(int argc, char *argv[])
314318
appendPQExpBuffer(pgdumpopts," --disable-dollar-quoting");
315319
if (disable_triggers)
316320
appendPQExpBuffer(pgdumpopts," --disable-triggers");
321+
if (no_tablespaces)
322+
appendPQExpBuffer(pgdumpopts," --no-tablespaces");
317323
if (use_setsessauth)
318324
appendPQExpBuffer(pgdumpopts," --use-set-session-authorization");
319325

@@ -444,7 +450,7 @@ main(int argc, char *argv[])
444450
dumpGroups(conn);
445451
}
446452

447-
if (!roles_only)
453+
if (!roles_only&& !no_tablespaces)
448454
{
449455
/* Dump tablespaces */
450456
if (server_version >=80000)
@@ -502,6 +508,7 @@ help(void)
502508
printf(_(" --disable-dollar-quoting\n"
503509
" disable dollar quoting, use SQL standard quoting\n"));
504510
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
511+
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
505512
printf(_(" --use-set-session-authorization\n"
506513
" use SESSION AUTHORIZATION commands instead of\n"
507514
" OWNER TO commands\n"));

‎src/bin/pg_dump/pg_restore.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
*
3636
* IDENTIFICATION
37-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.85 2007/12/11 19:01:06 tgl Exp $
37+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.86 2008/03/20 17:36:58 tgl Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -74,9 +74,10 @@ main(int argc, char **argv)
7474
char*inputFileSpec;
7575
externintoptind;
7676
externchar*optarg;
77-
staticintuse_setsessauth=0;
7877
staticintdisable_triggers=0;
7978
staticintno_data_for_failed_tables=0;
79+
staticintoutputNoTablespaces=0;
80+
staticintuse_setsessauth=0;
8081

8182
structoptioncmdopts[]= {
8283
{"clean",0,NULL,'c'},
@@ -110,9 +111,10 @@ main(int argc, char **argv)
110111
/*
111112
* the following options don't have an equivalent short option letter
112113
*/
113-
{"use-set-session-authorization",no_argument,&use_setsessauth,1},
114114
{"disable-triggers",no_argument,&disable_triggers,1},
115115
{"no-data-for-failed-tables",no_argument,&no_data_for_failed_tables,1},
116+
{"no-tablespaces",no_argument,&outputNoTablespaces,1},
117+
{"use-set-session-authorization",no_argument,&use_setsessauth,1},
116118

117119
{NULL,0,NULL,0}
118120
};
@@ -241,10 +243,14 @@ main(int argc, char **argv)
241243

242244
case'X':
243245
/* -X is a deprecated alternative to long options */
244-
if (strcmp(optarg,"use-set-session-authorization")==0)
245-
use_setsessauth=1;
246-
elseif (strcmp(optarg,"disable-triggers")==0)
246+
if (strcmp(optarg,"disable-triggers")==0)
247247
disable_triggers=1;
248+
elseif (strcmp(optarg,"no-data-for-failed-tables")==0)
249+
no_data_for_failed_tables=1;
250+
elseif (strcmp(optarg,"no-tablespaces")==0)
251+
outputNoTablespaces=1;
252+
elseif (strcmp(optarg,"use-set-session-authorization")==0)
253+
use_setsessauth=1;
248254
else
249255
{
250256
fprintf(stderr,
@@ -290,8 +296,9 @@ main(int argc, char **argv)
290296
}
291297

292298
opts->disable_triggers=disable_triggers;
293-
opts->use_setsessauth=use_setsessauth;
294299
opts->noDataForFailedTables=no_data_for_failed_tables;
300+
opts->noTablespace=outputNoTablespaces;
301+
opts->use_setsessauth=use_setsessauth;
295302

296303
if (opts->formatName)
297304
{
@@ -395,12 +402,13 @@ usage(const char *progname)
395402
printf(_(" -T, --trigger=NAME restore named trigger\n"));
396403
printf(_(" -x, --no-privileges skip restoration of access privileges (grant/revoke)\n"));
397404
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
398-
printf(_(" --use-set-session-authorization\n"
399-
" use SESSION AUTHORIZATION commands instead of\n"
400-
" OWNER TO commands\n"));
401405
printf(_(" --no-data-for-failed-tables\n"
402406
" do not restore data of tables that could not be\n"
403407
" created\n"));
408+
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
409+
printf(_(" --use-set-session-authorization\n"
410+
" use SESSION AUTHORIZATION commands instead of\n"
411+
" OWNER TO commands\n"));
404412
printf(_(" -1, --single-transaction\n"
405413
" restore as a single transaction\n"));
406414

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp