mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-02 23:06:49 +02:00
- Be more paranoid when getting views
- Support for 'isstrict' procedure attribute. - Disable --blobs and --table (replaced prior to attempting to fix sequence dump problems)
This commit is contained in:
parent
87db3b88e0
commit
f350481134
@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
|
|||||||
|
|
||||||
#define K_VERS_MAJOR 1
|
#define K_VERS_MAJOR 1
|
||||||
#define K_VERS_MINOR 4
|
#define K_VERS_MINOR 4
|
||||||
#define K_VERS_REV 15
|
#define K_VERS_REV 16
|
||||||
|
|
||||||
/* Data block types */
|
/* Data block types */
|
||||||
#define BLK_DATA 1
|
#define BLK_DATA 1
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.168 2000/09/18 06:47:46 pjw Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.169 2000/10/10 13:55:28 pjw Exp $
|
||||||
*
|
*
|
||||||
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
|
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
|
||||||
*
|
*
|
||||||
@ -87,6 +87,15 @@
|
|||||||
* Remove 'isViewRule' since we check the relkind when getting tables.
|
* Remove 'isViewRule' since we check the relkind when getting tables.
|
||||||
* Now uses temp table 'pgdump_oid' rather than 'pg_dump_oid' (errors otherwise).
|
* Now uses temp table 'pgdump_oid' rather than 'pg_dump_oid' (errors otherwise).
|
||||||
*
|
*
|
||||||
|
* Modifications - 02-Oct-2000 - pjw@rhyme.com.au
|
||||||
|
*
|
||||||
|
* - Be more paranoid when getting views: call get_viewdef in separate statement
|
||||||
|
* so we can be more informative in error messages.
|
||||||
|
* - Support for 'isstrict' procedure attribute.
|
||||||
|
* - Disable --blobs and --table since (a) it's a pain to get ONLY the blobs for the
|
||||||
|
* table with the currently implementation, and (b) it's not clear how to restore
|
||||||
|
* a partial BLOB backup (given the current OID-based BLOB implementation).
|
||||||
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -702,6 +711,7 @@ main(int argc, char **argv)
|
|||||||
case 'a': /* Dump data only */
|
case 'a': /* Dump data only */
|
||||||
dataOnly = true;
|
dataOnly = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b': /* Dump blobs */
|
case 'b': /* Dump blobs */
|
||||||
outputBlobs = true;
|
outputBlobs = true;
|
||||||
break;
|
break;
|
||||||
@ -719,48 +729,63 @@ main(int argc, char **argv)
|
|||||||
case 'd': /* dump data as proper insert strings */
|
case 'd': /* dump data as proper insert strings */
|
||||||
dumpData = true;
|
dumpData = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D': /* dump data as proper insert strings with
|
case 'D': /* dump data as proper insert strings with
|
||||||
* attr names */
|
* attr names */
|
||||||
dumpData = true;
|
dumpData = true;
|
||||||
attrNames = true;
|
attrNames = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
filename = optarg;
|
filename = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'F':
|
case 'F':
|
||||||
format = optarg;
|
format = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h': /* server host */
|
case 'h': /* server host */
|
||||||
pghost = optarg;
|
pghost = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i': /* ignore database version mismatch */
|
case 'i': /* ignore database version mismatch */
|
||||||
ignore_version = true;
|
ignore_version = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n': /* Do not force double-quotes on
|
case 'n': /* Do not force double-quotes on
|
||||||
* identifiers */
|
* identifiers */
|
||||||
force_quotes = false;
|
force_quotes = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'N': /* Force double-quotes on identifiers */
|
case 'N': /* Force double-quotes on identifiers */
|
||||||
force_quotes = true;
|
force_quotes = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o': /* Dump oids */
|
case 'o': /* Dump oids */
|
||||||
oids = true;
|
oids = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 'O': /* Don't reconnect to match owner */
|
case 'O': /* Don't reconnect to match owner */
|
||||||
outputNoOwner = 1;
|
outputNoOwner = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p': /* server port */
|
case 'p': /* server port */
|
||||||
pgport = optarg;
|
pgport = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'R': /* No reconnect */
|
case 'R': /* No reconnect */
|
||||||
outputNoReconnect = 1;
|
outputNoReconnect = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': /* dump schema only */
|
case 's': /* dump schema only */
|
||||||
schemaOnly = true;
|
schemaOnly = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'S': /* Username for superuser in plain text output */
|
case 'S': /* Username for superuser in plain text output */
|
||||||
outputSuperuser = strdup(optarg);
|
outputSuperuser = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't': /* Dump data for this table only */
|
case 't': /* Dump data for this table only */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -787,22 +812,28 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
use_password = true;
|
use_password = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v': /* verbose */
|
case 'v': /* verbose */
|
||||||
g_verbose = true;
|
g_verbose = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'x': /* skip ACL dump */
|
case 'x': /* skip ACL dump */
|
||||||
aclsSkip = true;
|
aclsSkip = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Z': /* Compression Level */
|
case 'Z': /* Compression Level */
|
||||||
compressLevel = atoi(optarg);
|
compressLevel = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'V':
|
case 'V':
|
||||||
version();
|
version();
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -841,6 +872,14 @@ main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (outputBlobs && (tablename != NULL) )
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"%s: BLOB output is not supported for a single table. Use a full dump instead.\n",
|
||||||
|
progname);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (dumpData == true && oids == true)
|
if (dumpData == true && oids == true)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@ -1713,6 +1752,7 @@ getFuncs(int *numFuncs)
|
|||||||
int i_prosrc;
|
int i_prosrc;
|
||||||
int i_probin;
|
int i_probin;
|
||||||
int i_iscachable;
|
int i_iscachable;
|
||||||
|
int i_isstrict;
|
||||||
int i_usename;
|
int i_usename;
|
||||||
|
|
||||||
/* find all user-defined funcs */
|
/* find all user-defined funcs */
|
||||||
@ -1721,7 +1761,7 @@ getFuncs(int *numFuncs)
|
|||||||
"SELECT pg_proc.oid, proname, prolang, pronargs, prorettype, "
|
"SELECT pg_proc.oid, proname, prolang, pronargs, prorettype, "
|
||||||
"proretset, proargtypes, prosrc, probin, "
|
"proretset, proargtypes, prosrc, probin, "
|
||||||
"(select usename from pg_user where proowner = usesysid) as usename, "
|
"(select usename from pg_user where proowner = usesysid) as usename, "
|
||||||
"proiscachable "
|
"proiscachable, proisstrict "
|
||||||
"from pg_proc "
|
"from pg_proc "
|
||||||
"where pg_proc.oid > '%u'::oid",
|
"where pg_proc.oid > '%u'::oid",
|
||||||
g_last_builtin_oid);
|
g_last_builtin_oid);
|
||||||
@ -1753,6 +1793,7 @@ getFuncs(int *numFuncs)
|
|||||||
i_prosrc = PQfnumber(res, "prosrc");
|
i_prosrc = PQfnumber(res, "prosrc");
|
||||||
i_probin = PQfnumber(res, "probin");
|
i_probin = PQfnumber(res, "probin");
|
||||||
i_iscachable = PQfnumber(res, "proiscachable");
|
i_iscachable = PQfnumber(res, "proiscachable");
|
||||||
|
i_isstrict = PQfnumber(res, "proisstrict");
|
||||||
i_usename = PQfnumber(res, "usename");
|
i_usename = PQfnumber(res, "usename");
|
||||||
|
|
||||||
for (i = 0; i < ntups; i++)
|
for (i = 0; i < ntups; i++)
|
||||||
@ -1769,6 +1810,7 @@ getFuncs(int *numFuncs)
|
|||||||
finfo[i].lang = atoi(PQgetvalue(res, i, i_prolang));
|
finfo[i].lang = atoi(PQgetvalue(res, i, i_prolang));
|
||||||
finfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
|
finfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
|
||||||
finfo[i].iscachable = (strcmp(PQgetvalue(res, i, i_iscachable),"t") == 0);
|
finfo[i].iscachable = (strcmp(PQgetvalue(res, i, i_iscachable),"t") == 0);
|
||||||
|
finfo[i].isstrict = (strcmp(PQgetvalue(res, i, i_isstrict),"t") == 0);
|
||||||
|
|
||||||
if (strlen(finfo[i].usename) == 0)
|
if (strlen(finfo[i].usename) == 0)
|
||||||
fprintf(stderr, "WARNING: owner of function '%s' appears to be invalid\n",
|
fprintf(stderr, "WARNING: owner of function '%s' appears to be invalid\n",
|
||||||
@ -1819,7 +1861,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
|
|||||||
int i_relchecks;
|
int i_relchecks;
|
||||||
int i_reltriggers;
|
int i_reltriggers;
|
||||||
int i_relhasindex;
|
int i_relhasindex;
|
||||||
int i_viewdef;
|
|
||||||
|
|
||||||
char relkindview[2];
|
char relkindview[2];
|
||||||
|
|
||||||
@ -1839,9 +1880,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
|
|||||||
appendPQExpBuffer(query,
|
appendPQExpBuffer(query,
|
||||||
"SELECT pg_class.oid, relname, relkind, relacl, "
|
"SELECT pg_class.oid, relname, relkind, relacl, "
|
||||||
"(select usename from pg_user where relowner = usesysid) as usename, "
|
"(select usename from pg_user where relowner = usesysid) as usename, "
|
||||||
"relchecks, reltriggers, relhasindex, "
|
"relchecks, reltriggers, relhasindex "
|
||||||
"Case When relkind = '%c' then pg_get_viewdef(relname) "
|
|
||||||
"Else NULL End as viewdef "
|
|
||||||
"from pg_class "
|
"from pg_class "
|
||||||
"where relname !~ '^pg_' "
|
"where relname !~ '^pg_' "
|
||||||
"and relkind in ('%c', '%c', '%c') "
|
"and relkind in ('%c', '%c', '%c') "
|
||||||
@ -1872,7 +1911,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
|
|||||||
i_relchecks = PQfnumber(res, "relchecks");
|
i_relchecks = PQfnumber(res, "relchecks");
|
||||||
i_reltriggers = PQfnumber(res, "reltriggers");
|
i_reltriggers = PQfnumber(res, "reltriggers");
|
||||||
i_relhasindex = PQfnumber(res, "relhasindex");
|
i_relhasindex = PQfnumber(res, "relhasindex");
|
||||||
i_viewdef = PQfnumber(res, "viewdef");
|
|
||||||
|
|
||||||
for (i = 0; i < ntups; i++)
|
for (i = 0; i < ntups; i++)
|
||||||
{
|
{
|
||||||
@ -1883,16 +1921,52 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
|
|||||||
tblinfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
|
tblinfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
|
||||||
tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
|
tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
|
||||||
tblinfo[i].ntrig = atoi(PQgetvalue(res, i, i_reltriggers));
|
tblinfo[i].ntrig = atoi(PQgetvalue(res, i, i_reltriggers));
|
||||||
if (strcmp(PQgetvalue(res, i, i_relkind), relkindview) == 0) {
|
|
||||||
tblinfo[i].viewdef = strdup(PQgetvalue(res, i, i_viewdef));
|
|
||||||
} else {
|
|
||||||
tblinfo[i].viewdef = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(tblinfo[i].usename) == 0)
|
if (strlen(tblinfo[i].usename) == 0)
|
||||||
fprintf(stderr, "WARNING: owner of table '%s' appears to be invalid\n",
|
fprintf(stderr, "WARNING: owner of table '%s' appears to be invalid\n",
|
||||||
tblinfo[i].relname);
|
tblinfo[i].relname);
|
||||||
|
|
||||||
|
/* Get view definition */
|
||||||
|
if (strcmp(PQgetvalue(res, i, i_relkind), relkindview) == 0)
|
||||||
|
{
|
||||||
|
PGresult *res2;
|
||||||
|
|
||||||
|
resetPQExpBuffer(query);
|
||||||
|
appendPQExpBuffer(query, "SELECT pg_get_viewdef('%s') as viewdef ", tblinfo[i].relname);
|
||||||
|
res2 = PQexec(g_conn, query->data);
|
||||||
|
if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "getTables(): SELECT (for VIEW DEFINITION) failed. "
|
||||||
|
"Explanation from backend: %s",
|
||||||
|
PQerrorMessage(g_conn));
|
||||||
|
exit_nicely(g_conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PQntuples(res2) != 1)
|
||||||
|
{
|
||||||
|
if (PQntuples(res2) < 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "getTables(): SELECT (for VIEW %s) returned no definitions",
|
||||||
|
tblinfo[i].relname);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "getTables(): SELECT (for VIEW %s) returned more than 1 definition",
|
||||||
|
tblinfo[i].relname);
|
||||||
|
}
|
||||||
|
exit_nicely(g_conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
tblinfo[i].viewdef = strdup(PQgetvalue(res2, 0, 0));
|
||||||
|
|
||||||
|
if (strlen(tblinfo[i].viewdef) == 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "getTables(): SELECT (for VIEW %s) returned empty definition",
|
||||||
|
tblinfo[i].relname);
|
||||||
|
exit_nicely(g_conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tblinfo[i].viewdef = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exclude inherited CHECKs from CHECK constraints total. If a
|
* Exclude inherited CHECKs from CHECK constraints total. If a
|
||||||
* constraint matches by name and condition with a constraint
|
* constraint matches by name and condition with a constraint
|
||||||
@ -2888,6 +2962,10 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
|
|||||||
int i_lanname;
|
int i_lanname;
|
||||||
char query[256];
|
char query[256];
|
||||||
|
|
||||||
|
char *listSep;
|
||||||
|
char *listSepComma = ",";
|
||||||
|
char *listSepNone = "";
|
||||||
|
|
||||||
if (finfo[i].dumped)
|
if (finfo[i].dumped)
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
@ -2961,9 +3039,21 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
|
|||||||
findTypeByOid(tinfo, numTypes, finfo[i].prorettype, zeroAsOpaque),
|
findTypeByOid(tinfo, numTypes, finfo[i].prorettype, zeroAsOpaque),
|
||||||
asPart->data, func_lang);
|
asPart->data, func_lang);
|
||||||
|
|
||||||
if (finfo[i].iscachable) /* OR in new attrs here */
|
if (finfo[i].iscachable || finfo[i].isstrict) /* OR in new attrs here */
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(q, " WITH (iscachable)");
|
appendPQExpBuffer(q, " WITH (");
|
||||||
|
listSep = listSepNone;
|
||||||
|
|
||||||
|
if (finfo[i].iscachable) {
|
||||||
|
appendPQExpBuffer(q, "%s iscachable", listSep);
|
||||||
|
listSep = listSepComma;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (finfo[i].isstrict) {
|
||||||
|
appendPQExpBuffer(q, "%s isstrict", listSep);
|
||||||
|
listSep = listSepComma;
|
||||||
|
}
|
||||||
|
appendPQExpBuffer(q, " )");
|
||||||
}
|
}
|
||||||
|
|
||||||
appendPQExpBuffer(q, ";\n");
|
appendPQExpBuffer(q, ";\n");
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: pg_dump.h,v 1.52 2000/09/15 04:35:16 pjw Exp $
|
* $Id: pg_dump.h,v 1.53 2000/10/10 13:55:28 pjw Exp $
|
||||||
*
|
*
|
||||||
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
|
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
|
||||||
*
|
*
|
||||||
@ -70,6 +70,7 @@ typedef struct _funcInfo
|
|||||||
char *probin;
|
char *probin;
|
||||||
char *usename;
|
char *usename;
|
||||||
int iscachable; /* Attr */
|
int iscachable; /* Attr */
|
||||||
|
int isstrict; /* Attr */
|
||||||
int dumped; /* 1 if already dumped */
|
int dumped; /* 1 if already dumped */
|
||||||
} FuncInfo;
|
} FuncInfo;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user