diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/pg_dump/common.c | 37 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dump.c | 113 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dump.h | 4 | ||||
-rw-r--r-- | src/bin/psql/psqlHelp.h | 6 |
4 files changed, 116 insertions, 44 deletions
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index bcc84f21f7..1e2ac00e61 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.3 1996/07/22 08:36:59 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.4 1996/08/24 20:49:17 scrappy Exp $ * * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * @@ -210,7 +210,6 @@ dumpSchema(FILE *fout, int *numTablesPtr, char *tablename) int numFuncs; int numTables; int numInherits; - int numIndices; int numAggregates; int numOperators; TypeInfo *tinfo; @@ -218,7 +217,6 @@ dumpSchema(FILE *fout, int *numTablesPtr, char *tablename) AggInfo *agginfo; TableInfo *tblinfo; InhInfo *inhinfo; - IndInfo *indinfo; OprInfo *oprinfo; if (g_verbose) fprintf(stderr,"%s reading user-defined types %s\n", @@ -253,10 +251,6 @@ if (g_verbose) fprintf(stderr, "%s flagging inherited attributes in subtables %s g_comment_start, g_comment_end); flagInhAttrs(tblinfo, numTables, inhinfo, numInherits); -if (g_verbose) fprintf(stderr,"%s reading indices information %s\n", - g_comment_start, g_comment_end); - indinfo = getIndices(&numIndices); - if (!tablename && fout) { if (g_verbose) fprintf(stderr,"%s dumping out user-defined types %s\n", g_comment_start, g_comment_end); @@ -288,16 +282,35 @@ if (!tablename && fout) { dumpOprs(fout, oprinfo, numOperators, tinfo, numTypes); } -if (fout) { - if (g_verbose) fprintf(stderr,"%s dumping out indices %s\n", - g_comment_start, g_comment_end); - dumpIndices(fout, indinfo, numIndices, tblinfo, numTables, tablename); -} *numTablesPtr = numTables; return tblinfo; } +/* + * dumpSchemaIdx: + * dump indexes at the end for performance + * + */ + +extern void +dumpSchemaIdx(FILE *fout, int *numTablesPtr, char *tablename, + TableInfo* tblinfo, int numTables) +{ + int numIndices; + IndInfo *indinfo; + + if (g_verbose) fprintf(stderr,"%s reading indices information %s\n", + g_comment_start, g_comment_end); + indinfo = getIndices(&numIndices); + + if (fout) { + if (g_verbose) fprintf(stderr,"%s dumping out indices %s\n", + g_comment_start, g_comment_end); + dumpIndices(fout, indinfo, numIndices, tblinfo, numTables, tablename); + } +} + /* flagInhAttrs - * for each table in tblinfo, flag its inherited attributes * so when we dump the table out, we don't dump out the inherited attributes diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 98e2fa3fd8..c6fd237012 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -20,7 +20,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.6 1996/08/14 05:33:11 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.7 1996/08/24 20:49:22 scrappy Exp $ * * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * @@ -80,14 +80,15 @@ usage(char* progname) fprintf(stderr, "%s - version 1.13.dhb.2\n\n",progname); fprintf(stderr, "usage: %s [options] [dbname]\n",progname); fprintf(stderr, "\t -f filename \t\t script output filename\n"); - fprintf(stderr, "\t -d[a] \t\t dump data as proper insert strings\n"); - fprintf(stderr, "\t \t\t (if 'a' then attribute names also)\n"); fprintf(stderr, "\t -H hostname \t\t server host name\n"); fprintf(stderr, "\t -p port \t\t server port number\n"); fprintf(stderr, "\t -v \t\t verbose\n"); + fprintf(stderr, "\t -d[a] \t\t dump data as proper insert strings\n"); + fprintf(stderr, "\t \t\t (if 'a' then attribute names also)\n"); fprintf(stderr, "\t -S \t\t dump out only the schema, no data\n"); fprintf(stderr, "\t -a \t\t dump out only the data, no schema\n"); fprintf(stderr, "\t -t table \t\t dump for this table only\n"); + fprintf(stderr, "\t -o \t\t dump object id's (oids)\n"); fprintf(stderr, "\n if dbname is not supplied, then the DATABASE environment name is used\n"); fprintf(stderr, "\n"); @@ -117,7 +118,7 @@ main(int argc, char** argv) char *pghost = NULL; char *pgport = NULL; char *tablename; - + int oids; TableInfo *tblinfo; int numTables; @@ -125,7 +126,8 @@ main(int argc, char** argv) filename = NULL; tablename = NULL; g_verbose = 0; - + oids = 0; + strcpy(g_comment_start,"-- "); g_comment_end[0] = '\0'; strcpy(g_opaque_type, "opaque"); @@ -134,7 +136,7 @@ main(int argc, char** argv) progname = *argv; - while ((c = getopt(argc, argv,"f:H:p:t:vSDd:a")) != EOF) { + while ((c = getopt(argc, argv,"f:H:p:t:vSDd:ao")) != EOF) { switch(c) { case 'f': /* output file name */ filename = optarg; @@ -161,6 +163,9 @@ main(int argc, char** argv) case 'a': /* Dump data only */ dataOnly = 1; break; + case 'o': /* Dump oids */ + oids = 1; + break; default: usage(progname); break; @@ -196,27 +201,27 @@ main(int argc, char** argv) g_last_builtin_oid = findLastBuiltinOid(); + if (oids) + setMaxOid(g_fout); if (!dataOnly) { - -if (g_verbose) - fprintf(stderr, "%s last builtin oid is %d %s\n", - g_comment_start, g_last_builtin_oid, g_comment_end); - - tblinfo = dumpSchema(g_fout, &numTables, tablename); - + if (g_verbose) + fprintf(stderr, "%s last builtin oid is %d %s\n", + g_comment_start, g_last_builtin_oid, g_comment_end); + tblinfo = dumpSchema(g_fout, &numTables, tablename); } - else { + else tblinfo = dumpSchema(NULL, &numTables, tablename); - } if (!schemaOnly) { - -if (g_verbose) fprintf(stderr,"%s dumping out the contents of each table %s\n", + if (g_verbose) + fprintf(stderr,"%s dumping out the contents of each table %s\n", g_comment_start, g_comment_end); - - dumpClasses(tblinfo, numTables, g_fout, tablename); + dumpClasses(tblinfo, numTables, g_fout, tablename, oids); } + if (!dataOnly) /* dump indexes at the end for performance */ + dumpSchemaIdx(g_fout, &numTables, tablename, tblinfo, numTables); + fflush(g_fout); fclose(g_fout); @@ -771,11 +776,11 @@ getTableAttrs(TableInfo* tblinfo, int numTables) /* we must read the attribute names in attribute number order! */ /* because we will use the attnum to index into the attnames array later */ -if (g_verbose) - fprintf(stderr,"%s finding the attrs and types for table: %s %s\n", - g_comment_start, - tblinfo[i].relname, - g_comment_end); + if (g_verbose) + fprintf(stderr,"%s finding the attrs and types for table: %s %s\n", + g_comment_start, + tblinfo[i].relname, + g_comment_end); sprintf(q,"SELECT a.attnum, a.attname, t.typname, a.attlen from pg_attribute a, pg_type t where a.attrelid = '%s'::oid and a.atttypid = t.oid and a.attnum > 0 order by attnum",tblinfo[i].oid); res = PQexec(g_conn, q); @@ -1356,7 +1361,7 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices, * dump the contents of all the classes. */ void -dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable) +dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable, int oids) { char query[255]; #define COPYBUFSIZ 8192 @@ -1371,7 +1376,7 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable) int field; int tuple; int copydone; - + for(i = 0; i < numTables; i++) { char *classname = tblinfo[i].relname; @@ -1382,8 +1387,14 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable) continue; if(!dumpData) { - fprintf(fout, "COPY %s from stdin;\n", classname); - sprintf(query, "COPY %s to stdout;\n", classname); + if (oids) { + fprintf(fout, "COPY %s WITH OIDS FROM stdin;\n", classname); + sprintf(query, "COPY %s WITH OIDS TO stdout;\n", classname); + } + else { + fprintf(fout, "COPY %s FROM stdin;\n", classname); + sprintf(query, "COPY %s TO stdout;\n", classname); + } res = PQexec(g_conn, query); if (!res || PQresultStatus(res) != PGRES_COPY_OUT) { @@ -1538,7 +1549,53 @@ dumpTuples(PGresult *res, FILE *fout, int* attrmap) } } +/* + * setMaxOid - + * find the maximum oid and generate a COPY statement to set it +*/ +void +setMaxOid(FILE *fout) +{ + char query[255]; + PGresult *res; + Oid max_oid; + + res = PQexec(g_conn, "CREATE TABLE pgdump_oid (dummy int4)"); + if (!res || + PQresultStatus(res) != PGRES_COMMAND_OK) { + fprintf(stderr,"Can not create pgdump_oid table\n"); + exit_nicely(g_conn); + } + PQclear(res); + res = PQexec(g_conn, "INSERT INTO pgdump_oid VALUES (0)"); + if (!res || + PQresultStatus(res) != PGRES_COMMAND_OK) { + fprintf(stderr,"Can not insert into pgdump_oid table\n"); + exit_nicely(g_conn); + } + max_oid = atol(PQoidStatus(res)); + if (max_oid == 0) { + fprintf(stderr,"Invalid max id in setMaxOid\n"); + exit_nicely(g_conn); + } + PQclear(res); + res = PQexec(g_conn, "DROP TABLE pgdump_oid;"); + if (!res || + PQresultStatus(res) != PGRES_COMMAND_OK) { + fprintf(stderr,"Can not drop pgdump_oid table\n"); + exit_nicely(g_conn); + } + PQclear(res); + if (g_verbose) + fprintf(stderr, "%s maximum system oid is %d %s\n", + g_comment_start, max_oid, g_comment_end); + fprintf(fout, "CREATE TABLE pgdump_oid (dummy int4);\n"); + fprintf(fout, "COPY pgdump_oid WITH OIDS FROM stdin;\n"); + fprintf(fout, "%-ld\t0\n", max_oid); + fprintf(fout, "\\.\n"); + fprintf(fout, "DROP TABLE pgdump_oid;\n"); +} /* * findLastBuiltInOid - diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index 3d0287fa58..7e8a830457 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_dump.h,v 1.3 1996/07/22 08:37:00 scrappy Exp $ + * $Id: pg_dump.h,v 1.4 1996/08/24 20:49:25 scrappy Exp $ * * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * @@ -142,6 +142,8 @@ extern char g_opaque_type[10]; /* name for the opaque type */ */ extern TableInfo* dumpSchema(FILE* fout, int *numTablesPtr, char *tablename); +extern void dumpSchemaIdx(FILE* fout, int *numTablesPtr, char *tablename, + TableInfo* tblinfo, int numTables); extern char* findTypeByOid(TypeInfo* tinfo, int numTypes, char* oid); extern char* findOprByOid(OprInfo *oprinfo, int numOprs, char *oid); diff --git a/src/bin/psql/psqlHelp.h b/src/bin/psql/psqlHelp.h index 2fbe50b02c..eee4cf30c5 100644 --- a/src/bin/psql/psqlHelp.h +++ b/src/bin/psql/psqlHelp.h @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: psqlHelp.h,v 1.2 1996/07/28 07:08:14 scrappy Exp $ + * $Id: psqlHelp.h,v 1.3 1996/08/24 20:49:41 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -49,7 +49,7 @@ static struct _helpStruct QL_HELP[] = { "commit [work]"}, { "copy", "copy data to and from a table", - "copy [binary] [nonulls] <relname>\n\t{to|from} {<filename>|stdin|stdout} [using delimiters <delim>];"}, + "copy [binary] <relname> [with oids]\n\t{to|from} {<filename>|stdin|stdout} [using delimiters <delim>];"}, { "create", "Please more be specific:", "\tcreate aggregate\n\tcreate database\n\tcreate function\n\tcreate index\n\tcreate operator\n\tcreate rule\n\tcreate table\n\tcreate type\n\tcreate view"}, @@ -64,7 +64,7 @@ static struct _helpStruct QL_HELP[] = { "create function <function_name> ([<type1>,...<typeN>]) returns <return_type>\n\tas '<object_filename>'|'<sql-queries>'\n\tlanguage 'c'|'sql'|'internal';"}, { "create index", "construct an index", - "create index <indexname> on <relname> using <access_method> (<attr1>|<funcname>(<attr1>,...) <type_class1>);"}, + "create index <indexname> on <relname> [using <access_method>] (<attr1>|<funcname>(<attr1>,...) [<type_class1>]);"}, { "create operator", "create a user-defined operator", "create operator <operator_name> (\n\t[leftarg = <type1>][,rightarg = <type2>]\n\t,procedure = <func_name>,\n\t[,commutator = <com_op>][,negator = <neg_op>]\n\t[,restrict = <res_proc>][,hashes]\n\t[,join = <join_proc>][,sort = <sort_op1>...<sort_opN>]);"}, |