#include "postgres_fe.h"
Go to the source code of this file.
typedef struct _attrDefInfo AttrDefInfo |
typedef struct _constraintInfo ConstraintInfo |
typedef struct _defaultACLInfo DefaultACLInfo |
typedef struct _dumpableObject DumpableObject |
typedef struct _evttriggerInfo EventTriggerInfo |
typedef struct _extensionInfo ExtensionInfo |
typedef struct _foreignServerInfo ForeignServerInfo |
typedef struct _namespaceInfo NamespaceInfo |
typedef enum _OidOptions OidOptions |
typedef struct _opclassInfo OpclassInfo |
typedef struct _opfamilyInfo OpfamilyInfo |
typedef struct _procLangInfo ProcLangInfo |
typedef struct _shellTypeInfo ShellTypeInfo |
typedef struct SimpleOidList SimpleOidList |
typedef struct SimpleOidListCell SimpleOidListCell |
typedef struct _tableDataInfo TableDataInfo |
typedef struct _tableInfo TableInfo |
typedef struct _triggerInfo TriggerInfo |
typedef struct _cfgInfo TSConfigInfo |
typedef struct _dictInfo TSDictInfo |
typedef struct _prsInfo TSParserInfo |
typedef struct _tmplInfo TSTemplateInfo |
enum _OidOptions |
Definition at line 503 of file pg_dump.h.
{ zeroAsOpaque = 1, zeroAsAny = 2, zeroAsStar = 4, zeroAsNone = 8 } OidOptions;
enum DumpableObjectType |
Definition at line 77 of file pg_dump.h.
{ /* When modifying this enum, update priority tables in pg_dump_sort.c! */ DO_NAMESPACE, DO_EXTENSION, DO_TYPE, DO_SHELL_TYPE, DO_FUNC, DO_AGG, DO_OPERATOR, DO_OPCLASS, DO_OPFAMILY, DO_COLLATION, DO_CONVERSION, DO_TABLE, DO_ATTRDEF, DO_INDEX, DO_RULE, DO_TRIGGER, DO_CONSTRAINT, DO_FK_CONSTRAINT, /* see note for ConstraintInfo */ DO_PROCLANG, DO_CAST, DO_TABLE_DATA, DO_DUMMY_TYPE, DO_TSPARSER, DO_TSDICT, DO_TSTEMPLATE, DO_TSCONFIG, DO_FDW, DO_FOREIGN_SERVER, DO_DEFAULT_ACL, DO_BLOB, DO_BLOB_DATA, DO_PRE_DATA_BOUNDARY, DO_POST_DATA_BOUNDARY, DO_EVENT_TRIGGER, DO_REFRESH_MATVIEW } DumpableObjectType;
void addObjectDependency | ( | DumpableObject * | dobj, | |
DumpId | refId | |||
) |
Definition at line 648 of file common.c.
References _dumpableObject::allocDeps, _dumpableObject::dependencies, _dumpableObject::nDeps, pg_malloc(), and pg_realloc().
Referenced by addBoundaryDependencies(), buildMatViewRefreshDependencies(), flagInhAttrs(), getCasts(), getDependencies(), getDomainConstraints(), getExtensionMembership(), getIndexes(), getProcLangs(), getRules(), getTableAttrs(), getTableDataFKConstraints(), getTypes(), makeTableDataInfo(), repairDomainConstraintMultiLoop(), repairTableAttrDefMultiLoop(), repairTableConstraintMultiLoop(), repairTypeFuncLoop(), and repairViewRuleMultiLoop().
{ if (dobj->nDeps >= dobj->allocDeps) { if (dobj->allocDeps <= 0) { dobj->allocDeps = 16; dobj->dependencies = (DumpId *) pg_malloc(dobj->allocDeps * sizeof(DumpId)); } else { dobj->allocDeps *= 2; dobj->dependencies = (DumpId *) pg_realloc(dobj->dependencies, dobj->allocDeps * sizeof(DumpId)); } } dobj->dependencies[dobj->nDeps++] = refId; }
void AssignDumpId | ( | DumpableObject * | dobj | ) |
Definition at line 412 of file common.c.
References _dumpableObject::allocDeps, allocedDumpIds, catalogIdMapValid, _dumpableObject::dependencies, _dumpableObject::dump, _dumpableObject::dumpId, _dumpableObject::ext_member, lastDumpId, _dumpableObject::name, _dumpableObject::nDeps, pg_malloc(), and pg_realloc().
Referenced by createBoundaryObjects(), flagInhAttrs(), getAggregates(), getBlobs(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDomainConstraints(), getEventTriggers(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getProcLangs(), getRules(), getTableAttrs(), getTables(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), and makeTableDataInfo().
{ dobj->dumpId = ++lastDumpId; dobj->name = NULL; /* must be set later */ dobj->namespace = NULL; /* may be set later */ dobj->dump = true; /* default assumption */ dobj->ext_member = false; /* default assumption */ dobj->dependencies = NULL; dobj->nDeps = 0; dobj->allocDeps = 0; while (dobj->dumpId >= allocedDumpIds) { int newAlloc; if (allocedDumpIds <= 0) { newAlloc = 256; dumpIdMap = (DumpableObject **) pg_malloc(newAlloc * sizeof(DumpableObject *)); } else { newAlloc = allocedDumpIds * 2; dumpIdMap = (DumpableObject **) pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *)); } memset(dumpIdMap + allocedDumpIds, 0, (newAlloc - allocedDumpIds) * sizeof(DumpableObject *)); allocedDumpIds = newAlloc; } dumpIdMap[dobj->dumpId] = dobj; /* mark catalogIdMap invalid, but don't rebuild it yet */ catalogIdMapValid = false; }
DumpId createDumpId | ( | void | ) |
Definition at line 456 of file common.c.
References lastDumpId.
Referenced by dumpACL(), dumpComment(), dumpCompositeTypeColComments(), dumpDatabase(), dumpEncoding(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpStdStrings(), dumpTableComment(), dumpTableSecLabel(), and dumpUserMappings().
{ return ++lastDumpId; }
Definition at line 739 of file common.c.
References findObjectByOid(), and numCollations.
Referenced by dumpCompositeType(), dumpDomain(), dumpRangeType(), and dumpTableSchema().
{ return (CollInfo *) findObjectByOid(oid, collinfoindex, numCollations); }
Definition at line 717 of file common.c.
References findObjectByOid(), and numFuncs.
Referenced by dumpCast(), dumpProcLang(), getCasts(), getProcLangs(), and getTypes().
{ return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs); }
NamespaceInfo* findNamespaceByOid | ( | Oid | oid | ) |
Definition at line 750 of file common.c.
References findObjectByOid(), and numNamespaces.
Referenced by findNamespace().
{ return (NamespaceInfo *) findObjectByOid(oid, nspinfoindex, numNamespaces); }
DumpableObject* findObjectByCatalogId | ( | CatalogId | catalogId | ) |
Definition at line 494 of file common.c.
References catalogIdMapValid, DOCatalogIdCompare(), free, getDumpableObjects(), numCatalogIds, CatalogId::oid, oidcmp, qsort, and CatalogId::tableoid.
Referenced by buildMatViewRefreshDependencies(), getDependencies(), and getExtensionMembership().
{ DumpableObject **low; DumpableObject **high; if (!catalogIdMapValid) { if (catalogIdMap) free(catalogIdMap); getDumpableObjects(&catalogIdMap, &numCatalogIds); if (numCatalogIds > 1) qsort((void *) catalogIdMap, numCatalogIds, sizeof(DumpableObject *), DOCatalogIdCompare); catalogIdMapValid = true; } /* * We could use bsearch() here, but the notational cruft of calling * bsearch is nearly as bad as doing it ourselves; and the generalized * bsearch function is noticeably slower as well. */ if (numCatalogIds <= 0) return NULL; low = catalogIdMap; high = catalogIdMap + (numCatalogIds - 1); while (low <= high) { DumpableObject **middle; int difference; middle = low + (high - low) / 2; /* comparison must match DOCatalogIdCompare, below */ difference = oidcmp((*middle)->catId.oid, catalogId.oid); if (difference == 0) difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid); if (difference == 0) return *middle; else if (difference < 0) low = middle + 1; else high = middle - 1; } return NULL; }
DumpableObject* findObjectByDumpId | ( | DumpId | dumpId | ) |
Definition at line 476 of file common.c.
References allocedDumpIds.
Referenced by binary_upgrade_extension_member(), BuildArchiveDependencies(), dumpConstraint(), dumpExtension(), findDumpableDependencies(), and findLoop().
{ if (dumpId <= 0 || dumpId >= allocedDumpIds) return NULL; /* out of range? */ return dumpIdMap[dumpId]; }
Definition at line 728 of file common.c.
References findObjectByOid(), and numOperators.
Referenced by convertOperatorReference().
{ return (OprInfo *) findObjectByOid(oid, oprinfoindex, numOperators); }
Definition at line 695 of file common.c.
References findObjectByOid(), and numTables.
Referenced by dumpSequence(), findParentsByOid(), getExtensionMembership(), getOwnedSeqs(), getRules(), getTableDataFKConstraints(), and selectDumpableType().
{ return (TableInfo *) findObjectByOid(oid, tblinfoindex, numTables); }
Definition at line 706 of file common.c.
References findObjectByOid(), and numTypes.
Referenced by dumpCast(), and getCasts().
{ return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes); }
Definition at line 3836 of file pg_dump.c.
References _aggInfo::aggfn, appendPQExpBuffer(), _funcInfo::argtypes, AssignDumpId(), atooid, binary_upgrade, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _funcInfo::dobj, ExecuteSqlQuery(), findNamespace(), g_last_builtin_oid, i, _funcInfo::lang, _dumpableObject::name, _funcInfo::nargs, NULL, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _funcInfo::proacl, _funcInfo::proiargs, _funcInfo::prorettype, Archive::remoteVersion, _funcInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); AggInfo *agginfo; int i_tableoid; int i_oid; int i_aggname; int i_aggnamespace; int i_pronargs; int i_proargtypes; int i_rolname; int i_aggacl; int i_proiargs; /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); /* * Find all user-defined aggregates. See comment in getFuncs() for the * rationale behind the filtering logic. */ if (fout->remoteVersion >= 80400) { appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, " "pronamespace AS aggnamespace, " "pronargs, proargtypes, " "pg_catalog.pg_get_function_identity_arguments(oid) AS proiargs," "(%s proowner) AS rolname, " "proacl AS aggacl " "FROM pg_proc p " "WHERE proisagg AND (" "pronamespace != " "(SELECT oid FROM pg_namespace " "WHERE nspname = 'pg_catalog')", username_subquery); if (binary_upgrade && fout->remoteVersion >= 90100) appendPQExpBuffer(query, " OR EXISTS(SELECT 1 FROM pg_depend WHERE " "classid = 'pg_proc'::regclass AND " "objid = p.oid AND " "refclassid = 'pg_extension'::regclass AND " "deptype = 'e')"); appendPQExpBuffer(query, ")"); } else if (fout->remoteVersion >= 80200) { appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, " "pronamespace AS aggnamespace, " "pronargs, proargtypes, " "NULL::text AS proiargs," "(%s proowner) AS rolname, " "proacl AS aggacl " "FROM pg_proc p " "WHERE proisagg AND (" "pronamespace != " "(SELECT oid FROM pg_namespace " "WHERE nspname = 'pg_catalog'))", username_subquery); } else if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, " "pronamespace AS aggnamespace, " "CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, " "proargtypes, " "NULL::text AS proiargs, " "(%s proowner) AS rolname, " "proacl AS aggacl " "FROM pg_proc " "WHERE proisagg " "AND pronamespace != " "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')", username_subquery); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT tableoid, oid, aggname, " "0::oid AS aggnamespace, " "CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, " "aggbasetype AS proargtypes, " "NULL::text AS proiargs, " "(%s aggowner) AS rolname, " "'{=X}' AS aggacl " "FROM pg_aggregate " "where oid > '%u'::oid", username_subquery, g_last_builtin_oid); } else { appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_aggregate') AS tableoid, " "oid, aggname, " "0::oid AS aggnamespace, " "CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, " "aggbasetype AS proargtypes, " "NULL::text AS proiargs, " "(%s aggowner) AS rolname, " "'{=X}' AS aggacl " "FROM pg_aggregate " "where oid > '%u'::oid", username_subquery, g_last_builtin_oid); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numAggs = ntups; agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_aggname = PQfnumber(res, "aggname"); i_aggnamespace = PQfnumber(res, "aggnamespace"); i_pronargs = PQfnumber(res, "pronargs"); i_proargtypes = PQfnumber(res, "proargtypes"); i_rolname = PQfnumber(res, "rolname"); i_aggacl = PQfnumber(res, "aggacl"); i_proiargs = PQfnumber(res, "proiargs"); for (i = 0; i < ntups; i++) { agginfo[i].aggfn.dobj.objType = DO_AGG; agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&agginfo[i].aggfn.dobj); agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname)); agginfo[i].aggfn.dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_aggnamespace)), agginfo[i].aggfn.dobj.catId.oid); agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); if (strlen(agginfo[i].aggfn.rolname) == 0) write_msg(NULL, "WARNING: owner of aggregate function \"%s\" appears to be invalid\n", agginfo[i].aggfn.dobj.name); agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */ agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */ agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl)); agginfo[i].aggfn.proiargs = pg_strdup(PQgetvalue(res, i, i_proiargs)); agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs)); if (agginfo[i].aggfn.nargs == 0) agginfo[i].aggfn.argtypes = NULL; else { agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid)); if (fout->remoteVersion >= 70300) parseOidArray(PQgetvalue(res, i, i_proargtypes), agginfo[i].aggfn.argtypes, agginfo[i].aggfn.nargs); else /* it's just aggbasetype */ agginfo[i].aggfn.argtypes[0] = atooid(PQgetvalue(res, i, i_proargtypes)); } /* Decide whether we want to dump it */ selectDumpableObject(&(agginfo[i].aggfn.dobj)); } PQclear(res); destroyPQExpBuffer(query); return agginfo; }
Definition at line 5988 of file pg_dump.c.
References addObjectDependency(), appendPQExpBuffer(), AssignDumpId(), atooid, _castInfo::castcontext, _castInfo::castfunc, _castInfo::castmethod, _castInfo::castsource, _castInfo::casttarget, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _funcInfo::dobj, _castInfo::dobj, _dumpableObject::dumpId, ExecuteSqlQuery(), findFuncByOid(), findTypeByOid(), i, initPQExpBuffer(), _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, OidIsValid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectSourceSchema(), and CatalogId::tableoid.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); CastInfo *castinfo; int i_tableoid; int i_oid; int i_castsource; int i_casttarget; int i_castfunc; int i_castcontext; int i_castmethod; /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); if (fout->remoteVersion >= 80400) { appendPQExpBuffer(query, "SELECT tableoid, oid, " "castsource, casttarget, castfunc, castcontext, " "castmethod " "FROM pg_cast ORDER BY 3,4"); } else if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT tableoid, oid, " "castsource, casttarget, castfunc, castcontext, " "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod " "FROM pg_cast ORDER BY 3,4"); } else { appendPQExpBuffer(query, "SELECT 0 AS tableoid, p.oid, " "t1.oid AS castsource, t2.oid AS casttarget, " "p.oid AS castfunc, 'e' AS castcontext, " "'f' AS castmethod " "FROM pg_type t1, pg_type t2, pg_proc p " "WHERE p.pronargs = 1 AND " "p.proargtypes[0] = t1.oid AND " "p.prorettype = t2.oid AND p.proname = t2.typname " "ORDER BY 3,4"); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numCasts = ntups; castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_castsource = PQfnumber(res, "castsource"); i_casttarget = PQfnumber(res, "casttarget"); i_castfunc = PQfnumber(res, "castfunc"); i_castcontext = PQfnumber(res, "castcontext"); i_castmethod = PQfnumber(res, "castmethod"); for (i = 0; i < ntups; i++) { PQExpBufferData namebuf; TypeInfo *sTypeInfo; TypeInfo *tTypeInfo; castinfo[i].dobj.objType = DO_CAST; castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&castinfo[i].dobj); castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource)); castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget)); castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc)); castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext)); castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod)); /* * Try to name cast as concatenation of typnames. This is only used * for purposes of sorting. If we fail to find either type, the name * will be an empty string. */ initPQExpBuffer(&namebuf); sTypeInfo = findTypeByOid(castinfo[i].castsource); tTypeInfo = findTypeByOid(castinfo[i].casttarget); if (sTypeInfo && tTypeInfo) appendPQExpBuffer(&namebuf, "%s %s", sTypeInfo->dobj.name, tTypeInfo->dobj.name); castinfo[i].dobj.name = namebuf.data; if (OidIsValid(castinfo[i].castfunc)) { /* * We need to make a dependency to ensure the function will be * dumped first. (In 7.3 and later the regular dependency * mechanism will handle this for us.) */ FuncInfo *funcInfo; funcInfo = findFuncByOid(castinfo[i].castfunc); if (funcInfo) addObjectDependency(&castinfo[i].dobj, funcInfo->dobj.dumpId); } } PQclear(res); destroyPQExpBuffer(query); return castinfo; }
Definition at line 3490 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _collInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _collInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query; CollInfo *collinfo; int i_tableoid; int i_oid; int i_collname; int i_collnamespace; int i_rolname; /* Collations didn't exist pre-9.1 */ if (fout->remoteVersion < 90100) { *numCollations = 0; return NULL; } query = createPQExpBuffer(); /* * find all collations, including builtin collations; we filter out * system-defined collations at dump-out time. */ /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT tableoid, oid, collname, " "collnamespace, " "(%s collowner) AS rolname " "FROM pg_collation", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numCollations = ntups; collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_collname = PQfnumber(res, "collname"); i_collnamespace = PQfnumber(res, "collnamespace"); i_rolname = PQfnumber(res, "rolname"); for (i = 0; i < ntups; i++) { collinfo[i].dobj.objType = DO_COLLATION; collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&collinfo[i].dobj); collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname)); collinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_collnamespace)), collinfo[i].dobj.catId.oid); collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); /* Decide whether we want to dump it */ selectDumpableObject(&(collinfo[i].dobj)); } PQclear(res); destroyPQExpBuffer(query); return collinfo; }
Definition at line 5191 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _constraintInfo::dobj, _tableInfo::dobj, _dumpableObject::dump, ExecuteSqlQuery(), g_verbose, _tableInfo::hastriggers, i, _dumpableObject::name, NULL, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, resetPQExpBuffer(), selectSourceSchema(), _constraintInfo::separate, CatalogId::tableoid, and write_msg().
Referenced by getSchemaData().
{ int i, j; ConstraintInfo *constrinfo; PQExpBuffer query; PGresult *res; int i_contableoid, i_conoid, i_conname, i_confrelid, i_condef; int ntups; /* pg_constraint was created in 7.3, so nothing to do if older */ if (fout->remoteVersion < 70300) return; query = createPQExpBuffer(); for (i = 0; i < numTables; i++) { TableInfo *tbinfo = &tblinfo[i]; if (!tbinfo->hastriggers || !tbinfo->dobj.dump) continue; if (g_verbose) write_msg(NULL, "reading foreign key constraints for table \"%s\"\n", tbinfo->dobj.name); /* * select table schema to ensure constraint expr is qualified if * needed */ selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); resetPQExpBuffer(query); appendPQExpBuffer(query, "SELECT tableoid, oid, conname, confrelid, " "pg_catalog.pg_get_constraintdef(oid) AS condef " "FROM pg_catalog.pg_constraint " "WHERE conrelid = '%u'::pg_catalog.oid " "AND contype = 'f'", tbinfo->dobj.catId.oid); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); i_contableoid = PQfnumber(res, "tableoid"); i_conoid = PQfnumber(res, "oid"); i_conname = PQfnumber(res, "conname"); i_confrelid = PQfnumber(res, "confrelid"); i_condef = PQfnumber(res, "condef"); constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo)); for (j = 0; j < ntups; j++) { constrinfo[j].dobj.objType = DO_FK_CONSTRAINT; constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid)); constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid)); AssignDumpId(&constrinfo[j].dobj); constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname)); constrinfo[j].dobj.namespace = tbinfo->dobj.namespace; constrinfo[j].contable = tbinfo; constrinfo[j].condomain = NULL; constrinfo[j].contype = 'f'; constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef)); constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid)); constrinfo[j].conindex = 0; constrinfo[j].condeferrable = false; constrinfo[j].condeferred = false; constrinfo[j].conislocal = true; constrinfo[j].separate = true; } PQclear(res); } destroyPQExpBuffer(query); }
Definition at line 3571 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _convInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _convInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); ConvInfo *convinfo; int i_tableoid; int i_oid; int i_conname; int i_connamespace; int i_rolname; /* Conversions didn't exist pre-7.3 */ if (fout->remoteVersion < 70300) { *numConversions = 0; return NULL; } /* * find all conversions, including builtin conversions; we filter out * system-defined conversions at dump-out time. */ /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " "connamespace, " "(%s conowner) AS rolname " "FROM pg_conversion", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numConversions = ntups; convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_conname = PQfnumber(res, "conname"); i_connamespace = PQfnumber(res, "connamespace"); i_rolname = PQfnumber(res, "rolname"); for (i = 0; i < ntups; i++) { convinfo[i].dobj.objType = DO_CONVERSION; convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&convinfo[i].dobj); convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname)); convinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_connamespace)), convinfo[i].dobj.catId.oid); convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); /* Decide whether we want to dump it */ selectDumpableObject(&(convinfo[i].dobj)); } PQclear(res); destroyPQExpBuffer(query); return convinfo; }
DefaultACLInfo* getDefaultACLs | ( | Archive * | fout, | |
int * | numDefaultACLs | |||
) |
Definition at line 7224 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _defaultACLInfo::defaclacl, _defaultACLInfo::defaclobjtype, _defaultACLInfo::defaclrole, destroyPQExpBuffer(), _defaultACLInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, InvalidOid, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectDumpableDefaultACL(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ DefaultACLInfo *daclinfo; PQExpBuffer query; PGresult *res; int i_oid; int i_tableoid; int i_defaclrole; int i_defaclnamespace; int i_defaclobjtype; int i_defaclacl; int i, ntups; if (fout->remoteVersion < 90000) { *numDefaultACLs = 0; return NULL; } query = createPQExpBuffer(); /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT oid, tableoid, " "(%s defaclrole) AS defaclrole, " "defaclnamespace, " "defaclobjtype, " "defaclacl " "FROM pg_default_acl", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numDefaultACLs = ntups; daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo)); i_oid = PQfnumber(res, "oid"); i_tableoid = PQfnumber(res, "tableoid"); i_defaclrole = PQfnumber(res, "defaclrole"); i_defaclnamespace = PQfnumber(res, "defaclnamespace"); i_defaclobjtype = PQfnumber(res, "defaclobjtype"); i_defaclacl = PQfnumber(res, "defaclacl"); for (i = 0; i < ntups; i++) { Oid nspid = atooid(PQgetvalue(res, i, i_defaclnamespace)); daclinfo[i].dobj.objType = DO_DEFAULT_ACL; daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&daclinfo[i].dobj); /* cheesy ... is it worth coming up with a better object name? */ daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype)); if (nspid != InvalidOid) daclinfo[i].dobj.namespace = findNamespace(fout, nspid, daclinfo[i].dobj.catId.oid); else daclinfo[i].dobj.namespace = NULL; daclinfo[i].defaclrole = pg_strdup(PQgetvalue(res, i, i_defaclrole)); daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype)); daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl)); /* Decide whether we want to dump it */ selectDumpableDefaultACL(&(daclinfo[i])); } PQclear(res); destroyPQExpBuffer(query); return daclinfo; }
void getDumpableObjects | ( | DumpableObject *** | objs, | |
int * | numObjs | |||
) |
Definition at line 626 of file common.c.
References allocedDumpIds, i, and pg_malloc().
Referenced by findObjectByCatalogId(), getTableDataFKConstraints(), and main().
{ int i, j; *objs = (DumpableObject **) pg_malloc(allocedDumpIds * sizeof(DumpableObject *)); j = 0; for (i = 1; i < allocedDumpIds; i++) { if (dumpIdMap[i]) (*objs)[j++] = dumpIdMap[i]; } *numObjs = j; }
EventTriggerInfo* getEventTriggers | ( | Archive * | fout, | |
int * | numEventTriggers | |||
) |
Definition at line 5747 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _evttriggerInfo::dobj, _evttriggerInfo::evtenabled, _evttriggerInfo::evtevent, _evttriggerInfo::evtfname, _evttriggerInfo::evtname, _evttriggerInfo::evtowner, _evttriggerInfo::evttags, ExecuteSqlQuery(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectSourceSchema(), CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ int i; PQExpBuffer query = createPQExpBuffer(); PGresult *res; EventTriggerInfo *evtinfo; int i_tableoid, i_oid, i_evtname, i_evtevent, i_evtowner, i_evttags, i_evtfname, i_evtenabled; int ntups; /* Before 9.3, there are no event triggers */ if (fout->remoteVersion < 90300) { *numEventTriggers = 0; return NULL; } /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT e.tableoid, e.oid, evtname, evtenabled, " "evtevent, (%s evtowner) AS evtowner, " "array_to_string(array(" "select quote_literal(x) " " from unnest(evttags) as t(x)), ', ') as evttags, " "e.evtfoid::regproc as evtfname " "FROM pg_event_trigger e " "ORDER BY e.oid", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numEventTriggers = ntups; evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_evtname = PQfnumber(res, "evtname"); i_evtevent = PQfnumber(res, "evtevent"); i_evtowner = PQfnumber(res, "evtowner"); i_evttags = PQfnumber(res, "evttags"); i_evtfname = PQfnumber(res, "evtfname"); i_evtenabled = PQfnumber(res, "evtenabled"); for (i = 0; i < ntups; i++) { evtinfo[i].dobj.objType = DO_EVENT_TRIGGER; evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&evtinfo[i].dobj); evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname)); evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname)); evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent)); evtinfo[i].evtowner = pg_strdup(PQgetvalue(res, i, i_evtowner)); evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags)); evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname)); evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled)); } PQclear(res); destroyPQExpBuffer(query); return evtinfo; }
void getExtensionMembership | ( | Archive * | fout, | |
ExtensionInfo | extinfo[], | |||
int | numExtensions | |||
) |
Definition at line 14499 of file pg_dump.c.
References addObjectDependency(), appendPQExpBuffer(), atooid, binary_upgrade, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _tableInfo::dataObj, destroyPQExpBuffer(), _tableInfo::dobj, _extensionInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, ExecuteSqlQuery(), _dumpableObject::ext_member, _extensionInfo::extcondition, _extensionInfo::extconfig, _tableDataInfo::filtercond, findObjectByCatalogId(), findTableByOid(), free, SimpleOidList::head, i, makeTableDataInfo(), NULL, CatalogId::oid, parsePGArray(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), selectSourceSchema(), simple_oid_list_member(), and CatalogId::tableoid.
Referenced by getSchemaData().
{ PQExpBuffer query; PGresult *res; int ntups, i; int i_classid, i_objid, i_refclassid, i_refobjid; DumpableObject *dobj, *refdobj; /* Nothing to do if no extensions */ if (numExtensions == 0) return; /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); query = createPQExpBuffer(); /* refclassid constraint is redundant but may speed the search */ appendPQExpBuffer(query, "SELECT " "classid, objid, refclassid, refobjid " "FROM pg_depend " "WHERE refclassid = 'pg_extension'::regclass " "AND deptype = 'e' " "ORDER BY 3,4"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); i_classid = PQfnumber(res, "classid"); i_objid = PQfnumber(res, "objid"); i_refclassid = PQfnumber(res, "refclassid"); i_refobjid = PQfnumber(res, "refobjid"); /* * Since we ordered the SELECT by referenced ID, we can expect that * multiple entries for the same extension will appear together; this * saves on searches. */ refdobj = NULL; for (i = 0; i < ntups; i++) { CatalogId objId; CatalogId refobjId; objId.tableoid = atooid(PQgetvalue(res, i, i_classid)); objId.oid = atooid(PQgetvalue(res, i, i_objid)); refobjId.tableoid = atooid(PQgetvalue(res, i, i_refclassid)); refobjId.oid = atooid(PQgetvalue(res, i, i_refobjid)); if (refdobj == NULL || refdobj->catId.tableoid != refobjId.tableoid || refdobj->catId.oid != refobjId.oid) refdobj = findObjectByCatalogId(refobjId); /* * Failure to find objects mentioned in pg_depend is not unexpected, * since for example we don't collect info about TOAST tables. */ if (refdobj == NULL) { #ifdef NOT_USED fprintf(stderr, "no referenced object %u %u\n", refobjId.tableoid, refobjId.oid); #endif continue; } dobj = findObjectByCatalogId(objId); if (dobj == NULL) { #ifdef NOT_USED fprintf(stderr, "no referencing object %u %u\n", objId.tableoid, objId.oid); #endif continue; } /* Record dependency so that getDependencies needn't repeat this */ addObjectDependency(dobj, refdobj->dumpId); dobj->ext_member = true; /* * Normally, mark the member object as not to be dumped. But in * binary upgrades, we still dump the members individually, since the * idea is to exactly reproduce the database contents rather than * replace the extension contents with something different. */ if (!binary_upgrade) dobj->dump = false; else dobj->dump = refdobj->dump; } PQclear(res); /* * Now identify extension configuration tables and create TableDataInfo * objects for them, ensuring their data will be dumped even though the * tables themselves won't be. * * Note that we create TableDataInfo objects even in schemaOnly mode, ie, * user data in a configuration table is treated like schema data. This * seems appropriate since system data in a config table would get * reloaded by CREATE EXTENSION. */ for (i = 0; i < numExtensions; i++) { ExtensionInfo *curext = &(extinfo[i]); char *extconfig = curext->extconfig; char *extcondition = curext->extcondition; char **extconfigarray = NULL; char **extconditionarray = NULL; int nconfigitems; int nconditionitems; if (parsePGArray(extconfig, &extconfigarray, &nconfigitems) && parsePGArray(extcondition, &extconditionarray, &nconditionitems) && nconfigitems == nconditionitems) { int j; for (j = 0; j < nconfigitems; j++) { TableInfo *configtbl; Oid configtbloid = atooid(extconfigarray[j]); bool dumpobj = curext->dobj.dump; configtbl = findTableByOid(configtbloid); if (configtbl == NULL) continue; /* * Tables of not-to-be-dumped extensions shouldn't be dumped * unless the table or its schema is explicitly included */ if (!curext->dobj.dump) { /* check table explicitly requested */ if (table_include_oids.head != NULL && simple_oid_list_member(&table_include_oids, configtbloid)) dumpobj = true; /* check table's schema explicitly requested */ if (configtbl->dobj.namespace->dobj.dump) dumpobj = true; } /* check table excluded by an exclusion switch */ if (table_exclude_oids.head != NULL && simple_oid_list_member(&table_exclude_oids, configtbloid)) dumpobj = false; /* check schema excluded by an exclusion switch */ if (simple_oid_list_member(&schema_exclude_oids, configtbl->dobj.namespace->dobj.catId.oid)) dumpobj = false; if (dumpobj) { /* * Note: config tables are dumped without OIDs regardless of * the --oids setting. This is because row filtering * conditions aren't compatible with dumping OIDs. */ makeTableDataInfo(configtbl, false); if (configtbl->dataObj != NULL) { if (strlen(extconditionarray[j]) > 0) configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]); } } } } if (extconfigarray) free(extconfigarray); if (extconditionarray) free(extconditionarray); } destroyPQExpBuffer(query); }
ExtensionInfo* getExtensions | ( | Archive * | fout, | |
int * | numExtensions | |||
) |
Definition at line 3023 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _extensionInfo::dobj, ExecuteSqlQuery(), _extensionInfo::extcondition, _extensionInfo::extconfig, _extensionInfo::extversion, i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _extensionInfo::relocatable, Archive::remoteVersion, selectDumpableExtension(), selectSourceSchema(), and CatalogId::tableoid.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query; ExtensionInfo *extinfo; int i_tableoid; int i_oid; int i_extname; int i_nspname; int i_extrelocatable; int i_extversion; int i_extconfig; int i_extcondition; /* * Before 9.1, there are no extensions. */ if (fout->remoteVersion < 90100) { *numExtensions = 0; return NULL; } query = createPQExpBuffer(); /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT x.tableoid, x.oid, " "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition " "FROM pg_extension x " "JOIN pg_namespace n ON n.oid = x.extnamespace"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_extname = PQfnumber(res, "extname"); i_nspname = PQfnumber(res, "nspname"); i_extrelocatable = PQfnumber(res, "extrelocatable"); i_extversion = PQfnumber(res, "extversion"); i_extconfig = PQfnumber(res, "extconfig"); i_extcondition = PQfnumber(res, "extcondition"); for (i = 0; i < ntups; i++) { extinfo[i].dobj.objType = DO_EXTENSION; extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&extinfo[i].dobj); extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname)); extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname)); extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't'; extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion)); extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig)); extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition)); /* Decide whether we want to dump it */ selectDumpableExtension(&(extinfo[i])); } PQclear(res); destroyPQExpBuffer(query); *numExtensions = ntups; return extinfo; }
Definition at line 7028 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _fdwInfo::dobj, ExecuteSqlQuery(), _fdwInfo::fdwacl, _fdwInfo::fdwhandler, _fdwInfo::fdwoptions, _fdwInfo::fdwvalidator, i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _fdwInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); FdwInfo *fdwinfo; int i_tableoid; int i_oid; int i_fdwname; int i_rolname; int i_fdwhandler; int i_fdwvalidator; int i_fdwacl; int i_fdwoptions; /* Before 8.4, there are no foreign-data wrappers */ if (fout->remoteVersion < 80400) { *numForeignDataWrappers = 0; return NULL; } /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); if (fout->remoteVersion >= 90100) { appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, " "(%s fdwowner) AS rolname, " "fdwhandler::pg_catalog.regproc, " "fdwvalidator::pg_catalog.regproc, fdwacl, " "array_to_string(ARRAY(" "SELECT quote_ident(option_name) || ' ' || " "quote_literal(option_value) " "FROM pg_options_to_table(fdwoptions) " "ORDER BY option_name" "), E',\n ') AS fdwoptions " "FROM pg_foreign_data_wrapper", username_subquery); } else { appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, " "(%s fdwowner) AS rolname, " "'-' AS fdwhandler, " "fdwvalidator::pg_catalog.regproc, fdwacl, " "array_to_string(ARRAY(" "SELECT quote_ident(option_name) || ' ' || " "quote_literal(option_value) " "FROM pg_options_to_table(fdwoptions) " "ORDER BY option_name" "), E',\n ') AS fdwoptions " "FROM pg_foreign_data_wrapper", username_subquery); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numForeignDataWrappers = ntups; fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_fdwname = PQfnumber(res, "fdwname"); i_rolname = PQfnumber(res, "rolname"); i_fdwhandler = PQfnumber(res, "fdwhandler"); i_fdwvalidator = PQfnumber(res, "fdwvalidator"); i_fdwacl = PQfnumber(res, "fdwacl"); i_fdwoptions = PQfnumber(res, "fdwoptions"); for (i = 0; i < ntups; i++) { fdwinfo[i].dobj.objType = DO_FDW; fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&fdwinfo[i].dobj); fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname)); fdwinfo[i].dobj.namespace = NULL; fdwinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler)); fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator)); fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions)); fdwinfo[i].fdwacl = pg_strdup(PQgetvalue(res, i, i_fdwacl)); /* Decide whether we want to dump it */ selectDumpableObject(&(fdwinfo[i].dobj)); } PQclear(res); destroyPQExpBuffer(query); return fdwinfo; }
ForeignServerInfo* getForeignServers | ( | Archive * | fout, | |
int * | numForeignServers | |||
) |
Definition at line 7134 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _foreignServerInfo::dobj, ExecuteSqlQuery(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _foreignServerInfo::rolname, selectDumpableObject(), selectSourceSchema(), _foreignServerInfo::srvacl, _foreignServerInfo::srvfdw, _foreignServerInfo::srvoptions, _foreignServerInfo::srvtype, _foreignServerInfo::srvversion, CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); ForeignServerInfo *srvinfo; int i_tableoid; int i_oid; int i_srvname; int i_rolname; int i_srvfdw; int i_srvtype; int i_srvversion; int i_srvacl; int i_srvoptions; /* Before 8.4, there are no foreign servers */ if (fout->remoteVersion < 80400) { *numForeignServers = 0; return NULL; } /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, " "(%s srvowner) AS rolname, " "srvfdw, srvtype, srvversion, srvacl," "array_to_string(ARRAY(" "SELECT quote_ident(option_name) || ' ' || " "quote_literal(option_value) " "FROM pg_options_to_table(srvoptions) " "ORDER BY option_name" "), E',\n ') AS srvoptions " "FROM pg_foreign_server", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numForeignServers = ntups; srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_srvname = PQfnumber(res, "srvname"); i_rolname = PQfnumber(res, "rolname"); i_srvfdw = PQfnumber(res, "srvfdw"); i_srvtype = PQfnumber(res, "srvtype"); i_srvversion = PQfnumber(res, "srvversion"); i_srvacl = PQfnumber(res, "srvacl"); i_srvoptions = PQfnumber(res, "srvoptions"); for (i = 0; i < ntups; i++) { srvinfo[i].dobj.objType = DO_FOREIGN_SERVER; srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&srvinfo[i].dobj); srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname)); srvinfo[i].dobj.namespace = NULL; srvinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw)); srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype)); srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion)); srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions)); srvinfo[i].srvacl = pg_strdup(PQgetvalue(res, i, i_srvacl)); /* Decide whether we want to dump it */ selectDumpableObject(&(srvinfo[i].dobj)); } PQclear(res); destroyPQExpBuffer(query); return srvinfo; }
Definition at line 4015 of file pg_dump.c.
References appendPQExpBuffer(), _funcInfo::argtypes, AssignDumpId(), atooid, binary_upgrade, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _funcInfo::dobj, ExecuteSqlQuery(), findNamespace(), g_last_builtin_oid, i, _funcInfo::lang, _dumpableObject::name, _funcInfo::nargs, NULL, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_malloc(), pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _funcInfo::proacl, _funcInfo::proiargs, _funcInfo::prorettype, Archive::remoteVersion, _funcInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); FuncInfo *finfo; int i_tableoid; int i_oid; int i_proname; int i_pronamespace; int i_rolname; int i_prolang; int i_pronargs; int i_proargtypes; int i_prorettype; int i_proacl; int i_proiargs; /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); /* * Find all user-defined functions. Normally we can exclude functions in * pg_catalog, which is worth doing since there are several thousand of * 'em. However, there are some extensions that create functions in * pg_catalog. In normal dumps we can still ignore those --- but in * binary-upgrade mode, we must dump the member objects of the extension, * so be sure to fetch any such functions. * * Also, in 9.2 and up, exclude functions that are internally dependent on * something else, since presumably those will be created as a result of * creating the something else. This currently only acts to suppress * constructor functions for range types. Note that this is OK only * because the constructors don't have any dependencies the range type * doesn't have; otherwise we might not get creation ordering correct. */ if (fout->remoteVersion >= 80400) { appendPQExpBuffer(query, "SELECT tableoid, oid, proname, prolang, " "pronargs, proargtypes, prorettype, proacl, " "pronamespace, " "pg_catalog.pg_get_function_identity_arguments(oid) AS proiargs," "(%s proowner) AS rolname " "FROM pg_proc p " "WHERE NOT proisagg AND (" "pronamespace != " "(SELECT oid FROM pg_namespace " "WHERE nspname = 'pg_catalog')", username_subquery); if (fout->remoteVersion >= 90200) appendPQExpBuffer(query, "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " "WHERE classid = 'pg_proc'::regclass AND " "objid = p.oid AND deptype = 'i')"); if (binary_upgrade && fout->remoteVersion >= 90100) appendPQExpBuffer(query, "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " "classid = 'pg_proc'::regclass AND " "objid = p.oid AND " "refclassid = 'pg_extension'::regclass AND " "deptype = 'e')"); appendPQExpBuffer(query, ")"); } else if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT tableoid, oid, proname, prolang, " "pronargs, proargtypes, prorettype, proacl, " "pronamespace, " "NULL::text AS proiargs," "(%s proowner) AS rolname " "FROM pg_proc p " "WHERE NOT proisagg AND (" "pronamespace != " "(SELECT oid FROM pg_namespace " "WHERE nspname = 'pg_catalog'))", username_subquery); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT tableoid, oid, proname, prolang, " "pronargs, proargtypes, prorettype, " "'{=X}' AS proacl, " "0::oid AS pronamespace, " "NULL::text AS proiargs," "(%s proowner) AS rolname " "FROM pg_proc " "WHERE pg_proc.oid > '%u'::oid", username_subquery, g_last_builtin_oid); } else { appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class " " WHERE relname = 'pg_proc') AS tableoid, " "oid, proname, prolang, " "pronargs, proargtypes, prorettype, " "'{=X}' AS proacl, " "0::oid AS pronamespace, " "NULL::text AS proiargs," "(%s proowner) AS rolname " "FROM pg_proc " "where pg_proc.oid > '%u'::oid", username_subquery, g_last_builtin_oid); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numFuncs = ntups; finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_proname = PQfnumber(res, "proname"); i_pronamespace = PQfnumber(res, "pronamespace"); i_rolname = PQfnumber(res, "rolname"); i_prolang = PQfnumber(res, "prolang"); i_pronargs = PQfnumber(res, "pronargs"); i_proargtypes = PQfnumber(res, "proargtypes"); i_prorettype = PQfnumber(res, "prorettype"); i_proacl = PQfnumber(res, "proacl"); i_proiargs = PQfnumber(res, "proiargs"); for (i = 0; i < ntups; i++) { finfo[i].dobj.objType = DO_FUNC; finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&finfo[i].dobj); finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname)); finfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_pronamespace)), finfo[i].dobj.catId.oid); finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang)); finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype)); finfo[i].proiargs = pg_strdup(PQgetvalue(res, i, i_proiargs)); finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl)); finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs)); if (finfo[i].nargs == 0) finfo[i].argtypes = NULL; else { finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid)); parseOidArray(PQgetvalue(res, i, i_proargtypes), finfo[i].argtypes, finfo[i].nargs); } /* Decide whether we want to dump it */ selectDumpableObject(&(finfo[i].dobj)); if (strlen(finfo[i].rolname) == 0) write_msg(NULL, "WARNING: owner of function \"%s\" appears to be invalid\n", finfo[i].dobj.name); } PQclear(res); destroyPQExpBuffer(query); return finfo; }
Definition at line 4843 of file pg_dump.c.
References addObjectDependency(), appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _constraintInfo::dobj, _indxInfo::dobj, _tableInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, ExecuteSqlQuery(), g_verbose, _tableInfo::hasindex, i, INDEX_MAX_KEYS, _indxInfo::indexconstraint, _indxInfo::indexdef, _indxInfo::indextable, _indxInfo::indisclustered, _indxInfo::indkeys, _indxInfo::indnkeys, _dumpableObject::name, NULL, _dumpableObject::objType, CatalogId::oid, _indxInfo::options, parseOidArray(), pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, RELKIND_MATVIEW, RELKIND_RELATION, _indxInfo::relpages, Archive::remoteVersion, resetPQExpBuffer(), selectSourceSchema(), _constraintInfo::separate, CatalogId::tableoid, _indxInfo::tablespace, and write_msg().
Referenced by getSchemaData().
{ int i, j; PQExpBuffer query = createPQExpBuffer(); PGresult *res; IndxInfo *indxinfo; ConstraintInfo *constrinfo; int i_tableoid, i_oid, i_indexname, i_indexdef, i_indnkeys, i_indkey, i_indisclustered, i_contype, i_conname, i_condeferrable, i_condeferred, i_contableoid, i_conoid, i_condef, i_tablespace, i_options, i_relpages; int ntups; for (i = 0; i < numTables; i++) { TableInfo *tbinfo = &tblinfo[i]; /* Only plain tables and materialized views have indexes. */ if (tbinfo->relkind != RELKIND_RELATION && tbinfo->relkind != RELKIND_MATVIEW) continue; if (!tbinfo->hasindex) continue; /* Ignore indexes of tables not to be dumped */ if (!tbinfo->dobj.dump) continue; if (g_verbose) write_msg(NULL, "reading indexes for table \"%s\"\n", tbinfo->dobj.name); /* Make sure we are in proper schema so indexdef is right */ selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); /* * The point of the messy-looking outer join is to find a constraint * that is related by an internal dependency link to the index. If we * find one, create a CONSTRAINT entry linked to the INDEX entry. We * assume an index won't have more than one internal dependency. * * As of 9.0 we don't need to look at pg_depend but can check for a * match to pg_constraint.conindid. The check on conrelid is * redundant but useful because that column is indexed while conindid * is not. */ resetPQExpBuffer(query); if (fout->remoteVersion >= 90000) { /* * the test on indisready is necessary in 9.2, and harmless in * earlier/later versions */ appendPQExpBuffer(query, "SELECT t.tableoid, t.oid, " "t.relname AS indexname, " "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, " "t.relnatts AS indnkeys, " "i.indkey, i.indisclustered, " "t.relpages, " "c.contype, c.conname, " "c.condeferrable, c.condeferred, " "c.tableoid AS contableoid, " "c.oid AS conoid, " "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, " "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, " "array_to_string(t.reloptions, ', ') AS options " "FROM pg_catalog.pg_index i " "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " "LEFT JOIN pg_catalog.pg_constraint c " "ON (i.indrelid = c.conrelid AND " "i.indexrelid = c.conindid AND " "c.contype IN ('p','u','x')) " "WHERE i.indrelid = '%u'::pg_catalog.oid " "AND i.indisvalid AND i.indisready " "ORDER BY indexname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 80200) { appendPQExpBuffer(query, "SELECT t.tableoid, t.oid, " "t.relname AS indexname, " "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, " "t.relnatts AS indnkeys, " "i.indkey, i.indisclustered, " "t.relpages, " "c.contype, c.conname, " "c.condeferrable, c.condeferred, " "c.tableoid AS contableoid, " "c.oid AS conoid, " "null AS condef, " "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, " "array_to_string(t.reloptions, ', ') AS options " "FROM pg_catalog.pg_index i " "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " "LEFT JOIN pg_catalog.pg_depend d " "ON (d.classid = t.tableoid " "AND d.objid = t.oid " "AND d.deptype = 'i') " "LEFT JOIN pg_catalog.pg_constraint c " "ON (d.refclassid = c.tableoid " "AND d.refobjid = c.oid) " "WHERE i.indrelid = '%u'::pg_catalog.oid " "AND i.indisvalid " "ORDER BY indexname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 80000) { appendPQExpBuffer(query, "SELECT t.tableoid, t.oid, " "t.relname AS indexname, " "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, " "t.relnatts AS indnkeys, " "i.indkey, i.indisclustered, " "t.relpages, " "c.contype, c.conname, " "c.condeferrable, c.condeferred, " "c.tableoid AS contableoid, " "c.oid AS conoid, " "null AS condef, " "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, " "null AS options " "FROM pg_catalog.pg_index i " "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " "LEFT JOIN pg_catalog.pg_depend d " "ON (d.classid = t.tableoid " "AND d.objid = t.oid " "AND d.deptype = 'i') " "LEFT JOIN pg_catalog.pg_constraint c " "ON (d.refclassid = c.tableoid " "AND d.refobjid = c.oid) " "WHERE i.indrelid = '%u'::pg_catalog.oid " "ORDER BY indexname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT t.tableoid, t.oid, " "t.relname AS indexname, " "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, " "t.relnatts AS indnkeys, " "i.indkey, i.indisclustered, " "t.relpages, " "c.contype, c.conname, " "c.condeferrable, c.condeferred, " "c.tableoid AS contableoid, " "c.oid AS conoid, " "null AS condef, " "NULL AS tablespace, " "null AS options " "FROM pg_catalog.pg_index i " "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " "LEFT JOIN pg_catalog.pg_depend d " "ON (d.classid = t.tableoid " "AND d.objid = t.oid " "AND d.deptype = 'i') " "LEFT JOIN pg_catalog.pg_constraint c " "ON (d.refclassid = c.tableoid " "AND d.refobjid = c.oid) " "WHERE i.indrelid = '%u'::pg_catalog.oid " "ORDER BY indexname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT t.tableoid, t.oid, " "t.relname AS indexname, " "pg_get_indexdef(i.indexrelid) AS indexdef, " "t.relnatts AS indnkeys, " "i.indkey, false AS indisclustered, " "t.relpages, " "CASE WHEN i.indisprimary THEN 'p'::char " "ELSE '0'::char END AS contype, " "t.relname AS conname, " "false AS condeferrable, " "false AS condeferred, " "0::oid AS contableoid, " "t.oid AS conoid, " "null AS condef, " "NULL AS tablespace, " "null AS options " "FROM pg_index i, pg_class t " "WHERE t.oid = i.indexrelid " "AND i.indrelid = '%u'::oid " "ORDER BY indexname", tbinfo->dobj.catId.oid); } else { appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_class') AS tableoid, " "t.oid, " "t.relname AS indexname, " "pg_get_indexdef(i.indexrelid) AS indexdef, " "t.relnatts AS indnkeys, " "i.indkey, false AS indisclustered, " "t.relpages, " "CASE WHEN i.indisprimary THEN 'p'::char " "ELSE '0'::char END AS contype, " "t.relname AS conname, " "false AS condeferrable, " "false AS condeferred, " "0::oid AS contableoid, " "t.oid AS conoid, " "null AS condef, " "NULL AS tablespace, " "null AS options " "FROM pg_index i, pg_class t " "WHERE t.oid = i.indexrelid " "AND i.indrelid = '%u'::oid " "ORDER BY indexname", tbinfo->dobj.catId.oid); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_indexname = PQfnumber(res, "indexname"); i_indexdef = PQfnumber(res, "indexdef"); i_indnkeys = PQfnumber(res, "indnkeys"); i_indkey = PQfnumber(res, "indkey"); i_indisclustered = PQfnumber(res, "indisclustered"); i_relpages = PQfnumber(res, "relpages"); i_contype = PQfnumber(res, "contype"); i_conname = PQfnumber(res, "conname"); i_condeferrable = PQfnumber(res, "condeferrable"); i_condeferred = PQfnumber(res, "condeferred"); i_contableoid = PQfnumber(res, "contableoid"); i_conoid = PQfnumber(res, "conoid"); i_condef = PQfnumber(res, "condef"); i_tablespace = PQfnumber(res, "tablespace"); i_options = PQfnumber(res, "options"); indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo)); constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo)); for (j = 0; j < ntups; j++) { char contype; indxinfo[j].dobj.objType = DO_INDEX; indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid)); indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid)); AssignDumpId(&indxinfo[j].dobj); indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname)); indxinfo[j].dobj.namespace = tbinfo->dobj.namespace; indxinfo[j].indextable = tbinfo; indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef)); indxinfo[j].indnkeys = atoi(PQgetvalue(res, j, i_indnkeys)); indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace)); indxinfo[j].options = pg_strdup(PQgetvalue(res, j, i_options)); /* * In pre-7.4 releases, indkeys may contain more entries than * indnkeys says (since indnkeys will be 1 for a functional * index). We don't actually care about this case since we don't * examine indkeys except for indexes associated with PRIMARY and * UNIQUE constraints, which are never functional indexes. But we * have to allocate enough space to keep parseOidArray from * complaining. */ indxinfo[j].indkeys = (Oid *) pg_malloc(INDEX_MAX_KEYS * sizeof(Oid)); parseOidArray(PQgetvalue(res, j, i_indkey), indxinfo[j].indkeys, INDEX_MAX_KEYS); indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't'); indxinfo[j].relpages = atoi(PQgetvalue(res, j, i_relpages)); contype = *(PQgetvalue(res, j, i_contype)); if (contype == 'p' || contype == 'u' || contype == 'x') { /* * If we found a constraint matching the index, create an * entry for it. * * In a pre-7.3 database, we take this path iff the index was * marked indisprimary. */ constrinfo[j].dobj.objType = DO_CONSTRAINT; constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid)); constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid)); AssignDumpId(&constrinfo[j].dobj); constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname)); constrinfo[j].dobj.namespace = tbinfo->dobj.namespace; constrinfo[j].contable = tbinfo; constrinfo[j].condomain = NULL; constrinfo[j].contype = contype; if (contype == 'x') constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef)); else constrinfo[j].condef = NULL; constrinfo[j].confrelid = InvalidOid; constrinfo[j].conindex = indxinfo[j].dobj.dumpId; constrinfo[j].condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't'; constrinfo[j].condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't'; constrinfo[j].conislocal = true; constrinfo[j].separate = true; indxinfo[j].indexconstraint = constrinfo[j].dobj.dumpId; /* If pre-7.3 DB, better make sure table comes first */ addObjectDependency(&constrinfo[j].dobj, tbinfo->dobj.dumpId); } else { /* Plain secondary index */ indxinfo[j].indexconstraint = 0; } } PQclear(res); } destroyPQExpBuffer(query); }
Definition at line 4793 of file pg_dump.c.
References appendPQExpBuffer(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), i, _inhInfo::inhparent, _inhInfo::inhrelid, pg_malloc(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), and selectSourceSchema().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); InhInfo *inhinfo; int i_inhrelid; int i_inhparent; /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); /* find all the inheritance information */ appendPQExpBuffer(query, "SELECT inhrelid, inhparent FROM pg_inherits"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numInherits = ntups; inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo)); i_inhrelid = PQfnumber(res, "inhrelid"); i_inhparent = PQfnumber(res, "inhparent"); for (i = 0; i < ntups; i++) { inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid)); inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent)); } PQclear(res); destroyPQExpBuffer(query); return inhinfo; }
DumpId getMaxDumpId | ( | void | ) |
Definition at line 465 of file common.c.
References lastDumpId.
Referenced by findDependencyLoops(), and TopoSort().
{ return lastDumpId; }
NamespaceInfo* getNamespaces | ( | Archive * | fout, | |
int * | numNamespaces | |||
) |
Definition at line 2881 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _namespaceInfo::dobj, ExecuteSqlQuery(), i, _dumpableObject::name, _namespaceInfo::nspacl, NULL, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _namespaceInfo::rolname, selectDumpableNamespace(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query; NamespaceInfo *nsinfo; int i_tableoid; int i_oid; int i_nspname; int i_rolname; int i_nspacl; /* * Before 7.3, there are no real namespaces; create two dummy entries, one * for user stuff and one for system stuff. */ if (fout->remoteVersion < 70300) { nsinfo = (NamespaceInfo *) pg_malloc(2 * sizeof(NamespaceInfo)); nsinfo[0].dobj.objType = DO_NAMESPACE; nsinfo[0].dobj.catId.tableoid = 0; nsinfo[0].dobj.catId.oid = 0; AssignDumpId(&nsinfo[0].dobj); nsinfo[0].dobj.name = pg_strdup("public"); nsinfo[0].rolname = pg_strdup(""); nsinfo[0].nspacl = pg_strdup(""); selectDumpableNamespace(&nsinfo[0]); nsinfo[1].dobj.objType = DO_NAMESPACE; nsinfo[1].dobj.catId.tableoid = 0; nsinfo[1].dobj.catId.oid = 1; AssignDumpId(&nsinfo[1].dobj); nsinfo[1].dobj.name = pg_strdup("pg_catalog"); nsinfo[1].rolname = pg_strdup(""); nsinfo[1].nspacl = pg_strdup(""); selectDumpableNamespace(&nsinfo[1]); *numNamespaces = 2; return nsinfo; } query = createPQExpBuffer(); /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); /* * we fetch all namespaces including system ones, so that every object we * read in can be linked to a containing namespace. */ appendPQExpBuffer(query, "SELECT tableoid, oid, nspname, " "(%s nspowner) AS rolname, " "nspacl FROM pg_namespace", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_nspname = PQfnumber(res, "nspname"); i_rolname = PQfnumber(res, "rolname"); i_nspacl = PQfnumber(res, "nspacl"); for (i = 0; i < ntups; i++) { nsinfo[i].dobj.objType = DO_NAMESPACE; nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&nsinfo[i].dobj); nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname)); nsinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); nsinfo[i].nspacl = pg_strdup(PQgetvalue(res, i, i_nspacl)); /* Decide whether to dump this namespace */ selectDumpableNamespace(&nsinfo[i]); if (strlen(nsinfo[i].rolname) == 0) write_msg(NULL, "WARNING: owner of schema \"%s\" appears to be invalid\n", nsinfo[i].dobj.name); } PQclear(res); destroyPQExpBuffer(query); *numNamespaces = ntups; return nsinfo; }
OpclassInfo* getOpclasses | ( | Archive * | fout, | |
int * | numOpclasses | |||
) |
Definition at line 3650 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _opclassInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, NULL, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _opclassInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); OpclassInfo *opcinfo; int i_tableoid; int i_oid; int i_opcname; int i_opcnamespace; int i_rolname; /* * find all opclasses, including builtin opclasses; we filter out * system-defined opclasses at dump-out time. */ /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, " "opcnamespace, " "(%s opcowner) AS rolname " "FROM pg_opclass", username_subquery); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, " "0::oid AS opcnamespace, " "''::name AS rolname " "FROM pg_opclass"); } else { appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_opclass') AS tableoid, " "oid, opcname, " "0::oid AS opcnamespace, " "''::name AS rolname " "FROM pg_opclass"); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numOpclasses = ntups; opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_opcname = PQfnumber(res, "opcname"); i_opcnamespace = PQfnumber(res, "opcnamespace"); i_rolname = PQfnumber(res, "rolname"); for (i = 0; i < ntups; i++) { opcinfo[i].dobj.objType = DO_OPCLASS; opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&opcinfo[i].dobj); opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname)); opcinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_opcnamespace)), opcinfo[i].dobj.catId.oid); opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); /* Decide whether we want to dump it */ selectDumpableObject(&(opcinfo[i].dobj)); if (fout->remoteVersion >= 70300) { if (strlen(opcinfo[i].rolname) == 0) write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n", opcinfo[i].dobj.name); } } PQclear(res); destroyPQExpBuffer(query); return opcinfo; }
Definition at line 3381 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _oprInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, NULL, _dumpableObject::objType, CatalogId::oid, _oprInfo::oprcode, oprinfo, _oprInfo::oprkind, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _oprInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); OprInfo *oprinfo; int i_tableoid; int i_oid; int i_oprname; int i_oprnamespace; int i_rolname; int i_oprkind; int i_oprcode; /* * find all operators, including builtin operators; we filter out * system-defined operators at dump-out time. */ /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " "oprnamespace, " "(%s oprowner) AS rolname, " "oprkind, " "oprcode::oid AS oprcode " "FROM pg_operator", username_subquery); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " "0::oid AS oprnamespace, " "(%s oprowner) AS rolname, " "oprkind, " "oprcode::oid AS oprcode " "FROM pg_operator", username_subquery); } else { appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_operator') AS tableoid, " "oid, oprname, " "0::oid AS oprnamespace, " "(%s oprowner) AS rolname, " "oprkind, " "oprcode::oid AS oprcode " "FROM pg_operator", username_subquery); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numOprs = ntups; oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_oprname = PQfnumber(res, "oprname"); i_oprnamespace = PQfnumber(res, "oprnamespace"); i_rolname = PQfnumber(res, "rolname"); i_oprkind = PQfnumber(res, "oprkind"); i_oprcode = PQfnumber(res, "oprcode"); for (i = 0; i < ntups; i++) { oprinfo[i].dobj.objType = DO_OPERATOR; oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&oprinfo[i].dobj); oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname)); oprinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_oprnamespace)), oprinfo[i].dobj.catId.oid); oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0]; oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode)); /* Decide whether we want to dump it */ selectDumpableObject(&(oprinfo[i].dobj)); if (strlen(oprinfo[i].rolname) == 0) write_msg(NULL, "WARNING: owner of operator \"%s\" appears to be invalid\n", oprinfo[i].dobj.name); } PQclear(res); destroyPQExpBuffer(query); return oprinfo; }
OpfamilyInfo* getOpfamilies | ( | Archive * | fout, | |
int * | numOpfamilies | |||
) |
Definition at line 3748 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _opfamilyInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, NULL, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _opfamilyInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, username_subquery, and write_msg().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query; OpfamilyInfo *opfinfo; int i_tableoid; int i_oid; int i_opfname; int i_opfnamespace; int i_rolname; /* Before 8.3, there is no separate concept of opfamilies */ if (fout->remoteVersion < 80300) { *numOpfamilies = 0; return NULL; } query = createPQExpBuffer(); /* * find all opfamilies, including builtin opfamilies; we filter out * system-defined opfamilies at dump-out time. */ /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, " "opfnamespace, " "(%s opfowner) AS rolname " "FROM pg_opfamily", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numOpfamilies = ntups; opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_opfname = PQfnumber(res, "opfname"); i_opfnamespace = PQfnumber(res, "opfnamespace"); i_rolname = PQfnumber(res, "rolname"); for (i = 0; i < ntups; i++) { opfinfo[i].dobj.objType = DO_OPFAMILY; opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&opfinfo[i].dobj); opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname)); opfinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_opfnamespace)), opfinfo[i].dobj.catId.oid); opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); /* Decide whether we want to dump it */ selectDumpableObject(&(opfinfo[i].dobj)); if (fout->remoteVersion >= 70300) { if (strlen(opfinfo[i].rolname) == 0) write_msg(NULL, "WARNING: owner of operator family \"%s\" appears to be invalid\n", opfinfo[i].dobj.name); } } PQclear(res); destroyPQExpBuffer(query); return opfinfo; }
Definition at line 4759 of file pg_dump.c.
References _tableInfo::dobj, _dumpableObject::dump, findTableByOid(), i, _tableInfo::interesting, OidIsValid, and _tableInfo::owning_tab.
Referenced by getSchemaData().
{ int i; /* * Force sequences that are "owned" by table columns to be dumped whenever * their owning table is being dumped. */ for (i = 0; i < numTables; i++) { TableInfo *seqinfo = &tblinfo[i]; TableInfo *owning_tab; if (!OidIsValid(seqinfo->owning_tab)) continue; /* not an owned sequence */ if (seqinfo->dobj.dump) continue; /* no need to search */ owning_tab = findTableByOid(seqinfo->owning_tab); if (owning_tab && owning_tab->dobj.dump) { seqinfo->interesting = true; seqinfo->dobj.dump = true; } } }
ProcLangInfo* getProcLangs | ( | Archive * | fout, | |
int * | numProcLangs | |||
) |
Definition at line 5833 of file pg_dump.c.
References addObjectDependency(), appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _funcInfo::dobj, _procLangInfo::dobj, _dumpableObject::dumpId, ExecuteSqlQuery(), findFuncByOid(), i, _procLangInfo::lanacl, _procLangInfo::laninline, _procLangInfo::lanowner, _procLangInfo::lanplcallfoid, _procLangInfo::lanpltrusted, _procLangInfo::lanvalidator, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectSourceSchema(), CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); ProcLangInfo *planginfo; int i_tableoid; int i_oid; int i_lanname; int i_lanpltrusted; int i_lanplcallfoid; int i_laninline; int i_lanvalidator; int i_lanacl; int i_lanowner; /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); if (fout->remoteVersion >= 90000) { /* pg_language has a laninline column */ appendPQExpBuffer(query, "SELECT tableoid, oid, " "lanname, lanpltrusted, lanplcallfoid, " "laninline, lanvalidator, lanacl, " "(%s lanowner) AS lanowner " "FROM pg_language " "WHERE lanispl " "ORDER BY oid", username_subquery); } else if (fout->remoteVersion >= 80300) { /* pg_language has a lanowner column */ appendPQExpBuffer(query, "SELECT tableoid, oid, " "lanname, lanpltrusted, lanplcallfoid, " "lanvalidator, lanacl, " "(%s lanowner) AS lanowner " "FROM pg_language " "WHERE lanispl " "ORDER BY oid", username_subquery); } else if (fout->remoteVersion >= 80100) { /* Languages are owned by the bootstrap superuser, OID 10 */ appendPQExpBuffer(query, "SELECT tableoid, oid, *, " "(%s '10') AS lanowner " "FROM pg_language " "WHERE lanispl " "ORDER BY oid", username_subquery); } else if (fout->remoteVersion >= 70400) { /* Languages are owned by the bootstrap superuser, sysid 1 */ appendPQExpBuffer(query, "SELECT tableoid, oid, *, " "(%s '1') AS lanowner " "FROM pg_language " "WHERE lanispl " "ORDER BY oid", username_subquery); } else if (fout->remoteVersion >= 70100) { /* No clear notion of an owner at all before 7.4 ... */ appendPQExpBuffer(query, "SELECT tableoid, oid, * FROM pg_language " "WHERE lanispl " "ORDER BY oid"); } else { appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_language') AS tableoid, " "oid, * FROM pg_language " "WHERE lanispl " "ORDER BY oid"); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numProcLangs = ntups; planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_lanname = PQfnumber(res, "lanname"); i_lanpltrusted = PQfnumber(res, "lanpltrusted"); i_lanplcallfoid = PQfnumber(res, "lanplcallfoid"); /* these may fail and return -1: */ i_laninline = PQfnumber(res, "laninline"); i_lanvalidator = PQfnumber(res, "lanvalidator"); i_lanacl = PQfnumber(res, "lanacl"); i_lanowner = PQfnumber(res, "lanowner"); for (i = 0; i < ntups; i++) { planginfo[i].dobj.objType = DO_PROCLANG; planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&planginfo[i].dobj); planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname)); planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't'; planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid)); if (i_laninline >= 0) planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline)); else planginfo[i].laninline = InvalidOid; if (i_lanvalidator >= 0) planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator)); else planginfo[i].lanvalidator = InvalidOid; if (i_lanacl >= 0) planginfo[i].lanacl = pg_strdup(PQgetvalue(res, i, i_lanacl)); else planginfo[i].lanacl = pg_strdup("{=U}"); if (i_lanowner >= 0) planginfo[i].lanowner = pg_strdup(PQgetvalue(res, i, i_lanowner)); else planginfo[i].lanowner = pg_strdup(""); if (fout->remoteVersion < 70300) { /* * We need to make a dependency to ensure the function will be * dumped first. (In 7.3 and later the regular dependency * mechanism will handle this for us.) */ FuncInfo *funcInfo = findFuncByOid(planginfo[i].lanplcallfoid); if (funcInfo) addObjectDependency(&planginfo[i].dobj, funcInfo->dobj.dumpId); } } PQclear(res); destroyPQExpBuffer(query); return planginfo; }
Definition at line 5389 of file pg_dump.c.
References addObjectDependency(), appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _tableInfo::dobj, _ruleInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, _ruleInfo::ev_enabled, _ruleInfo::ev_type, ExecuteSqlQuery(), exit_horribly(), findTableByOid(), i, _ruleInfo::is_instead, _dumpableObject::name, NULL, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, RELKIND_MATVIEW, RELKIND_VIEW, _ruleInfo::reloptions, Archive::remoteVersion, _ruleInfo::ruletable, selectSourceSchema(), _ruleInfo::separate, and CatalogId::tableoid.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); RuleInfo *ruleinfo; int i_tableoid; int i_oid; int i_rulename; int i_ruletable; int i_ev_type; int i_is_instead; int i_ev_enabled; /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); if (fout->remoteVersion >= 80300) { appendPQExpBuffer(query, "SELECT " "tableoid, oid, rulename, " "ev_class AS ruletable, ev_type, is_instead, " "ev_enabled " "FROM pg_rewrite " "ORDER BY oid"); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT " "tableoid, oid, rulename, " "ev_class AS ruletable, ev_type, is_instead, " "'O'::char AS ev_enabled " "FROM pg_rewrite " "ORDER BY oid"); } else { appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_rewrite') AS tableoid, " "oid, rulename, " "ev_class AS ruletable, ev_type, is_instead, " "'O'::char AS ev_enabled " "FROM pg_rewrite " "ORDER BY oid"); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numRules = ntups; ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_rulename = PQfnumber(res, "rulename"); i_ruletable = PQfnumber(res, "ruletable"); i_ev_type = PQfnumber(res, "ev_type"); i_is_instead = PQfnumber(res, "is_instead"); i_ev_enabled = PQfnumber(res, "ev_enabled"); for (i = 0; i < ntups; i++) { Oid ruletableoid; ruleinfo[i].dobj.objType = DO_RULE; ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&ruleinfo[i].dobj); ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename)); ruletableoid = atooid(PQgetvalue(res, i, i_ruletable)); ruleinfo[i].ruletable = findTableByOid(ruletableoid); if (ruleinfo[i].ruletable == NULL) exit_horribly(NULL, "failed sanity check, parent table OID %u of pg_rewrite entry OID %u not found\n", ruletableoid, ruleinfo[i].dobj.catId.oid); ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace; ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump; ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type)); ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't'; ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled)); if (ruleinfo[i].ruletable) { /* * If the table is a view or materialized view, force its ON * SELECT rule to be sorted before the view itself --- this * ensures that any dependencies for the rule affect the table's * positioning. Other rules are forced to appear after their * table. */ if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW || ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) && ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead) { addObjectDependency(&ruleinfo[i].ruletable->dobj, ruleinfo[i].dobj.dumpId); /* We'll merge the rule into CREATE VIEW, if possible */ ruleinfo[i].separate = false; } else { addObjectDependency(&ruleinfo[i].dobj, ruleinfo[i].ruletable->dobj.dumpId); ruleinfo[i].separate = true; } } else ruleinfo[i].separate = true; /* * If we're forced to break a dependency loop by dumping a view as a * table and separate _RETURN rule, we'll move the view's reloptions * to the rule. (This is necessary because tables and views have * different valid reloptions, so we can't apply the options until the * backend knows it's a view.) Otherwise the rule's reloptions stay * NULL. */ ruleinfo[i].reloptions = NULL; } PQclear(res); destroyPQExpBuffer(query); return ruleinfo; }
Definition at line 81 of file common.c.
References buildIndexArray(), flagInhAttrs(), flagInhTables(), g_verbose, getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getEventTriggers(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getInherits(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getOwnedSeqs(), getProcLangs(), getRules(), getTableAttrs(), getTables(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), NULL, numCollations, numFuncs, numNamespaces, numOperators, numTables, numTypes, and write_msg().
Referenced by main().
{ ExtensionInfo *extinfo; InhInfo *inhinfo; CollInfo *collinfo; int numExtensions; int numAggregates; int numInherits; int numRules; int numProcLangs; int numCasts; int numOpclasses; int numOpfamilies; int numConversions; int numTSParsers; int numTSTemplates; int numTSDicts; int numTSConfigs; int numForeignDataWrappers; int numForeignServers; int numDefaultACLs; int numEventTriggers; if (g_verbose) write_msg(NULL, "reading schemas\n"); nspinfo = getNamespaces(fout, &numNamespaces); nspinfoindex = buildIndexArray(nspinfo, numNamespaces, sizeof(NamespaceInfo)); /* * getTables should be done as soon as possible, so as to minimize the * window between starting our transaction and acquiring per-table locks. * However, we have to do getNamespaces first because the tables get * linked to their containing namespaces during getTables. */ if (g_verbose) write_msg(NULL, "reading user-defined tables\n"); tblinfo = getTables(fout, &numTables); tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo)); /* Do this after we've built tblinfoindex */ getOwnedSeqs(fout, tblinfo, numTables); if (g_verbose) write_msg(NULL, "reading extensions\n"); extinfo = getExtensions(fout, &numExtensions); if (g_verbose) write_msg(NULL, "reading user-defined functions\n"); funinfo = getFuncs(fout, &numFuncs); funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo)); /* this must be after getTables and getFuncs */ if (g_verbose) write_msg(NULL, "reading user-defined types\n"); typinfo = getTypes(fout, &numTypes); typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo)); /* this must be after getFuncs, too */ if (g_verbose) write_msg(NULL, "reading procedural languages\n"); getProcLangs(fout, &numProcLangs); if (g_verbose) write_msg(NULL, "reading user-defined aggregate functions\n"); getAggregates(fout, &numAggregates); if (g_verbose) write_msg(NULL, "reading user-defined operators\n"); oprinfo = getOperators(fout, &numOperators); oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo)); if (g_verbose) write_msg(NULL, "reading user-defined operator classes\n"); getOpclasses(fout, &numOpclasses); if (g_verbose) write_msg(NULL, "reading user-defined operator families\n"); getOpfamilies(fout, &numOpfamilies); if (g_verbose) write_msg(NULL, "reading user-defined text search parsers\n"); getTSParsers(fout, &numTSParsers); if (g_verbose) write_msg(NULL, "reading user-defined text search templates\n"); getTSTemplates(fout, &numTSTemplates); if (g_verbose) write_msg(NULL, "reading user-defined text search dictionaries\n"); getTSDictionaries(fout, &numTSDicts); if (g_verbose) write_msg(NULL, "reading user-defined text search configurations\n"); getTSConfigurations(fout, &numTSConfigs); if (g_verbose) write_msg(NULL, "reading user-defined foreign-data wrappers\n"); getForeignDataWrappers(fout, &numForeignDataWrappers); if (g_verbose) write_msg(NULL, "reading user-defined foreign servers\n"); getForeignServers(fout, &numForeignServers); if (g_verbose) write_msg(NULL, "reading default privileges\n"); getDefaultACLs(fout, &numDefaultACLs); if (g_verbose) write_msg(NULL, "reading user-defined collations\n"); collinfo = getCollations(fout, &numCollations); collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo)); if (g_verbose) write_msg(NULL, "reading user-defined conversions\n"); getConversions(fout, &numConversions); if (g_verbose) write_msg(NULL, "reading type casts\n"); getCasts(fout, &numCasts); if (g_verbose) write_msg(NULL, "reading table inheritance information\n"); inhinfo = getInherits(fout, &numInherits); if (g_verbose) write_msg(NULL, "reading rewrite rules\n"); getRules(fout, &numRules); /* * Identify extension member objects and mark them as not to be dumped. * This must happen after reading all objects that can be direct members * of extensions, but before we begin to process table subsidiary objects. */ if (g_verbose) write_msg(NULL, "finding extension members\n"); getExtensionMembership(fout, extinfo, numExtensions); /* Link tables to parents, mark parents of target tables interesting */ if (g_verbose) write_msg(NULL, "finding inheritance relationships\n"); flagInhTables(tblinfo, numTables, inhinfo, numInherits); if (g_verbose) write_msg(NULL, "reading column info for interesting tables\n"); getTableAttrs(fout, tblinfo, numTables); if (g_verbose) write_msg(NULL, "flagging inherited columns in subtables\n"); flagInhAttrs(tblinfo, numTables); if (g_verbose) write_msg(NULL, "reading indexes\n"); getIndexes(fout, tblinfo, numTables); if (g_verbose) write_msg(NULL, "reading constraints\n"); getConstraints(fout, tblinfo, numTables); if (g_verbose) write_msg(NULL, "reading triggers\n"); getTriggers(fout, tblinfo, numTables); if (g_verbose) write_msg(NULL, "reading event triggers\n"); getEventTriggers(fout, &numEventTriggers); *numTablesPtr = numTables; return tblinfo; }
Definition at line 6115 of file pg_dump.c.
References addObjectDependency(), _attrDefInfo::adef_expr, _attrDefInfo::adnum, _attrDefInfo::adtable, appendPQExpBuffer(), AssignDumpId(), atooid, _tableInfo::attalign, _tableInfo::attcollation, _tableInfo::attfdwoptions, _tableInfo::attisdropped, _tableInfo::attislocal, _tableInfo::attlen, _tableInfo::attnames, _tableInfo::attoptions, _tableInfo::attrdefs, _tableInfo::attstattarget, _tableInfo::attstorage, _tableInfo::atttypmod, _tableInfo::atttypnames, _dumpableObject::catId, _tableInfo::checkexprs, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::confrelid, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _constraintInfo::dobj, _attrDefInfo::dobj, _tableInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, ExecuteSqlQuery(), exit_horribly(), exit_nicely, g_verbose, i, _tableInfo::inhNotNull, _tableInfo::interesting, _dumpableObject::name, _tableInfo::ncheck, ngettext, _tableInfo::notnull, NULL, _tableInfo::numatts, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relkind, RELKIND_SEQUENCE, RELKIND_VIEW, Archive::remoteVersion, resetPQExpBuffer(), selectSourceSchema(), _constraintInfo::separate, _attrDefInfo::separate, shouldPrintColumn(), CatalogId::tableoid, _tableInfo::typstorage, and write_msg().
Referenced by getSchemaData().
{ int i, j; PQExpBuffer q = createPQExpBuffer(); int i_attnum; int i_attname; int i_atttypname; int i_atttypmod; int i_attstattarget; int i_attstorage; int i_typstorage; int i_attnotnull; int i_atthasdef; int i_attisdropped; int i_attlen; int i_attalign; int i_attislocal; int i_attoptions; int i_attcollation; int i_attfdwoptions; PGresult *res; int ntups; bool hasdefaults; for (i = 0; i < numTables; i++) { TableInfo *tbinfo = &tblinfo[i]; /* Don't bother to collect info for sequences */ if (tbinfo->relkind == RELKIND_SEQUENCE) continue; /* Don't bother with uninteresting tables, either */ if (!tbinfo->interesting) continue; /* * Make sure we are in proper schema for this table; this allows * correct retrieval of formatted type names and default exprs */ selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); /* find all the user attributes and their types */ /* * we must read the attribute names in attribute number order! because * we will use the attnum to index into the attnames array later. We * actually ask to order by "attrelid, attnum" because (at least up to * 7.3) the planner is not smart enough to realize it needn't re-sort * the output of an indexscan on pg_attribute_relid_attnum_index. */ if (g_verbose) write_msg(NULL, "finding the columns and types of table \"%s\"\n", tbinfo->dobj.name); resetPQExpBuffer(q); if (fout->remoteVersion >= 90200) { /* * attfdwoptions is new in 9.2. */ appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, " "a.attstattarget, a.attstorage, t.typstorage, " "a.attnotnull, a.atthasdef, a.attisdropped, " "a.attlen, a.attalign, a.attislocal, " "pg_catalog.format_type(t.oid,a.atttypmod) AS atttypname, " "array_to_string(a.attoptions, ', ') AS attoptions, " "CASE WHEN a.attcollation <> t.typcollation " "THEN a.attcollation ELSE 0 END AS attcollation, " "pg_catalog.array_to_string(ARRAY(" "SELECT pg_catalog.quote_ident(option_name) || " "' ' || pg_catalog.quote_literal(option_value) " "FROM pg_catalog.pg_options_to_table(attfdwoptions) " "ORDER BY option_name" "), E',\n ') AS attfdwoptions " "FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_type t " "ON a.atttypid = t.oid " "WHERE a.attrelid = '%u'::pg_catalog.oid " "AND a.attnum > 0::pg_catalog.int2 " "ORDER BY a.attrelid, a.attnum", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 90100) { /* * attcollation is new in 9.1. Since we only want to dump COLLATE * clauses for attributes whose collation is different from their * type's default, we use a CASE here to suppress uninteresting * attcollations cheaply. */ appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, " "a.attstattarget, a.attstorage, t.typstorage, " "a.attnotnull, a.atthasdef, a.attisdropped, " "a.attlen, a.attalign, a.attislocal, " "pg_catalog.format_type(t.oid,a.atttypmod) AS atttypname, " "array_to_string(a.attoptions, ', ') AS attoptions, " "CASE WHEN a.attcollation <> t.typcollation " "THEN a.attcollation ELSE 0 END AS attcollation, " "NULL AS attfdwoptions " "FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_type t " "ON a.atttypid = t.oid " "WHERE a.attrelid = '%u'::pg_catalog.oid " "AND a.attnum > 0::pg_catalog.int2 " "ORDER BY a.attrelid, a.attnum", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 90000) { /* attoptions is new in 9.0 */ appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, " "a.attstattarget, a.attstorage, t.typstorage, " "a.attnotnull, a.atthasdef, a.attisdropped, " "a.attlen, a.attalign, a.attislocal, " "pg_catalog.format_type(t.oid,a.atttypmod) AS atttypname, " "array_to_string(a.attoptions, ', ') AS attoptions, " "0 AS attcollation, " "NULL AS attfdwoptions " "FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_type t " "ON a.atttypid = t.oid " "WHERE a.attrelid = '%u'::pg_catalog.oid " "AND a.attnum > 0::pg_catalog.int2 " "ORDER BY a.attrelid, a.attnum", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70300) { /* need left join here to not fail on dropped columns ... */ appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, " "a.attstattarget, a.attstorage, t.typstorage, " "a.attnotnull, a.atthasdef, a.attisdropped, " "a.attlen, a.attalign, a.attislocal, " "pg_catalog.format_type(t.oid,a.atttypmod) AS atttypname, " "'' AS attoptions, 0 AS attcollation, " "NULL AS attfdwoptions " "FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_type t " "ON a.atttypid = t.oid " "WHERE a.attrelid = '%u'::pg_catalog.oid " "AND a.attnum > 0::pg_catalog.int2 " "ORDER BY a.attrelid, a.attnum", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70100) { /* * attstattarget doesn't exist in 7.1. It does exist in 7.2, but * we don't dump it because we can't tell whether it's been * explicitly set or was just a default. * * attislocal doesn't exist before 7.3, either; in older databases * we assume it's TRUE, else we'd fail to dump non-inherited atts. */ appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, " "-1 AS attstattarget, a.attstorage, " "t.typstorage, a.attnotnull, a.atthasdef, " "false AS attisdropped, a.attlen, " "a.attalign, true AS attislocal, " "format_type(t.oid,a.atttypmod) AS atttypname, " "'' AS attoptions, 0 AS attcollation, " "NULL AS attfdwoptions " "FROM pg_attribute a LEFT JOIN pg_type t " "ON a.atttypid = t.oid " "WHERE a.attrelid = '%u'::oid " "AND a.attnum > 0::int2 " "ORDER BY a.attrelid, a.attnum", tbinfo->dobj.catId.oid); } else { /* format_type not available before 7.1 */ appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, " "-1 AS attstattarget, " "attstorage, attstorage AS typstorage, " "attnotnull, atthasdef, false AS attisdropped, " "attlen, attalign, " "true AS attislocal, " "(SELECT typname FROM pg_type WHERE oid = atttypid) AS atttypname, " "'' AS attoptions, 0 AS attcollation, " "NULL AS attfdwoptions " "FROM pg_attribute a " "WHERE attrelid = '%u'::oid " "AND attnum > 0::int2 " "ORDER BY attrelid, attnum", tbinfo->dobj.catId.oid); } res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); ntups = PQntuples(res); i_attnum = PQfnumber(res, "attnum"); i_attname = PQfnumber(res, "attname"); i_atttypname = PQfnumber(res, "atttypname"); i_atttypmod = PQfnumber(res, "atttypmod"); i_attstattarget = PQfnumber(res, "attstattarget"); i_attstorage = PQfnumber(res, "attstorage"); i_typstorage = PQfnumber(res, "typstorage"); i_attnotnull = PQfnumber(res, "attnotnull"); i_atthasdef = PQfnumber(res, "atthasdef"); i_attisdropped = PQfnumber(res, "attisdropped"); i_attlen = PQfnumber(res, "attlen"); i_attalign = PQfnumber(res, "attalign"); i_attislocal = PQfnumber(res, "attislocal"); i_attoptions = PQfnumber(res, "attoptions"); i_attcollation = PQfnumber(res, "attcollation"); i_attfdwoptions = PQfnumber(res, "attfdwoptions"); tbinfo->numatts = ntups; tbinfo->attnames = (char **) pg_malloc(ntups * sizeof(char *)); tbinfo->atttypnames = (char **) pg_malloc(ntups * sizeof(char *)); tbinfo->atttypmod = (int *) pg_malloc(ntups * sizeof(int)); tbinfo->attstattarget = (int *) pg_malloc(ntups * sizeof(int)); tbinfo->attstorage = (char *) pg_malloc(ntups * sizeof(char)); tbinfo->typstorage = (char *) pg_malloc(ntups * sizeof(char)); tbinfo->attisdropped = (bool *) pg_malloc(ntups * sizeof(bool)); tbinfo->attlen = (int *) pg_malloc(ntups * sizeof(int)); tbinfo->attalign = (char *) pg_malloc(ntups * sizeof(char)); tbinfo->attislocal = (bool *) pg_malloc(ntups * sizeof(bool)); tbinfo->attoptions = (char **) pg_malloc(ntups * sizeof(char *)); tbinfo->attcollation = (Oid *) pg_malloc(ntups * sizeof(Oid)); tbinfo->attfdwoptions = (char **) pg_malloc(ntups * sizeof(char *)); tbinfo->notnull = (bool *) pg_malloc(ntups * sizeof(bool)); tbinfo->inhNotNull = (bool *) pg_malloc(ntups * sizeof(bool)); tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(ntups * sizeof(AttrDefInfo *)); hasdefaults = false; for (j = 0; j < ntups; j++) { if (j + 1 != atoi(PQgetvalue(res, j, i_attnum))) exit_horribly(NULL, "invalid column numbering in table \"%s\"\n", tbinfo->dobj.name); tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, j, i_attname)); tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, j, i_atttypname)); tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod)); tbinfo->attstattarget[j] = atoi(PQgetvalue(res, j, i_attstattarget)); tbinfo->attstorage[j] = *(PQgetvalue(res, j, i_attstorage)); tbinfo->typstorage[j] = *(PQgetvalue(res, j, i_typstorage)); tbinfo->attisdropped[j] = (PQgetvalue(res, j, i_attisdropped)[0] == 't'); tbinfo->attlen[j] = atoi(PQgetvalue(res, j, i_attlen)); tbinfo->attalign[j] = *(PQgetvalue(res, j, i_attalign)); tbinfo->attislocal[j] = (PQgetvalue(res, j, i_attislocal)[0] == 't'); tbinfo->notnull[j] = (PQgetvalue(res, j, i_attnotnull)[0] == 't'); tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, j, i_attoptions)); tbinfo->attcollation[j] = atooid(PQgetvalue(res, j, i_attcollation)); tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, j, i_attfdwoptions)); tbinfo->attrdefs[j] = NULL; /* fix below */ if (PQgetvalue(res, j, i_atthasdef)[0] == 't') hasdefaults = true; /* these flags will be set in flagInhAttrs() */ tbinfo->inhNotNull[j] = false; } PQclear(res); /* * Get info about column defaults */ if (hasdefaults) { AttrDefInfo *attrdefs; int numDefaults; if (g_verbose) write_msg(NULL, "finding default expressions of table \"%s\"\n", tbinfo->dobj.name); resetPQExpBuffer(q); if (fout->remoteVersion >= 70300) { appendPQExpBuffer(q, "SELECT tableoid, oid, adnum, " "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc " "FROM pg_catalog.pg_attrdef " "WHERE adrelid = '%u'::pg_catalog.oid", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70200) { /* 7.2 did not have OIDs in pg_attrdef */ appendPQExpBuffer(q, "SELECT tableoid, 0 AS oid, adnum, " "pg_get_expr(adbin, adrelid) AS adsrc " "FROM pg_attrdef " "WHERE adrelid = '%u'::oid", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70100) { /* no pg_get_expr, so must rely on adsrc */ appendPQExpBuffer(q, "SELECT tableoid, oid, adnum, adsrc " "FROM pg_attrdef " "WHERE adrelid = '%u'::oid", tbinfo->dobj.catId.oid); } else { /* no pg_get_expr, no tableoid either */ appendPQExpBuffer(q, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_attrdef') AS tableoid, " "oid, adnum, adsrc " "FROM pg_attrdef " "WHERE adrelid = '%u'::oid", tbinfo->dobj.catId.oid); } res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); numDefaults = PQntuples(res); attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo)); for (j = 0; j < numDefaults; j++) { int adnum; adnum = atoi(PQgetvalue(res, j, 2)); if (adnum <= 0 || adnum > ntups) exit_horribly(NULL, "invalid adnum value %d for table \"%s\"\n", adnum, tbinfo->dobj.name); /* * dropped columns shouldn't have defaults, but just in case, * ignore 'em */ if (tbinfo->attisdropped[adnum - 1]) continue; attrdefs[j].dobj.objType = DO_ATTRDEF; attrdefs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, 0)); attrdefs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, 1)); AssignDumpId(&attrdefs[j].dobj); attrdefs[j].adtable = tbinfo; attrdefs[j].adnum = adnum; attrdefs[j].adef_expr = pg_strdup(PQgetvalue(res, j, 3)); attrdefs[j].dobj.name = pg_strdup(tbinfo->dobj.name); attrdefs[j].dobj.namespace = tbinfo->dobj.namespace; attrdefs[j].dobj.dump = tbinfo->dobj.dump; /* * Defaults on a VIEW must always be dumped as separate ALTER * TABLE commands. Defaults on regular tables are dumped as * part of the CREATE TABLE if possible, which it won't be if * the column is not going to be emitted explicitly. */ if (tbinfo->relkind == RELKIND_VIEW) { attrdefs[j].separate = true; /* needed in case pre-7.3 DB: */ addObjectDependency(&attrdefs[j].dobj, tbinfo->dobj.dumpId); } else if (!shouldPrintColumn(tbinfo, adnum - 1)) { /* column will be suppressed, print default separately */ attrdefs[j].separate = true; /* needed in case pre-7.3 DB: */ addObjectDependency(&attrdefs[j].dobj, tbinfo->dobj.dumpId); } else { attrdefs[j].separate = false; /* * Mark the default as needing to appear before the table, * so that any dependencies it has must be emitted before * the CREATE TABLE. If this is not possible, we'll * change to "separate" mode while sorting dependencies. */ addObjectDependency(&tbinfo->dobj, attrdefs[j].dobj.dumpId); } tbinfo->attrdefs[adnum - 1] = &attrdefs[j]; } PQclear(res); } /* * Get info about table CHECK constraints */ if (tbinfo->ncheck > 0) { ConstraintInfo *constrs; int numConstrs; if (g_verbose) write_msg(NULL, "finding check constraints for table \"%s\"\n", tbinfo->dobj.name); resetPQExpBuffer(q); if (fout->remoteVersion >= 90200) { /* * convalidated is new in 9.2 (actually, it is there in 9.1, * but it wasn't ever false for check constraints until 9.2). */ appendPQExpBuffer(q, "SELECT tableoid, oid, conname, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, " "conislocal, convalidated " "FROM pg_catalog.pg_constraint " "WHERE conrelid = '%u'::pg_catalog.oid " " AND contype = 'c' " "ORDER BY conname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 80400) { /* conislocal is new in 8.4 */ appendPQExpBuffer(q, "SELECT tableoid, oid, conname, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, " "conislocal, true AS convalidated " "FROM pg_catalog.pg_constraint " "WHERE conrelid = '%u'::pg_catalog.oid " " AND contype = 'c' " "ORDER BY conname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70400) { appendPQExpBuffer(q, "SELECT tableoid, oid, conname, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, " "true AS conislocal, true AS convalidated " "FROM pg_catalog.pg_constraint " "WHERE conrelid = '%u'::pg_catalog.oid " " AND contype = 'c' " "ORDER BY conname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70300) { /* no pg_get_constraintdef, must use consrc */ appendPQExpBuffer(q, "SELECT tableoid, oid, conname, " "'CHECK (' || consrc || ')' AS consrc, " "true AS conislocal, true AS convalidated " "FROM pg_catalog.pg_constraint " "WHERE conrelid = '%u'::pg_catalog.oid " " AND contype = 'c' " "ORDER BY conname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70200) { /* 7.2 did not have OIDs in pg_relcheck */ appendPQExpBuffer(q, "SELECT tableoid, 0 AS oid, " "rcname AS conname, " "'CHECK (' || rcsrc || ')' AS consrc, " "true AS conislocal, true AS convalidated " "FROM pg_relcheck " "WHERE rcrelid = '%u'::oid " "ORDER BY rcname", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(q, "SELECT tableoid, oid, " "rcname AS conname, " "'CHECK (' || rcsrc || ')' AS consrc, " "true AS conislocal, true AS convalidated " "FROM pg_relcheck " "WHERE rcrelid = '%u'::oid " "ORDER BY rcname", tbinfo->dobj.catId.oid); } else { /* no tableoid in 7.0 */ appendPQExpBuffer(q, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_relcheck') AS tableoid, " "oid, rcname AS conname, " "'CHECK (' || rcsrc || ')' AS consrc, " "true AS conislocal, true AS convalidated " "FROM pg_relcheck " "WHERE rcrelid = '%u'::oid " "ORDER BY rcname", tbinfo->dobj.catId.oid); } res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); numConstrs = PQntuples(res); if (numConstrs != tbinfo->ncheck) { write_msg(NULL, ngettext("expected %d check constraint on table \"%s\" but found %d\n", "expected %d check constraints on table \"%s\" but found %d\n", tbinfo->ncheck), tbinfo->ncheck, tbinfo->dobj.name, numConstrs); write_msg(NULL, "(The system catalogs might be corrupted.)\n"); exit_nicely(1); } constrs = (ConstraintInfo *) pg_malloc(numConstrs * sizeof(ConstraintInfo)); tbinfo->checkexprs = constrs; for (j = 0; j < numConstrs; j++) { bool validated = PQgetvalue(res, j, 5)[0] == 't'; constrs[j].dobj.objType = DO_CONSTRAINT; constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, 0)); constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, 1)); AssignDumpId(&constrs[j].dobj); constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, 2)); constrs[j].dobj.namespace = tbinfo->dobj.namespace; constrs[j].contable = tbinfo; constrs[j].condomain = NULL; constrs[j].contype = 'c'; constrs[j].condef = pg_strdup(PQgetvalue(res, j, 3)); constrs[j].confrelid = InvalidOid; constrs[j].conindex = 0; constrs[j].condeferrable = false; constrs[j].condeferred = false; constrs[j].conislocal = (PQgetvalue(res, j, 4)[0] == 't'); /* * An unvalidated constraint needs to be dumped separately, so * that potentially-violating existing data is loaded before * the constraint. */ constrs[j].separate = !validated; constrs[j].dobj.dump = tbinfo->dobj.dump; /* * Mark the constraint as needing to appear before the table * --- this is so that any other dependencies of the * constraint will be emitted before we try to create the * table. If the constraint is to be dumped separately, it * will be dumped after data is loaded anyway, so don't do it. * (There's an automatic dependency in the opposite direction * anyway, so don't need to add one manually here.) */ if (!constrs[j].separate) addObjectDependency(&tbinfo->dobj, constrs[j].dobj.dumpId); /* * If the constraint is inherited, this will be detected later * (in pre-8.4 databases). We also detect later if the * constraint must be split out from the table definition. */ } PQclear(res); } } destroyPQExpBuffer(q); }
Definition at line 4198 of file pg_dump.c.
References appendPQExpBuffer(), appendStringLiteralConn(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _tableInfo::dobj, _dumpableObject::dump, ExecuteSqlQuery(), ExecuteSqlStatement(), findNamespace(), fmtQualifiedId(), _tableInfo::frozenxid, GetConnection(), _tableInfo::hasindex, _tableInfo::hasoids, _tableInfo::hasrules, _tableInfo::hastriggers, i, _tableInfo::interesting, _tableInfo::isscannable, lockWaitTimeout, _dumpableObject::name, _tableInfo::ncheck, NULL, _dumpableObject::objType, CatalogId::oid, _tableInfo::owning_col, _tableInfo::owning_tab, pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), _tableInfo::relacl, _tableInfo::relkind, RELKIND_COMPOSITE_TYPE, RELKIND_FOREIGN_TABLE, RELKIND_MATVIEW, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, _tableInfo::reloftype, _tableInfo::reloptions, _tableInfo::relpages, _tableInfo::relpersistence, _tableInfo::reltablespace, Archive::remoteVersion, resetPQExpBuffer(), _tableInfo::rolname, selectDumpableTable(), selectSourceSchema(), CatalogId::tableoid, tblinfo, _tableInfo::toast_frozenxid, _tableInfo::toast_oid, _tableInfo::toast_reloptions, username_subquery, and write_msg().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); TableInfo *tblinfo; int i_reltableoid; int i_reloid; int i_relname; int i_relnamespace; int i_relkind; int i_relacl; int i_rolname; int i_relchecks; int i_relhastriggers; int i_relhasindex; int i_relhasrules; int i_relhasoids; int i_relfrozenxid; int i_toastoid; int i_toastfrozenxid; int i_relpersistence; int i_isscannable; int i_owning_tab; int i_owning_col; int i_reltablespace; int i_reloptions; int i_toastreloptions; int i_reloftype; int i_relpages; /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); /* * Find all the tables and table-like objects. * * We include system catalogs, so that we can work if a user table is * defined to inherit from a system catalog (pretty weird, but...) * * We ignore relations that are not ordinary tables, sequences, views, * materialized views, composite types, or foreign tables. * * Composite-type table entries won't be dumped as such, but we have to * make a DumpableObject for them so that we can track dependencies of the * composite type (pg_depend entries for columns of the composite type * link to the pg_class entry not the pg_type entry). * * Note: in this phase we should collect only a minimal amount of * information about each table, basically just enough to decide if it is * interesting. We must fetch all tables in this phase because otherwise * we cannot correctly identify inherited columns, owned sequences, etc. */ if (fout->remoteVersion >= 90300) { /* * Left join to pick up dependency info linking sequences to their * owning column, if any (note this dependency is AUTO as of 8.2) */ appendPQExpBuffer(query, "SELECT c.tableoid, c.oid, c.relname, " "c.relacl, c.relkind, c.relnamespace, " "(%s c.relowner) AS rolname, " "c.relchecks, c.relhastriggers, " "c.relhasindex, c.relhasrules, c.relhasoids, " "c.relfrozenxid, tc.oid AS toid, " "tc.relfrozenxid AS tfrozenxid, " "c.relpersistence, " "CASE WHEN c.relkind = '%c' THEN pg_relation_is_scannable(c.oid) ELSE 't'::bool END as isscannable, " "c.relpages, " "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " "d.refobjid AS owning_tab, " "d.refobjsubid AS owning_col, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " "array_to_string(c.reloptions, ', ') AS reloptions, " "array_to_string(array(SELECT 'toast.' || x FROM unnest(tc.reloptions) x), ', ') AS toast_reloptions " "FROM pg_class c " "LEFT JOIN pg_depend d ON " "(c.relkind = '%c' AND " "d.classid = c.tableoid AND d.objid = c.oid AND " "d.objsubid = 0 AND " "d.refclassid = c.tableoid AND d.deptype = 'a') " "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c') " "ORDER BY c.oid", username_subquery, RELKIND_MATVIEW, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE); } else if (fout->remoteVersion >= 90100) { /* * Left join to pick up dependency info linking sequences to their * owning column, if any (note this dependency is AUTO as of 8.2) */ appendPQExpBuffer(query, "SELECT c.tableoid, c.oid, c.relname, " "c.relacl, c.relkind, c.relnamespace, " "(%s c.relowner) AS rolname, " "c.relchecks, c.relhastriggers, " "c.relhasindex, c.relhasrules, c.relhasoids, " "c.relfrozenxid, tc.oid AS toid, " "tc.relfrozenxid AS tfrozenxid, " "c.relpersistence, 't'::bool as isscannable, " "c.relpages, " "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " "d.refobjid AS owning_tab, " "d.refobjsubid AS owning_col, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " "array_to_string(c.reloptions, ', ') AS reloptions, " "array_to_string(array(SELECT 'toast.' || x FROM unnest(tc.reloptions) x), ', ') AS toast_reloptions " "FROM pg_class c " "LEFT JOIN pg_depend d ON " "(c.relkind = '%c' AND " "d.classid = c.tableoid AND d.objid = c.oid AND " "d.objsubid = 0 AND " "d.refclassid = c.tableoid AND d.deptype = 'a') " "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c') " "ORDER BY c.oid", username_subquery, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE); } else if (fout->remoteVersion >= 90000) { /* * Left join to pick up dependency info linking sequences to their * owning column, if any (note this dependency is AUTO as of 8.2) */ appendPQExpBuffer(query, "SELECT c.tableoid, c.oid, c.relname, " "c.relacl, c.relkind, c.relnamespace, " "(%s c.relowner) AS rolname, " "c.relchecks, c.relhastriggers, " "c.relhasindex, c.relhasrules, c.relhasoids, " "c.relfrozenxid, tc.oid AS toid, " "tc.relfrozenxid AS tfrozenxid, " "'p' AS relpersistence, 't'::bool as isscannable, " "c.relpages, " "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " "d.refobjid AS owning_tab, " "d.refobjsubid AS owning_col, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " "array_to_string(c.reloptions, ', ') AS reloptions, " "array_to_string(array(SELECT 'toast.' || x FROM unnest(tc.reloptions) x), ', ') AS toast_reloptions " "FROM pg_class c " "LEFT JOIN pg_depend d ON " "(c.relkind = '%c' AND " "d.classid = c.tableoid AND d.objid = c.oid AND " "d.objsubid = 0 AND " "d.refclassid = c.tableoid AND d.deptype = 'a') " "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " "WHERE c.relkind in ('%c', '%c', '%c', '%c') " "ORDER BY c.oid", username_subquery, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); } else if (fout->remoteVersion >= 80400) { /* * Left join to pick up dependency info linking sequences to their * owning column, if any (note this dependency is AUTO as of 8.2) */ appendPQExpBuffer(query, "SELECT c.tableoid, c.oid, c.relname, " "c.relacl, c.relkind, c.relnamespace, " "(%s c.relowner) AS rolname, " "c.relchecks, c.relhastriggers, " "c.relhasindex, c.relhasrules, c.relhasoids, " "c.relfrozenxid, tc.oid AS toid, " "tc.relfrozenxid AS tfrozenxid, " "'p' AS relpersistence, 't'::bool as isscannable, " "c.relpages, " "NULL AS reloftype, " "d.refobjid AS owning_tab, " "d.refobjsubid AS owning_col, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " "array_to_string(c.reloptions, ', ') AS reloptions, " "array_to_string(array(SELECT 'toast.' || x FROM unnest(tc.reloptions) x), ', ') AS toast_reloptions " "FROM pg_class c " "LEFT JOIN pg_depend d ON " "(c.relkind = '%c' AND " "d.classid = c.tableoid AND d.objid = c.oid AND " "d.objsubid = 0 AND " "d.refclassid = c.tableoid AND d.deptype = 'a') " "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " "WHERE c.relkind in ('%c', '%c', '%c', '%c') " "ORDER BY c.oid", username_subquery, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); } else if (fout->remoteVersion >= 80200) { /* * Left join to pick up dependency info linking sequences to their * owning column, if any (note this dependency is AUTO as of 8.2) */ appendPQExpBuffer(query, "SELECT c.tableoid, c.oid, c.relname, " "c.relacl, c.relkind, c.relnamespace, " "(%s c.relowner) AS rolname, " "c.relchecks, (c.reltriggers <> 0) AS relhastriggers, " "c.relhasindex, c.relhasrules, c.relhasoids, " "c.relfrozenxid, tc.oid AS toid, " "tc.relfrozenxid AS tfrozenxid, " "'p' AS relpersistence, 't'::bool as isscannable, " "c.relpages, " "NULL AS reloftype, " "d.refobjid AS owning_tab, " "d.refobjsubid AS owning_col, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " "array_to_string(c.reloptions, ', ') AS reloptions, " "NULL AS toast_reloptions " "FROM pg_class c " "LEFT JOIN pg_depend d ON " "(c.relkind = '%c' AND " "d.classid = c.tableoid AND d.objid = c.oid AND " "d.objsubid = 0 AND " "d.refclassid = c.tableoid AND d.deptype = 'a') " "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " "WHERE c.relkind in ('%c', '%c', '%c', '%c') " "ORDER BY c.oid", username_subquery, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); } else if (fout->remoteVersion >= 80000) { /* * Left join to pick up dependency info linking sequences to their * owning column, if any */ appendPQExpBuffer(query, "SELECT c.tableoid, c.oid, relname, " "relacl, relkind, relnamespace, " "(%s relowner) AS rolname, " "relchecks, (reltriggers <> 0) AS relhastriggers, " "relhasindex, relhasrules, relhasoids, " "0 AS relfrozenxid, " "0 AS toid, " "0 AS tfrozenxid, " "'p' AS relpersistence, 't'::bool as isscannable, " "relpages, " "NULL AS reloftype, " "d.refobjid AS owning_tab, " "d.refobjsubid AS owning_col, " "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " "NULL AS reloptions, " "NULL AS toast_reloptions " "FROM pg_class c " "LEFT JOIN pg_depend d ON " "(c.relkind = '%c' AND " "d.classid = c.tableoid AND d.objid = c.oid AND " "d.objsubid = 0 AND " "d.refclassid = c.tableoid AND d.deptype = 'i') " "WHERE relkind in ('%c', '%c', '%c', '%c') " "ORDER BY c.oid", username_subquery, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); } else if (fout->remoteVersion >= 70300) { /* * Left join to pick up dependency info linking sequences to their * owning column, if any */ appendPQExpBuffer(query, "SELECT c.tableoid, c.oid, relname, " "relacl, relkind, relnamespace, " "(%s relowner) AS rolname, " "relchecks, (reltriggers <> 0) AS relhastriggers, " "relhasindex, relhasrules, relhasoids, " "0 AS relfrozenxid, " "0 AS toid, " "0 AS tfrozenxid, " "'p' AS relpersistence, 't'::bool as isscannable, " "relpages, " "NULL AS reloftype, " "d.refobjid AS owning_tab, " "d.refobjsubid AS owning_col, " "NULL AS reltablespace, " "NULL AS reloptions, " "NULL AS toast_reloptions " "FROM pg_class c " "LEFT JOIN pg_depend d ON " "(c.relkind = '%c' AND " "d.classid = c.tableoid AND d.objid = c.oid AND " "d.objsubid = 0 AND " "d.refclassid = c.tableoid AND d.deptype = 'i') " "WHERE relkind IN ('%c', '%c', '%c', '%c') " "ORDER BY c.oid", username_subquery, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); } else if (fout->remoteVersion >= 70200) { appendPQExpBuffer(query, "SELECT tableoid, oid, relname, relacl, relkind, " "0::oid AS relnamespace, " "(%s relowner) AS rolname, " "relchecks, (reltriggers <> 0) AS relhastriggers, " "relhasindex, relhasrules, relhasoids, " "0 AS relfrozenxid, " "0 AS toid, " "0 AS tfrozenxid, " "'p' AS relpersistence, 't'::bool as isscannable, " "relpages, " "NULL AS reloftype, " "NULL::oid AS owning_tab, " "NULL::int4 AS owning_col, " "NULL AS reltablespace, " "NULL AS reloptions, " "NULL AS toast_reloptions " "FROM pg_class " "WHERE relkind IN ('%c', '%c', '%c') " "ORDER BY oid", username_subquery, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW); } else if (fout->remoteVersion >= 70100) { /* all tables have oids in 7.1 */ appendPQExpBuffer(query, "SELECT tableoid, oid, relname, relacl, relkind, " "0::oid AS relnamespace, " "(%s relowner) AS rolname, " "relchecks, (reltriggers <> 0) AS relhastriggers, " "relhasindex, relhasrules, " "'t'::bool AS relhasoids, " "0 AS relfrozenxid, " "0 AS toid, " "0 AS tfrozenxid, " "'p' AS relpersistence, 't'::bool as isscannable, " "relpages, " "NULL AS reloftype, " "NULL::oid AS owning_tab, " "NULL::int4 AS owning_col, " "NULL AS reltablespace, " "NULL AS reloptions, " "NULL AS toast_reloptions " "FROM pg_class " "WHERE relkind IN ('%c', '%c', '%c') " "ORDER BY oid", username_subquery, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW); } else { /* * Before 7.1, view relkind was not set to 'v', so we must check if we * have a view by looking for a rule in pg_rewrite. */ appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_class') AS tableoid, " "oid, relname, relacl, " "CASE WHEN relhasrules and relkind = 'r' " " and EXISTS(SELECT rulename FROM pg_rewrite r WHERE " " r.ev_class = c.oid AND r.ev_type = '1') " "THEN '%c'::\"char\" " "ELSE relkind END AS relkind," "0::oid AS relnamespace, " "(%s relowner) AS rolname, " "relchecks, (reltriggers <> 0) AS relhastriggers, " "relhasindex, relhasrules, " "'t'::bool AS relhasoids, " "0 as relfrozenxid, " "0 AS toid, " "0 AS tfrozenxid, " "'p' AS relpersistence, 't'::bool as isscannable, " "0 AS relpages, " "NULL AS reloftype, " "NULL::oid AS owning_tab, " "NULL::int4 AS owning_col, " "NULL AS reltablespace, " "NULL AS reloptions, " "NULL AS toast_reloptions " "FROM pg_class c " "WHERE relkind IN ('%c', '%c') " "ORDER BY oid", RELKIND_VIEW, username_subquery, RELKIND_RELATION, RELKIND_SEQUENCE); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numTables = ntups; /* * Extract data from result and lock dumpable tables. We do the locking * before anything else, to minimize the window wherein a table could * disappear under us. * * Note that we have to save info about all tables here, even when dumping * only one, because we don't yet know which tables might be inheritance * ancestors of the target table. */ tblinfo = (TableInfo *) pg_malloc0(ntups * sizeof(TableInfo)); i_reltableoid = PQfnumber(res, "tableoid"); i_reloid = PQfnumber(res, "oid"); i_relname = PQfnumber(res, "relname"); i_relnamespace = PQfnumber(res, "relnamespace"); i_relacl = PQfnumber(res, "relacl"); i_relkind = PQfnumber(res, "relkind"); i_rolname = PQfnumber(res, "rolname"); i_relchecks = PQfnumber(res, "relchecks"); i_relhastriggers = PQfnumber(res, "relhastriggers"); i_relhasindex = PQfnumber(res, "relhasindex"); i_relhasrules = PQfnumber(res, "relhasrules"); i_relhasoids = PQfnumber(res, "relhasoids"); i_relfrozenxid = PQfnumber(res, "relfrozenxid"); i_toastoid = PQfnumber(res, "toid"); i_toastfrozenxid = PQfnumber(res, "tfrozenxid"); i_relpersistence = PQfnumber(res, "relpersistence"); i_isscannable = PQfnumber(res, "isscannable"); i_relpages = PQfnumber(res, "relpages"); i_owning_tab = PQfnumber(res, "owning_tab"); i_owning_col = PQfnumber(res, "owning_col"); i_reltablespace = PQfnumber(res, "reltablespace"); i_reloptions = PQfnumber(res, "reloptions"); i_toastreloptions = PQfnumber(res, "toast_reloptions"); i_reloftype = PQfnumber(res, "reloftype"); if (lockWaitTimeout && fout->remoteVersion >= 70300) { /* * Arrange to fail instead of waiting forever for a table lock. * * NB: this coding assumes that the only queries issued within the * following loop are LOCK TABLEs; else the timeout may be undesirably * applied to other things too. */ resetPQExpBuffer(query); appendPQExpBuffer(query, "SET statement_timeout = "); appendStringLiteralConn(query, lockWaitTimeout, GetConnection(fout)); ExecuteSqlStatement(fout, query->data); } for (i = 0; i < ntups; i++) { tblinfo[i].dobj.objType = DO_TABLE; tblinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_reltableoid)); tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid)); AssignDumpId(&tblinfo[i].dobj); tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname)); tblinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_relnamespace)), tblinfo[i].dobj.catId.oid); tblinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); tblinfo[i].relacl = pg_strdup(PQgetvalue(res, i, i_relacl)); tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind)); tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence)); tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0); tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0); tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0); tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0); tblinfo[i].isscannable = (strcmp(PQgetvalue(res, i, i_isscannable), "t") == 0); tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages)); tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid)); tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid)); tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid)); if (PQgetisnull(res, i, i_reloftype)) tblinfo[i].reloftype = NULL; else tblinfo[i].reloftype = pg_strdup(PQgetvalue(res, i, i_reloftype)); tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks)); if (PQgetisnull(res, i, i_owning_tab)) { tblinfo[i].owning_tab = InvalidOid; tblinfo[i].owning_col = 0; } else { tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab)); tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col)); } tblinfo[i].reltablespace = pg_strdup(PQgetvalue(res, i, i_reltablespace)); tblinfo[i].reloptions = pg_strdup(PQgetvalue(res, i, i_reloptions)); tblinfo[i].toast_reloptions = pg_strdup(PQgetvalue(res, i, i_toastreloptions)); /* other fields were zeroed above */ /* * Decide whether we want to dump this table. */ if (tblinfo[i].relkind == RELKIND_COMPOSITE_TYPE) tblinfo[i].dobj.dump = false; else selectDumpableTable(&tblinfo[i]); tblinfo[i].interesting = tblinfo[i].dobj.dump; /* * Read-lock target tables to make sure they aren't DROPPED or altered * in schema before we get around to dumping them. * * Note that we don't explicitly lock parents of the target tables; we * assume our lock on the child is enough to prevent schema * alterations to parent tables. * * NOTE: it'd be kinda nice to lock other relations too, not only * plain tables, but the backend doesn't presently allow that. */ if (tblinfo[i].dobj.dump && tblinfo[i].relkind == RELKIND_RELATION) { resetPQExpBuffer(query); appendPQExpBuffer(query, "LOCK TABLE %s IN ACCESS SHARE MODE", fmtQualifiedId(fout->remoteVersion, tblinfo[i].dobj.namespace->dobj.name, tblinfo[i].dobj.name)); ExecuteSqlStatement(fout, query->data); } /* Emit notice if join for owner failed */ if (strlen(tblinfo[i].rolname) == 0) write_msg(NULL, "WARNING: owner of table \"%s\" appears to be invalid\n", tblinfo[i].dobj.name); } if (lockWaitTimeout && fout->remoteVersion >= 70300) { ExecuteSqlStatement(fout, "SET statement_timeout = 0"); } PQclear(res); destroyPQExpBuffer(query); return tblinfo; }
Definition at line 5525 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _triggerInfo::dobj, _tableInfo::dobj, _dumpableObject::dump, ExecuteSqlQuery(), exit_horribly(), g_verbose, _tableInfo::hastriggers, i, _dumpableObject::name, NULL, _dumpableObject::objType, CatalogId::oid, OidIsValid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, resetPQExpBuffer(), selectSourceSchema(), CatalogId::tableoid, _triggerInfo::tgargs, _triggerInfo::tgconstrname, _triggerInfo::tgconstrrelid, _triggerInfo::tgconstrrelname, _triggerInfo::tgdef, _triggerInfo::tgdeferrable, _triggerInfo::tgenabled, _triggerInfo::tgfname, _triggerInfo::tginitdeferred, _triggerInfo::tgisconstraint, _triggerInfo::tgnargs, _triggerInfo::tgtable, _triggerInfo::tgtype, and write_msg().
Referenced by getSchemaData().
{ int i, j; PQExpBuffer query = createPQExpBuffer(); PGresult *res; TriggerInfo *tginfo; int i_tableoid, i_oid, i_tgname, i_tgfname, i_tgtype, i_tgnargs, i_tgargs, i_tgisconstraint, i_tgconstrname, i_tgconstrrelid, i_tgconstrrelname, i_tgenabled, i_tgdeferrable, i_tginitdeferred, i_tgdef; int ntups; for (i = 0; i < numTables; i++) { TableInfo *tbinfo = &tblinfo[i]; if (!tbinfo->hastriggers || !tbinfo->dobj.dump) continue; if (g_verbose) write_msg(NULL, "reading triggers for table \"%s\"\n", tbinfo->dobj.name); /* * select table schema to ensure regproc name is qualified if needed */ selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); resetPQExpBuffer(query); if (fout->remoteVersion >= 90000) { /* * NB: think not to use pretty=true in pg_get_triggerdef. It * could result in non-forward-compatible dumps of WHEN clauses * due to under-parenthesization. */ appendPQExpBuffer(query, "SELECT tgname, " "tgfoid::pg_catalog.regproc AS tgfname, " "pg_catalog.pg_get_triggerdef(oid, false) AS tgdef, " "tgenabled, tableoid, oid " "FROM pg_catalog.pg_trigger t " "WHERE tgrelid = '%u'::pg_catalog.oid " "AND NOT tgisinternal", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 80300) { /* * We ignore triggers that are tied to a foreign-key constraint */ appendPQExpBuffer(query, "SELECT tgname, " "tgfoid::pg_catalog.regproc AS tgfname, " "tgtype, tgnargs, tgargs, tgenabled, " "tgisconstraint, tgconstrname, tgdeferrable, " "tgconstrrelid, tginitdeferred, tableoid, oid, " "tgconstrrelid::pg_catalog.regclass AS tgconstrrelname " "FROM pg_catalog.pg_trigger t " "WHERE tgrelid = '%u'::pg_catalog.oid " "AND tgconstraint = 0", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70300) { /* * We ignore triggers that are tied to a foreign-key constraint, * but in these versions we have to grovel through pg_constraint * to find out */ appendPQExpBuffer(query, "SELECT tgname, " "tgfoid::pg_catalog.regproc AS tgfname, " "tgtype, tgnargs, tgargs, tgenabled, " "tgisconstraint, tgconstrname, tgdeferrable, " "tgconstrrelid, tginitdeferred, tableoid, oid, " "tgconstrrelid::pg_catalog.regclass AS tgconstrrelname " "FROM pg_catalog.pg_trigger t " "WHERE tgrelid = '%u'::pg_catalog.oid " "AND (NOT tgisconstraint " " OR NOT EXISTS" " (SELECT 1 FROM pg_catalog.pg_depend d " " JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) " " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))", tbinfo->dobj.catId.oid); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT tgname, tgfoid::regproc AS tgfname, " "tgtype, tgnargs, tgargs, tgenabled, " "tgisconstraint, tgconstrname, tgdeferrable, " "tgconstrrelid, tginitdeferred, tableoid, oid, " "(SELECT relname FROM pg_class WHERE oid = tgconstrrelid) " " AS tgconstrrelname " "FROM pg_trigger " "WHERE tgrelid = '%u'::oid", tbinfo->dobj.catId.oid); } else { appendPQExpBuffer(query, "SELECT tgname, tgfoid::regproc AS tgfname, " "tgtype, tgnargs, tgargs, tgenabled, " "tgisconstraint, tgconstrname, tgdeferrable, " "tgconstrrelid, tginitdeferred, " "(SELECT oid FROM pg_class WHERE relname = 'pg_trigger') AS tableoid, " "oid, " "(SELECT relname FROM pg_class WHERE oid = tgconstrrelid) " " AS tgconstrrelname " "FROM pg_trigger " "WHERE tgrelid = '%u'::oid", tbinfo->dobj.catId.oid); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_tgname = PQfnumber(res, "tgname"); i_tgfname = PQfnumber(res, "tgfname"); i_tgtype = PQfnumber(res, "tgtype"); i_tgnargs = PQfnumber(res, "tgnargs"); i_tgargs = PQfnumber(res, "tgargs"); i_tgisconstraint = PQfnumber(res, "tgisconstraint"); i_tgconstrname = PQfnumber(res, "tgconstrname"); i_tgconstrrelid = PQfnumber(res, "tgconstrrelid"); i_tgconstrrelname = PQfnumber(res, "tgconstrrelname"); i_tgenabled = PQfnumber(res, "tgenabled"); i_tgdeferrable = PQfnumber(res, "tgdeferrable"); i_tginitdeferred = PQfnumber(res, "tginitdeferred"); i_tgdef = PQfnumber(res, "tgdef"); tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo)); for (j = 0; j < ntups; j++) { tginfo[j].dobj.objType = DO_TRIGGER; tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid)); tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid)); AssignDumpId(&tginfo[j].dobj); tginfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_tgname)); tginfo[j].dobj.namespace = tbinfo->dobj.namespace; tginfo[j].tgtable = tbinfo; tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled)); if (i_tgdef >= 0) { tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef)); /* remaining fields are not valid if we have tgdef */ tginfo[j].tgfname = NULL; tginfo[j].tgtype = 0; tginfo[j].tgnargs = 0; tginfo[j].tgargs = NULL; tginfo[j].tgisconstraint = false; tginfo[j].tgdeferrable = false; tginfo[j].tginitdeferred = false; tginfo[j].tgconstrname = NULL; tginfo[j].tgconstrrelid = InvalidOid; tginfo[j].tgconstrrelname = NULL; } else { tginfo[j].tgdef = NULL; tginfo[j].tgfname = pg_strdup(PQgetvalue(res, j, i_tgfname)); tginfo[j].tgtype = atoi(PQgetvalue(res, j, i_tgtype)); tginfo[j].tgnargs = atoi(PQgetvalue(res, j, i_tgnargs)); tginfo[j].tgargs = pg_strdup(PQgetvalue(res, j, i_tgargs)); tginfo[j].tgisconstraint = *(PQgetvalue(res, j, i_tgisconstraint)) == 't'; tginfo[j].tgdeferrable = *(PQgetvalue(res, j, i_tgdeferrable)) == 't'; tginfo[j].tginitdeferred = *(PQgetvalue(res, j, i_tginitdeferred)) == 't'; if (tginfo[j].tgisconstraint) { tginfo[j].tgconstrname = pg_strdup(PQgetvalue(res, j, i_tgconstrname)); tginfo[j].tgconstrrelid = atooid(PQgetvalue(res, j, i_tgconstrrelid)); if (OidIsValid(tginfo[j].tgconstrrelid)) { if (PQgetisnull(res, j, i_tgconstrrelname)) exit_horribly(NULL, "query produced null referenced table name for foreign key trigger \"%s\" on table \"%s\" (OID of table: %u)\n", tginfo[j].dobj.name, tbinfo->dobj.name, tginfo[j].tgconstrrelid); tginfo[j].tgconstrrelname = pg_strdup(PQgetvalue(res, j, i_tgconstrrelname)); } else tginfo[j].tgconstrrelname = NULL; } else { tginfo[j].tgconstrname = NULL; tginfo[j].tgconstrrelid = InvalidOid; tginfo[j].tgconstrrelname = NULL; } } } PQclear(res); } destroyPQExpBuffer(query); }
TSConfigInfo* getTSConfigurations | ( | Archive * | fout, | |
int * | numTSConfigs | |||
) |
Definition at line 6950 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, _cfgInfo::cfgparser, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _cfgInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _cfgInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query; TSConfigInfo *cfginfo; int i_tableoid; int i_oid; int i_cfgname; int i_cfgnamespace; int i_rolname; int i_cfgparser; /* Before 8.3, there is no built-in text search support */ if (fout->remoteVersion < 80300) { *numTSConfigs = 0; return NULL; } query = createPQExpBuffer(); /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT tableoid, oid, cfgname, " "cfgnamespace, (%s cfgowner) AS rolname, cfgparser " "FROM pg_ts_config", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numTSConfigs = ntups; cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_cfgname = PQfnumber(res, "cfgname"); i_cfgnamespace = PQfnumber(res, "cfgnamespace"); i_rolname = PQfnumber(res, "rolname"); i_cfgparser = PQfnumber(res, "cfgparser"); for (i = 0; i < ntups; i++) { cfginfo[i].dobj.objType = DO_TSCONFIG; cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&cfginfo[i].dobj); cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname)); cfginfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_cfgnamespace)), cfginfo[i].dobj.catId.oid); cfginfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser)); /* Decide whether we want to dump it */ selectDumpableObject(&(cfginfo[i].dobj)); } PQclear(res); destroyPQExpBuffer(query); return cfginfo; }
TSDictInfo* getTSDictionaries | ( | Archive * | fout, | |
int * | numTSDicts | |||
) |
Definition at line 6788 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _dictInfo::dictinitoption, _dictInfo::dicttemplate, _dictInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _dictInfo::rolname, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, and username_subquery.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query; TSDictInfo *dictinfo; int i_tableoid; int i_oid; int i_dictname; int i_dictnamespace; int i_rolname; int i_dicttemplate; int i_dictinitoption; /* Before 8.3, there is no built-in text search support */ if (fout->remoteVersion < 80300) { *numTSDicts = 0; return NULL; } query = createPQExpBuffer(); /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT tableoid, oid, dictname, " "dictnamespace, (%s dictowner) AS rolname, " "dicttemplate, dictinitoption " "FROM pg_ts_dict", username_subquery); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numTSDicts = ntups; dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_dictname = PQfnumber(res, "dictname"); i_dictnamespace = PQfnumber(res, "dictnamespace"); i_rolname = PQfnumber(res, "rolname"); i_dictinitoption = PQfnumber(res, "dictinitoption"); i_dicttemplate = PQfnumber(res, "dicttemplate"); for (i = 0; i < ntups; i++) { dictinfo[i].dobj.objType = DO_TSDICT; dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&dictinfo[i].dobj); dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname)); dictinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_dictnamespace)), dictinfo[i].dobj.catId.oid); dictinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate)); if (PQgetisnull(res, i, i_dictinitoption)) dictinfo[i].dictinitoption = NULL; else dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption)); /* Decide whether we want to dump it */ selectDumpableObject(&(dictinfo[i].dobj)); } PQclear(res); destroyPQExpBuffer(query); return dictinfo; }
TSParserInfo* getTSParsers | ( | Archive * | fout, | |
int * | numTSParsers | |||
) |
Definition at line 6696 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _prsInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _prsInfo::prsend, _prsInfo::prsheadline, _prsInfo::prslextype, _prsInfo::prsstart, _prsInfo::prstoken, Archive::remoteVersion, selectDumpableObject(), selectSourceSchema(), and CatalogId::tableoid.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query; TSParserInfo *prsinfo; int i_tableoid; int i_oid; int i_prsname; int i_prsnamespace; int i_prsstart; int i_prstoken; int i_prsend; int i_prsheadline; int i_prslextype; /* Before 8.3, there is no built-in text search support */ if (fout->remoteVersion < 80300) { *numTSParsers = 0; return NULL; } query = createPQExpBuffer(); /* * find all text search objects, including builtin ones; we filter out * system-defined objects at dump-out time. */ /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT tableoid, oid, prsname, prsnamespace, " "prsstart::oid, prstoken::oid, " "prsend::oid, prsheadline::oid, prslextype::oid " "FROM pg_ts_parser"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numTSParsers = ntups; prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_prsname = PQfnumber(res, "prsname"); i_prsnamespace = PQfnumber(res, "prsnamespace"); i_prsstart = PQfnumber(res, "prsstart"); i_prstoken = PQfnumber(res, "prstoken"); i_prsend = PQfnumber(res, "prsend"); i_prsheadline = PQfnumber(res, "prsheadline"); i_prslextype = PQfnumber(res, "prslextype"); for (i = 0; i < ntups; i++) { prsinfo[i].dobj.objType = DO_TSPARSER; prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&prsinfo[i].dobj); prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname)); prsinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_prsnamespace)), prsinfo[i].dobj.catId.oid); prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart)); prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken)); prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend)); prsinfo[i].prsheadline = atooid(PQgetvalue(res, i, i_prsheadline)); prsinfo[i].prslextype = atooid(PQgetvalue(res, i, i_prslextype)); /* Decide whether we want to dump it */ selectDumpableObject(&(prsinfo[i].dobj)); } PQclear(res); destroyPQExpBuffer(query); return prsinfo; }
TSTemplateInfo* getTSTemplates | ( | Archive * | fout, | |
int * | numTSTemplates | |||
) |
Definition at line 6873 of file pg_dump.c.
References appendPQExpBuffer(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _tmplInfo::dobj, ExecuteSqlQuery(), findNamespace(), i, _dumpableObject::name, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectDumpableObject(), selectSourceSchema(), CatalogId::tableoid, _tmplInfo::tmplinit, and _tmplInfo::tmpllexize.
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query; TSTemplateInfo *tmplinfo; int i_tableoid; int i_oid; int i_tmplname; int i_tmplnamespace; int i_tmplinit; int i_tmpllexize; /* Before 8.3, there is no built-in text search support */ if (fout->remoteVersion < 80300) { *numTSTemplates = 0; return NULL; } query = createPQExpBuffer(); /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); appendPQExpBuffer(query, "SELECT tableoid, oid, tmplname, " "tmplnamespace, tmplinit::oid, tmpllexize::oid " "FROM pg_ts_template"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); *numTSTemplates = ntups; tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_tmplname = PQfnumber(res, "tmplname"); i_tmplnamespace = PQfnumber(res, "tmplnamespace"); i_tmplinit = PQfnumber(res, "tmplinit"); i_tmpllexize = PQfnumber(res, "tmpllexize"); for (i = 0; i < ntups; i++) { tmplinfo[i].dobj.objType = DO_TSTEMPLATE; tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&tmplinfo[i].dobj); tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname)); tmplinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_tmplnamespace)), tmplinfo[i].dobj.catId.oid); tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit)); tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize)); /* Decide whether we want to dump it */ selectDumpableObject(&(tmplinfo[i].dobj)); } PQclear(res); destroyPQExpBuffer(query); return tmplinfo; }
Definition at line 3109 of file pg_dump.c.
References addObjectDependency(), appendPQExpBuffer(), AssignDumpId(), atooid, _shellTypeInfo::baseType, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _funcInfo::dobj, _shellTypeInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, ExecuteSqlQuery(), findFuncByOid(), findNamespace(), getDomainConstraints(), i, _dumpableObject::name, NULL, _dumpableObject::objType, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectDumpableType(), selectSourceSchema(), TYPTYPE_BASE, TYPTYPE_DOMAIN, TYPTYPE_RANGE, username_subquery, and write_msg().
Referenced by getSchemaData().
{ PGresult *res; int ntups; int i; PQExpBuffer query = createPQExpBuffer(); TypeInfo *tyinfo; ShellTypeInfo *stinfo; int i_tableoid; int i_oid; int i_typname; int i_typnamespace; int i_typacl; int i_rolname; int i_typinput; int i_typoutput; int i_typelem; int i_typrelid; int i_typrelkind; int i_typtype; int i_typisdefined; int i_isarray; /* * we include even the built-in types because those may be used as array * elements by user-defined types * * we filter out the built-in types when we dump out the types * * same approach for undefined (shell) types and array types * * Note: as of 8.3 we can reliably detect whether a type is an * auto-generated array type by checking the element type's typarray. * (Before that the test is capable of generating false positives.) We * still check for name beginning with '_', though, so as to avoid the * cost of the subselect probe for all standard types. This would have to * be revisited if the backend ever allows renaming of array types. */ /* Make sure we are in proper schema */ selectSourceSchema(fout, "pg_catalog"); if (fout->remoteVersion >= 90200) { appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " "typnamespace, typacl, " "(%s typowner) AS rolname, " "typinput::oid AS typinput, " "typoutput::oid AS typoutput, typelem, typrelid, " "CASE WHEN typrelid = 0 THEN ' '::\"char\" " "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " "typtype, typisdefined, " "typname[0] = '_' AND typelem != 0 AND " "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray " "FROM pg_type", username_subquery); } else if (fout->remoteVersion >= 80300) { appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " "typnamespace, '{=U}' AS typacl, " "(%s typowner) AS rolname, " "typinput::oid AS typinput, " "typoutput::oid AS typoutput, typelem, typrelid, " "CASE WHEN typrelid = 0 THEN ' '::\"char\" " "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " "typtype, typisdefined, " "typname[0] = '_' AND typelem != 0 AND " "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray " "FROM pg_type", username_subquery); } else if (fout->remoteVersion >= 70300) { appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " "typnamespace, '{=U}' AS typacl, " "(%s typowner) AS rolname, " "typinput::oid AS typinput, " "typoutput::oid AS typoutput, typelem, typrelid, " "CASE WHEN typrelid = 0 THEN ' '::\"char\" " "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " "typtype, typisdefined, " "typname[0] = '_' AND typelem != 0 AS isarray " "FROM pg_type", username_subquery); } else if (fout->remoteVersion >= 70100) { appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " "0::oid AS typnamespace, '{=U}' AS typacl, " "(%s typowner) AS rolname, " "typinput::oid AS typinput, " "typoutput::oid AS typoutput, typelem, typrelid, " "CASE WHEN typrelid = 0 THEN ' '::\"char\" " "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " "typtype, typisdefined, " "typname[0] = '_' AND typelem != 0 AS isarray " "FROM pg_type", username_subquery); } else { appendPQExpBuffer(query, "SELECT " "(SELECT oid FROM pg_class WHERE relname = 'pg_type') AS tableoid, " "oid, typname, " "0::oid AS typnamespace, '{=U}' AS typacl, " "(%s typowner) AS rolname, " "typinput::oid AS typinput, " "typoutput::oid AS typoutput, typelem, typrelid, " "CASE WHEN typrelid = 0 THEN ' '::\"char\" " "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, " "typtype, typisdefined, " "typname[0] = '_' AND typelem != 0 AS isarray " "FROM pg_type", username_subquery); } res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); ntups = PQntuples(res); tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(TypeInfo)); i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_typname = PQfnumber(res, "typname"); i_typnamespace = PQfnumber(res, "typnamespace"); i_typacl = PQfnumber(res, "typacl"); i_rolname = PQfnumber(res, "rolname"); i_typinput = PQfnumber(res, "typinput"); i_typoutput = PQfnumber(res, "typoutput"); i_typelem = PQfnumber(res, "typelem"); i_typrelid = PQfnumber(res, "typrelid"); i_typrelkind = PQfnumber(res, "typrelkind"); i_typtype = PQfnumber(res, "typtype"); i_typisdefined = PQfnumber(res, "typisdefined"); i_isarray = PQfnumber(res, "isarray"); for (i = 0; i < ntups; i++) { tyinfo[i].dobj.objType = DO_TYPE; tyinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&tyinfo[i].dobj); tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname)); tyinfo[i].dobj.namespace = findNamespace(fout, atooid(PQgetvalue(res, i, i_typnamespace)), tyinfo[i].dobj.catId.oid); tyinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); tyinfo[i].typacl = pg_strdup(PQgetvalue(res, i, i_typacl)); tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem)); tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid)); tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind); tyinfo[i].typtype = *PQgetvalue(res, i, i_typtype); tyinfo[i].shellType = NULL; if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0) tyinfo[i].isDefined = true; else tyinfo[i].isDefined = false; if (strcmp(PQgetvalue(res, i, i_isarray), "t") == 0) tyinfo[i].isArray = true; else tyinfo[i].isArray = false; /* Decide whether we want to dump it */ selectDumpableType(&tyinfo[i]); /* * If it's a domain, fetch info about its constraints, if any */ tyinfo[i].nDomChecks = 0; tyinfo[i].domChecks = NULL; if (tyinfo[i].dobj.dump && tyinfo[i].typtype == TYPTYPE_DOMAIN) getDomainConstraints(fout, &(tyinfo[i])); /* * If it's a base type, make a DumpableObject representing a shell * definition of the type. We will need to dump that ahead of the I/O * functions for the type. Similarly, range types need a shell * definition in case they have a canonicalize function. * * Note: the shell type doesn't have a catId. You might think it * should copy the base type's catId, but then it might capture the * pg_depend entries for the type, which we don't want. */ if (tyinfo[i].dobj.dump && (tyinfo[i].typtype == TYPTYPE_BASE || tyinfo[i].typtype == TYPTYPE_RANGE)) { stinfo = (ShellTypeInfo *) pg_malloc(sizeof(ShellTypeInfo)); stinfo->dobj.objType = DO_SHELL_TYPE; stinfo->dobj.catId = nilCatalogId; AssignDumpId(&stinfo->dobj); stinfo->dobj.name = pg_strdup(tyinfo[i].dobj.name); stinfo->dobj.namespace = tyinfo[i].dobj.namespace; stinfo->baseType = &(tyinfo[i]); tyinfo[i].shellType = stinfo; /* * Initially mark the shell type as not to be dumped. We'll only * dump it if the I/O or canonicalize functions need to be dumped; * this is taken care of while sorting dependencies. */ stinfo->dobj.dump = false; /* * However, if dumping from pre-7.3, there will be no dependency * info so we have to fake it here. We only need to worry about * typinput and typoutput since the other functions only exist * post-7.3. */ if (fout->remoteVersion < 70300) { Oid typinput; Oid typoutput; FuncInfo *funcInfo; typinput = atooid(PQgetvalue(res, i, i_typinput)); typoutput = atooid(PQgetvalue(res, i, i_typoutput)); funcInfo = findFuncByOid(typinput); if (funcInfo && funcInfo->dobj.dump) { /* base type depends on function */ addObjectDependency(&tyinfo[i].dobj, funcInfo->dobj.dumpId); /* function depends on shell type */ addObjectDependency(&funcInfo->dobj, stinfo->dobj.dumpId); /* mark shell type as to be dumped */ stinfo->dobj.dump = true; } funcInfo = findFuncByOid(typoutput); if (funcInfo && funcInfo->dobj.dump) { /* base type depends on function */ addObjectDependency(&tyinfo[i].dobj, funcInfo->dobj.dumpId); /* function depends on shell type */ addObjectDependency(&funcInfo->dobj, stinfo->dobj.dumpId); /* mark shell type as to be dumped */ stinfo->dobj.dump = true; } } } if (strlen(tyinfo[i].rolname) == 0 && tyinfo[i].isDefined) write_msg(NULL, "WARNING: owner of data type \"%s\" appears to be invalid\n", tyinfo[i].dobj.name); } *numTypes = ntups; PQclear(res); destroyPQExpBuffer(query); return tyinfo; }
void parseOidArray | ( | const char * | str, | |
Oid * | array, | |||
int | arraysize | |||
) |
Definition at line 816 of file common.c.
References atooid, exit_nicely, NULL, and write_msg().
Referenced by getAggregates(), getFuncs(), and getIndexes().
{ int j, argNum; char temp[100]; char s; argNum = 0; j = 0; for (;;) { s = *str++; if (s == ' ' || s == '\0') { if (j > 0) { if (argNum >= arraysize) { write_msg(NULL, "could not parse numeric array \"%s\": too many numbers\n", str); exit_nicely(1); } temp[j] = '\0'; array[argNum++] = atooid(temp); j = 0; } if (s == '\0') break; } else { if (!(isdigit((unsigned char) s) || s == '-') || j >= sizeof(temp) - 1) { write_msg(NULL, "could not parse numeric array \"%s\": invalid character in number\n", str); exit_nicely(1); } temp[j++] = s; } } while (argNum < arraysize) array[argNum++] = InvalidOid; }
void removeObjectDependency | ( | DumpableObject * | dobj, | |
DumpId | refId | |||
) |
Definition at line 675 of file common.c.
References _dumpableObject::dependencies, i, and _dumpableObject::nDeps.
Referenced by repairDependencyLoop(), repairDomainConstraintLoop(), repairDomainConstraintMultiLoop(), repairTableAttrDefLoop(), repairTableAttrDefMultiLoop(), repairTableConstraintLoop(), repairTableConstraintMultiLoop(), repairTypeFuncLoop(), repairViewRuleLoop(), and repairViewRuleMultiLoop().
{ int i; int j = 0; for (i = 0; i < dobj->nDeps; i++) { if (dobj->dependencies[i] != refId) dobj->dependencies[j++] = dobj->dependencies[i]; } dobj->nDeps = j; }
Definition at line 6680 of file pg_dump.c.
References _tableInfo::attisdropped, _tableInfo::attislocal, and binary_upgrade.
Referenced by dumpTableSchema(), flagInhAttrs(), and getTableAttrs().
{ if (binary_upgrade) return true; return (tbinfo->attislocal[colno] && !tbinfo->attisdropped[colno]); }
void simple_oid_list_append | ( | SimpleOidList * | list, | |
Oid | val | |||
) |
Definition at line 887 of file common.c.
References SimpleOidList::head, SimpleOidListCell::next, pg_malloc(), SimpleOidList::tail, and SimpleOidListCell::val.
Referenced by expand_schema_name_patterns(), and expand_table_name_patterns().
{ SimpleOidListCell *cell; cell = (SimpleOidListCell *) pg_malloc(sizeof(SimpleOidListCell)); cell->next = NULL; cell->val = val; if (list->tail) list->tail->next = cell; else list->head = cell; list->tail = cell; }
bool simple_oid_list_member | ( | SimpleOidList * | list, | |
Oid | val | |||
) |
Definition at line 903 of file common.c.
References SimpleOidList::head, SimpleOidListCell::next, and SimpleOidListCell::val.
Referenced by getExtensionMembership(), makeTableDataInfo(), selectDumpableNamespace(), and selectDumpableTable().
{ SimpleOidListCell *cell; for (cell = list->head; cell; cell = cell->next) { if (cell->val == val) return true; } return false; }
void sortDataAndIndexObjectsBySize | ( | DumpableObject ** | objs, | |
int | numObjs | |||
) |
Definition at line 183 of file pg_dump_sort.c.
References DO_INDEX, DO_TABLE_DATA, DOSizeCompare(), findFirstDifferentType(), findFirstEqualType(), and qsort.
Referenced by main().
{ int startIdx, endIdx; void *startPtr; if (numObjs <= 1) return; startIdx = findFirstEqualType(DO_TABLE_DATA, objs, numObjs); if (startIdx >= 0) { endIdx = findFirstDifferentType(DO_TABLE_DATA, objs, numObjs, startIdx); startPtr = objs + startIdx; qsort(startPtr, endIdx - startIdx, sizeof(DumpableObject *), DOSizeCompare); } startIdx = findFirstEqualType(DO_INDEX, objs, numObjs); if (startIdx >= 0) { endIdx = findFirstDifferentType(DO_INDEX, objs, numObjs, startIdx); startPtr = objs + startIdx; qsort(startPtr, endIdx - startIdx, sizeof(DumpableObject *), DOSizeCompare); } }
void sortDumpableObjects | ( | DumpableObject ** | objs, | |
int | numObjs, | |||
DumpId | preBoundaryId, | |||
DumpId | postBoundaryId | |||
) |
Definition at line 361 of file pg_dump_sort.c.
References findDependencyLoops(), free, pg_malloc(), postDataBoundId, preDataBoundId, and TopoSort().
Referenced by main().
{ DumpableObject **ordering; int nOrdering; if (numObjs <= 0) /* can't happen anymore ... */ return; /* * Saving the boundary IDs in static variables is a bit grotty, but seems * better than adding them to parameter lists of subsidiary functions. */ preDataBoundId = preBoundaryId; postDataBoundId = postBoundaryId; ordering = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *)); while (!TopoSort(objs, numObjs, ordering, &nOrdering)) findDependencyLoops(ordering, nOrdering, numObjs); memcpy(objs, ordering, numObjs * sizeof(DumpableObject *)); free(ordering); }
void sortDumpableObjectsByTypeName | ( | DumpableObject ** | objs, | |
int | numObjs | |||
) |
Definition at line 245 of file pg_dump_sort.c.
References DOTypeNameCompare(), and qsort.
Referenced by main().
{ if (numObjs > 1) qsort((void *) objs, numObjs, sizeof(DumpableObject *), DOTypeNameCompare); }
void sortDumpableObjectsByTypeOid | ( | DumpableObject ** | objs, | |
int | numObjs | |||
) |
Definition at line 329 of file pg_dump_sort.c.
References DOTypeOidCompare(), and qsort.
Referenced by main().
{ if (numObjs > 1) qsort((void *) objs, numObjs, sizeof(DumpableObject *), DOTypeOidCompare); }
char g_comment_end[10] |
char g_comment_start[10] |
char g_opaque_type[10] |
Definition at line 126 of file pg_dump.c.
Referenced by getFormattedTypeName(), and main().
Definition at line 89 of file pg_dump.c.
Referenced by dumpBlobs(), dumpDatabase(), dumpEncoding(), dumpStdStrings(), dumpTableData_copy(), getBlobs(), getConstraints(), getDependencies(), getIndexes(), getSchemaData(), getTableAttrs(), getTriggers(), and main().