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

Commitebc8649

Browse files
committed
Since I needed this feature badly, I added the -n / --schema switch to
pg_restore. It restores the given schemaname only. It can be used inconjunction with the -t and other switches to make the selection veryfine grained.Richard van den Bergg, CISSP
1 parent4d0e7b4 commitebc8649

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

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

Lines changed: 13 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.51 2005/05/29 03:32:18 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.52 2005/06/09 17:56:51 momjian Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<refmeta>
@@ -239,6 +239,18 @@
239239
</listitem>
240240
</varlistentry>
241241

242+
<varlistentry>
243+
<term><option>-n <replaceable class="parameter">namespace</replaceable></option></term>
244+
<term><option>--schema=<replaceable class="parameter">schema</replaceable></option></term>
245+
<listitem>
246+
<para>
247+
Restore only definitions and/or data in the named schema. Not to be
248+
confused with the <option>-s</option> option. This can be combined with
249+
<option>-t</option> option.
250+
</para>
251+
</listitem>
252+
</varlistentry>
253+
242254
<varlistentry>
243255
<term><option>-O</option></term>
244256
<term><option>--no-owner</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.34 2004/11/06 19:36:01 tgl Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.35 2005/06/09 17:56:51 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -98,6 +98,7 @@ typedef struct _restoreOptions
9898
char*indexNames;
9999
char*functionNames;
100100
char*tableNames;
101+
char*schemaNames;
101102
char*triggerNames;
102103

103104
intuseDB;

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 9 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_archiver.c,v 1.109 2005/05/17 17:30:29 tgl Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.110 2005/06/09 17:56:51 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1997,6 +1997,14 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls)
19971997
/* Check if tablename only is wanted */
19981998
if (ropt->selTypes)
19991999
{
2000+
if (ropt->schemaNames)
2001+
{
2002+
/* If no namespace is specified, it means all. */
2003+
if (!te->namespace)
2004+
return0;
2005+
if(strcmp(ropt->schemaNames,te->namespace)!=0)
2006+
return0;
2007+
}
20002008
if ((strcmp(te->desc,"TABLE")==0)|| (strcmp(te->desc,"TABLE DATA")==0))
20012009
{
20022010
if (!ropt->selTable)

‎src/bin/pg_dump/pg_restore.c

Lines changed: 9 additions & 2 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.70 2005/04/29 07:08:06 neilc Exp $
37+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.71 2005/06/09 17:56:51 momjian Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -103,6 +103,7 @@ main(int argc, char **argv)
103103
{"no-reconnect",0,NULL,'R'},
104104
{"port",1,NULL,'p'},
105105
{"password",0,NULL,'W'},
106+
{"schema",1,NULL,'n'},
106107
{"schema-only",0,NULL,'s'},
107108
{"superuser",1,NULL,'S'},
108109
{"table",1,NULL,'t'},
@@ -141,7 +142,7 @@ main(int argc, char **argv)
141142
}
142143
}
143144

144-
while ((c=getopt_long(argc,argv,"acCd:ef:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
145+
while ((c=getopt_long(argc,argv,"acCd:ef:F:h:iI:lL:n:Op:P:RsS:t:T:uU:vWxX:",
145146
cmdopts,NULL))!=-1)
146147
{
147148
switch (c)
@@ -223,6 +224,11 @@ main(int argc, char **argv)
223224
opts->tableNames=strdup(optarg);
224225
break;
225226

227+
case'n':/* Dump data for this schema only */
228+
opts->selTypes=1;
229+
opts->schemaNames=strdup(optarg);
230+
break;
231+
226232
case'u':
227233
opts->requirePassword= true;
228234
opts->username=simple_prompt("User name: ",100, true);
@@ -375,6 +381,7 @@ usage(const char *progname)
375381
printf(_(" -I, --index=NAME restore named index\n"));
376382
printf(_(" -L, --use-list=FILENAME use specified table of contents for ordering\n"
377383
" output from this file\n"));
384+
printf(_(" -n, --schema=NAME restore only objects in this schema\n"));
378385
printf(_(" -O, --no-owner skip restoration of object ownership\n"));
379386
printf(_(" -P, --function=NAME(args)\n"
380387
" restore named function\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp