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

Commit500b62b

Browse files
committed
pg_dump patch from Philip Warner
1 parent20c01ef commit500b62b

File tree

14 files changed

+3882
-388
lines changed

14 files changed

+3882
-388
lines changed

‎doc/TODO.detail/function

Lines changed: 519 additions & 0 deletions
Large diffs are not rendered by default.

‎src/bin/pg_dump/Makefile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.17 2000/07/03 16:35:39 petere Exp $
7+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.18 2000/07/04 14:25:26 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/bin/pg_dump
1212
top_builddir = ../../..
1313
include ../../Makefile.global
1414

15-
OBJS= pg_dump.o common.o$(STRDUP)
15+
OBJS= pg_backup_archiver.o pg_backup_custom.o pg_backup_files.o\
16+
pg_backup_plain_text.o$(STRDUP)
1617

1718
CFLAGS+= -I$(LIBPQDIR)
19+
LDFLAGS+= -lz
1820

21+
all: submake pg_dump$(X) pg_restore$(X)
1922

20-
all: submake pg_dump pg_dumpall
23+
pg_dump$(X): pg_dump.o common.o$(OBJS)$(LIBPQDIR)/libpq.a
24+
$(CC)$(CFLAGS) -o$@ pg_dump.o common.o$(OBJS)$(LIBPQ)$(LDFLAGS)
2125

22-
pg_dump:$(OBJS)$(LIBPQDIR)/libpq.a
23-
$(CC)$(CFLAGS) -o$@$(OBJS)$(LIBPQ)$(LDFLAGS)
24-
25-
pg_dumpall: pg_dumpall.sh
26-
sed -e's:__VERSION__:$(VERSION):g'\
27-
-e's:__MULTIBYTE__:$(MULTIBYTE):g'\
28-
-e's:__bindir__:$(bindir):g'\
29-
<$<>$@
26+
pg_restore$(X): pg_restore.o$(OBJS)$(LIBPQDIR)/libpq.a
27+
$(CC)$(CFLAGS) -o$@ pg_restore.o$(OBJS)$(LIBPQ)$(LDFLAGS)
3028

3129
../../utils/strdup.o:
3230
$(MAKE) -C ../../utils strdup.o
@@ -37,6 +35,7 @@ submake:
3735

3836
install: all installdirs
3937
$(INSTALL_PROGRAM) pg_dump$(X)$(bindir)/pg_dump$(X)
38+
$(INSTALL_PROGRAM) pg_restore$(X)$(bindir)/pg_restore$(X)
4039
$(INSTALL_SCRIPT) pg_dumpall$(bindir)/pg_dumpall
4140
$(INSTALL_SCRIPT) pg_upgrade$(bindir)/pg_upgrade
4241

@@ -50,7 +49,7 @@ depend dep:
5049
$(CC) -MM$(CFLAGS)*.c>depend
5150

5251
cleandistcleanmaintainer-clean:
53-
rm -f pg_dump$(X)$(OBJS)pg_dumpall
52+
rm -f pg_dump$(X)pg_restore$(X)$(OBJS)pg_dump.o common.o pg_restore.o
5453

5554
ifeq (depend,$(wildcard depend))
5655
include depend

‎src/bin/pg_dump/README

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Notes on pg_dump
2+
================
3+
4+
pg_dump, by default, still outputs text files.
5+
6+
pg_dumpall forces all pg_dump output to be text, since it also outputs text into the same output stream.
7+
8+
The plain text output format can not be used as input into pg_restore.
9+
10+
11+
To dump a database into the next custom format, type:
12+
13+
pg_dump <db-name> -Fc > <backup-file>
14+
15+
To restore, try
16+
17+
To list contents:
18+
19+
pg_restore -l <backup-file> | less
20+
21+
or to list tables:
22+
23+
pg_restore <backup-file> --table | less
24+
25+
or to list in a differnet orderL
26+
27+
pg_restore <backup-file> -l --oid --rearrange | less
28+
29+
Once you are happy with the list, just remove the '-l', and an SQL script will be output.
30+
31+
32+
You can also dump a listing:
33+
34+
pg_restore -l <backup-file> > toc.lis
35+
or
36+
pg_restore -l <backup-file> -f toc.lis
37+
38+
edit it, and rearrange the lines (or delete some):
39+
40+
vi toc.lis
41+
42+
then use it to restore selected items:
43+
44+
pg_restore <backup-file> --use=toc.lis -l | less
45+
46+
When you like the list, type
47+
48+
pg_restore backup.bck --use=toc.lis > script.sql
49+
50+
or, simply:
51+
52+
createdb newdbname
53+
pg_restore backup.bck --use=toc.lis | psql newdbname
54+
55+
56+
Philip Warner, 3-Jul-2000
57+
pjw@rhyme.com.au
58+
59+
60+

