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

Commit5ce94b2

Browse files
committed
Add --tablespaces-only and --roles-only options to pg_dumpall.
Dave Page
1 parentef65f6f commit5ce94b2

File tree

2 files changed

+85
-17
lines changed

2 files changed

+85
-17
lines changed

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

Lines changed: 21 additions & 1 deletion
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.59 2007/01/15 17:22:46 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.60 2007/01/25 02:30:32 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -193,6 +193,16 @@ PostgreSQL documentation
193193
</listitem>
194194
</varlistentry>
195195

196+
<varlistentry>
197+
<term><option>-r</option></term>
198+
<term><option>--roles-only</option></term>
199+
<listitem>
200+
<para>
201+
Dump only roles, no databases or tablespaces.
202+
</para>
203+
</listitem>
204+
</varlistentry>
205+
196206
<varlistentry>
197207
<term><option>-s</option></term>
198208
<term><option>--schema-only</option></term>
@@ -216,6 +226,16 @@ PostgreSQL documentation
216226
</listitem>
217227
</varlistentry>
218228

229+
<varlistentry>
230+
<term><option>-t</option></term>
231+
<term><option>--tablespaces-only</option></term>
232+
<listitem>
233+
<para>
234+
Dump only tablespaces, no databases or roles.
235+
</para>
236+
</listitem>
237+
</varlistentry>
238+
219239
<varlistentry>
220240
<term><option>-v</></term>
221241
<term><option>--verbose</></term>

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 64 additions & 16 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.86 2007/01/05 22:19:48 momjian Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.87 2007/01/25 02:30:32 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -78,6 +78,8 @@ main(int argc, char *argv[])
7878
boolforce_password= false;
7979
booldata_only= false;
8080
boolglobals_only= false;
81+
boolroles_only= false;
82+
booltablespaces_only= false;
8183
boolschema_only= false;
8284
PGconn*conn;
8385
intencoding;
@@ -97,11 +99,13 @@ main(int argc, char *argv[])
9799
{"oids",no_argument,NULL,'o'},
98100
{"no-owner",no_argument,NULL,'O'},
99101
{"port",required_argument,NULL,'p'},
100-
{"password",no_argument,NULL,'W'},
102+
{"roles-only",no_argument,NULL,'r'},
101103
{"schema-only",no_argument,NULL,'s'},
102104
{"superuser",required_argument,NULL,'S'},
105+
{"tablespaces-only",no_argument,NULL,'t'},
103106
{"username",required_argument,NULL,'U'},
104107
{"verbose",no_argument,NULL,'v'},
108+
{"password",no_argument,NULL,'W'},
105109
{"no-privileges",no_argument,NULL,'x'},
106110
{"no-acl",no_argument,NULL,'x'},
107111

@@ -161,7 +165,7 @@ main(int argc, char *argv[])
161165

162166
pgdumpopts=createPQExpBuffer();
163167

164-
while ((c=getopt_long(argc,argv,"acdDgh:ioOp:sS:U:vWxX:",long_options,&optindex))!=-1)
168+
while ((c=getopt_long(argc,argv,"acdDgh:ioOp:rsS:tU:vWxX:",long_options,&optindex))!=-1)
165169
{
166170
switch (c)
167171
{
@@ -214,6 +218,10 @@ main(int argc, char *argv[])
214218
appendPQExpBuffer(pgdumpopts," -p \"%s\"",pgport);
215219
#endif
216220
break;
221+
222+
case'r':
223+
roles_only= true;
224+
break;
217225

218226
case's':
219227
schema_only= true;
@@ -227,6 +235,10 @@ main(int argc, char *argv[])
227235
appendPQExpBuffer(pgdumpopts," -S \"%s\"",optarg);
228236
#endif
229237
break;
238+
239+
case't':
240+
tablespaces_only= true;
241+
break;
230242

231243
case'U':
232244
pguser=optarg;
@@ -295,6 +307,34 @@ main(int argc, char *argv[])
295307
progname);
296308
exit(1);
297309
}
310+
311+
/* Make sure the user hasn't specified a mix of globals-only options */
312+
if (globals_only&&roles_only)
313+
{
314+
fprintf(stderr,_("%s: --globals-only and --roles-only cannot be used together\n"),
315+
progname);
316+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
317+
progname);
318+
exit(1);
319+
}
320+
321+
if (globals_only&&tablespaces_only)
322+
{
323+
fprintf(stderr,_("%s: --globals-only and --tablespaces-only cannot be used together\n"),
324+
progname);
325+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
326+
progname);
327+
exit(1);
328+
}
329+
330+
if (roles_only&&tablespaces_only)
331+
{
332+
fprintf(stderr,_("%s: --roles-only and --tablespaces-only cannot be used together\n"),
333+
progname);
334+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
335+
progname);
336+
exit(1);
337+
}
298338

299339
/*
300340
* First try to connect to database "postgres", and failing that
@@ -332,25 +372,31 @@ main(int argc, char *argv[])
332372
printf("SET escape_string_warning = 'off';\n");
333373
printf("\n");
334374

335-
/* Dump roles (users) */
336-
dumpRoles(conn);
337-
338-
/* Dump role memberships --- need different method for pre-8.1 */
339-
if (server_version >=80100)
340-
dumpRoleMembership(conn);
341-
else
342-
dumpGroups(conn);
375+
if (!tablespaces_only)
376+
{
377+
/* Dump roles (users) */
378+
dumpRoles(conn);
379+
380+
/* Dump role memberships --- need different method for pre-8.1 */
381+
if (server_version >=80100)
382+
dumpRoleMembership(conn);
383+
else
384+
dumpGroups(conn);
385+
}
343386

344-
/* Dump tablespaces */
345-
if (server_version >=80000)
346-
dumpTablespaces(conn);
387+
if (!roles_only)
388+
{
389+
/* Dump tablespaces */
390+
if (server_version >=80000)
391+
dumpTablespaces(conn);
392+
}
347393

348394
/* Dump CREATE DATABASE commands */
349-
if (!globals_only)
395+
if (!globals_only&& !roles_only&& !tablespaces_only)
350396
dumpCreateDB(conn);
351397
}
352398

353-
if (!globals_only)
399+
if (!globals_only&& !roles_only&& !tablespaces_only)
354400
dumpDatabases(conn);
355401

356402
PQfinish(conn);
@@ -384,8 +430,10 @@ help(void)
384430
printf(_(" -g, --globals-only dump only global objects, no databases\n"));
385431
printf(_(" -o, --oids include OIDs in dump\n"));
386432
printf(_(" -O, --no-owner skip restoration of object ownership\n"));
433+
printf(_(" -r, --roles-only dump only roles, no databases or tablespaces\n"));
387434
printf(_(" -s, --schema-only dump only the schema, no data\n"));
388435
printf(_(" -S, --superuser=NAME specify the superuser user name to use in the dump\n"));
436+
printf(_(" -t, --tablespaces-only dump only tablespaces, no databases or roles\n"));
389437
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
390438
printf(_(" --disable-dollar-quoting\n"
391439
" disable dollar quoting, use SQL standard quoting\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp