PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_dump.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <ctype.h>
#include "getopt_long.h"
#include "access/attnum.h"
#include "access/sysattr.h"
#include "access/transam.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_am.h"
#include "catalog/pg_attribute.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_class.h"
#include "catalog/pg_default_acl.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_type.h"
#include "libpq/libpq-fs.h"
#include "dumputils.h"
#include "parallel.h"
#include "pg_backup_db.h"
#include "pg_backup_utils.h"
#include "pg_dump.h"
#include "fe_utils/string_utils.h"
Include dependency graph for pg_dump.c:

Go to the source code of this file.

Data Structures

struct  CommentItem
 
struct  SecLabelItem
 

Typedefs

typedef enum OidOptions OidOptions
 

Enumerations

enum  OidOptions { zeroAsOpaque = 1, zeroAsAny = 2, zeroAsStar = 4, zeroAsNone = 8 }
 

Functions

static void help (const char *progname)
 
static void setup_connection (Archive *AH, const char *dumpencoding, const char *dumpsnapshot, char *use_role)
 
static ArchiveFormat parseArchiveFormat (const char *format, ArchiveMode *mode)
 
static void expand_schema_name_patterns (Archive *fout, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names)
 
static void expand_table_name_patterns (Archive *fout, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names)
 
static NamespaceInfofindNamespace (Archive *fout, Oid nsoid)
 
static void dumpTableData (Archive *fout, TableDataInfo *tdinfo)
 
static void refreshMatViewData (Archive *fout, TableDataInfo *tdinfo)
 
static void guessConstraintInheritance (TableInfo *tblinfo, int numTables)
 
static void dumpComment (Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
 
static int findComments (Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
 
static int collectComments (Archive *fout, CommentItem **items)
 
static void dumpSecLabel (Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
 
static int findSecLabels (Archive *fout, Oid classoid, Oid objoid, SecLabelItem **items)
 
static int collectSecLabels (Archive *fout, SecLabelItem **items)
 
static void dumpDumpableObject (Archive *fout, DumpableObject *dobj)
 
static void dumpNamespace (Archive *fout, NamespaceInfo *nspinfo)
 
static void dumpExtension (Archive *fout, ExtensionInfo *extinfo)
 
static void dumpType (Archive *fout, TypeInfo *tyinfo)
 
static void dumpBaseType (Archive *fout, TypeInfo *tyinfo)
 
static void dumpEnumType (Archive *fout, TypeInfo *tyinfo)
 
static void dumpRangeType (Archive *fout, TypeInfo *tyinfo)
 
static void dumpUndefinedType (Archive *fout, TypeInfo *tyinfo)
 
static void dumpDomain (Archive *fout, TypeInfo *tyinfo)
 
static void dumpCompositeType (Archive *fout, TypeInfo *tyinfo)
 
static void dumpCompositeTypeColComments (Archive *fout, TypeInfo *tyinfo)
 
static void dumpShellType (Archive *fout, ShellTypeInfo *stinfo)
 
static void dumpProcLang (Archive *fout, ProcLangInfo *plang)
 
static void dumpFunc (Archive *fout, FuncInfo *finfo)
 
static void dumpCast (Archive *fout, CastInfo *cast)
 
static void dumpTransform (Archive *fout, TransformInfo *transform)
 
static void dumpOpr (Archive *fout, OprInfo *oprinfo)
 
static void dumpAccessMethod (Archive *fout, AccessMethodInfo *oprinfo)
 
static void dumpOpclass (Archive *fout, OpclassInfo *opcinfo)
 
static void dumpOpfamily (Archive *fout, OpfamilyInfo *opfinfo)
 
static void dumpCollation (Archive *fout, CollInfo *collinfo)
 
static void dumpConversion (Archive *fout, ConvInfo *convinfo)
 
static void dumpRule (Archive *fout, RuleInfo *rinfo)
 
static void dumpAgg (Archive *fout, AggInfo *agginfo)
 
static void dumpTrigger (Archive *fout, TriggerInfo *tginfo)
 
static void dumpEventTrigger (Archive *fout, EventTriggerInfo *evtinfo)
 
static void dumpTable (Archive *fout, TableInfo *tbinfo)
 
static void dumpTableSchema (Archive *fout, TableInfo *tbinfo)
 
static void dumpAttrDef (Archive *fout, AttrDefInfo *adinfo)
 
static void dumpSequence (Archive *fout, TableInfo *tbinfo)
 
static void dumpSequenceData (Archive *fout, TableDataInfo *tdinfo)
 
static void dumpIndex (Archive *fout, IndxInfo *indxinfo)
 
static void dumpStatisticsExt (Archive *fout, StatsExtInfo *statsextinfo)
 
static void dumpConstraint (Archive *fout, ConstraintInfo *coninfo)
 
static void dumpTableConstraintComment (Archive *fout, ConstraintInfo *coninfo)
 
static void dumpTSParser (Archive *fout, TSParserInfo *prsinfo)
 
static void dumpTSDictionary (Archive *fout, TSDictInfo *dictinfo)
 
static void dumpTSTemplate (Archive *fout, TSTemplateInfo *tmplinfo)
 
static void dumpTSConfig (Archive *fout, TSConfigInfo *cfginfo)
 
static void dumpForeignDataWrapper (Archive *fout, FdwInfo *fdwinfo)
 
static void dumpForeignServer (Archive *fout, ForeignServerInfo *srvinfo)
 
static void dumpUserMappings (Archive *fout, const char *servername, const char *namespace, const char *owner, CatalogId catalogId, DumpId dumpId)
 
static void dumpDefaultACL (Archive *fout, DefaultACLInfo *daclinfo)
 
static void dumpACL (Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *tag, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
 
static void getDependencies (Archive *fout)
 
static void BuildArchiveDependencies (Archive *fout)
 
static void findDumpableDependencies (ArchiveHandle *AH, DumpableObject *dobj, DumpId **dependencies, int *nDeps, int *allocDeps)
 
static DumpableObjectcreateBoundaryObjects (void)
 
static void addBoundaryDependencies (DumpableObject **dobjs, int numObjs, DumpableObject *boundaryObjs)
 
static void getDomainConstraints (Archive *fout, TypeInfo *tyinfo)
 
static void getTableData (DumpOptions *dopt, TableInfo *tblinfo, int numTables, bool oids, char relkind)
 
static void makeTableDataInfo (DumpOptions *dopt, TableInfo *tbinfo, bool oids)
 
static void buildMatViewRefreshDependencies (Archive *fout)
 
static void getTableDataFKConstraints (void)
 
static char * format_function_arguments (FuncInfo *finfo, char *funcargs, bool is_agg)
 
static char * format_function_arguments_old (Archive *fout, FuncInfo *finfo, int nallargs, char **allargtypes, char **argmodes, char **argnames)
 
static char * format_function_signature (Archive *fout, FuncInfo *finfo, bool honor_quotes)
 
static char * convertRegProcReference (Archive *fout, const char *proc)
 
static char * convertOperatorReference (Archive *fout, const char *opr)
 
static char * convertTSFunction (Archive *fout, Oid funcOid)
 
static Oid findLastBuiltinOid_V71 (Archive *fout, const char *)
 
static void selectSourceSchema (Archive *fout, const char *schemaName)
 
static char * getFormattedTypeName (Archive *fout, Oid oid, OidOptions opts)
 
static void getBlobs (Archive *fout)
 
static void dumpBlob (Archive *fout, BlobInfo *binfo)
 
static int dumpBlobs (Archive *fout, void *arg)
 
static void dumpPolicy (Archive *fout, PolicyInfo *polinfo)
 
static void dumpPublication (Archive *fout, PublicationInfo *pubinfo)
 
static void dumpPublicationTable (Archive *fout, PublicationRelInfo *pubrinfo)
 
static void dumpSubscription (Archive *fout, SubscriptionInfo *subinfo)
 
static void dumpDatabase (Archive *AH)
 
static void dumpEncoding (Archive *AH)
 
static void dumpStdStrings (Archive *AH)
 
static void binary_upgrade_set_type_oids_by_type_oid (Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid, bool force_array_type)
 
static bool binary_upgrade_set_type_oids_by_rel_oid (Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_rel_oid)
 
static void binary_upgrade_set_pg_class_oids (Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
 
static void binary_upgrade_extension_member (PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
 
static const char * getAttrName (int attrnum, TableInfo *tblInfo)
 
static const char * fmtCopyColumnList (const TableInfo *ti, PQExpBuffer buffer)
 
static bool nonemptyReloptions (const char *reloptions)
 
static void appendReloptionsArrayAH (PQExpBuffer buffer, const char *reloptions, const char *prefix, Archive *fout)
 
static char * get_synchronized_snapshot (Archive *fout)
 
static void setupDumpWorker (Archive *AHX)
 
static TableInfogetRootTableInfo (TableInfo *tbinfo)
 
int main (int argc, char **argv)
 
static bool checkExtensionMembership (DumpableObject *dobj, Archive *fout)
 
static void selectDumpableNamespace (NamespaceInfo *nsinfo, Archive *fout)
 
static void selectDumpableTable (TableInfo *tbinfo, Archive *fout)
 
static void selectDumpableType (TypeInfo *tyinfo, Archive *fout)
 
static void selectDumpableDefaultACL (DefaultACLInfo *dinfo, DumpOptions *dopt)
 
static void selectDumpableCast (CastInfo *cast, Archive *fout)
 
static void selectDumpableProcLang (ProcLangInfo *plang, Archive *fout)
 
static void selectDumpableAccessMethod (AccessMethodInfo *method, Archive *fout)
 
static void selectDumpableExtension (ExtensionInfo *extinfo, DumpOptions *dopt)
 
static void selectDumpablePublicationTable (DumpableObject *dobj, Archive *fout)
 
static void selectDumpableObject (DumpableObject *dobj, Archive *fout)
 
static int dumpTableData_copy (Archive *fout, void *dcontext)
 
static int dumpTableData_insert (Archive *fout, void *dcontext)
 
void getPolicies (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getPublications (Archive *fout)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
static bool is_superuser (Archive *fout)
 
void getSubscriptions (Archive *fout)
 
NamespaceInfogetNamespaces (Archive *fout, int *numNamespaces)
 
ExtensionInfogetExtensions (Archive *fout, int *numExtensions)
 
TypeInfogetTypes (Archive *fout, int *numTypes)
 
OprInfogetOperators (Archive *fout, int *numOprs)
 
CollInfogetCollations (Archive *fout, int *numCollations)
 
ConvInfogetConversions (Archive *fout, int *numConversions)
 
AccessMethodInfogetAccessMethods (Archive *fout, int *numAccessMethods)
 
OpclassInfogetOpclasses (Archive *fout, int *numOpclasses)
 
OpfamilyInfogetOpfamilies (Archive *fout, int *numOpfamilies)
 
AggInfogetAggregates (Archive *fout, int *numAggs)
 
FuncInfogetFuncs (Archive *fout, int *numFuncs)
 
TableInfogetTables (Archive *fout, int *numTables)
 
void getOwnedSeqs (Archive *fout, TableInfo tblinfo[], int numTables)
 
InhInfogetInherits (Archive *fout, int *numInherits)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getConstraints (Archive *fout, TableInfo tblinfo[], int numTables)
 
RuleInfogetRules (Archive *fout, int *numRules)
 
void getTriggers (Archive *fout, TableInfo tblinfo[], int numTables)
 
EventTriggerInfogetEventTriggers (Archive *fout, int *numEventTriggers)
 
ProcLangInfogetProcLangs (Archive *fout, int *numProcLangs)
 
CastInfogetCasts (Archive *fout, int *numCasts)
 
static char * get_language_name (Archive *fout, Oid langid)
 
TransformInfogetTransforms (Archive *fout, int *numTransforms)
 
void getTableAttrs (Archive *fout, TableInfo *tblinfo, int numTables)
 
bool shouldPrintColumn (DumpOptions *dopt, TableInfo *tbinfo, int colno)
 
TSParserInfogetTSParsers (Archive *fout, int *numTSParsers)
 
TSDictInfogetTSDictionaries (Archive *fout, int *numTSDicts)
 
TSTemplateInfogetTSTemplates (Archive *fout, int *numTSTemplates)
 
TSConfigInfogetTSConfigurations (Archive *fout, int *numTSConfigs)
 
FdwInfogetForeignDataWrappers (Archive *fout, int *numForeignDataWrappers)
 
ForeignServerInfogetForeignServers (Archive *fout, int *numForeignServers)
 
DefaultACLInfogetDefaultACLs (Archive *fout, int *numDefaultACLs)
 
static void dumpTableComment (Archive *fout, TableInfo *tbinfo, const char *reltypename)
 
static char * format_aggregate_signature (AggInfo *agginfo, Archive *fout, bool honor_quotes)
 
static void dumpTableSecLabel (Archive *fout, TableInfo *tbinfo, const char *reltypename)
 
static PQExpBuffer createViewAsClause (Archive *fout, TableInfo *tbinfo)
 
static PQExpBuffer createDummyViewAsClause (Archive *fout, TableInfo *tbinfo)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 

Variables

bool g_verbose
 
static bool dosync = true
 
static const char * username_subquery
 
static Oid g_last_builtin_oid
 
static int strict_names = 0
 
static SimpleStringList schema_include_patterns = {NULL, NULL}
 
static SimpleOidList schema_include_oids = {NULL, NULL}
 
static SimpleStringList schema_exclude_patterns = {NULL, NULL}
 
static SimpleOidList schema_exclude_oids = {NULL, NULL}
 
static SimpleStringList table_include_patterns = {NULL, NULL}
 
static SimpleOidList table_include_oids = {NULL, NULL}
 
static SimpleStringList table_exclude_patterns = {NULL, NULL}
 
static SimpleOidList table_exclude_oids = {NULL, NULL}
 
static SimpleStringList tabledata_exclude_patterns = {NULL, NULL}
 
static SimpleOidList tabledata_exclude_oids = {NULL, NULL}
 
char g_opaque_type [10]
 
char g_comment_start [10]
 
char g_comment_end [10]
 
static const CatalogId nilCatalogId = {0, 0}
 

Typedef Documentation

Enumeration Type Documentation

enum OidOptions
Enumerator
zeroAsOpaque 
zeroAsAny 
zeroAsStar 
zeroAsNone 

Definition at line 83 of file pg_dump.c.

84 {
85  zeroAsOpaque = 1,
86  zeroAsAny = 2,
87  zeroAsStar = 4,
88  zeroAsNone = 8
89 } OidOptions;
OidOptions
Definition: pg_dump.c:83

Function Documentation

static void addBoundaryDependencies ( DumpableObject **  dobjs,
int  numObjs,
DumpableObject boundaryObjs 
)
static

Definition at line 17728 of file pg_dump.c.

References addObjectDependency(), DO_ACCESS_METHOD, DO_AGG, DO_ATTRDEF, DO_BLOB, DO_BLOB_DATA, DO_CAST, DO_COLLATION, DO_CONSTRAINT, DO_CONVERSION, DO_DEFAULT_ACL, DO_DUMMY_TYPE, DO_EVENT_TRIGGER, DO_EXTENSION, DO_FDW, DO_FK_CONSTRAINT, DO_FOREIGN_SERVER, DO_FUNC, DO_INDEX, DO_NAMESPACE, DO_OPCLASS, DO_OPERATOR, DO_OPFAMILY, DO_POLICY, DO_POST_DATA_BOUNDARY, DO_PRE_DATA_BOUNDARY, DO_PROCLANG, DO_PUBLICATION, DO_PUBLICATION_REL, DO_REFRESH_MATVIEW, DO_RULE, DO_SEQUENCE_SET, DO_SHELL_TYPE, DO_STATSEXT, DO_SUBSCRIPTION, DO_TABLE, DO_TABLE_DATA, DO_TRANSFORM, DO_TRIGGER, DO_TSCONFIG, DO_TSDICT, DO_TSPARSER, DO_TSTEMPLATE, DO_TYPE, _dumpableObject::dumpId, i, and _dumpableObject::objType.

Referenced by main().

17730 {
17731  DumpableObject *preDataBound = boundaryObjs + 0;
17732  DumpableObject *postDataBound = boundaryObjs + 1;
17733  int i;
17734 
17735  for (i = 0; i < numObjs; i++)
17736  {
17737  DumpableObject *dobj = dobjs[i];
17738 
17739  /*
17740  * The classification of object types here must match the SECTION_xxx
17741  * values assigned during subsequent ArchiveEntry calls!
17742  */
17743  switch (dobj->objType)
17744  {
17745  case DO_NAMESPACE:
17746  case DO_EXTENSION:
17747  case DO_TYPE:
17748  case DO_SHELL_TYPE:
17749  case DO_FUNC:
17750  case DO_AGG:
17751  case DO_OPERATOR:
17752  case DO_ACCESS_METHOD:
17753  case DO_OPCLASS:
17754  case DO_OPFAMILY:
17755  case DO_COLLATION:
17756  case DO_CONVERSION:
17757  case DO_TABLE:
17758  case DO_ATTRDEF:
17759  case DO_PROCLANG:
17760  case DO_CAST:
17761  case DO_DUMMY_TYPE:
17762  case DO_TSPARSER:
17763  case DO_TSDICT:
17764  case DO_TSTEMPLATE:
17765  case DO_TSCONFIG:
17766  case DO_FDW:
17767  case DO_FOREIGN_SERVER:
17768  case DO_TRANSFORM:
17769  case DO_BLOB:
17770  /* Pre-data objects: must come before the pre-data boundary */
17771  addObjectDependency(preDataBound, dobj->dumpId);
17772  break;
17773  case DO_TABLE_DATA:
17774  case DO_SEQUENCE_SET:
17775  case DO_BLOB_DATA:
17776  /* Data objects: must come between the boundaries */
17777  addObjectDependency(dobj, preDataBound->dumpId);
17778  addObjectDependency(postDataBound, dobj->dumpId);
17779  break;
17780  case DO_INDEX:
17781  case DO_STATSEXT:
17782  case DO_REFRESH_MATVIEW:
17783  case DO_TRIGGER:
17784  case DO_EVENT_TRIGGER:
17785  case DO_DEFAULT_ACL:
17786  case DO_POLICY:
17787  case DO_PUBLICATION:
17788  case DO_PUBLICATION_REL:
17789  case DO_SUBSCRIPTION:
17790  /* Post-data objects: must come after the post-data boundary */
17791  addObjectDependency(dobj, postDataBound->dumpId);
17792  break;
17793  case DO_RULE:
17794  /* Rules are post-data, but only if dumped separately */
17795  if (((RuleInfo *) dobj)->separate)
17796  addObjectDependency(dobj, postDataBound->dumpId);
17797  break;
17798  case DO_CONSTRAINT:
17799  case DO_FK_CONSTRAINT:
17800  /* Constraints are post-data, but only if dumped separately */
17801  if (((ConstraintInfo *) dobj)->separate)
17802  addObjectDependency(dobj, postDataBound->dumpId);
17803  break;
17804  case DO_PRE_DATA_BOUNDARY:
17805  /* nothing to do */
17806  break;
17807  case DO_POST_DATA_BOUNDARY:
17808  /* must come after the pre-data boundary */
17809  addObjectDependency(dobj, preDataBound->dumpId);
17810  break;
17811  }
17812  }
17813 }
DumpId dumpId
Definition: pg_dump.h:132
Definition: pg_dump.h:49
Definition: pg_dump.h:73
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:712
int i
DumpableObjectType objType
Definition: pg_dump.h:130
static void appendReloptionsArrayAH ( PQExpBuffer  buffer,
const char *  reloptions,
const char *  prefix,
Archive fout 
)
static

Definition at line 18059 of file pg_dump.c.

References appendReloptionsArray(), Archive::encoding, Archive::std_strings, and write_msg().

Referenced by dumpConstraint(), dumpRule(), and dumpTableSchema().

18061 {
18062  bool res;
18063 
18064  res = appendReloptionsArray(buffer, reloptions, prefix, fout->encoding,
18065  fout->std_strings);
18066  if (!res)
18067  write_msg(NULL, "WARNING: could not parse reloptions array\n");
18068 }
int encoding
Definition: pg_backup.h:196
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
Definition: string_utils.c:747
void write_msg(const char *modulename, const char *fmt,...)
bool std_strings
Definition: pg_backup.h:197
static void binary_upgrade_extension_member ( PQExpBuffer  upgrade_buffer,
DumpableObject dobj,
const char *  objlabel 
)
static

Definition at line 4135 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), _dumpableObject::dependencies, DO_EXTENSION, exit_horribly(), _dumpableObject::ext_member, findObjectByDumpId(), fmtId(), i, _dumpableObject::name, _dumpableObject::nDeps, and _dumpableObject::objType.

Referenced by dumpAccessMethod(), dumpAgg(), dumpBaseType(), dumpCast(), dumpCollation(), dumpCompositeType(), dumpConversion(), dumpDomain(), dumpEnumType(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpProcLang(), dumpRangeType(), dumpSequence(), dumpTableSchema(), dumpTransform(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), and dumpUndefinedType().

4138 {
4139  DumpableObject *extobj = NULL;
4140  int i;
4141 
4142  if (!dobj->ext_member)
4143  return;
4144 
4145  /*
4146  * Find the parent extension. We could avoid this search if we wanted to
4147  * add a link field to DumpableObject, but the space costs of that would
4148  * be considerable. We assume that member objects could only have a
4149  * direct dependency on their own extension, not any others.
4150  */
4151  for (i = 0; i < dobj->nDeps; i++)
4152  {
4153  extobj = findObjectByDumpId(dobj->dependencies[i]);
4154  if (extobj && extobj->objType == DO_EXTENSION)
4155  break;
4156  extobj = NULL;
4157  }
4158  if (extobj == NULL)
4159  exit_horribly(NULL, "could not find parent extension for %s\n", objlabel);
4160 
4161  appendPQExpBufferStr(upgrade_buffer,
4162  "\n-- For binary upgrade, handle extension membership the hard way\n");
4163  appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s;\n",
4164  fmtId(extobj->name),
4165  objlabel);
4166 }
char * name
Definition: pg_dump.h:133
DumpId * dependencies
Definition: pg_dump.h:138
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
bool ext_member
Definition: pg_dump.h:137
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:540
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
void exit_horribly(const char *modulename, const char *fmt,...)
int i
DumpableObjectType objType
Definition: pg_dump.h:130
static void binary_upgrade_set_pg_class_oids ( Archive fout,
PQExpBuffer  upgrade_buffer,
Oid  pg_class_oid,
bool  is_index 
)
static

Definition at line 4068 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQueryForSingleRow(), OidIsValid, PQclear(), PQfnumber(), and PQgetvalue().

Referenced by dumpCompositeType(), dumpConstraint(), dumpIndex(), dumpSequence(), and dumpTableSchema().

4071 {
4072  PQExpBuffer upgrade_query = createPQExpBuffer();
4073  PGresult *upgrade_res;
4074  Oid pg_class_reltoastrelid;
4075  Oid pg_index_indexrelid;
4076 
4077  appendPQExpBuffer(upgrade_query,
4078  "SELECT c.reltoastrelid, i.indexrelid "
4079  "FROM pg_catalog.pg_class c LEFT JOIN "
4080  "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
4081  "WHERE c.oid = '%u'::pg_catalog.oid;",
4082  pg_class_oid);
4083 
4084  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4085 
4086  pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
4087  pg_index_indexrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "indexrelid")));
4088 
4089  appendPQExpBufferStr(upgrade_buffer,
4090  "\n-- For binary upgrade, must preserve pg_class oids\n");
4091 
4092  if (!is_index)
4093  {
4094  appendPQExpBuffer(upgrade_buffer,
4095  "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
4096  pg_class_oid);
4097  /* only tables have toast tables, not indexes */
4098  if (OidIsValid(pg_class_reltoastrelid))
4099  {
4100  /*
4101  * One complexity is that the table definition might not require
4102  * the creation of a TOAST table, and the TOAST table might have
4103  * been created long after table creation, when the table was
4104  * loaded with wide data. By setting the TOAST oid we force
4105  * creation of the TOAST heap and TOAST index by the backend so we
4106  * can cleanly copy the files during binary upgrade.
4107  */
4108 
4109  appendPQExpBuffer(upgrade_buffer,
4110  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
4111  pg_class_reltoastrelid);
4112 
4113  /* every toast table has an index */
4114  appendPQExpBuffer(upgrade_buffer,
4115  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4116  pg_index_indexrelid);
4117  }
4118  }
4119  else
4120  appendPQExpBuffer(upgrade_buffer,
4121  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4122  pg_class_oid);
4123 
4124  appendPQExpBufferChar(upgrade_buffer, '\n');
4125 
4126  PQclear(upgrade_res);
4127  destroyPQExpBuffer(upgrade_query);
4128 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
void PQclear(PGresult *res)
Definition: fe-exec.c:671
static bool binary_upgrade_set_type_oids_by_rel_oid ( Archive fout,
PQExpBuffer  upgrade_buffer,
Oid  pg_rel_oid 
)
static

Definition at line 4022 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), atooid, binary_upgrade_set_type_oids_by_type_oid(), createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQueryForSingleRow(), PQclear(), PQfnumber(), PQgetisnull(), and PQgetvalue().

Referenced by dumpSequence(), and dumpTableSchema().

4025 {
4026  PQExpBuffer upgrade_query = createPQExpBuffer();
4027  PGresult *upgrade_res;
4028  Oid pg_type_oid;
4029  bool toast_set = false;
4030 
4031  /* we only support old >= 8.3 for binary upgrades */
4032  appendPQExpBuffer(upgrade_query,
4033  "SELECT c.reltype AS crel, t.reltype AS trel "
4034  "FROM pg_catalog.pg_class c "
4035  "LEFT JOIN pg_catalog.pg_class t ON "
4036  " (c.reltoastrelid = t.oid) "
4037  "WHERE c.oid = '%u'::pg_catalog.oid;",
4038  pg_rel_oid);
4039 
4040  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4041 
4042  pg_type_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "crel")));
4043 
4044  binary_upgrade_set_type_oids_by_type_oid(fout, upgrade_buffer,
4045  pg_type_oid, false);
4046 
4047  if (!PQgetisnull(upgrade_res, 0, PQfnumber(upgrade_res, "trel")))
4048  {
4049  /* Toast tables do not have pg_type array rows */
4050  Oid pg_type_toast_oid = atooid(PQgetvalue(upgrade_res, 0,
4051  PQfnumber(upgrade_res, "trel")));
4052 
4053  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
4054  appendPQExpBuffer(upgrade_buffer,
4055  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4056  pg_type_toast_oid);
4057 
4058  toast_set = true;
4059  }
4060 
4061  PQclear(upgrade_res);
4062  destroyPQExpBuffer(upgrade_query);
4063 
4064  return toast_set;
4065 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid, bool force_array_type)
Definition: pg_dump.c:3953
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
static void binary_upgrade_set_type_oids_by_type_oid ( Archive fout,
PQExpBuffer  upgrade_buffer,
Oid  pg_type_oid,
bool  force_array_type 
)
static

Definition at line 3953 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQueryForSingleRow(), FirstNormalObjectId, OidIsValid, PQclear(), PQfnumber(), PQgetvalue(), and printfPQExpBuffer().

Referenced by binary_upgrade_set_type_oids_by_rel_oid(), dumpBaseType(), dumpCompositeType(), dumpDomain(), dumpEnumType(), dumpRangeType(), dumpShellType(), and dumpUndefinedType().

3957 {
3958  PQExpBuffer upgrade_query = createPQExpBuffer();
3959  PGresult *res;
3960  Oid pg_type_array_oid;
3961 
3962  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
3963  appendPQExpBuffer(upgrade_buffer,
3964  "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3965  pg_type_oid);
3966 
3967  /* we only support old >= 8.3 for binary upgrades */
3968  appendPQExpBuffer(upgrade_query,
3969  "SELECT typarray "
3970  "FROM pg_catalog.pg_type "
3971  "WHERE oid = '%u'::pg_catalog.oid;",
3972  pg_type_oid);
3973 
3974  res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
3975 
3976  pg_type_array_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typarray")));
3977 
3978  PQclear(res);
3979 
3980  if (!OidIsValid(pg_type_array_oid) && force_array_type)
3981  {
3982  /*
3983  * If the old version didn't assign an array type, but the new version
3984  * does, we must select an unused type OID to assign. This currently
3985  * only happens for domains, when upgrading pre-v11 to v11 and up.
3986  *
3987  * Note: local state here is kind of ugly, but we must have some,
3988  * since we mustn't choose the same unused OID more than once.
3989  */
3990  static Oid next_possible_free_oid = FirstNormalObjectId;
3991  bool is_dup;
3992 
3993  do
3994  {
3995  ++next_possible_free_oid;
3996  printfPQExpBuffer(upgrade_query,
3997  "SELECT EXISTS(SELECT 1 "
3998  "FROM pg_catalog.pg_type "
3999  "WHERE oid = '%u'::pg_catalog.oid);",
4000  next_possible_free_oid);
4001  res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4002  is_dup = (PQgetvalue(res, 0, 0)[0] == 't');
4003  PQclear(res);
4004  } while (is_dup);
4005 
4006  pg_type_array_oid = next_possible_free_oid;
4007  }
4008 
4009  if (OidIsValid(pg_type_array_oid))
4010  {
4011  appendPQExpBufferStr(upgrade_buffer,
4012  "\n-- For binary upgrade, must preserve pg_type array oid\n");
4013  appendPQExpBuffer(upgrade_buffer,
4014  "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4015  pg_type_array_oid);
4016  }
4017 
4018  destroyPQExpBuffer(upgrade_query);
4019 }
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:234
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
#define FirstNormalObjectId
Definition: transam.h:94
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
static void BuildArchiveDependencies ( Archive fout)
static

Definition at line 17840 of file pg_dump.c.

References _tocEntry::dependencies, _tocEntry::dumpId, findDumpableDependencies(), findObjectByDumpId(), free, _dumpableObject::nDeps, _tocEntry::nDeps, _tocEntry::next, pg_malloc(), pg_realloc(), _tocEntry::reqs, and _archiveHandle::toc.

Referenced by main().

17841 {
17842  ArchiveHandle *AH = (ArchiveHandle *) fout;
17843  TocEntry *te;
17844 
17845  /* Scan all TOC entries in the archive */
17846  for (te = AH->toc->next; te != AH->toc; te = te->next)
17847  {
17848  DumpableObject *dobj;
17849  DumpId *dependencies;
17850  int nDeps;
17851  int allocDeps;
17852 
17853  /* No need to process entries that will not be dumped */
17854  if (te->reqs == 0)
17855  continue;
17856  /* Ignore entries that already have "special" dependencies */
17857  if (te->nDeps > 0)
17858  continue;
17859  /* Otherwise, look up the item's original DumpableObject, if any */
17860  dobj = findObjectByDumpId(te->dumpId);
17861  if (dobj == NULL)
17862  continue;
17863  /* No work if it has no dependencies */
17864  if (dobj->nDeps <= 0)
17865  continue;
17866  /* Set up work array */
17867  allocDeps = 64;
17868  dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(DumpId));
17869  nDeps = 0;
17870  /* Recursively find all dumpable dependencies */
17871  findDumpableDependencies(AH, dobj,
17872  &dependencies, &nDeps, &allocDeps);
17873  /* And save 'em ... */
17874  if (nDeps > 0)
17875  {
17876  dependencies = (DumpId *) pg_realloc(dependencies,
17877  nDeps * sizeof(DumpId));
17878  te->dependencies = dependencies;
17879  te->nDeps = nDeps;
17880  }
17881  else
17882  free(dependencies);
17883  }
17884 }
struct _tocEntry * next
int DumpId
Definition: pg_backup.h:230
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:540
struct _tocEntry * toc
DumpId * dependencies
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
static void findDumpableDependencies(ArchiveHandle *AH, DumpableObject *dobj, DumpId **dependencies, int *nDeps, int *allocDeps)
Definition: pg_dump.c:17888
#define free(a)
Definition: header.h:65
static void buildMatViewRefreshDependencies ( Archive fout)
static

Definition at line 2291 of file pg_dump.c.

References addObjectDependency(), appendPQExpBufferStr(), Assert, atooid, CppAsString2, createPQExpBuffer(), PQExpBufferData::data, _tableInfo::dataObj, destroyPQExpBuffer(), DO_REFRESH_MATVIEW, DO_TABLE, _dumpableObject::dumpId, ExecuteSqlQuery(), findObjectByCatalogId(), i, _dumpableObject::objType, CatalogId::oid, PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), _tableInfo::relispopulated, _tableInfo::relkind, RELKIND_MATVIEW, RELKIND_VIEW, Archive::remoteVersion, selectSourceSchema(), and CatalogId::tableoid.

Referenced by main().

2292 {
2293  PQExpBuffer query;
2294  PGresult *res;
2295  int ntups,
2296  i;
2297  int i_classid,
2298  i_objid,
2299  i_refobjid;
2300 
2301  /* No Mat Views before 9.3. */
2302  if (fout->remoteVersion < 90300)
2303  return;
2304 
2305  /* Make sure we are in proper schema */
2306  selectSourceSchema(fout, "pg_catalog");
2307 
2308  query = createPQExpBuffer();
2309 
2310  appendPQExpBufferStr(query, "WITH RECURSIVE w AS "
2311  "( "
2312  "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2313  "FROM pg_depend d1 "
2314  "JOIN pg_class c1 ON c1.oid = d1.objid "
2315  "AND c1.relkind = " CppAsString2(RELKIND_MATVIEW)
2316  " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2317  "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2318  "AND d2.objid = r1.oid "
2319  "AND d2.refobjid <> d1.objid "
2320  "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2321  "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2323  "WHERE d1.classid = 'pg_class'::regclass "
2324  "UNION "
2325  "SELECT w.objid, d3.refobjid, c3.relkind "
2326  "FROM w "
2327  "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2328  "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2329  "AND d3.objid = r3.oid "
2330  "AND d3.refobjid <> w.refobjid "
2331  "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2332  "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2334  ") "
2335  "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2336  "FROM w "
2337  "WHERE refrelkind = " CppAsString2(RELKIND_MATVIEW));
2338 
2339  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
2340 
2341  ntups = PQntuples(res);
2342 
2343  i_classid = PQfnumber(res, "classid");
2344  i_objid = PQfnumber(res, "objid");
2345  i_refobjid = PQfnumber(res, "refobjid");
2346 
2347  for (i = 0; i < ntups; i++)
2348  {
2349  CatalogId objId;
2350  CatalogId refobjId;
2351  DumpableObject *dobj;
2352  DumpableObject *refdobj;
2353  TableInfo *tbinfo;
2354  TableInfo *reftbinfo;
2355 
2356  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
2357  objId.oid = atooid(PQgetvalue(res, i, i_objid));
2358  refobjId.tableoid = objId.tableoid;
2359  refobjId.oid = atooid(PQgetvalue(res, i, i_refobjid));
2360 
2361  dobj = findObjectByCatalogId(objId);
2362  if (dobj == NULL)
2363  continue;
2364 
2365  Assert(dobj->objType == DO_TABLE);
2366  tbinfo = (TableInfo *) dobj;
2367  Assert(tbinfo->relkind == RELKIND_MATVIEW);
2368  dobj = (DumpableObject *) tbinfo->dataObj;
2369  if (dobj == NULL)
2370  continue;
2371  Assert(dobj->objType == DO_REFRESH_MATVIEW);
2372 
2373  refdobj = findObjectByCatalogId(refobjId);
2374  if (refdobj == NULL)
2375  continue;
2376 
2377  Assert(refdobj->objType == DO_TABLE);
2378  reftbinfo = (TableInfo *) refdobj;
2379  Assert(reftbinfo->relkind == RELKIND_MATVIEW);
2380  refdobj = (DumpableObject *) reftbinfo->dataObj;
2381  if (refdobj == NULL)
2382  continue;
2383  Assert(refdobj->objType == DO_REFRESH_MATVIEW);
2384 
2385  addObjectDependency(dobj, refdobj->dumpId);
2386 
2387  if (!reftbinfo->relispopulated)
2388  tbinfo->relispopulated = false;
2389  }
2390 
2391  PQclear(res);
2392 
2393  destroyPQExpBuffer(query);
2394 }
char relkind
Definition: pg_dump.h:267
Oid tableoid
Definition: pg_backup.h:226
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
#define RELKIND_MATVIEW
Definition: pg_class.h:165
DumpId dumpId
Definition: pg_dump.h:132
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:558
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
#define CppAsString2(x)
Definition: c.h:162
struct _tableDataInfo * dataObj
Definition: pg_dump.h:331
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define Assert(condition)
Definition: c.h:681
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:712
#define RELKIND_VIEW
Definition: pg_class.h:164
int i
bool relispopulated
Definition: pg_dump.h:269
DumpableObjectType objType
Definition: pg_dump.h:130
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
static bool checkExtensionMembership ( DumpableObject dobj,
Archive fout 
)
static

Definition at line 1329 of file pg_dump.c.

References addObjectDependency(), _dumpOptions::binary_upgrade, _dumpableObject::catId, _extensionInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_NONE, DUMP_COMPONENT_POLICY, DUMP_COMPONENT_SECLABEL, _dumpableObject::dump_contains, _dumpableObject::dumpId, _dumpableObject::ext_member, findOwningExtension(), and Archive::remoteVersion.

Referenced by selectDumpableAccessMethod(), selectDumpableCast(), selectDumpableNamespace(), selectDumpableObject(), selectDumpableProcLang(), selectDumpablePublicationTable(), selectDumpableTable(), and selectDumpableType().

1330 {
1331  ExtensionInfo *ext = findOwningExtension(dobj->catId);
1332 
1333  if (ext == NULL)
1334  return false;
1335 
1336  dobj->ext_member = true;
1337 
1338  /* Record dependency so that getDependencies needn't deal with that */
1339  addObjectDependency(dobj, ext->dobj.dumpId);
1340 
1341  /*
1342  * In 9.6 and above, mark the member object to have any non-initial ACL,
1343  * policies, and security labels dumped.
1344  *
1345  * Note that any initial ACLs (see pg_init_privs) will be removed when we
1346  * extract the information about the object. We don't provide support for
1347  * initial policies and security labels and it seems unlikely for those to
1348  * ever exist, but we may have to revisit this later.
1349  *
1350  * Prior to 9.6, we do not include any extension member components.
1351  *
1352  * In binary upgrades, we still dump all components of the members
1353  * individually, since the idea is to exactly reproduce the database
1354  * contents rather than replace the extension contents with something
1355  * different.
1356  */
1357  if (fout->dopt->binary_upgrade)
1358  dobj->dump = ext->dobj.dump;
1359  else
1360  {
1361  if (fout->remoteVersion < 90600)
1362  dobj->dump = DUMP_COMPONENT_NONE;
1363  else
1364  dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL |
1367  }
1368 
1369  return true;
1370 }
DumpableObject dobj
Definition: pg_dump.h:155
DumpComponents dump
Definition: pg_dump.h:134
DumpId dumpId
Definition: pg_dump.h:132
bool ext_member
Definition: pg_dump.h:137
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:91
int binary_upgrade
Definition: pg_backup.h:135
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition: common.c:852
DumpOptions * dopt
Definition: pg_backup.h:181
DumpComponents dump_contains
Definition: pg_dump.h:136
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:95
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:712
CatalogId catId
Definition: pg_dump.h:131
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:97
int remoteVersion
Definition: pg_backup.h:186
static int collectComments ( Archive fout,
CommentItem **  items 
)
static

Definition at line 9400 of file pg_dump.c.

References appendPQExpBufferStr(), atooid, CommentItem::classoid, createPQExpBuffer(), PQExpBufferData::data, CommentItem::descr, destroyPQExpBuffer(), ExecuteSqlQuery(), i, CommentItem::objoid, CommentItem::objsubid, pg_malloc(), PGRES_TUPLES_OK, PQfnumber(), PQgetvalue(), and PQntuples().

Referenced by findComments().

9401 {
9402  PGresult *res;
9403  PQExpBuffer query;
9404  int i_description;
9405  int i_classoid;
9406  int i_objoid;
9407  int i_objsubid;
9408  int ntups;
9409  int i;
9410  CommentItem *comments;
9411 
9412  /*
9413  * Note we do NOT change source schema here; preserve the caller's
9414  * setting, instead.
9415  */
9416 
9417  query = createPQExpBuffer();
9418 
9419  appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
9420  "FROM pg_catalog.pg_description "
9421  "ORDER BY classoid, objoid, objsubid");
9422 
9423  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9424 
9425  /* Construct lookup table containing OIDs in numeric form */
9426 
9427  i_description = PQfnumber(res, "description");
9428  i_classoid = PQfnumber(res, "classoid");
9429  i_objoid = PQfnumber(res, "objoid");
9430  i_objsubid = PQfnumber(res, "objsubid");
9431 
9432  ntups = PQntuples(res);
9433 
9434  comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
9435 
9436  for (i = 0; i < ntups; i++)
9437  {
9438  comments[i].descr = PQgetvalue(res, i, i_description);
9439  comments[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
9440  comments[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
9441  comments[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
9442  }
9443 
9444  /* Do NOT free the PGresult since we are keeping pointers into it */
9445  destroyPQExpBuffer(query);
9446 
9447  *items = comments;
9448  return ntups;
9449 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:71
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
#define atooid(x)
Definition: postgres_ext.h:42
const char * descr
Definition: pg_dump.c:68
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
Oid objoid
Definition: pg_dump.c:70
Oid classoid
Definition: pg_dump.c:69
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
static int collectSecLabels ( Archive fout,
SecLabelItem **  items 
)
static

Definition at line 14963 of file pg_dump.c.

References appendPQExpBufferStr(), atooid, SecLabelItem::classoid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), i, SecLabelItem::label, SecLabelItem::objoid, SecLabelItem::objsubid, pg_malloc(), PGRES_TUPLES_OK, PQfnumber(), PQgetvalue(), PQntuples(), and SecLabelItem::provider.

Referenced by findSecLabels().

14964 {
14965  PGresult *res;
14966  PQExpBuffer query;
14967  int i_label;
14968  int i_provider;
14969  int i_classoid;
14970  int i_objoid;
14971  int i_objsubid;
14972  int ntups;
14973  int i;
14974  SecLabelItem *labels;
14975 
14976  query = createPQExpBuffer();
14977 
14978  appendPQExpBufferStr(query,
14979  "SELECT label, provider, classoid, objoid, objsubid "
14980  "FROM pg_catalog.pg_seclabel "
14981  "ORDER BY classoid, objoid, objsubid");
14982 
14983  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
14984 
14985  /* Construct lookup table containing OIDs in numeric form */
14986  i_label = PQfnumber(res, "label");
14987  i_provider = PQfnumber(res, "provider");
14988  i_classoid = PQfnumber(res, "classoid");
14989  i_objoid = PQfnumber(res, "objoid");
14990  i_objsubid = PQfnumber(res, "objsubid");
14991 
14992  ntups = PQntuples(res);
14993 
14994  labels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
14995 
14996  for (i = 0; i < ntups; i++)
14997  {
14998  labels[i].label = PQgetvalue(res, i, i_label);
14999  labels[i].provider = PQgetvalue(res, i, i_provider);
15000  labels[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
15001  labels[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
15002  labels[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
15003  }
15004 
15005  /* Do NOT free the PGresult since we are keeping pointers into it */
15006  destroyPQExpBuffer(query);
15007 
15008  *items = labels;
15009  return ntups;
15010 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
Oid objoid
Definition: pg_dump.c:79
const char * provider
Definition: pg_dump.c:76
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
int objsubid
Definition: pg_dump.c:80
int i
Oid classoid
Definition: pg_dump.c:78
const char * label
Definition: pg_dump.c:77
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
static char * convertOperatorReference ( Archive fout,
const char *  opr 
)
static

Definition at line 12328 of file pg_dump.c.

References free, name, pg_strdup(), and psprintf().

Referenced by dumpAgg(), and dumpOpr().

12329 {
12330  char *name;
12331  char *oname;
12332  char *ptr;
12333  bool inquote;
12334  bool sawdot;
12335 
12336  /* In all cases "0" means a null reference */
12337  if (strcmp(opr, "0") == 0)
12338  return NULL;
12339 
12340  name = pg_strdup(opr);
12341  /* find non-double-quoted left paren, and check for non-quoted dot */
12342  inquote = false;
12343  sawdot = false;
12344  for (ptr = name; *ptr; ptr++)
12345  {
12346  if (*ptr == '"')
12347  inquote = !inquote;
12348  else if (*ptr == '.' && !inquote)
12349  sawdot = true;
12350  else if (*ptr == '(' && !inquote)
12351  {
12352  *ptr = '\0';
12353  break;
12354  }
12355  }
12356  /* If not schema-qualified, don't need to add OPERATOR() */
12357  if (!sawdot)
12358  return name;
12359  oname = psprintf("OPERATOR(%s)", name);
12360  free(name);
12361  return oname;
12362 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
const char * name
Definition: encode.c:521
static char * convertRegProcReference ( Archive fout,
const char *  proc 
)
static

Definition at line 12292 of file pg_dump.c.

References name, and pg_strdup().

Referenced by dumpOpr().

12293 {
12294  char *name;
12295  char *paren;
12296  bool inquote;
12297 
12298  /* In all cases "-" means a null reference */
12299  if (strcmp(proc, "-") == 0)
12300  return NULL;
12301 
12302  name = pg_strdup(proc);
12303  /* find non-double-quoted left paren */
12304  inquote = false;
12305  for (paren = name; *paren; paren++)
12306  {
12307  if (*paren == '(' && !inquote)
12308  {
12309  *paren = '\0';
12310  break;
12311  }
12312  if (*paren == '"')
12313  inquote = !inquote;
12314  }
12315  return name;
12316 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
const char * name
Definition: encode.c:521
static char * convertTSFunction ( Archive fout,
Oid  funcOid 
)
static

Definition at line 12373 of file pg_dump.c.

References ExecuteSqlQueryForSingleRow(), pg_strdup(), PQclear(), PQgetvalue(), and snprintf().

Referenced by dumpTSParser(), and dumpTSTemplate().

12374 {
12375  char *result;
12376  char query[128];
12377  PGresult *res;
12378 
12379  snprintf(query, sizeof(query),
12380  "SELECT '%u'::pg_catalog.regproc", funcOid);
12381  res = ExecuteSqlQueryForSingleRow(fout, query);
12382 
12383  result = pg_strdup(PQgetvalue(res, 0, 0));
12384 
12385  PQclear(res);
12386 
12387  return result;
12388 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
void PQclear(PGresult *res)
Definition: fe-exec.c:671
static DumpableObject * createBoundaryObjects ( void  )
static

Definition at line 17704 of file pg_dump.c.

References AssignDumpId(), _dumpableObject::catId, DO_POST_DATA_BOUNDARY, DO_PRE_DATA_BOUNDARY, _dumpableObject::name, nilCatalogId, _dumpableObject::objType, pg_malloc(), and pg_strdup().

Referenced by main().

17705 {
17706  DumpableObject *dobjs;
17707 
17708  dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject));
17709 
17710  dobjs[0].objType = DO_PRE_DATA_BOUNDARY;
17711  dobjs[0].catId = nilCatalogId;
17712  AssignDumpId(dobjs + 0);
17713  dobjs[0].name = pg_strdup("PRE-DATA BOUNDARY");
17714 
17715  dobjs[1].objType = DO_POST_DATA_BOUNDARY;
17716  dobjs[1].catId = nilCatalogId;
17717  AssignDumpId(dobjs + 1);
17718  dobjs[1].name = pg_strdup("POST-DATA BOUNDARY");
17719 
17720  return dobjs;
17721 }
char * name
Definition: pg_dump.h:133
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
CatalogId catId
Definition: pg_dump.h:131
static const CatalogId nilCatalogId
Definition: pg_dump.c:133
DumpableObjectType objType
Definition: pg_dump.h:130
static PQExpBuffer createDummyViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

Definition at line 15201 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), _tableInfo::attcollation, _tableInfo::attnames, _tableInfo::atttypnames, createPQExpBuffer(), _collInfo::dobj, findCollationByOid(), fmtId(), _dumpableObject::name, _tableInfo::numatts, and OidIsValid.

Referenced by dumpRule(), and dumpTableSchema().

15202 {
15203  PQExpBuffer result = createPQExpBuffer();
15204  int j;
15205 
15206  appendPQExpBufferStr(result, "SELECT");
15207 
15208  for (j = 0; j < tbinfo->numatts; j++)
15209  {
15210  if (j > 0)
15211  appendPQExpBufferChar(result, ',');
15212  appendPQExpBufferStr(result, "\n ");
15213 
15214  appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]);
15215 
15216  /*
15217  * Must add collation if not default for the type, because CREATE OR
15218  * REPLACE VIEW won't change it
15219  */
15220  if (OidIsValid(tbinfo->attcollation[j]))
15221  {
15222  CollInfo *coll;
15223 
15224  coll = findCollationByOid(tbinfo->attcollation[j]);
15225  if (coll)
15226  {
15227  /* always schema-qualify, don't try to be smart */
15228  appendPQExpBuffer(result, " COLLATE %s.",
15229  fmtId(coll->dobj.namespace->dobj.name));
15230  appendPQExpBufferStr(result, fmtId(coll->dobj.name));
15231  }
15232  }
15233 
15234  appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j]));
15235  }
15236 
15237  return result;
15238 }
char * name
Definition: pg_dump.h:133
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char ** atttypnames
Definition: pg_dump.h:305
char ** attnames
Definition: pg_dump.h:304
#define OidIsValid(objectId)
Definition: c.h:532
DumpableObject dobj
Definition: pg_dump.h:246
Oid * attcollation
Definition: pg_dump.h:316
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
int numatts
Definition: pg_dump.h:303
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:803
static PQExpBuffer createViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

Definition at line 15152 of file pg_dump.c.

References appendBinaryPQExpBuffer(), appendPQExpBuffer(), Assert, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _tableInfo::dobj, ExecuteSqlQuery(), exit_horribly(), _dumpableObject::name, CatalogId::oid, PGRES_TUPLES_OK, PQclear(), PQgetlength(), PQgetvalue(), and PQntuples().

Referenced by dumpRule(), and dumpTableSchema().

15153 {
15154  PQExpBuffer query = createPQExpBuffer();
15155  PQExpBuffer result = createPQExpBuffer();
15156  PGresult *res;
15157  int len;
15158 
15159  /* Fetch the view definition */
15160  appendPQExpBuffer(query,
15161  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
15162  tbinfo->dobj.catId.oid);
15163 
15164  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
15165 
15166  if (PQntuples(res) != 1)
15167  {
15168  if (PQntuples(res) < 1)
15169  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned no data\n",
15170  tbinfo->dobj.name);
15171  else
15172  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned more than one definition\n",
15173  tbinfo->dobj.name);
15174  }
15175 
15176  len = PQgetlength(res, 0, 0);
15177 
15178  if (len == 0)
15179  exit_horribly(NULL, "definition of view \"%s\" appears to be empty (length zero)\n",
15180  tbinfo->dobj.name);
15181 
15182  /* Strip off the trailing semicolon so that other things may follow. */
15183  Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
15184  appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
15185 
15186  PQclear(res);
15187  destroyPQExpBuffer(query);
15188 
15189  return result;
15190 }
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3129
char * name
Definition: pg_dump.h:133
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
DumpableObject dobj
Definition: pg_dump.h:261
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define Assert(condition)
Definition: c.h:681
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:415
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
static void dumpAccessMethod ( Archive fout,
AccessMethodInfo oprinfo 
)
static

Definition at line 12395 of file pg_dump.c.

References _accessMethodInfo::amhandler, _accessMethodInfo::amtype, AMTYPE_INDEX, appendPQExpBuffer(), ArchiveEntry(), _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), _accessMethodInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, dumpComment(), _dumpableObject::dumpId, fmtId(), _dumpableObject::name, pg_free(), pg_strdup(), SECTION_PRE_DATA, and write_msg().

Referenced by dumpDumpableObject().

12396 {
12397  DumpOptions *dopt = fout->dopt;
12398  PQExpBuffer q;
12399  PQExpBuffer delq;
12400  PQExpBuffer labelq;
12401  char *qamname;
12402 
12403  /* Skip if not to be dumped */
12404  if (!aminfo->dobj.dump || dopt->dataOnly)
12405  return;
12406 
12407  q = createPQExpBuffer();
12408  delq = createPQExpBuffer();
12409  labelq = createPQExpBuffer();
12410 
12411  qamname = pg_strdup(fmtId(aminfo->dobj.name));
12412 
12413  appendPQExpBuffer(q, "CREATE ACCESS METHOD %s ", qamname);
12414 
12415  switch (aminfo->amtype)
12416  {
12417  case AMTYPE_INDEX:
12418  appendPQExpBuffer(q, "TYPE INDEX ");
12419  break;
12420  default:
12421  write_msg(NULL, "WARNING: invalid type \"%c\" of access method \"%s\"\n",
12422  aminfo->amtype, qamname);
12423  pg_free(qamname);
12424  destroyPQExpBuffer(q);
12425  destroyPQExpBuffer(delq);
12426  destroyPQExpBuffer(labelq);
12427  return;
12428  }
12429 
12430  appendPQExpBuffer(q, "HANDLER %s;\n", aminfo->amhandler);
12431 
12432  appendPQExpBuffer(delq, "DROP ACCESS METHOD %s;\n",
12433  qamname);
12434 
12435  appendPQExpBuffer(labelq, "ACCESS METHOD %s",
12436  qamname);
12437 
12438  if (dopt->binary_upgrade)
12439  binary_upgrade_extension_member(q, &aminfo->dobj, labelq->data);
12440 
12441  if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
12442  ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
12443  aminfo->dobj.name,
12444  NULL,
12445  NULL,
12446  "",
12447  false, "ACCESS METHOD", SECTION_PRE_DATA,
12448  q->data, delq->data, NULL,
12449  NULL, 0,
12450  NULL, NULL);
12451 
12452  /* Dump Access Method Comments */
12453  if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT)
12454  dumpComment(fout, labelq->data,
12455  NULL, "",
12456  aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
12457 
12458  pg_free(qamname);
12459 
12460  destroyPQExpBuffer(q);
12461  destroyPQExpBuffer(delq);
12462  destroyPQExpBuffer(labelq);
12463 }
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9161
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define AMTYPE_INDEX
Definition: pg_am.h:61
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4135
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static void dumpACL ( Archive fout,
CatalogId  objCatId,
DumpId  objDumpId,
const char *  type,
const char *  name,
const char *  subname,
const char *  tag,
const char *  nspname,
const char *  owner,
const char *  acls,
const char *  racls,
const char *  initacls,
const char *  initracls 
)
static

Definition at line 14653 of file pg_dump.c.

References _dumpOptions::aclsSkip, appendPQExpBuffer(), ArchiveEntry(), buildACLCommands(), createDumpId(), createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), Archive::dopt, exit_horribly(), PQExpBufferData::len, Archive::remoteVersion, and SECTION_NONE.

Referenced by dumpAgg(), dumpBaseType(), dumpBlob(), dumpCompositeType(), dumpDomain(), dumpEnumType(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpNamespace(), dumpProcLang(), dumpRangeType(), dumpTable(), and dumpUndefinedType().

14658 {
14659  DumpOptions *dopt = fout->dopt;
14660  PQExpBuffer sql;
14661 
14662  /* Do nothing if ACL dump is not enabled */
14663  if (dopt->aclsSkip)
14664  return;
14665 
14666  /* --data-only skips ACLs *except* BLOB ACLs */
14667  if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
14668  return;
14669 
14670  sql = createPQExpBuffer();
14671 
14672  /*
14673  * Check to see if this object has had any initial ACLs included for it.
14674  * If so, we are in binary upgrade mode and these are the ACLs to turn
14675  * into GRANT and REVOKE statements to set and record the initial
14676  * privileges for an extension object. Let the backend know that these
14677  * are to be recorded by calling binary_upgrade_set_record_init_privs()
14678  * before and after.
14679  */
14680  if (strlen(initacls) != 0 || strlen(initracls) != 0)
14681  {
14682  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
14683  if (!buildACLCommands(name, subname, type, initacls, initracls, owner,
14684  "", fout->remoteVersion, sql))
14685  exit_horribly(NULL,
14686  "could not parse initial GRANT ACL list (%s) or initial REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14687  initacls, initracls, name, type);
14688  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
14689  }
14690 
14691  if (!buildACLCommands(name, subname, type, acls, racls, owner,
14692  "", fout->remoteVersion, sql))
14693  exit_horribly(NULL,
14694  "could not parse GRANT ACL list (%s) or REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14695  acls, racls, name, type);
14696 
14697  if (sql->len > 0)
14699  tag, nspname,
14700  NULL,
14701  owner ? owner : "",
14702  false, "ACL", SECTION_NONE,
14703  sql->data, "", NULL,
14704  &(objDumpId), 1,
14705  NULL, NULL);
14706 
14707  destroyPQExpBuffer(sql);
14708 }
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
bool aclsSkip
Definition: pg_backup.h:141
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
bool buildACLCommands(const char *name, const char *subname, const char *type, const char *acls, const char *racls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql)
Definition: dumputils.c:55
const char * name
Definition: encode.c:521
void exit_horribly(const char *modulename, const char *fmt,...)
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:133
DumpId createDumpId(void)
Definition: common.c:520
int remoteVersion
Definition: pg_backup.h:186
static void dumpAgg ( Archive fout,
AggInfo agginfo 
)
static

Definition at line 13415 of file pg_dump.c.

References _aggInfo::aggfn, AGGKIND_HYPOTHETICAL, AGGKIND_NORMAL, AGGMODIFY_READ_ONLY, AGGMODIFY_READ_WRITE, AGGMODIFY_SHARABLE, appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), _dumpableObject::catId, convertOperatorReference(), createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), _funcInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_SECLABEL, dumpACL(), dumpComment(), _dumpableObject::dumpId, dumpSecLabel(), ExecuteSqlQueryForSingleRow(), exit_horribly(), fmtId(), format_aggregate_signature(), format_function_arguments(), format_function_signature(), free, _funcInfo::initproacl, _funcInfo::initrproacl, _dumpableObject::name, CatalogId::oid, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), _funcInfo::proacl, PROPARALLEL_RESTRICTED, PROPARALLEL_SAFE, PROPARALLEL_UNSAFE, Archive::remoteVersion, _funcInfo::rolname, _funcInfo::rproacl, SECTION_PRE_DATA, selectSourceSchema(), and write_msg().

Referenced by dumpDumpableObject().

13416 {
13417  DumpOptions *dopt = fout->dopt;
13418  PQExpBuffer query;
13419  PQExpBuffer q;
13420  PQExpBuffer delq;
13421  PQExpBuffer labelq;
13422  PQExpBuffer details;
13423  char *aggsig; /* identity signature */
13424  char *aggfullsig = NULL; /* full signature */
13425  char *aggsig_tag;
13426  PGresult *res;
13427  int i_aggtransfn;
13428  int i_aggfinalfn;
13429  int i_aggcombinefn;
13430  int i_aggserialfn;
13431  int i_aggdeserialfn;
13432  int i_aggmtransfn;
13433  int i_aggminvtransfn;
13434  int i_aggmfinalfn;
13435  int i_aggfinalextra;
13436  int i_aggmfinalextra;
13437  int i_aggfinalmodify;
13438  int i_aggmfinalmodify;
13439  int i_aggsortop;
13440  int i_aggkind;
13441  int i_aggtranstype;
13442  int i_aggtransspace;
13443  int i_aggmtranstype;
13444  int i_aggmtransspace;
13445  int i_agginitval;
13446  int i_aggminitval;
13447  int i_convertok;
13448  int i_proparallel;
13449  const char *aggtransfn;
13450  const char *aggfinalfn;
13451  const char *aggcombinefn;
13452  const char *aggserialfn;
13453  const char *aggdeserialfn;
13454  const char *aggmtransfn;
13455  const char *aggminvtransfn;
13456  const char *aggmfinalfn;
13457  bool aggfinalextra;
13458  bool aggmfinalextra;
13459  char aggfinalmodify;
13460  char aggmfinalmodify;
13461  const char *aggsortop;
13462  char *aggsortconvop;
13463  char aggkind;
13464  const char *aggtranstype;
13465  const char *aggtransspace;
13466  const char *aggmtranstype;
13467  const char *aggmtransspace;
13468  const char *agginitval;
13469  const char *aggminitval;
13470  bool convertok;
13471  const char *proparallel;
13472  char defaultfinalmodify;
13473 
13474  /* Skip if not to be dumped */
13475  if (!agginfo->aggfn.dobj.dump || dopt->dataOnly)
13476  return;
13477 
13478  query = createPQExpBuffer();
13479  q = createPQExpBuffer();
13480  delq = createPQExpBuffer();
13481  labelq = createPQExpBuffer();
13482  details = createPQExpBuffer();
13483 
13484  /* Make sure we are in proper schema */
13485  selectSourceSchema(fout, agginfo->aggfn.dobj.namespace->dobj.name);
13486 
13487  /* Get aggregate-specific details */
13488  if (fout->remoteVersion >= 110000)
13489  {
13490  appendPQExpBuffer(query, "SELECT aggtransfn, "
13491  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13492  "aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, "
13493  "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13494  "aggfinalextra, aggmfinalextra, "
13495  "aggfinalmodify, aggmfinalmodify, "
13496  "aggsortop::pg_catalog.regoperator, "
13497  "aggkind, "
13498  "aggtransspace, agginitval, "
13499  "aggmtransspace, aggminitval, "
13500  "true AS convertok, "
13501  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13502  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, "
13503  "p.proparallel "
13504  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13505  "WHERE a.aggfnoid = p.oid "
13506  "AND p.oid = '%u'::pg_catalog.oid",
13507  agginfo->aggfn.dobj.catId.oid);
13508  }
13509  else if (fout->remoteVersion >= 90600)
13510  {
13511  appendPQExpBuffer(query, "SELECT aggtransfn, "
13512  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13513  "aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, "
13514  "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13515  "aggfinalextra, aggmfinalextra, "
13516  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13517  "aggsortop::pg_catalog.regoperator, "
13518  "aggkind, "
13519  "aggtransspace, agginitval, "
13520  "aggmtransspace, aggminitval, "
13521  "true AS convertok, "
13522  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13523  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, "
13524  "p.proparallel "
13525  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13526  "WHERE a.aggfnoid = p.oid "
13527  "AND p.oid = '%u'::pg_catalog.oid",
13528  agginfo->aggfn.dobj.catId.oid);
13529  }
13530  else if (fout->remoteVersion >= 90400)
13531  {
13532  appendPQExpBuffer(query, "SELECT aggtransfn, "
13533  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13534  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13535  "'-' AS aggdeserialfn, aggmtransfn, aggminvtransfn, "
13536  "aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13537  "aggfinalextra, aggmfinalextra, "
13538  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13539  "aggsortop::pg_catalog.regoperator, "
13540  "aggkind, "
13541  "aggtransspace, agginitval, "
13542  "aggmtransspace, aggminitval, "
13543  "true AS convertok, "
13544  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13545  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13546  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13547  "WHERE a.aggfnoid = p.oid "
13548  "AND p.oid = '%u'::pg_catalog.oid",
13549  agginfo->aggfn.dobj.catId.oid);
13550  }
13551  else if (fout->remoteVersion >= 80400)
13552  {
13553  appendPQExpBuffer(query, "SELECT aggtransfn, "
13554  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13555  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13556  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13557  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13558  "0 AS aggmtranstype, false AS aggfinalextra, "
13559  "false AS aggmfinalextra, "
13560  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13561  "aggsortop::pg_catalog.regoperator, "
13562  "'n' AS aggkind, "
13563  "0 AS aggtransspace, agginitval, "
13564  "0 AS aggmtransspace, NULL AS aggminitval, "
13565  "true AS convertok, "
13566  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13567  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13568  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13569  "WHERE a.aggfnoid = p.oid "
13570  "AND p.oid = '%u'::pg_catalog.oid",
13571  agginfo->aggfn.dobj.catId.oid);
13572  }
13573  else if (fout->remoteVersion >= 80100)
13574  {
13575  appendPQExpBuffer(query, "SELECT aggtransfn, "
13576  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13577  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13578  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13579  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13580  "0 AS aggmtranstype, false AS aggfinalextra, "
13581  "false AS aggmfinalextra, "
13582  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13583  "aggsortop::pg_catalog.regoperator, "
13584  "'n' AS aggkind, "
13585  "0 AS aggtransspace, agginitval, "
13586  "0 AS aggmtransspace, NULL AS aggminitval, "
13587  "true AS convertok "
13588  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13589  "WHERE a.aggfnoid = p.oid "
13590  "AND p.oid = '%u'::pg_catalog.oid",
13591  agginfo->aggfn.dobj.catId.oid);
13592  }
13593  else
13594  {
13595  appendPQExpBuffer(query, "SELECT aggtransfn, "
13596  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13597  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13598  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13599  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13600  "0 AS aggmtranstype, false AS aggfinalextra, "
13601  "false AS aggmfinalextra, "
13602  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13603  "0 AS aggsortop, "
13604  "'n' AS aggkind, "
13605  "0 AS aggtransspace, agginitval, "
13606  "0 AS aggmtransspace, NULL AS aggminitval, "
13607  "true AS convertok "
13608  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13609  "WHERE a.aggfnoid = p.oid "
13610  "AND p.oid = '%u'::pg_catalog.oid",
13611  agginfo->aggfn.dobj.catId.oid);
13612  }
13613 
13614  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13615 
13616  i_aggtransfn = PQfnumber(res, "aggtransfn");
13617  i_aggfinalfn = PQfnumber(res, "aggfinalfn");
13618  i_aggcombinefn = PQfnumber(res, "aggcombinefn");
13619  i_aggserialfn = PQfnumber(res, "aggserialfn");
13620  i_aggdeserialfn = PQfnumber(res, "aggdeserialfn");
13621  i_aggmtransfn = PQfnumber(res, "aggmtransfn");
13622  i_aggminvtransfn = PQfnumber(res, "aggminvtransfn");
13623  i_aggmfinalfn = PQfnumber(res, "aggmfinalfn");
13624  i_aggfinalextra = PQfnumber(res, "aggfinalextra");
13625  i_aggmfinalextra = PQfnumber(res, "aggmfinalextra");
13626  i_aggfinalmodify = PQfnumber(res, "aggfinalmodify");
13627  i_aggmfinalmodify = PQfnumber(res, "aggmfinalmodify");
13628  i_aggsortop = PQfnumber(res, "aggsortop");
13629  i_aggkind = PQfnumber(res, "aggkind");
13630  i_aggtranstype = PQfnumber(res, "aggtranstype");
13631  i_aggtransspace = PQfnumber(res, "aggtransspace");
13632  i_aggmtranstype = PQfnumber(res, "aggmtranstype");
13633  i_aggmtransspace = PQfnumber(res, "aggmtransspace");
13634  i_agginitval = PQfnumber(res, "agginitval");
13635  i_aggminitval = PQfnumber(res, "aggminitval");
13636  i_convertok = PQfnumber(res, "convertok");
13637  i_proparallel = PQfnumber(res, "proparallel");
13638 
13639  aggtransfn = PQgetvalue(res, 0, i_aggtransfn);
13640  aggfinalfn = PQgetvalue(res, 0, i_aggfinalfn);
13641  aggcombinefn = PQgetvalue(res, 0, i_aggcombinefn);
13642  aggserialfn = PQgetvalue(res, 0, i_aggserialfn);
13643  aggdeserialfn = PQgetvalue(res, 0, i_aggdeserialfn);
13644  aggmtransfn = PQgetvalue(res, 0, i_aggmtransfn);
13645  aggminvtransfn = PQgetvalue(res, 0, i_aggminvtransfn);
13646  aggmfinalfn = PQgetvalue(res, 0, i_aggmfinalfn);
13647  aggfinalextra = (PQgetvalue(res, 0, i_aggfinalextra)[0] == 't');
13648  aggmfinalextra = (PQgetvalue(res, 0, i_aggmfinalextra)[0] == 't');
13649  aggfinalmodify = PQgetvalue(res, 0, i_aggfinalmodify)[0];
13650  aggmfinalmodify = PQgetvalue(res, 0, i_aggmfinalmodify)[0];
13651  aggsortop = PQgetvalue(res, 0, i_aggsortop);
13652  aggkind = PQgetvalue(res, 0, i_aggkind)[0];
13653  aggtranstype = PQgetvalue(res, 0, i_aggtranstype);
13654  aggtransspace = PQgetvalue(res, 0, i_aggtransspace);
13655  aggmtranstype = PQgetvalue(res, 0, i_aggmtranstype);
13656  aggmtransspace = PQgetvalue(res, 0, i_aggmtransspace);
13657  agginitval = PQgetvalue(res, 0, i_agginitval);
13658  aggminitval = PQgetvalue(res, 0, i_aggminitval);
13659  convertok = (PQgetvalue(res, 0, i_convertok)[0] == 't');
13660 
13661  if (fout->remoteVersion >= 80400)
13662  {
13663  /* 8.4 or later; we rely on server-side code for most of the work */
13664  char *funcargs;
13665  char *funciargs;
13666 
13667  funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs"));
13668  funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs"));
13669  aggfullsig = format_function_arguments(&agginfo->aggfn, funcargs, true);
13670  aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true);
13671  }
13672  else
13673  /* pre-8.4, do it ourselves */
13674  aggsig = format_aggregate_signature(agginfo, fout, true);
13675 
13676  aggsig_tag = format_aggregate_signature(agginfo, fout, false);
13677 
13678  if (i_proparallel != -1)
13679  proparallel = PQgetvalue(res, 0, PQfnumber(res, "proparallel"));
13680  else
13681  proparallel = NULL;
13682 
13683  if (!convertok)
13684  {
13685  write_msg(NULL, "WARNING: aggregate function %s could not be dumped correctly for this database version; ignored\n",
13686  aggsig);
13687 
13688  if (aggfullsig)
13689  free(aggfullsig);
13690 
13691  free(aggsig);
13692 
13693  return;
13694  }
13695 
13696  /* identify default modify flag for aggkind (must match DefineAggregate) */
13697  defaultfinalmodify = (aggkind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
13698  /* replace omitted flags for old versions */
13699  if (aggfinalmodify == '0')
13700  aggfinalmodify = defaultfinalmodify;
13701  if (aggmfinalmodify == '0')
13702  aggmfinalmodify = defaultfinalmodify;
13703 
13704  /* regproc and regtype output is already sufficiently quoted */
13705  appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
13706  aggtransfn, aggtranstype);
13707 
13708  if (strcmp(aggtransspace, "0") != 0)
13709  {
13710  appendPQExpBuffer(details, ",\n SSPACE = %s",
13711  aggtransspace);
13712  }
13713 
13714  if (!PQgetisnull(res, 0, i_agginitval))
13715  {
13716  appendPQExpBufferStr(details, ",\n INITCOND = ");
13717  appendStringLiteralAH(details, agginitval, fout);
13718  }
13719 
13720  if (strcmp(aggfinalfn, "-") != 0)
13721  {
13722  appendPQExpBuffer(details, ",\n FINALFUNC = %s",
13723  aggfinalfn);
13724  if (aggfinalextra)
13725  appendPQExpBufferStr(details, ",\n FINALFUNC_EXTRA");
13726  if (aggfinalmodify != defaultfinalmodify)
13727  {
13728  switch (aggfinalmodify)
13729  {
13730  case AGGMODIFY_READ_ONLY:
13731  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = READ_ONLY");
13732  break;
13733  case AGGMODIFY_SHARABLE:
13734  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = SHARABLE");
13735  break;
13736  case AGGMODIFY_READ_WRITE:
13737  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = READ_WRITE");
13738  break;
13739  default:
13740  exit_horribly(NULL, "unrecognized aggfinalmodify value for aggregate \"%s\"\n",
13741  agginfo->aggfn.dobj.name);
13742  break;
13743  }
13744  }
13745  }
13746 
13747  if (strcmp(aggcombinefn, "-") != 0)
13748  appendPQExpBuffer(details, ",\n COMBINEFUNC = %s", aggcombinefn);
13749 
13750  if (strcmp(aggserialfn, "-") != 0)
13751  appendPQExpBuffer(details, ",\n SERIALFUNC = %s", aggserialfn);
13752 
13753  if (strcmp(aggdeserialfn, "-") != 0)
13754  appendPQExpBuffer(details, ",\n DESERIALFUNC = %s", aggdeserialfn);
13755 
13756  if (strcmp(aggmtransfn, "-") != 0)
13757  {
13758  appendPQExpBuffer(details, ",\n MSFUNC = %s,\n MINVFUNC = %s,\n MSTYPE = %s",
13759  aggmtransfn,
13760  aggminvtransfn,
13761  aggmtranstype);
13762  }
13763 
13764  if (strcmp(aggmtransspace, "0") != 0)
13765  {
13766  appendPQExpBuffer(details, ",\n MSSPACE = %s",
13767  aggmtransspace);
13768  }
13769 
13770  if (!PQgetisnull(res, 0, i_aggminitval))
13771  {
13772  appendPQExpBufferStr(details, ",\n MINITCOND = ");
13773  appendStringLiteralAH(details, aggminitval, fout);
13774  }
13775 
13776  if (strcmp(aggmfinalfn, "-") != 0)
13777  {
13778  appendPQExpBuffer(details, ",\n MFINALFUNC = %s",
13779  aggmfinalfn);
13780  if (aggmfinalextra)
13781  appendPQExpBufferStr(details, ",\n MFINALFUNC_EXTRA");
13782  if (aggmfinalmodify != defaultfinalmodify)
13783  {
13784  switch (aggmfinalmodify)
13785  {
13786  case AGGMODIFY_READ_ONLY:
13787  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = READ_ONLY");
13788  break;
13789  case AGGMODIFY_SHARABLE:
13790  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = SHARABLE");
13791  break;
13792  case AGGMODIFY_READ_WRITE:
13793  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = READ_WRITE");
13794  break;
13795  default:
13796  exit_horribly(NULL, "unrecognized aggmfinalmodify value for aggregate \"%s\"\n",
13797  agginfo->aggfn.dobj.name);
13798  break;
13799  }
13800  }
13801  }
13802 
13803  aggsortconvop = convertOperatorReference(fout, aggsortop);
13804  if (aggsortconvop)
13805  {
13806  appendPQExpBuffer(details, ",\n SORTOP = %s",
13807  aggsortconvop);
13808  free(aggsortconvop);
13809  }
13810 
13811  if (aggkind == AGGKIND_HYPOTHETICAL)
13812  appendPQExpBufferStr(details, ",\n HYPOTHETICAL");
13813 
13814  if (proparallel != NULL && proparallel[0] != PROPARALLEL_UNSAFE)
13815  {
13816  if (proparallel[0] == PROPARALLEL_SAFE)
13817  appendPQExpBufferStr(details, ",\n PARALLEL = safe");
13818  else if (proparallel[0] == PROPARALLEL_RESTRICTED)
13819  appendPQExpBufferStr(details, ",\n PARALLEL = restricted");
13820  else if (proparallel[0] != PROPARALLEL_UNSAFE)
13821  exit_horribly(NULL, "unrecognized proparallel value for function \"%s\"\n",
13822  agginfo->aggfn.dobj.name);
13823  }
13824 
13825  /*
13826  * DROP must be fully qualified in case same name appears in pg_catalog
13827  */
13828  appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n",
13829  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
13830  aggsig);
13831 
13832  appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n",
13833  aggfullsig ? aggfullsig : aggsig, details->data);
13834 
13835  appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig);
13836 
13837  if (dopt->binary_upgrade)
13838  binary_upgrade_extension_member(q, &agginfo->aggfn.dobj, labelq->data);
13839 
13840  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_DEFINITION)
13841  ArchiveEntry(fout, agginfo->aggfn.dobj.catId,
13842  agginfo->aggfn.dobj.dumpId,
13843  aggsig_tag,
13844  agginfo->aggfn.dobj.namespace->dobj.name,
13845  NULL,
13846  agginfo->aggfn.rolname,
13847  false, "AGGREGATE", SECTION_PRE_DATA,
13848  q->data, delq->data, NULL,
13849  NULL, 0,
13850  NULL, NULL);
13851 
13852  /* Dump Aggregate Comments */
13853  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_COMMENT)
13854  dumpComment(fout, labelq->data,
13855  agginfo->aggfn.dobj.namespace->dobj.name,
13856  agginfo->aggfn.rolname,
13857  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13858 
13859  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_SECLABEL)
13860  dumpSecLabel(fout, labelq->data,
13861  agginfo->aggfn.dobj.namespace->dobj.name,
13862  agginfo->aggfn.rolname,
13863  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13864 
13865  /*
13866  * Since there is no GRANT ON AGGREGATE syntax, we have to make the ACL
13867  * command look like a function's GRANT; in particular this affects the
13868  * syntax for zero-argument aggregates and ordered-set aggregates.
13869  */
13870  free(aggsig);
13871  free(aggsig_tag);
13872 
13873  aggsig = format_function_signature(fout, &agginfo->aggfn, true);
13874  aggsig_tag = format_function_signature(fout, &agginfo->aggfn, false);
13875 
13876  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_ACL)
13877  dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
13878  "FUNCTION",
13879  aggsig, NULL, aggsig_tag,
13880  agginfo->aggfn.dobj.namespace->dobj.name,
13881  agginfo->aggfn.rolname, agginfo->aggfn.proacl,
13882  agginfo->aggfn.rproacl,
13883  agginfo->aggfn.initproacl, agginfo->aggfn.initrproacl);
13884 
13885  free(aggsig);
13886  if (aggfullsig)
13887  free(aggfullsig);
13888  free(aggsig_tag);
13889 
13890  PQclear(res);
13891 
13892  destroyPQExpBuffer(query);
13893  destroyPQExpBuffer(q);
13894  destroyPQExpBuffer(delq);
13895  destroyPQExpBuffer(labelq);
13896  destroyPQExpBuffer(details);
13897 }
char * name
Definition: pg_dump.h:133
#define AGGMODIFY_READ_ONLY
Definition: pg_aggregate.h:143
#define AGGMODIFY_READ_WRITE
Definition: pg_aggregate.h:145
DumpComponents dump
Definition: pg_dump.h:134
static char * convertOperatorReference(Archive *fout, const char *opr)
Definition: pg_dump.c:12328
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * initrproacl
Definition: pg_dump.h:207
DumpableObject dobj
Definition: pg_dump.h:198
#define PROPARALLEL_RESTRICTED
Definition: pg_proc.h:5543
DumpId dumpId
Definition: pg_dump.h:132
static char * format_function_arguments(FuncInfo *finfo, char *funcargs, bool is_agg)
Definition: pg_dump.c:11199
FuncInfo aggfn
Definition: pg_dump.h:213
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9161
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void dumpSecLabel(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14729
#define AGGKIND_NORMAL
Definition: pg_aggregate.h:128
#define AGGMODIFY_SHARABLE
Definition: pg_aggregate.h:144
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5542
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
#define PROPARALLEL_UNSAFE
Definition: pg_proc.h:5544
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4135
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
void write_msg(const char *modulename, const char *fmt,...)
char * initproacl
Definition: pg_dump.h:206
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *tag, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14653
static char * format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11294
char * rolname
Definition: pg_dump.h:199
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:95
char * proacl
Definition: pg_dump.h:204
char * rproacl
Definition: pg_dump.h:205
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
#define AGGKIND_HYPOTHETICAL
Definition: pg_aggregate.h:130
static char * format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
Definition: pg_dump.c:13377
int remoteVersion
Definition: pg_backup.h:186
static void dumpAttrDef ( Archive fout,
AttrDefInfo adinfo 
)
static

Definition at line 15972 of file pg_dump.c.

References _attrDefInfo::adef_expr, _attrDefInfo::adnum, _attrDefInfo::adtable, appendPQExpBuffer(), ArchiveEntry(), _tableInfo::attnames, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), _tableInfo::dobj, _attrDefInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_DEFINITION, _dumpableObject::dumpId, fmtId(), free, _dumpableObject::name, psprintf(), _tableInfo::rolname, SECTION_PRE_DATA, and _attrDefInfo::separate.

Referenced by dumpDumpableObject().

15973 {
15974  DumpOptions *dopt = fout->dopt;
15975  TableInfo *tbinfo = adinfo->adtable;
15976  int adnum = adinfo->adnum;
15977  PQExpBuffer q;
15978  PQExpBuffer delq;
15979  char *tag;
15980 
15981  /* Skip if table definition not to be dumped */
15982  if (!tbinfo->dobj.dump || dopt->dataOnly)
15983  return;
15984 
15985  /* Skip if not "separate"; it was dumped in the table's definition */
15986  if (!adinfo->separate)
15987  return;
15988 
15989  q = createPQExpBuffer();
15990  delq = createPQExpBuffer();
15991 
15992  appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
15993  fmtId(tbinfo->dobj.name));
15994  appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n",
15995  fmtId(tbinfo->attnames[adnum - 1]),
15996  adinfo->adef_expr);
15997 
15998  /*
15999  * DROP must be fully qualified in case same name appears in pg_catalog
16000  */
16001  appendPQExpBuffer(delq, "ALTER TABLE %s.",
16002  fmtId(tbinfo->dobj.namespace->dobj.name));
16003  appendPQExpBuffer(delq, "%s ",
16004  fmtId(tbinfo->dobj.name));
16005  appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n",
16006  fmtId(tbinfo->attnames[adnum - 1]));
16007 
16008  tag = psprintf("%s %s", tbinfo->dobj.name, tbinfo->attnames[adnum - 1]);
16009 
16010  if (adinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16011  ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
16012  tag,
16013  tbinfo->dobj.namespace->dobj.name,
16014  NULL,
16015  tbinfo->rolname,
16016  false, "DEFAULT", SECTION_PRE_DATA,
16017  q->data, delq->data, NULL,
16018  NULL, 0,
16019  NULL, NULL);
16020 
16021  free(tag);
16022  destroyPQExpBuffer(q);
16023  destroyPQExpBuffer(delq);
16024 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * rolname
Definition: pg_dump.h:262
DumpId dumpId
Definition: pg_dump.h:132
char ** attnames
Definition: pg_dump.h:304
DumpableObject dobj
Definition: pg_dump.h:261
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
bool separate
Definition: pg_dump.h:342
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
TableInfo * adtable
Definition: pg_dump.h:339
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:338
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
char * adef_expr
Definition: pg_dump.h:341
static void dumpBaseType ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10181 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), atooid, _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), binary_upgrade_set_type_oids_by_type_oid(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _typeInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_SECLABEL, dumpACL(), dumpComment(), _dumpableObject::dumpId, dumpSecLabel(), ExecuteSqlQueryForSingleRow(), fmtId(), free, getFormattedTypeName(), _typeInfo::initrtypacl, _typeInfo::inittypacl, _dumpableObject::name, CatalogId::oid, OidIsValid, pg_strdup(), PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), Archive::remoteVersion, _typeInfo::rolname, _typeInfo::rtypacl, SECTION_PRE_DATA, selectSourceSchema(), _typeInfo::typacl, _typeInfo::typelem, and zeroAsOpaque.

Referenced by dumpType().

10182 {
10183  DumpOptions *dopt = fout->dopt;
10185  PQExpBuffer delq = createPQExpBuffer();
10186  PQExpBuffer labelq = createPQExpBuffer();
10187  PQExpBuffer query = createPQExpBuffer();
10188  PGresult *res;
10189  char *qtypname;
10190  char *typlen;
10191  char *typinput;
10192  char *typoutput;
10193  char *typreceive;
10194  char *typsend;
10195  char *typmodin;
10196  char *typmodout;
10197  char *typanalyze;
10198  Oid typreceiveoid;
10199  Oid typsendoid;
10200  Oid typmodinoid;
10201  Oid typmodoutoid;
10202  Oid typanalyzeoid;
10203  char *typcategory;
10204  char *typispreferred;
10205  char *typdelim;
10206  char *typbyval;
10207  char *typalign;
10208  char *typstorage;
10209  char *typcollatable;
10210  char *typdefault;
10211  bool typdefault_is_literal = false;
10212 
10213  /* Set proper schema search path so regproc references list correctly */
10214  selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
10215 
10216  /* Fetch type-specific details */
10217  if (fout->remoteVersion >= 90100)
10218  {
10219  appendPQExpBuffer(query, "SELECT typlen, "
10220  "typinput, typoutput, typreceive, typsend, "
10221  "typmodin, typmodout, typanalyze, "
10222  "typreceive::pg_catalog.oid AS typreceiveoid, "
10223  "typsend::pg_catalog.oid AS typsendoid, "
10224  "typmodin::pg_catalog.oid AS typmodinoid, "
10225  "typmodout::pg_catalog.oid AS typmodoutoid, "
10226  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10227  "typcategory, typispreferred, "
10228  "typdelim, typbyval, typalign, typstorage, "
10229  "(typcollation <> 0) AS typcollatable, "
10230  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10231  "FROM pg_catalog.pg_type "
10232  "WHERE oid = '%u'::pg_catalog.oid",
10233  tyinfo->dobj.catId.oid);
10234  }
10235  else if (fout->remoteVersion >= 80400)
10236  {
10237  appendPQExpBuffer(query, "SELECT typlen, "
10238  "typinput, typoutput, typreceive, typsend, "
10239  "typmodin, typmodout, typanalyze, "
10240  "typreceive::pg_catalog.oid AS typreceiveoid, "
10241  "typsend::pg_catalog.oid AS typsendoid, "
10242  "typmodin::pg_catalog.oid AS typmodinoid, "
10243  "typmodout::pg_catalog.oid AS typmodoutoid, "
10244  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10245  "typcategory, typispreferred, "
10246  "typdelim, typbyval, typalign, typstorage, "
10247  "false AS typcollatable, "
10248  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10249  "FROM pg_catalog.pg_type "
10250  "WHERE oid = '%u'::pg_catalog.oid",
10251  tyinfo->dobj.catId.oid);
10252  }
10253  else if (fout->remoteVersion >= 80300)
10254  {
10255  /* Before 8.4, pg_get_expr does not allow 0 for its second arg */
10256  appendPQExpBuffer(query, "SELECT typlen, "
10257  "typinput, typoutput, typreceive, typsend, "
10258  "typmodin, typmodout, typanalyze, "
10259  "typreceive::pg_catalog.oid AS typreceiveoid, "
10260  "typsend::pg_catalog.oid AS typsendoid, "
10261  "typmodin::pg_catalog.oid AS typmodinoid, "
10262  "typmodout::pg_catalog.oid AS typmodoutoid, "
10263  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10264  "'U' AS typcategory, false AS typispreferred, "
10265  "typdelim, typbyval, typalign, typstorage, "
10266  "false AS typcollatable, "
10267  "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10268  "FROM pg_catalog.pg_type "
10269  "WHERE oid = '%u'::pg_catalog.oid",
10270  tyinfo->dobj.catId.oid);
10271  }
10272  else
10273  {
10274  appendPQExpBuffer(query, "SELECT typlen, "
10275  "typinput, typoutput, typreceive, typsend, "
10276  "'-' AS typmodin, '-' AS typmodout, "
10277  "typanalyze, "
10278  "typreceive::pg_catalog.oid AS typreceiveoid, "
10279  "typsend::pg_catalog.oid AS typsendoid, "
10280  "0 AS typmodinoid, 0 AS typmodoutoid, "
10281  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10282  "'U' AS typcategory, false AS typispreferred, "
10283  "typdelim, typbyval, typalign, typstorage, "
10284  "false AS typcollatable, "
10285  "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10286  "FROM pg_catalog.pg_type "
10287  "WHERE oid = '%u'::pg_catalog.oid",
10288  tyinfo->dobj.catId.oid);
10289  }
10290 
10291  res = ExecuteSqlQueryForSingleRow(fout, query->data);
10292 
10293  typlen = PQgetvalue(res, 0, PQfnumber(res, "typlen"));
10294  typinput = PQgetvalue(res, 0, PQfnumber(res, "typinput"));
10295  typoutput = PQgetvalue(res, 0, PQfnumber(res, "typoutput"));
10296  typreceive = PQgetvalue(res, 0, PQfnumber(res, "typreceive"));
10297  typsend = PQgetvalue(res, 0, PQfnumber(res, "typsend"));
10298  typmodin = PQgetvalue(res, 0, PQfnumber(res, "typmodin"));
10299  typmodout = PQgetvalue(res, 0, PQfnumber(res, "typmodout"));
10300  typanalyze = PQgetvalue(res, 0, PQfnumber(res, "typanalyze"));
10301  typreceiveoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typreceiveoid")));
10302  typsendoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typsendoid")));
10303  typmodinoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodinoid")));
10304  typmodoutoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodoutoid")));
10305  typanalyzeoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typanalyzeoid")));
10306  typcategory = PQgetvalue(res, 0, PQfnumber(res, "typcategory"));
10307  typispreferred = PQgetvalue(res, 0, PQfnumber(res, "typispreferred"));
10308  typdelim = PQgetvalue(res, 0, PQfnumber(res, "typdelim"));
10309  typbyval = PQgetvalue(res, 0, PQfnumber(res, "typbyval"));
10310  typalign = PQgetvalue(res, 0, PQfnumber(res, "typalign"));
10311  typstorage = PQgetvalue(res, 0, PQfnumber(res, "typstorage"));
10312  typcollatable = PQgetvalue(res, 0, PQfnumber(res, "typcollatable"));
10313  if (!PQgetisnull(res, 0, PQfnumber(res, "typdefaultbin")))
10314  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefaultbin"));
10315  else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
10316  {
10317  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault"));
10318  typdefault_is_literal = true; /* it needs quotes */
10319  }
10320  else
10321  typdefault = NULL;
10322 
10323  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
10324 
10325  /*
10326  * DROP must be fully qualified in case same name appears in pg_catalog.
10327  * The reason we include CASCADE is that the circular dependency between
10328  * the type and its I/O functions makes it impossible to drop the type any
10329  * other way.
10330  */
10331  appendPQExpBuffer(delq, "DROP TYPE %s.",
10332  fmtId(tyinfo->dobj.namespace->dobj.name));
10333  appendPQExpBuffer(delq, "%s CASCADE;\n",
10334  qtypname);
10335 
10336  /*
10337  * We might already have a shell type, but setting pg_type_oid is
10338  * harmless, and in any case we'd better set the array type OID.
10339  */
10340  if (dopt->binary_upgrade)
10342  tyinfo->dobj.catId.oid,
10343  false);
10344 
10346  "CREATE TYPE %s (\n"
10347  " INTERNALLENGTH = %s",
10348  qtypname,
10349  (strcmp(typlen, "-1") == 0) ? "variable" : typlen);
10350 
10351  /* regproc result is sufficiently quoted already */
10352  appendPQExpBuffer(q, ",\n INPUT = %s", typinput);
10353  appendPQExpBuffer(q, ",\n OUTPUT = %s", typoutput);
10354  if (OidIsValid(typreceiveoid))
10355  appendPQExpBuffer(q, ",\n RECEIVE = %s", typreceive);
10356  if (OidIsValid(typsendoid))
10357  appendPQExpBuffer(q, ",\n SEND = %s", typsend);
10358  if (OidIsValid(typmodinoid))
10359  appendPQExpBuffer(q, ",\n TYPMOD_IN = %s", typmodin);
10360  if (OidIsValid(typmodoutoid))
10361  appendPQExpBuffer(q, ",\n TYPMOD_OUT = %s", typmodout);
10362  if (OidIsValid(typanalyzeoid))
10363  appendPQExpBuffer(q, ",\n ANALYZE = %s", typanalyze);
10364 
10365  if (strcmp(typcollatable, "t") == 0)
10366  appendPQExpBufferStr(q, ",\n COLLATABLE = true");
10367 
10368  if (typdefault != NULL)
10369  {
10370  appendPQExpBufferStr(q, ",\n DEFAULT = ");
10371  if (typdefault_is_literal)
10372  appendStringLiteralAH(q, typdefault, fout);
10373  else
10374  appendPQExpBufferStr(q, typdefault);
10375  }
10376 
10377  if (OidIsValid(tyinfo->typelem))
10378  {
10379  char *elemType;
10380 
10381  /* reselect schema in case changed by function dump */
10382  selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
10383  elemType = getFormattedTypeName(fout, tyinfo->typelem, zeroAsOpaque);
10384  appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType);
10385  free(elemType);
10386  }
10387 
10388  if (strcmp(typcategory, "U") != 0)
10389  {
10390  appendPQExpBufferStr(q, ",\n CATEGORY = ");
10391  appendStringLiteralAH(q, typcategory, fout);
10392  }
10393 
10394  if (strcmp(typispreferred, "t") == 0)
10395  appendPQExpBufferStr(q, ",\n PREFERRED = true");
10396 
10397  if (typdelim && strcmp(typdelim, ",") != 0)
10398  {
10399  appendPQExpBufferStr(q, ",\n DELIMITER = ");
10400  appendStringLiteralAH(q, typdelim, fout);
10401  }
10402 
10403  if (strcmp(typalign, "c") == 0)
10404  appendPQExpBufferStr(q, ",\n ALIGNMENT = char");
10405  else if (strcmp(typalign, "s") == 0)
10406  appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
10407  else if (strcmp(typalign, "i") == 0)
10408  appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
10409  else if (strcmp(typalign, "d") == 0)
10410  appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
10411 
10412  if (strcmp(typstorage, "p") == 0)
10413  appendPQExpBufferStr(q, ",\n STORAGE = plain");
10414  else if (strcmp(typstorage, "e") == 0)
10415  appendPQExpBufferStr(q, ",\n STORAGE = external");
10416  else if (strcmp(typstorage, "x") == 0)
10417  appendPQExpBufferStr(q, ",\n STORAGE = extended");
10418  else if (strcmp(typstorage, "m") == 0)
10419  appendPQExpBufferStr(q, ",\n STORAGE = main");
10420 
10421  if (strcmp(typbyval, "t") == 0)
10422  appendPQExpBufferStr(q, ",\n PASSEDBYVALUE");
10423 
10424  appendPQExpBufferStr(q, "\n);\n");
10425 
10426  appendPQExpBuffer(labelq, "TYPE %s", qtypname);
10427 
10428  if (dopt->binary_upgrade)
10429  binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
10430 
10431  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
10432  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
10433  tyinfo->dobj.name,
10434  tyinfo->dobj.namespace->dobj.name,
10435  NULL,
10436  tyinfo->rolname, false,
10437  "TYPE", SECTION_PRE_DATA,
10438  q->data, delq->data, NULL,
10439  NULL, 0,
10440  NULL, NULL);
10441 
10442  /* Dump Type Comments and Security Labels */
10443  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10444  dumpComment(fout, labelq->data,
10445  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10446  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10447 
10448  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
10449  dumpSecLabel(fout, labelq->data,
10450  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10451  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10452 
10453  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
10454  dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
10455  qtypname, NULL, tyinfo->dobj.name,
10456  tyinfo->dobj.namespace->dobj.name,
10457  tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl,
10458  tyinfo->inittypacl, tyinfo->initrtypacl);
10459 
10460  PQclear(res);
10461  destroyPQExpBuffer(q);
10462  destroyPQExpBuffer(delq);
10463  destroyPQExpBuffer(labelq);
10464  destroyPQExpBuffer(query);
10465 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:17976
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
char * inittypacl
Definition: pg_dump.h:174
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * initrtypacl
Definition: pg_dump.h:175
char * typacl
Definition: pg_dump.h:172
DumpId dumpId
Definition: pg_dump.h:132
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:532
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9161
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static void dumpSecLabel(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14729
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
Oid typelem
Definition: pg_dump.h:176
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
DumpableObject dobj
Definition: pg_dump.h:165
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid, bool force_array_type)
Definition: pg_dump.c:3953
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4135
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
char * rtypacl
Definition: pg_dump.h:173
char * rolname
Definition: pg_dump.h:171
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *tag, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14653
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:95
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
int remoteVersion
Definition: pg_backup.h:186
static void dumpBlob ( Archive fout,
BlobInfo binfo 
)
static

Definition at line 3057 of file pg_dump.c.

References appendPQExpBuffer(), ArchiveEntry(), _blobInfo::blobacl, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _blobInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_SECLABEL, dumpACL(), dumpComment(), _dumpableObject::dumpId, dumpSecLabel(), _blobInfo::initblobacl, _blobInfo::initrblobacl, _dumpableObject::name, _blobInfo::rblobacl, resetPQExpBuffer(), _blobInfo::rolname, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

3058 {
3059  PQExpBuffer cquery = createPQExpBuffer();
3060  PQExpBuffer dquery = createPQExpBuffer();
3061 
3062  appendPQExpBuffer(cquery,
3063  "SELECT pg_catalog.lo_create('%s');\n",
3064  binfo->dobj.name);
3065 
3066  appendPQExpBuffer(dquery,
3067  "SELECT pg_catalog.lo_unlink('%s');\n",
3068  binfo->dobj.name);
3069 
3070  if (binfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
3071  ArchiveEntry(fout, binfo->dobj.catId, binfo->dobj.dumpId,
3072  binfo->dobj.name,
3073  NULL, NULL,
3074  binfo->rolname, false,
3075  "BLOB", SECTION_PRE_DATA,
3076  cquery->data, dquery->data, NULL,
3077  NULL, 0,
3078  NULL, NULL);
3079 
3080  /* set up tag for comment and/or ACL */
3081  resetPQExpBuffer(cquery);
3082  appendPQExpBuffer(cquery, "LARGE OBJECT %s", binfo->dobj.name);
3083 
3084  /* Dump comment if any */
3085  if (binfo->dobj.dump & DUMP_COMPONENT_COMMENT)
3086  dumpComment(fout, cquery->data,
3087  NULL, binfo->rolname,
3088  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3089 
3090  /* Dump security label if any */
3091  if (binfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
3092  dumpSecLabel(fout, cquery->data,
3093  NULL, binfo->rolname,
3094  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3095 
3096  /* Dump ACL if any */
3097  if (binfo->blobacl && (binfo->dobj.dump & DUMP_COMPONENT_ACL))
3098  dumpACL(fout, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT",
3099  binfo->dobj.name, NULL, cquery->data,
3100  NULL, binfo->rolname, binfo->blobacl, binfo->rblobacl,
3101  binfo->initblobacl, binfo->initrblobacl);
3102 
3103  destroyPQExpBuffer(cquery);
3104  destroyPQExpBuffer(dquery);
3105 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
DumpId dumpId
Definition: pg_dump.h:132
char * initblobacl
Definition: pg_dump.h:555
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:551
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9161
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static void dumpSecLabel(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14729
char * rolname
Definition: pg_dump.h:552
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *tag, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14653
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:95
char * blobacl
Definition: pg_dump.h:553
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
char * rblobacl
Definition: pg_dump.h:554
char * initrblobacl
Definition: pg_dump.h:556
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
static int dumpBlobs ( Archive fout,
void *  arg 
)
static

Definition at line 3112 of file pg_dump.c.

References atooid, buf, conn, EndBlob(), ExecuteSqlQuery(), ExecuteSqlStatement(), exit_horribly(), g_verbose, GetConnection(), i, INV_READ, lo_close(), lo_open(), lo_read(), LOBBUFSIZE, PGRES_TUPLES_OK, PQclear(), PQerrorMessage(), PQgetvalue(), PQntuples(), Archive::remoteVersion, selectSourceSchema(), StartBlob(), write_msg(), and WriteData().

Referenced by dumpDumpableObject().

3113 {
3114  const char *blobQry;
3115  const char *blobFetchQry;
3116  PGconn *conn = GetConnection(fout);
3117  PGresult *res;
3118  char buf[LOBBUFSIZE];
3119  int ntups;
3120  int i;
3121  int cnt;
3122 
3123  if (g_verbose)
3124  write_msg(NULL, "saving large objects\n");
3125 
3126  /* Make sure we are in proper schema */
3127  selectSourceSchema(fout, "pg_catalog");
3128 
3129  /*
3130  * Currently, we re-fetch all BLOB OIDs using a cursor. Consider scanning
3131  * the already-in-memory dumpable objects instead...
3132  */
3133  if (fout->remoteVersion >= 90000)
3134  blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_largeobject_metadata";
3135  else
3136  blobQry = "DECLARE bloboid CURSOR FOR SELECT DISTINCT loid FROM pg_largeobject";
3137 
3138  ExecuteSqlStatement(fout, blobQry);
3139 
3140  /* Command to fetch from cursor */
3141  blobFetchQry = "FETCH 1000 IN bloboid";
3142 
3143  do
3144  {
3145  /* Do a fetch */
3146  res = ExecuteSqlQuery(fout, blobFetchQry, PGRES_TUPLES_OK);
3147 
3148  /* Process the tuples, if any */
3149  ntups = PQntuples(res);
3150  for (i = 0; i < ntups; i++)
3151  {
3152  Oid blobOid;
3153  int loFd;
3154 
3155  blobOid = atooid(PQgetvalue(res, i, 0));
3156  /* Open the BLOB */
3157  loFd = lo_open(conn, blobOid, INV_READ);
3158  if (loFd == -1)
3159  exit_horribly(NULL, "could not open large object %u: %s",
3160  blobOid, PQerrorMessage(conn));
3161 
3162  StartBlob(fout, blobOid);
3163 
3164  /* Now read it in chunks, sending data to archive */
3165  do
3166  {
3167  cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
3168  if (cnt < 0)
3169  exit_horribly(NULL, "error reading large object %u: %s",
3170  blobOid, PQerrorMessage(conn));
3171 
3172  WriteData(fout, buf, cnt);
3173  } while (cnt > 0);
3174 
3175  lo_close(conn, loFd);
3176 
3177  EndBlob(fout, blobOid);
3178  }
3179 
3180  PQclear(res);
3181  } while (ntups > 0);
3182 
3183  return 1;
3184 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6097
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
#define INV_READ
Definition: libpq-fs.h:22
int lo_close(PGconn *conn, int fd)
Definition: fe-lobj.c:99
int StartBlob(Archive *AH, Oid oid)
PGconn * conn
Definition: streamutil.c:46
static char * buf
Definition: pg_test_fsync.c:67
int lo_read(int fd, char *buf, int len)
Definition: be-fsstubs.c:155
void WriteData(Archive *AH, const void *data, size_t dLen)
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
int lo_open(PGconn *conn, Oid lobjId, int mode)
Definition: fe-lobj.c:57
void PQclear(PGresult *res)
Definition: fe-exec.c:671
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt)
Definition: connection.c:107
void write_msg(const char *modulename, const char *fmt,...)
void ExecuteSqlStatement(Archive *AHX, const char *query)
Definition: pg_backup_db.c:395
void exit_horribly(const char *modulename, const char *fmt,...)
int EndBlob(Archive *AH, Oid oid)
int i
#define LOBBUFSIZE
bool g_verbose
Definition: pg_dump.c:92
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
static void dumpCast ( Archive fout,
CastInfo cast 
)
static

Definition at line 11830 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), ArchiveEntry(), _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), _castInfo::castcontext, _castInfo::castfunc, _castInfo::castmethod, _castInfo::castsource, _castInfo::casttarget, _dumpableObject::catId, COERCION_METHOD_BINARY, COERCION_METHOD_FUNCTION, COERCION_METHOD_INOUT, createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), _funcInfo::dobj, _castInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, dumpComment(), _dumpableObject::dumpId, exit_horribly(), findFuncByOid(), fmtId(), format_function_signature(), free, getFormattedTypeName(), _dumpableObject::name, OidIsValid, SECTION_PRE_DATA, selectSourceSchema(), write_msg(), and zeroAsNone.

Referenced by dumpDumpableObject().

11831 {
11832  DumpOptions *dopt = fout->dopt;
11833  PQExpBuffer defqry;
11834  PQExpBuffer delqry;
11835  PQExpBuffer labelq;
11836  FuncInfo *funcInfo = NULL;
11837  char *sourceType;
11838  char *targetType;
11839 
11840  /* Skip if not to be dumped */
11841  if (!cast->dobj.dump || dopt->dataOnly)
11842  return;
11843 
11844  /* Cannot dump if we don't have the cast function's info */
11845  if (OidIsValid(cast->castfunc))
11846  {
11847  funcInfo = findFuncByOid(cast->castfunc);
11848  if (funcInfo == NULL)
11849  exit_horribly(NULL, "could not find function definition for function with OID %u\n",
11850  cast->castfunc);
11851  }
11852 
11853  /*
11854  * Make sure we are in proper schema (needed for getFormattedTypeName).
11855  * Casts don't have a schema of their own, so use pg_catalog.
11856  */
11857  selectSourceSchema(fout, "pg_catalog");
11858 
11859  defqry = createPQExpBuffer();
11860  delqry = createPQExpBuffer();
11861  labelq = createPQExpBuffer();
11862 
11863  sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone);
11864  targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone);
11865  appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
11866  sourceType, targetType);
11867 
11868  appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
11869  sourceType, targetType);
11870 
11871  switch (cast->castmethod)
11872  {
11874  appendPQExpBufferStr(defqry, "WITHOUT FUNCTION");
11875  break;
11876  case COERCION_METHOD_INOUT:
11877  appendPQExpBufferStr(defqry, "WITH INOUT");
11878  break;
11880  if (funcInfo)
11881  {
11882  char *fsig = format_function_signature(fout, funcInfo, true);
11883 
11884  /*
11885  * Always qualify the function name, in case it is not in
11886  * pg_catalog schema (format_function_signature won't qualify
11887  * it).
11888  */
11889  appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
11890  fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
11891  free(fsig);
11892  }
11893  else
11894  write_msg(NULL, "WARNING: bogus value in pg_cast.castfunc or pg_cast.castmethod field\n");
11895  break;
11896  default:
11897  write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
11898  }
11899 
11900  if (cast->castcontext == 'a')
11901  appendPQExpBufferStr(defqry, " AS ASSIGNMENT");
11902  else if (cast->castcontext == 'i')
11903  appendPQExpBufferStr(defqry, " AS IMPLICIT");
11904  appendPQExpBufferStr(defqry, ";\n");
11905 
11906  appendPQExpBuffer(labelq, "CAST (%s AS %s)",
11907  sourceType, targetType);
11908 
11909  if (dopt->binary_upgrade)
11910  binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data);
11911 
11912  if (cast->dobj.dump & DUMP_COMPONENT_DEFINITION)
11913  ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
11914  labelq->data,
11915  "pg_catalog", NULL, "",
11916  false, "CAST", SECTION_PRE_DATA,
11917  defqry->data, delqry->data, NULL,
11918  NULL, 0,
11919  NULL, NULL);
11920 
11921  /* Dump Cast Comments */
11922  if (cast->dobj.dump & DUMP_COMPONENT_COMMENT)
11923  dumpComment(fout, labelq->data,
11924  "pg_catalog", "",
11925  cast->dobj.catId, 0, cast->dobj.dumpId);
11926 
11927  free(sourceType);
11928  free(targetType);
11929 
11930  destroyPQExpBuffer(defqry);
11931  destroyPQExpBuffer(delqry);
11932  destroyPQExpBuffer(labelq);
11933 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:17976
char * name
Definition: pg_dump.h:133
Oid castsource
Definition: pg_dump.h:456
DumpComponents dump
Definition: pg_dump.h:134
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
DumpableObject dobj
Definition: pg_dump.h:198
DumpId dumpId
Definition: pg_dump.h:132
Oid castfunc
Definition: pg_dump.h:458
#define OidIsValid(objectId)
Definition: c.h:532
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpableObject dobj
Definition: pg_dump.h:455
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9161
Oid casttarget
Definition: pg_dump.h:457
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
FuncInfo * findFuncByOid(Oid oid)
Definition: common.c:781
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4135
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
void write_msg(const char *modulename, const char *fmt,...)
static char * format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11294
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
char castmethod
Definition: pg_dump.h:460
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
char castcontext
Definition: pg_dump.h:459
static void dumpCollation ( Archive fout,
CollInfo collinfo 
)
static

Definition at line 13124 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), _collInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, dumpComment(), _dumpableObject::dumpId, ExecuteSqlQueryForSingleRow(), exit_horribly(), fmtId(), _dumpableObject::name, CatalogId::oid, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), Archive::remoteVersion, _collInfo::rolname, SECTION_PRE_DATA, and selectSourceSchema().

Referenced by dumpDumpableObject().

13125 {
13126  DumpOptions *dopt = fout->dopt;
13127  PQExpBuffer query;
13128  PQExpBuffer q;
13129  PQExpBuffer delq;
13130  PQExpBuffer labelq;
13131  PGresult *res;
13132  int i_collprovider;
13133  int i_collcollate;
13134  int i_collctype;
13135  const char *collprovider;
13136  const char *collcollate;
13137  const char *collctype;
13138 
13139  /* Skip if not to be dumped */
13140  if (!collinfo->dobj.dump || dopt->dataOnly)
13141  return;
13142 
13143  query = createPQExpBuffer();
13144  q = createPQExpBuffer();
13145  delq = createPQExpBuffer();
13146  labelq = createPQExpBuffer();
13147 
13148  /* Make sure we are in proper schema */
13149  selectSourceSchema(fout, collinfo->dobj.namespace->dobj.name);
13150 
13151  /* Get collation-specific details */
13152  if (fout->remoteVersion >= 100000)
13153  appendPQExpBuffer(query, "SELECT "
13154  "collprovider, "
13155  "collcollate, "
13156  "collctype, "
13157  "collversion "
13158  "FROM pg_catalog.pg_collation c "
13159  "WHERE c.oid = '%u'::pg_catalog.oid",
13160  collinfo->dobj.catId.oid);
13161  else
13162  appendPQExpBuffer(query, "SELECT "
13163  "'c'::char AS collprovider, "
13164  "collcollate, "
13165  "collctype, "
13166  "NULL AS collversion "
13167  "FROM pg_catalog.pg_collation c "
13168  "WHERE c.oid = '%u'::pg_catalog.oid",
13169  collinfo->dobj.catId.oid);
13170 
13171  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13172 
13173  i_collprovider = PQfnumber(res, "collprovider");
13174  i_collcollate = PQfnumber(res, "collcollate");
13175  i_collctype = PQfnumber(res, "collctype");
13176 
13177  collprovider = PQgetvalue(res, 0, i_collprovider);
13178  collcollate = PQgetvalue(res, 0, i_collcollate);
13179  collctype = PQgetvalue(res, 0, i_collctype);
13180 
13181  /*
13182  * DROP must be fully qualified in case same name appears in pg_catalog
13183  */
13184  appendPQExpBuffer(delq, "DROP COLLATION %s",
13185  fmtId(collinfo->dobj.namespace->dobj.name));
13186  appendPQExpBuffer(delq, ".%s;\n",
13187  fmtId(collinfo->dobj.name));
13188 
13189  appendPQExpBuffer(q, "CREATE COLLATION %s (",
13190  fmtId(collinfo->dobj.name));
13191 
13192  appendPQExpBufferStr(q, "provider = ");
13193  if (collprovider[0] == 'c')
13194  appendPQExpBufferStr(q, "libc");
13195  else if (collprovider[0] == 'i')
13196  appendPQExpBufferStr(q, "icu");
13197  else if (collprovider[0] == 'd')
13198  /* to allow dumping pg_catalog; not accepted on input */
13199  appendPQExpBufferStr(q, "default");
13200  else
13201  exit_horribly(NULL,
13202  "unrecognized collation provider: %s\n",
13203  collprovider);
13204 
13205  if (strcmp(collcollate, collctype) == 0)
13206  {
13207  appendPQExpBufferStr(q, ", locale = ");
13208  appendStringLiteralAH(q, collcollate, fout);
13209  }
13210  else
13211  {
13212  appendPQExpBufferStr(q, ", lc_collate = ");
13213  appendStringLiteralAH(q, collcollate, fout);
13214  appendPQExpBufferStr(q, ", lc_ctype = ");
13215  appendStringLiteralAH(q, collctype, fout);
13216  }
13217 
13218  /*
13219  * For binary upgrade, carry over the collation version. For normal
13220  * dump/restore, omit the version, so that it is computed upon restore.
13221  */
13222  if (dopt->binary_upgrade)
13223  {
13224  int i_collversion;
13225 
13226  i_collversion = PQfnumber(res, "collversion");
13227  if (!PQgetisnull(res, 0, i_collversion))
13228  {
13229  appendPQExpBufferStr(q, ", version = ");
13231  PQgetvalue(res, 0, i_collversion),
13232  fout);
13233  }
13234  }
13235 
13236  appendPQExpBufferStr(q, ");\n");
13237 
13238  appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name));
13239 
13240  if (dopt->binary_upgrade)
13241  binary_upgrade_extension_member(q, &collinfo->dobj, labelq->data);
13242 
13243  if (collinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13244  ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId,
13245  collinfo->dobj.name,
13246  collinfo->dobj.namespace->dobj.name,
13247  NULL,
13248  collinfo->rolname,
13249  false, "COLLATION", SECTION_PRE_DATA,
13250  q->data, delq->data, NULL,
13251  NULL, 0,
13252  NULL, NULL);
13253 
13254  /* Dump Collation Comments */
13255  if (collinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13256  dumpComment(fout, labelq->data,
13257  collinfo->dobj.namespace->dobj.name, collinfo->rolname,
13258  collinfo->dobj.catId, 0, collinfo->dobj.dumpId);
13259 
13260  PQclear(res);
13261 
13262  destroyPQExpBuffer(query);
13263  destroyPQExpBuffer(q);
13264  destroyPQExpBuffer(delq);
13265  destroyPQExpBuffer(labelq);
13266 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
DumpId dumpId
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:246
char * rolname
Definition: pg_dump.h:247
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9161
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4135
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
int remoteVersion
Definition: pg_backup.h:186
static void dumpComment ( Archive fout,
const char *  target,
const char *  namespace,
const char *  owner,
CatalogId  catalogId,
int  subid,
DumpId  dumpId 
)
static

Definition at line 9161 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), _dumpOptions::binary_upgrade, createDumpId(), createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, CommentItem::descr, destroyPQExpBuffer(), Archive::dopt, findComments(), CommentItem::objsubid, CatalogId::oid, _dumpOptions::schemaOnly, SECTION_NONE, and CatalogId::tableoid.

Referenced by dumpAccessMethod(), dumpAgg(), dumpBaseType(), dumpBlob(), dumpCast(), dumpCollation(), dumpCompositeType(), dumpConversion(), dumpDatabase(), dumpDomain(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpIndex(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpProcLang(), dumpPublication(), dumpRangeType(), dumpRule(), dumpSequence(), dumpStatisticsExt(), dumpSubscription(), dumpTableConstraintComment(), dumpTransform(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), and dumpUndefinedType().

9164 {
9165  DumpOptions *dopt = fout->dopt;
9166  CommentItem *comments;
9167  int ncomments;
9168 
9169  /* Comments are schema not data ... except blob comments are data */
9170  if (strncmp(target, "LARGE OBJECT ", 13) != 0)
9171  {
9172  if (dopt->dataOnly)
9173  return;
9174  }
9175  else
9176  {
9177  /* We do dump blob comments in binary-upgrade mode */
9178  if (dopt->schemaOnly && !dopt->binary_upgrade)
9179  return;
9180  }
9181 
9182  /* Search for comments associated with catalogId, using table */
9183  ncomments = findComments(fout, catalogId.tableoid, catalogId.oid,
9184  &comments);
9185 
9186  /* Is there one matching the subid? */
9187  while (ncomments > 0)
9188  {
9189  if (comments->objsubid == subid)
9190  break;
9191  comments++;
9192  ncomments--;
9193  }
9194 
9195  /* If a comment exists, build COMMENT ON statement */
9196  if (ncomments > 0)
9197  {
9198  PQExpBuffer query = createPQExpBuffer();
9199 
9200  appendPQExpBuffer(query, "COMMENT ON %s IS ", target);
9201  appendStringLiteralAH(query, comments->descr, fout);
9202  appendPQExpBufferStr(query, ";\n");
9203 
9204  /*
9205  * We mark comments as SECTION_NONE because they really belong in the
9206  * same section as their parent, whether that is pre-data or
9207  * post-data.
9208  */
9210  target, namespace, NULL, owner,
9211  false, "COMMENT", SECTION_NONE,
9212  query->data, "", NULL,
9213  &(dumpId), 1,
9214  NULL, NULL);
9215 
9216  destroyPQExpBuffer(query);
9217  }
9218 }
Oid tableoid
Definition: pg_backup.h:226
bool schemaOnly
Definition: pg_backup.h:138
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:71
static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9316
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
const char * descr
Definition: pg_dump.c:68
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:133
DumpId createDumpId(void)
Definition: common.c:520
static void dumpCompositeType ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10661 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), atooid, _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), binary_upgrade_set_pg_class_oids(), binary_upgrade_set_type_oids_by_type_oid(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _typeInfo::dobj, _collInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_SECLABEL, dumpACL(), dumpComment(), dumpCompositeTypeColComments(), _dumpableObject::dumpId, dumpSecLabel(), ExecuteSqlQuery(), findCollationByOid(), fmtId(), i, _typeInfo::initrtypacl, _typeInfo::inittypacl, _dumpableObject::name, CatalogId::oid, OidIsValid, pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), Archive::remoteVersion, _typeInfo::rolname, _typeInfo::rtypacl, SECTION_PRE_DATA, selectSourceSchema(), _typeInfo::typacl, and _typeInfo::typrelid.

Referenced by dumpType().

10662 {
10663  DumpOptions *dopt = fout->dopt;
10665  PQExpBuffer dropped = createPQExpBuffer();
10666  PQExpBuffer delq = createPQExpBuffer();
10667  PQExpBuffer labelq = createPQExpBuffer();
10668  PQExpBuffer query = createPQExpBuffer();
10669  PGresult *res;
10670  char *qtypname;
10671  int ntups;
10672  int i_attname;
10673  int i_atttypdefn;
10674  int i_attlen;
10675  int i_attalign;
10676  int i_attisdropped;
10677  int i_attcollation;
10678  int i;
10679  int actual_atts;
10680 
10681  /* Set proper schema search path so type references list correctly */
10682  selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
10683 
10684  /* Fetch type specific details */
10685  if (fout->remoteVersion >= 90100)
10686  {
10687  /*
10688  * attcollation is new in 9.1. Since we only want to dump COLLATE
10689  * clauses for attributes whose collation is different from their
10690  * type's default, we use a CASE here to suppress uninteresting
10691  * attcollations cheaply. atttypid will be 0 for dropped columns;
10692  * collation does not matter for those.
10693  */
10694  appendPQExpBuffer(query, "SELECT a.attname, "
10695  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
10696  "a.attlen, a.attalign, a.attisdropped, "
10697  "CASE WHEN a.attcollation <> at.typcollation "
10698  "THEN a.attcollation ELSE 0 END AS attcollation "
10699  "FROM pg_catalog.pg_type ct "
10700  "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
10701  "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
10702  "WHERE ct.oid = '%u'::pg_catalog.oid "
10703  "ORDER BY a.attnum ",
10704  tyinfo->dobj.catId.oid);
10705  }
10706  else
10707  {
10708  /*
10709  * Since ALTER TYPE could not drop columns until 9.1, attisdropped
10710  * should always be false.
10711  */
10712  appendPQExpBuffer(query, "SELECT a.attname, "
10713  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
10714  "a.attlen, a.attalign, a.attisdropped, "
10715  "0 AS attcollation "
10716  "FROM pg_catalog.pg_type ct, pg_catalog.pg_attribute a "
10717  "WHERE ct.oid = '%u'::pg_catalog.oid "
10718  "AND a.attrelid = ct.typrelid "
10719  "ORDER BY a.attnum ",
10720  tyinfo->dobj.catId.oid);
10721  }
10722 
10723  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10724 
10725  ntups = PQntuples(res);
10726 
10727  i_attname = PQfnumber(res, "attname");
10728  i_atttypdefn = PQfnumber(res, "atttypdefn");
10729  i_attlen = PQfnumber(res, "attlen");
10730  i_attalign = PQfnumber(res, "attalign");
10731  i_attisdropped = PQfnumber(res, "attisdropped");
10732  i_attcollation = PQfnumber(res, "attcollation");
10733 
10734  if (dopt->binary_upgrade)
10735  {
10737  tyinfo->dobj.catId.oid,
10738  false);
10739  binary_upgrade_set_pg_class_oids(fout, q, tyinfo->typrelid, false);
10740  }
10741 
10742  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
10743 
10744  appendPQExpBuffer(q, "CREATE TYPE %s AS (",
10745  qtypname);
10746 
10747  actual_atts = 0;
10748  for (i = 0; i < ntups; i++)
10749  {
10750  char *attname;
10751  char *atttypdefn;
10752  char *attlen;
10753  char *attalign;
10754  bool attisdropped;
10755  Oid attcollation;
10756 
10757  attname = PQgetvalue(res, i, i_attname);
10758  atttypdefn = PQgetvalue(res, i, i_atttypdefn);
10759  attlen = PQgetvalue(res, i, i_attlen);
10760  attalign = PQgetvalue(res, i, i_attalign);
10761  attisdropped = (PQgetvalue(res, i, i_attisdropped)[0] == 't');
10762  attcollation = atooid(PQgetvalue(res, i, i_attcollation));
10763 
10764  if (attisdropped && !dopt->binary_upgrade)
10765  continue;
10766 
10767  /* Format properly if not first attr */
10768  if (actual_atts++ > 0)
10769  appendPQExpBufferChar(q, ',');
10770  appendPQExpBufferStr(q, "\n\t");
10771 
10772  if (!attisdropped)
10773  {
10774  appendPQExpBuffer(q, "%s %s", fmtId(attname), atttypdefn);
10775 
10776  /* Add collation if not default for the column type */
10777  if (OidIsValid(attcollation))
10778  {
10779  CollInfo *coll;
10780 
10781  coll = findCollationByOid(attcollation);
10782  if (coll)
10783  {
10784  /* always schema-qualify, don't try to be smart */
10785  appendPQExpBuffer(q, " COLLATE %s.",
10786  fmtId(coll->dobj.namespace->dobj.name));
10787  appendPQExpBufferStr(q, fmtId(coll->dobj.name));
10788  }
10789  }
10790  }
10791  else
10792  {
10793  /*
10794  * This is a dropped attribute and we're in binary_upgrade mode.
10795  * Insert a placeholder for it in the CREATE TYPE command, and set
10796  * length and alignment with direct UPDATE to the catalogs
10797  * afterwards. See similar code in dumpTableSchema().
10798  */
10799  appendPQExpBuffer(q, "%s INTEGER /* dummy */", fmtId(attname));
10800 
10801  /* stash separately for insertion after the CREATE TYPE */
10802  appendPQExpBufferStr(dropped,
10803  "\n-- For binary upgrade, recreate dropped column.\n");
10804  appendPQExpBuffer(dropped, "UPDATE pg_catalog.pg_attribute\n"
10805  "SET attlen = %s, "
10806  "attalign = '%s', attbyval = false\n"
10807  "WHERE attname = ", attlen, attalign);
10808  appendStringLiteralAH(dropped, attname, fout);
10809  appendPQExpBufferStr(dropped, "\n AND attrelid = ");
10810  appendStringLiteralAH(dropped, qtypname, fout);
10811  appendPQExpBufferStr(dropped, "::pg_catalog.regclass;\n");
10812 
10813  appendPQExpBuffer(dropped, "ALTER TYPE %s ",
10814  qtypname);
10815  appendPQExpBuffer(dropped, "DROP ATTRIBUTE %s;\n",
10816  fmtId(attname));
10817  }
10818  }
10819  appendPQExpBufferStr(q, "\n);\n");
10820  appendPQExpBufferStr(q, dropped->data);
10821 
10822  /*
10823  * DROP must be fully qualified in case same name appears in pg_catalog
10824  */
10825  appendPQExpBuffer(delq, "DROP TYPE %s.",
10826  fmtId(tyinfo->dobj.namespace->dobj.name));
10827  appendPQExpBuffer(delq, "%s;\n",
10828  qtypname);
10829 
10830  appendPQExpBuffer(labelq, "TYPE %s", qtypname);
10831 
10832  if (dopt->binary_upgrade)
10833  binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
10834 
10835  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
10836  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
10837  tyinfo->dobj.name,
10838  tyinfo->dobj.namespace->dobj.name,
10839  NULL,
10840  tyinfo->rolname, false,
10841  "TYPE", SECTION_PRE_DATA,
10842  q->data, delq->data, NULL,
10843  NULL, 0,
10844  NULL, NULL);
10845 
10846 
10847  /* Dump Type Comments and Security Labels */
10848  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10849  dumpComment(fout, labelq->data,
10850  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10851  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10852 
10853  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
10854  dumpSecLabel(fout, labelq->data,
10855  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10856  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10857 
10858  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
10859  dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
10860  qtypname, NULL, tyinfo->dobj.name,
10861  tyinfo->dobj.namespace->dobj.name,
10862  tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl,
10863  tyinfo->inittypacl, tyinfo->initrtypacl);
10864 
10865  PQclear(res);
10866  destroyPQExpBuffer(q);
10867  destroyPQExpBuffer(dropped);
10868  destroyPQExpBuffer(delq);
10869  destroyPQExpBuffer(labelq);
10870  destroyPQExpBuffer(query);
10871 
10872  /* Dump any per-column comments */
10873  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10874  dumpCompositeTypeColComments(fout, tyinfo);
10875 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
char * inittypacl
Definition: pg_dump.h:174
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
Oid typrelid
Definition: pg_dump.h:177
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * initrtypacl
Definition: pg_dump.h:175
static void dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
Definition: pg_dump.c:10883
char * typacl
Definition: pg_dump.h:172
DumpId dumpId
Definition: pg_dump.h:132
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
#define OidIsValid(objectId)
Definition: c.h:532
DumpableObject dobj
Definition: pg_dump.h:246
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9161
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static void dumpSecLabel(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14729
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
Definition: pg_dump.c:4068
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
DumpableObject dobj
Definition: pg_dump.h:165
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid, bool force_array_type)
Definition: pg_dump.c:3953
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4135
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
char * rtypacl
Definition: pg_dump.h:173
char * rolname
Definition: pg_dump.h:171
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *tag, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14653
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:803
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:95
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
int i
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
int remoteVersion
Definition: pg_backup.h:186
static void dumpCompositeTypeColComments ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10883 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), atooid, createDumpId(), createPQExpBuffer(), PQExpBufferData::data, CommentItem::descr, destroyPQExpBuffer(), _typeInfo::dobj, _dumpableObject::dumpId, ExecuteSqlQuery(), findComments(), fmtId(), i, _dumpableObject::name, CommentItem::objsubid, PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), resetPQExpBuffer(), _typeInfo::rolname, SECTION_NONE, and _typeInfo::typrelid.

Referenced by dumpCompositeType().

10884 {
10885  CommentItem *comments;
10886  int ncomments;
10887  PGresult *res;
10888  PQExpBuffer query;
10889  PQExpBuffer target;
10890  Oid pgClassOid;
10891  int i;
10892  int ntups;
10893  int i_attname;
10894  int i_attnum;
10895 
10896  query = createPQExpBuffer();
10897 
10898  appendPQExpBuffer(query,
10899  "SELECT c.tableoid, a.attname, a.attnum "
10900  "FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
10901  "WHERE c.oid = '%u' AND c.oid = a.attrelid "
10902  " AND NOT a.attisdropped "
10903  "ORDER BY a.attnum ",
10904  tyinfo->typrelid);
10905 
10906  /* Fetch column attnames */
10907  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10908 
10909  ntups = PQntuples(res);
10910  if (ntups < 1)
10911  {
10912  PQclear(res);
10913  destroyPQExpBuffer(query);
10914  return;
10915  }
10916 
10917  pgClassOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "tableoid")));
10918 
10919  /* Search for comments associated with type's pg_class OID */
10920  ncomments = findComments(fout,
10921  pgClassOid,
10922  tyinfo->typrelid,
10923  &comments);
10924 
10925  /* If no comments exist, we're done */
10926  if (ncomments <= 0)
10927  {
10928  PQclear(res);
10929  destroyPQExpBuffer(query);
10930  return;
10931  }
10932 
10933  /* Build COMMENT ON statements */
10934  target = createPQExpBuffer();
10935 
10936  i_attnum = PQfnumber(res, "attnum");
10937  i_attname = PQfnumber(res, "attname");
10938  while (ncomments > 0)
10939  {
10940  const char *attname;
10941 
10942  attname = NULL;
10943  for (i = 0; i < ntups; i++)
10944  {
10945  if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid)
10946  {
10947  attname = PQgetvalue(res, i, i_attname);
10948  break;
10949  }
10950  }
10951  if (attname) /* just in case we don't find it */
10952  {
10953  const char *descr = comments->descr;
10954 
10955  resetPQExpBuffer(target);
10956  appendPQExpBuffer(target, "COLUMN %s.",
10957  fmtId(tyinfo->dobj.name));
10958  appendPQExpBufferStr(target, fmtId(attname));
10959 
10960  resetPQExpBuffer(query);
10961  appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
10962  appendStringLiteralAH(query, descr, fout);
10963  appendPQExpBufferStr(query, ";\n");
10964 
10966  target->data,
10967  tyinfo->dobj.namespace->dobj.name,
10968  NULL, tyinfo->rolname,
10969  false, "COMMENT", SECTION_NONE,
10970  query->data, "", NULL,
10971  &(tyinfo->dobj.dumpId), 1,
10972  NULL, NULL);
10973  }
10974 
10975  comments++;
10976  ncomments--;
10977  }
10978 
10979  PQclear(res);
10980  destroyPQExpBuffer(query);
10981  destroyPQExpBuffer(target);
10982 }
char * name
Definition: pg_dump.h:133
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
Oid typrelid
Definition: pg_dump.h:177
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:71
DumpId dumpId
Definition: pg_dump.h:132
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9316
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
const char * descr
Definition: pg_dump.c:68
DumpableObject dobj
Definition: pg_dump.h:165
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:671
char * rolname
Definition: pg_dump.h:171
int i
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:133
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DumpId createDumpId(void)
Definition: common.c:520
static void dumpConstraint ( Archive fout,
ConstraintInfo coninfo 
)
static

Definition at line 16213 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendReloptionsArrayAH(), ArchiveEntry(), _dumpOptions::binary_upgrade, binary_upgrade_set_pg_class_oids(), _dumpableObject::catId, _constraintInfo::condef, _constraintInfo::condeferrable, _constraintInfo::condeferred, _constraintInfo::condomain, _constraintInfo::conindex, _constraintInfo::conislocal, _constraintInfo::contable, _constraintInfo::contype, createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), _typeInfo::dobj, _tableInfo::dobj, _indxInfo::dobj, _constraintInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, _dumpableObject::dumpId, dumpTableConstraintComment(), exit_horribly(), findObjectByDumpId(), fmtId(), free, getAttrName(), _indxInfo::indisclustered, _indxInfo::indkeys, _indxInfo::indnkeys, _indxInfo::indreloptions, InvalidAttrNumber, _dumpableObject::name, nonemptyReloptions(), CatalogId::oid, psprintf(), _typeInfo::rolname, _tableInfo::rolname, SECTION_POST_DATA, _constraintInfo::separate, and _indxInfo::tablespace.

Referenced by dumpDumpableObject().

16214 {
16215  DumpOptions *dopt = fout->dopt;
16216  TableInfo *tbinfo = coninfo->contable;
16217  PQExpBuffer q;
16218  PQExpBuffer delq;
16219  char *tag = NULL;
16220 
16221  /* Skip if not to be dumped */
16222  if (!coninfo->dobj.dump || dopt->dataOnly)
16223  return;
16224 
16225  q = createPQExpBuffer();
16226  delq = createPQExpBuffer();
16227 
16228  if (coninfo->contype == 'p' ||
16229  coninfo->contype == 'u' ||
16230  coninfo->contype == 'x')
16231  {
16232  /* Index-related constraint */
16233  IndxInfo *indxinfo;
16234  int k;
16235 
16236  indxinfo = (IndxInfo *) findObjectByDumpId(coninfo->conindex);
16237 
16238  if (indxinfo == NULL)
16239  exit_horribly(NULL, "missing index for constraint \"%s\"\n",
16240  coninfo->dobj.name);
16241 
16242  if (dopt->binary_upgrade)
16244  indxinfo->dobj.catId.oid, true);
16245 
16246  appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
16247  fmtId(tbinfo->dobj.name));
16248  appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
16249  fmtId(coninfo->dobj.name));
16250 
16251  if (coninfo->condef)
16252  {
16253  /* pg_get_constraintdef should have provided everything */
16254  appendPQExpBuffer(q, "%s;\n", coninfo->condef);
16255  }
16256  else
16257  {
16258  appendPQExpBuffer(q, "%s (",
16259  coninfo->contype == 'p' ? "PRIMARY KEY" : "UNIQUE");
16260  for (k = 0; k < indxinfo->indnkeys; k++)
16261  {
16262  int indkey = (int) indxinfo->indkeys[k];
16263  const char *attname;
16264 
16265  if (indkey == InvalidAttrNumber)
16266  break;
16267  attname = getAttrName(indkey, tbinfo);
16268 
16269  appendPQExpBuffer(q, "%s%s",
16270  (k == 0) ? "" : ", ",
16271  fmtId(attname));
16272  }
16273 
16274  appendPQExpBufferChar(q, ')');
16275 
16276  if (nonemptyReloptions(indxinfo->indreloptions))
16277  {
16278  appendPQExpBufferStr(q, " WITH (");
16279  appendReloptionsArrayAH(q, indxinfo->indreloptions, "", fout);
16280  appendPQExpBufferChar(q, ')');
16281  }
16282 
16283  if (coninfo->condeferrable)
16284  {
16285  appendPQExpBufferStr(q, " DEFERRABLE");
16286  if (coninfo->condeferred)
16287  appendPQExpBufferStr(q, " INITIALLY DEFERRED");
16288  }
16289 
16290  appendPQExpBufferStr(q, ";\n");
16291  }
16292 
16293  /* If the index is clustered, we need to record that. */
16294  if (indxinfo->indisclustered)
16295  {
16296  appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER",
16297  fmtId(tbinfo->dobj.name));
16298  appendPQExpBuffer(q, " ON %s;\n",
16299  fmtId(indxinfo->dobj.name));
16300  }
16301 
16302  /*
16303  * DROP must be fully qualified in case same name appears in
16304  * pg_catalog
16305  */
16306  appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.",
16307  fmtId(tbinfo->dobj.namespace->dobj.name));
16308  appendPQExpBuffer(delq, "%s ",
16309  fmtId(tbinfo->dobj.name));
16310  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16311  fmtId(coninfo->dobj.name));
16312 
16313  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16314 
16315  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16316  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16317  tag,
16318  tbinfo->dobj.namespace->dobj.name,
16319  indxinfo->tablespace,
16320  tbinfo->rolname, false,
16321  "CONSTRAINT", SECTION_POST_DATA,
16322  q->data, delq->data, NULL,
16323  NULL, 0,
16324  NULL, NULL);
16325  }
16326  else if (coninfo->contype == 'f')
16327  {
16328  /*
16329  * XXX Potentially wrap in a 'SET CONSTRAINTS OFF' block so that the
16330  * current table data is not processed
16331  */
16332  appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
16333  fmtId(tbinfo->dobj.name));
16334  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16335  fmtId(coninfo->dobj.name),
16336  coninfo->condef);
16337 
16338  /*
16339  * DROP must be fully qualified in case same name appears in
16340  * pg_catalog
16341  */
16342  appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.",
16343  fmtId(tbinfo->dobj.namespace->dobj.name));
16344  appendPQExpBuffer(delq, "%s ",
16345  fmtId(tbinfo->dobj.name));
16346  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16347  fmtId(coninfo->dobj.name));
16348 
16349  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16350 
16351  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16352  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16353  tag,
16354  tbinfo->dobj.namespace->dobj.name,
16355  NULL,
16356  tbinfo->rolname, false,
16357  "FK CONSTRAINT", SECTION_POST_DATA,
16358  q->data, delq->data, NULL,
16359  NULL, 0,
16360  NULL, NULL);
16361  }
16362  else if (coninfo->contype == 'c' && tbinfo)
16363  {
16364  /* CHECK constraint on a table */
16365 
16366  /* Ignore if not to be dumped separately, or if it was inherited */
16367  if (coninfo->separate && coninfo->conislocal)
16368  {
16369  /* not ONLY since we want it to propagate to children */
16370  appendPQExpBuffer(q, "ALTER TABLE %s\n",
16371  fmtId(tbinfo->dobj.name));
16372  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16373  fmtId(coninfo->dobj.name),
16374  coninfo->condef);
16375 
16376  /*
16377  * DROP must be fully qualified in case same name appears in
16378  * pg_catalog
16379  */
16380  appendPQExpBuffer(delq, "ALTER TABLE %s.",
16381  fmtId(tbinfo->dobj.namespace->dobj.name));
16382  appendPQExpBuffer(delq, "%s ",
16383  fmtId(tbinfo->dobj.name));
16384  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16385  fmtId(coninfo->dobj.name));
16386 
16387  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16388 
16389  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16390  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16391  tag,
16392  tbinfo->dobj.namespace->dobj.name,
16393  NULL,
16394  tbinfo->rolname, false,
16395  "CHECK CONSTRAINT", SECTION_POST_DATA,
16396  q->data, delq->data, NULL,
16397  NULL, 0,
16398  NULL, NULL);
16399  }
16400  }
16401  else if (coninfo->contype == 'c' && tbinfo == NULL)
16402  {
16403  /* CHECK constraint on a domain */
16404  TypeInfo *tyinfo = coninfo->condomain;
16405 
16406  /* Ignore if not to be dumped separately */
16407  if (coninfo->separate)
16408  {
16409  appendPQExpBuffer(q, "ALTER DOMAIN %s\n",
16410  fmtId(tyinfo->dobj.name));
16411  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16412  fmtId(coninfo->dobj.name),
16413  coninfo->condef);
16414 
16415  /*
16416  * DROP must be fully qualified in case same name appears in
16417  * pg_catalog
16418  */
16419  appendPQExpBuffer(delq, "ALTER DOMAIN %s.",
16420  fmtId(tyinfo->dobj.namespace->dobj.name));
16421  appendPQExpBuffer(delq, "%s ",
16422  fmtId(tyinfo->dobj.name));
16423  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16424  fmtId(coninfo->dobj.name));
16425 
16426  tag = psprintf("%s %s", tyinfo->dobj.name, coninfo->dobj.name);
16427 
16428  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16429  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16430  tag,
16431  tyinfo->dobj.namespace->dobj.name,
16432  NULL,
16433  tyinfo->rolname, false,
16434  "CHECK CONSTRAINT", SECTION_POST_DATA,
16435  q->data, delq->data, NULL,
16436  NULL, 0,
16437  NULL, NULL);
16438  }
16439  }
16440  else
16441  {
16442  exit_horribly(NULL, "unrecognized constraint type: %c\n",
16443  coninfo->contype);
16444  }
16445 
16446  /* Dump Constraint Comments --- only works for table constraints */
16447  if (tbinfo && coninfo->separate &&
16448  coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
16449  dumpTableConstraintComment(fout, coninfo);
16450 
16451  free(tag);
16452  destroyPQExpBuffer(q);
16453  destroyPQExpBuffer(delq);
16454 }
char * tablespace
Definition: pg_dump.h:358
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static void appendReloptionsArrayAH(PQExpBuffer buffer, const char *reloptions, const char *prefix, Archive *fout)
Definition: pg_dump.c:18059
char * rolname
Definition: pg_dump.h:262
DumpId dumpId
Definition: pg_dump.h:132
DumpId conindex
Definition: pg_dump.h:432
DumpableObject dobj
Definition: pg_dump.h:261
char * condef
Definition: pg_dump.h:430
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpableObject dobj
Definition: pg_dump.h:426
DumpOptions * dopt
Definition: pg_backup.h:181
static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
Definition: pg_dump.c:16464
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:540
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
Oid * indkeys
Definition: pg_dump.h:361
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
Definition: pg_dump.c:4068
static const char * getAttrName(int attrnum, TableInfo *tblInfo)
Definition: pg_dump.c:16034
bool condeferrable
Definition: pg_dump.h:433
static bool nonemptyReloptions(const char *reloptions)
Definition: pg_dump.c:18047
int indnkeys
Definition: pg_dump.h:360
char * indreloptions
Definition: pg_dump.h:359
DumpableObject dobj
Definition: pg_dump.h:165
TypeInfo * condomain
Definition: pg_dump.h:428
bool conislocal
Definition: pg_dump.h:435
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
TableInfo * contable
Definition: pg_dump.h:427
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
bool condeferred
Definition: pg_dump.h:434
char * rolname
Definition: pg_dump.h:171
#define InvalidAttrNumber
Definition: attnum.h:23
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:355
bool indisclustered
Definition: pg_dump.h:362
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static void dumpConversion ( Archive fout,
ConvInfo convinfo 
)
static

Definition at line 13273 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), _convInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, dumpComment(), _dumpableObject::dumpId, ExecuteSqlQueryForSingleRow(), fmtId(), _dumpableObject::name, CatalogId::oid, PQclear(), PQfnumber(), PQgetvalue(), _convInfo::rolname, SECTION_PRE_DATA, and selectSourceSchema().

Referenced by dumpDumpableObject().

13274 {
13275  DumpOptions *dopt = fout->dopt;
13276  PQExpBuffer query;
13277  PQExpBuffer q;
13278  PQExpBuffer delq;
13279  PQExpBuffer labelq;
13280  PGresult *res;
13281  int i_conforencoding;
13282  int i_contoencoding;
13283  int i_conproc;
13284  int i_condefault;
13285  const char *conforencoding;
13286  const char *contoencoding;
13287  const char *conproc;
13288  bool condefault;
13289 
13290  /* Skip if not to be dumped */
13291  if (!convinfo->dobj.dump || dopt->dataOnly)
13292  return;
13293 
13294  query = createPQExpBuffer();
13295  q = createPQExpBuffer();
13296  delq = createPQExpBuffer();
13297  labelq = createPQExpBuffer();
13298 
13299  /* Make sure we are in proper schema */
13300  selectSourceSchema(fout, convinfo->dobj.namespace->dobj.name);
13301 
13302  /* Get conversion-specific details */
13303  appendPQExpBuffer(query, "SELECT "
13304  "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
13305  "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
13306  "conproc, condefault "
13307  "FROM pg_catalog.pg_conversion c "
13308  "WHERE c.oid = '%u'::pg_catalog.oid",
13309  convinfo->dobj.catId.oid);
13310 
13311  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13312 
13313  i_conforencoding = PQfnumber(res, "conforencoding");
13314  i_contoencoding = PQfnumber(res, "contoencoding");
13315  i_conproc = PQfnumber(res, "conproc");
13316  i_condefault = PQfnumber(res, "condefault");
13317 
13318  conforencoding = PQgetvalue(res, 0, i_conforencoding);
13319  contoencoding = PQgetvalue(res, 0, i_contoencoding);
13320  conproc = PQgetvalue(res, 0, i_conproc);
13321  condefault = (PQgetvalue(res, 0, i_condefault)[0] == 't');
13322 
13323  /*
13324  * DROP must be fully qualified in case same name appears in pg_catalog
13325  */
13326  appendPQExpBuffer(delq, "DROP CONVERSION %s",
13327  fmtId(convinfo->dobj.namespace->dobj.name));
13328  appendPQExpBuffer(delq, ".%s;\n",
13329  fmtId(convinfo->dobj.name));
13330 
13331  appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ",
13332  (condefault) ? "DEFAULT " : "",
13333  fmtId(convinfo->dobj.name));
13334  appendStringLiteralAH(q, conforencoding, fout);
13335  appendPQExpBufferStr(q, " TO ");
13336  appendStringLiteralAH(q, contoencoding, fout);
13337  /* regproc output is already sufficiently quoted */
13338  appendPQExpBuffer(q, " FROM %s;\n", conproc);
13339 
13340  appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name));
13341 
13342  if (dopt->binary_upgrade)
13343  binary_upgrade_extension_member(q, &convinfo->dobj, labelq->data);
13344 
13345  if (convinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13346  ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
13347  convinfo->dobj.name,
13348  convinfo->dobj.namespace->dobj.name,
13349  NULL,
13350  convinfo->rolname,
13351  false, "CONVERSION", SECTION_PRE_DATA,
13352  q->data, delq->data, NULL,
13353  NULL, 0,
13354  NULL, NULL);
13355 
13356  /* Dump Conversion Comments */
13357  if (convinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13358  dumpComment(fout, labelq->data,
13359  convinfo->dobj.namespace->dobj.name, convinfo->rolname,
13360  convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
13361 
13362  PQclear(res);
13363 
13364  destroyPQExpBuffer(query);
13365  destroyPQExpBuffer(q);
13366  destroyPQExpBuffer(delq);
13367  destroyPQExpBuffer(labelq);
13368 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * rolname
Definition: pg_dump.h:253
DumpId dumpId
Definition: pg_dump.h:132
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9161
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17950
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2832
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4135
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
DumpableObject dobj
Definition: pg_dump.h:252
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)