‎src/bin/pg_dump/common.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.43 2000/06/14 18:17:50 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.44 2000/07/04 14:25:27 momjian Exp $
1212
*
1313
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1414
*
@@ -232,10 +232,13 @@ strInArray(const char *pattern, char **arr, int arr_size)
232232
*/
233233

234234
TableInfo*
235-
dumpSchema(FILE*fout,
236-
int*numTablesPtr,
237-
constchar*tablename,
238-
constboolaclsSkip)
235+
dumpSchema(Archive*fout,
236+
int*numTablesPtr,
237+
constchar*tablename,
238+
constboolaclsSkip,
239+
constbooloids,
240+
constboolschemaOnly,
241+
constbooldataOnly)
239242
{
240243
intnumTypes;
241244
intnumFuncs;
@@ -290,7 +293,7 @@ dumpSchema(FILE *fout,
290293
g_comment_start,g_comment_end);
291294
flagInhAttrs(tblinfo,numTables,inhinfo,numInherits);
292295

293-
if (!tablename&&fout)
296+
if (!tablename&&!dataOnly)
294297
{
295298
if (g_verbose)
296299
fprintf(stderr,"%s dumping out database comment %s\n",
@@ -306,40 +309,37 @@ dumpSchema(FILE *fout,
306309
dumpTypes(fout,finfo,numFuncs,tinfo,numTypes);
307310
}
308311

309-
if (fout)
310-
{
311-
if (g_verbose)
312-
fprintf(stderr,"%s dumping out tables %s\n",
313-
g_comment_start,g_comment_end);
314-
dumpTables(fout,tblinfo,numTables,inhinfo,numInherits,
315-
tinfo,numTypes,tablename,aclsSkip);
316-
}
312+
if (g_verbose)
313+
fprintf(stderr,"%s dumping out tables %s\n",
314+
g_comment_start,g_comment_end);
315+
dumpTables(fout,tblinfo,numTables,inhinfo,numInherits,
316+
tinfo,numTypes,tablename,aclsSkip,oids,schemaOnly,dataOnly);
317317

318-
if (!tablename&&fout)
318+
if (!tablename&&!dataOnly)
319319
{
320320
if (g_verbose)
321321
fprintf(stderr,"%s dumping out user-defined procedural languages %s\n",
322322
g_comment_start,g_comment_end);
323323
dumpProcLangs(fout,finfo,numFuncs,tinfo,numTypes);
324324
}
325325

326-
if (!tablename&&fout)
326+
if (!tablename&&!dataOnly)
327327
{
328328
if (g_verbose)
329329
fprintf(stderr,"%s dumping out user-defined functions %s\n",
330330
g_comment_start,g_comment_end);
331331
dumpFuncs(fout,finfo,numFuncs,tinfo,numTypes);
332332
}
333333

334-
if (!tablename&&fout)
334+
if (!tablename&&!dataOnly)
335335
{
336336
if (g_verbose)
337337
fprintf(stderr,"%s dumping out user-defined aggregates %s\n",
338338
g_comment_start,g_comment_end);
339339
dumpAggs(fout,agginfo,numAggregates,tinfo,numTypes);
340340
}
341341

342-
if (!tablename&&fout)
342+
if (!tablename&&!dataOnly)
343343
{
344344
if (g_verbose)
345345
fprintf(stderr,"%s dumping out user-defined operators %s\n",
@@ -363,7 +363,7 @@ dumpSchema(FILE *fout,
363363
*/
364364

365365
externvoid
366-
dumpSchemaIdx(FILE*fout,constchar*tablename,
366+
dumpSchemaIdx(Archive*fout,constchar*tablename,
367367
TableInfo*tblinfo,intnumTables)
368368
{
369369
intnumIndices;

‎src/bin/pg_dump/pg_backup.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_backup.h
4+
*
5+
*Public interface to the pg_dump archiver routines.
6+
*
7+
*See the headers to pg_restore for more details.
8+
*
9+
* Copyright (c) 2000, Philip Warner
10+
* Rights are granted to use this software in any way so long
11+
* as this notice is not removed.
12+
*
13+
*The author is not responsible for loss or damages that may
14+
*result from it's use.
15+
*
16+
*
17+
* IDENTIFICATION
18+
*
19+
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
20+
*
21+
*Initial version.
22+
*
23+
*-------------------------------------------------------------------------
24+
*/
25+
26+
#ifndefPG_BACKUP__
27+
28+
#include"config.h"
29+
#include"c.h"
30+
31+
#definePG_BACKUP__
32+
33+
typedefenum_archiveFormat {
34+
archUnknown=0,
35+
archCustom=1,
36+
archFiles=2,
37+
archTar=3,
38+
archPlainText=4
39+
}ArchiveFormat;
40+
41+
/*
42+
* We may want to have so user-readbale data, but in the mean
43+
* time this gives us some abstraction and type checking.
44+
*/
45+
typedefstruct_Archive {
46+
/* Nothing here */
47+
}Archive;
48+
49+
typedefint (*DataDumperPtr)(Archive*AH,char*oid,void*userArg);
50+
51+
typedefstruct_restoreOptions {
52+
intdataOnly;
53+
intdropSchema;
54+
char*filename;
55+
intschemaOnly;
56+
intverbose;
57+
intaclsSkip;
58+
inttocSummary;
59+
char*tocFile;
60+
intoidOrder;
61+
intorigOrder;
62+
intrearrange;
63+
intformat;
64+
char*formatName;
65+
66+
intselTypes;
67+
intselIndex;
68+
intselFunction;
69+
intselTrigger;
70+
intselTable;
71+
char*indexNames;
72+
char*functionNames;
73+
char*tableNames;
74+
char*triggerNames;
75+
76+
int*idWanted;
77+
intlimitToList;
78+
intcompression;
79+
80+
}RestoreOptions;
81+
82+
/*
83+
* Main archiver interface.
84+
*/
85+
86+
/* Called to add a TOC entry */
87+
externvoidArchiveEntry(Archive*AH,constchar*oid,constchar*name,
88+
constchar*desc,constchar* (deps[]),constchar*defn,
89+
constchar*dropStmt,constchar*owner,
90+
DataDumperPtrdumpFn,void*dumpArg);
91+
92+
/* Called to write *data* to the archive */
93+
externintWriteData(Archive*AH,constvoid*data,intdLen);
94+
95+
externvoidCloseArchive(Archive*AH);
96+
97+
externvoidRestoreArchive(Archive*AH,RestoreOptions*ropt);
98+
99+
/* Open an existing archive */
100+
externArchive*OpenArchive(constchar*FileSpec,ArchiveFormatfmt);
101+
102+
/* Create a new archive */
103+
externArchive*CreateArchive(constchar*FileSpec,ArchiveFormatfmt,intcompression);
104+
105+
/* The --list option */
106+
externvoidPrintTOCSummary(Archive*AH,RestoreOptions*ropt);
107+
108+
externRestoreOptions*NewRestoreOptions(void);
109+
110+
/* Rearrange TOC entries */
111+
externvoidMoveToStart(Archive*AH,char*oType);
112+
externvoidMoveToEnd(Archive*AH,char*oType);
113+
externvoidSortTocByOID(Archive*AH);
114+
externvoidSortTocByID(Archive*AH);
115+
externvoidSortTocFromFile(Archive*AH,RestoreOptions*ropt);
116+
117+
/* Convenience functions used only when writing DATA */
118+
externintarchputs(constchar*s,Archive*AH);
119+
externintarchputc(constcharc,Archive*AH);
120+
externintarchprintf(Archive*AH,constchar*fmt, ...);
121+
122+
#endif
123+
124+
125+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp