PostgreSQL Source Code  git master
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_d.h"
#include "catalog/pg_am_d.h"
#include "catalog/pg_attribute_d.h"
#include "catalog/pg_cast_d.h"
#include "catalog/pg_class_d.h"
#include "catalog/pg_default_acl_d.h"
#include "catalog/pg_largeobject_d.h"
#include "catalog/pg_largeobject_metadata_d.h"
#include "catalog/pg_proc_d.h"
#include "catalog/pg_trigger_d.h"
#include "catalog/pg_type_d.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/connect.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
 

Macros

#define fmtQualifiedDumpable(obj)
 

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 *type, const char *name, 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 *type, const char *name, 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 dumpIndexAttach (Archive *fout, IndexAttachInfo *attachinfo)
 
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 *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 * getFormattedOperatorName (Archive *fout, const char *oproid)
 
static char * convertTSFunction (Archive *fout, Oid funcOid)
 
static Oid findLastBuiltinOid_V71 (Archive *fout)
 
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 dumpDatabaseConfig (Archive *AH, PQExpBuffer outbuf, const char *dbname, Oid dboid)
 
static void dumpEncoding (Archive *AH)
 
static void dumpStdStrings (Archive *AH)
 
static void dumpSearchPath (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 *objtype, const char *objname, const char *objnamespace)
 
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)
 
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}
 

Macro Definition Documentation

◆ fmtQualifiedDumpable

Typedef Documentation

◆ OidOptions

Enumeration Type Documentation

◆ OidOptions

enum OidOptions
Enumerator
zeroAsOpaque 
zeroAsAny 
zeroAsStar 
zeroAsNone 

Definition at line 84 of file pg_dump.c.

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

Function Documentation

◆ addBoundaryDependencies()

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

Definition at line 17788 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_INDEX_ATTACH, 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().

17790 {
17791  DumpableObject *preDataBound = boundaryObjs + 0;
17792  DumpableObject *postDataBound = boundaryObjs + 1;
17793  int i;
17794 
17795  for (i = 0; i < numObjs; i++)
17796  {
17797  DumpableObject *dobj = dobjs[i];
17798 
17799  /*
17800  * The classification of object types here must match the SECTION_xxx
17801  * values assigned during subsequent ArchiveEntry calls!
17802  */
17803  switch (dobj->objType)
17804  {
17805  case DO_NAMESPACE:
17806  case DO_EXTENSION:
17807  case DO_TYPE:
17808  case DO_SHELL_TYPE:
17809  case DO_FUNC:
17810  case DO_AGG:
17811  case DO_OPERATOR:
17812  case DO_ACCESS_METHOD:
17813  case DO_OPCLASS:
17814  case DO_OPFAMILY:
17815  case DO_COLLATION:
17816  case DO_CONVERSION:
17817  case DO_TABLE:
17818  case DO_ATTRDEF:
17819  case DO_PROCLANG:
17820  case DO_CAST:
17821  case DO_DUMMY_TYPE:
17822  case DO_TSPARSER:
17823  case DO_TSDICT:
17824  case DO_TSTEMPLATE:
17825  case DO_TSCONFIG:
17826  case DO_FDW:
17827  case DO_FOREIGN_SERVER:
17828  case DO_TRANSFORM:
17829  case DO_BLOB:
17830  /* Pre-data objects: must come before the pre-data boundary */
17831  addObjectDependency(preDataBound, dobj->dumpId);
17832  break;
17833  case DO_TABLE_DATA:
17834  case DO_SEQUENCE_SET:
17835  case DO_BLOB_DATA:
17836  /* Data objects: must come between the boundaries */
17837  addObjectDependency(dobj, preDataBound->dumpId);
17838  addObjectDependency(postDataBound, dobj->dumpId);
17839  break;
17840  case DO_INDEX:
17841  case DO_INDEX_ATTACH:
17842  case DO_STATSEXT:
17843  case DO_REFRESH_MATVIEW:
17844  case DO_TRIGGER:
17845  case DO_EVENT_TRIGGER:
17846  case DO_DEFAULT_ACL:
17847  case DO_POLICY:
17848  case DO_PUBLICATION:
17849  case DO_PUBLICATION_REL:
17850  case DO_SUBSCRIPTION:
17851  /* Post-data objects: must come after the post-data boundary */
17852  addObjectDependency(dobj, postDataBound->dumpId);
17853  break;
17854  case DO_RULE:
17855  /* Rules are post-data, but only if dumped separately */
17856  if (((RuleInfo *) dobj)->separate)
17857  addObjectDependency(dobj, postDataBound->dumpId);
17858  break;
17859  case DO_CONSTRAINT:
17860  case DO_FK_CONSTRAINT:
17861  /* Constraints are post-data, but only if dumped separately */
17862  if (((ConstraintInfo *) dobj)->separate)
17863  addObjectDependency(dobj, postDataBound->dumpId);
17864  break;
17865  case DO_PRE_DATA_BOUNDARY:
17866  /* nothing to do */
17867  break;
17868  case DO_POST_DATA_BOUNDARY:
17869  /* must come after the pre-data boundary */
17870  addObjectDependency(dobj, preDataBound->dumpId);
17871  break;
17872  }
17873  }
17874 }
DumpId dumpId
Definition: pg_dump.h:133
Definition: pg_dump.h:49
Definition: pg_dump.h:74
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:805
int i
DumpableObjectType objType
Definition: pg_dump.h:131

◆ appendReloptionsArrayAH()

static void appendReloptionsArrayAH ( PQExpBuffer  buffer,
const char *  reloptions,
const char *  prefix,
Archive fout 
)
static

Definition at line 18088 of file pg_dump.c.

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

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

18090 {
18091  bool res;
18092 
18093  res = appendReloptionsArray(buffer, reloptions, prefix, fout->encoding,
18094  fout->std_strings);
18095  if (!res)
18096  write_msg(NULL, "WARNING: could not parse reloptions array\n");
18097 }
int encoding
Definition: pg_backup.h:198
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:199

◆ binary_upgrade_extension_member()

static void binary_upgrade_extension_member ( PQExpBuffer  upgrade_buffer,
DumpableObject dobj,
const char *  objtype,
const char *  objname,
const char *  objnamespace 
)
static

Definition at line 4401 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().

4406 {
4407  DumpableObject *extobj = NULL;
4408  int i;
4409 
4410  if (!dobj->ext_member)
4411  return;
4412 
4413  /*
4414  * Find the parent extension. We could avoid this search if we wanted to
4415  * add a link field to DumpableObject, but the space costs of that would
4416  * be considerable. We assume that member objects could only have a
4417  * direct dependency on their own extension, not any others.
4418  */
4419  for (i = 0; i < dobj->nDeps; i++)
4420  {
4421  extobj = findObjectByDumpId(dobj->dependencies[i]);
4422  if (extobj && extobj->objType == DO_EXTENSION)
4423  break;
4424  extobj = NULL;
4425  }
4426  if (extobj == NULL)
4427  exit_horribly(NULL, "could not find parent extension for %s %s\n",
4428  objtype, objname);
4429 
4430  appendPQExpBufferStr(upgrade_buffer,
4431  "\n-- For binary upgrade, handle extension membership the hard way\n");
4432  appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s ",
4433  fmtId(extobj->name),
4434  objtype);
4435  if (objnamespace && *objnamespace)
4436  appendPQExpBuffer(upgrade_buffer, "%s.", fmtId(objnamespace));
4437  appendPQExpBuffer(upgrade_buffer, "%s;\n", objname);
4438 }
char * name
Definition: pg_dump.h:134
DumpId * dependencies
Definition: pg_dump.h:139
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:138
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:633
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:131

◆ binary_upgrade_set_pg_class_oids()

static void binary_upgrade_set_pg_class_oids ( Archive fout,
PQExpBuffer  upgrade_buffer,
Oid  pg_class_oid,
bool  is_index 
)
static

Definition at line 4331 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().

4334 {
4335  PQExpBuffer upgrade_query = createPQExpBuffer();
4336  PGresult *upgrade_res;
4337  Oid pg_class_reltoastrelid;
4338  Oid pg_index_indexrelid;
4339 
4340  appendPQExpBuffer(upgrade_query,
4341  "SELECT c.reltoastrelid, i.indexrelid "
4342  "FROM pg_catalog.pg_class c LEFT JOIN "
4343  "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
4344  "WHERE c.oid = '%u'::pg_catalog.oid;",
4345  pg_class_oid);
4346 
4347  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4348 
4349  pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
4350  pg_index_indexrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "indexrelid")));
4351 
4352  appendPQExpBufferStr(upgrade_buffer,
4353  "\n-- For binary upgrade, must preserve pg_class oids\n");
4354 
4355  if (!is_index)
4356  {
4357  appendPQExpBuffer(upgrade_buffer,
4358  "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
4359  pg_class_oid);
4360  /* only tables have toast tables, not indexes */
4361  if (OidIsValid(pg_class_reltoastrelid))
4362  {
4363  /*
4364  * One complexity is that the table definition might not require
4365  * the creation of a TOAST table, and the TOAST table might have
4366  * been created long after table creation, when the table was
4367  * loaded with wide data. By setting the TOAST oid we force
4368  * creation of the TOAST heap and TOAST index by the backend so we
4369  * can cleanly copy the files during binary upgrade.
4370  */
4371 
4372  appendPQExpBuffer(upgrade_buffer,
4373  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
4374  pg_class_reltoastrelid);
4375 
4376  /* every toast table has an index */
4377  appendPQExpBuffer(upgrade_buffer,
4378  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4379  pg_index_indexrelid);
4380  }
4381  }
4382  else
4383  appendPQExpBuffer(upgrade_buffer,
4384  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4385  pg_class_oid);
4386 
4387  appendPQExpBufferChar(upgrade_buffer, '\n');
4388 
4389  PQclear(upgrade_res);
4390  destroyPQExpBuffer(upgrade_query);
4391 }
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:605
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:420
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
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

◆ binary_upgrade_set_type_oids_by_rel_oid()

static bool binary_upgrade_set_type_oids_by_rel_oid ( Archive fout,
PQExpBuffer  upgrade_buffer,
Oid  pg_rel_oid 
)
static

Definition at line 4285 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().

4288 {
4289  PQExpBuffer upgrade_query = createPQExpBuffer();
4290  PGresult *upgrade_res;
4291  Oid pg_type_oid;
4292  bool toast_set = false;
4293 
4294  /* we only support old >= 8.3 for binary upgrades */
4295  appendPQExpBuffer(upgrade_query,
4296  "SELECT c.reltype AS crel, t.reltype AS trel "
4297  "FROM pg_catalog.pg_class c "
4298  "LEFT JOIN pg_catalog.pg_class t ON "
4299  " (c.reltoastrelid = t.oid) "
4300  "WHERE c.oid = '%u'::pg_catalog.oid;",
4301  pg_rel_oid);
4302 
4303  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4304 
4305  pg_type_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "crel")));
4306 
4307  binary_upgrade_set_type_oids_by_type_oid(fout, upgrade_buffer,
4308  pg_type_oid, false);
4309 
4310  if (!PQgetisnull(upgrade_res, 0, PQfnumber(upgrade_res, "trel")))
4311  {
4312  /* Toast tables do not have pg_type array rows */
4313  Oid pg_type_toast_oid = atooid(PQgetvalue(upgrade_res, 0,
4314  PQfnumber(upgrade_res, "trel")));
4315 
4316  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
4317  appendPQExpBuffer(upgrade_buffer,
4318  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4319  pg_type_toast_oid);
4320 
4321  toast_set = true;
4322  }
4323 
4324  PQclear(upgrade_res);
4325  destroyPQExpBuffer(upgrade_query);
4326 
4327  return toast_set;
4328 }
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
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:420
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
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:4216
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

◆ binary_upgrade_set_type_oids_by_type_oid()

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 4216 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().

4220 {
4221  PQExpBuffer upgrade_query = createPQExpBuffer();
4222  PGresult *res;
4223  Oid pg_type_array_oid;
4224 
4225  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
4226  appendPQExpBuffer(upgrade_buffer,
4227  "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4228  pg_type_oid);
4229 
4230  /* we only support old >= 8.3 for binary upgrades */
4231  appendPQExpBuffer(upgrade_query,
4232  "SELECT typarray "
4233  "FROM pg_catalog.pg_type "
4234  "WHERE oid = '%u'::pg_catalog.oid;",
4235  pg_type_oid);
4236 
4237  res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4238 
4239  pg_type_array_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typarray")));
4240 
4241  PQclear(res);
4242 
4243  if (!OidIsValid(pg_type_array_oid) && force_array_type)
4244  {
4245  /*
4246  * If the old version didn't assign an array type, but the new version
4247  * does, we must select an unused type OID to assign. This currently
4248  * only happens for domains, when upgrading pre-v11 to v11 and up.
4249  *
4250  * Note: local state here is kind of ugly, but we must have some,
4251  * since we mustn't choose the same unused OID more than once.
4252  */
4253  static Oid next_possible_free_oid = FirstNormalObjectId;
4254  bool is_dup;
4255 
4256  do
4257  {
4258  ++next_possible_free_oid;
4259  printfPQExpBuffer(upgrade_query,
4260  "SELECT EXISTS(SELECT 1 "
4261  "FROM pg_catalog.pg_type "
4262  "WHERE oid = '%u'::pg_catalog.oid);",
4263  next_possible_free_oid);
4264  res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4265  is_dup = (PQgetvalue(res, 0, 0)[0] == 't');
4266  PQclear(res);
4267  } while (is_dup);
4268 
4269  pg_type_array_oid = next_possible_free_oid;
4270  }
4271 
4272  if (OidIsValid(pg_type_array_oid))
4273  {
4274  appendPQExpBufferStr(upgrade_buffer,
4275  "\n-- For binary upgrade, must preserve pg_type array oid\n");
4276  appendPQExpBuffer(upgrade_buffer,
4277  "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4278  pg_type_array_oid);
4279  }
4280 
4281  destroyPQExpBuffer(upgrade_query);
4282 }
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:605
#define FirstNormalObjectId
Definition: transam.h:94
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:420
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
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

◆ BuildArchiveDependencies()

static void BuildArchiveDependencies ( Archive fout)
static

Definition at line 17901 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().

17902 {
17903  ArchiveHandle *AH = (ArchiveHandle *) fout;
17904  TocEntry *te;
17905 
17906  /* Scan all TOC entries in the archive */
17907  for (te = AH->toc->next; te != AH->toc; te = te->next)
17908  {
17909  DumpableObject *dobj;
17910  DumpId *dependencies;
17911  int nDeps;
17912  int allocDeps;
17913 
17914  /* No need to process entries that will not be dumped */
17915  if (te->reqs == 0)
17916  continue;
17917  /* Ignore entries that already have "special" dependencies */
17918  if (te->nDeps > 0)
17919  continue;
17920  /* Otherwise, look up the item's original DumpableObject, if any */
17921  dobj = findObjectByDumpId(te->dumpId);
17922  if (dobj == NULL)
17923  continue;
17924  /* No work if it has no dependencies */
17925  if (dobj->nDeps <= 0)
17926  continue;
17927  /* Set up work array */
17928  allocDeps = 64;
17929  dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(DumpId));
17930  nDeps = 0;
17931  /* Recursively find all dumpable dependencies */
17932  findDumpableDependencies(AH, dobj,
17933  &dependencies, &nDeps, &allocDeps);
17934  /* And save 'em ... */
17935  if (nDeps > 0)
17936  {
17937  dependencies = (DumpId *) pg_realloc(dependencies,
17938  nDeps * sizeof(DumpId));
17939  te->dependencies = dependencies;
17940  te->nDeps = nDeps;
17941  }
17942  else
17943  free(dependencies);
17944  }
17945 }
struct _tocEntry * next
int DumpId
Definition: pg_backup.h:235
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:633
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:17949
#define free(a)
Definition: header.h:65

◆ buildMatViewRefreshDependencies()

static void buildMatViewRefreshDependencies ( Archive fout)
static

Definition at line 2298 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, Archive::remoteVersion, and CatalogId::tableoid.

Referenced by main().

2299 {
2300  PQExpBuffer query;
2301  PGresult *res;
2302  int ntups,
2303  i;
2304  int i_classid,
2305  i_objid,
2306  i_refobjid;
2307 
2308  /* No Mat Views before 9.3. */
2309  if (fout->remoteVersion < 90300)
2310  return;
2311 
2312  query = createPQExpBuffer();
2313 
2314  appendPQExpBufferStr(query, "WITH RECURSIVE w AS "
2315  "( "
2316  "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2317  "FROM pg_depend d1 "
2318  "JOIN pg_class c1 ON c1.oid = d1.objid "
2319  "AND c1.relkind = " CppAsString2(RELKIND_MATVIEW)
2320  " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2321  "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2322  "AND d2.objid = r1.oid "
2323  "AND d2.refobjid <> d1.objid "
2324  "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2325  "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2326  CppAsString2(RELKIND_VIEW) ") "
2327  "WHERE d1.classid = 'pg_class'::regclass "
2328  "UNION "
2329  "SELECT w.objid, d3.refobjid, c3.relkind "
2330  "FROM w "
2331  "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2332  "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2333  "AND d3.objid = r3.oid "
2334  "AND d3.refobjid <> w.refobjid "
2335  "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2336  "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2337  CppAsString2(RELKIND_VIEW) ") "
2338  ") "
2339  "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2340  "FROM w "
2341  "WHERE refrelkind = " CppAsString2(RELKIND_MATVIEW));
2342 
2343  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
2344 
2345  ntups = PQntuples(res);
2346 
2347  i_classid = PQfnumber(res, "classid");
2348  i_objid = PQfnumber(res, "objid");
2349  i_refobjid = PQfnumber(res, "refobjid");
2350 
2351  for (i = 0; i < ntups; i++)
2352  {
2353  CatalogId objId;
2354  CatalogId refobjId;
2355  DumpableObject *dobj;
2356  DumpableObject *refdobj;
2357  TableInfo *tbinfo;
2358  TableInfo *reftbinfo;
2359 
2360  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
2361  objId.oid = atooid(PQgetvalue(res, i, i_objid));
2362  refobjId.tableoid = objId.tableoid;
2363  refobjId.oid = atooid(PQgetvalue(res, i, i_refobjid));
2364 
2365  dobj = findObjectByCatalogId(objId);
2366  if (dobj == NULL)
2367  continue;
2368 
2369  Assert(dobj->objType == DO_TABLE);
2370  tbinfo = (TableInfo *) dobj;
2371  Assert(tbinfo->relkind == RELKIND_MATVIEW);
2372  dobj = (DumpableObject *) tbinfo->dataObj;
2373  if (dobj == NULL)
2374  continue;
2375  Assert(dobj->objType == DO_REFRESH_MATVIEW);
2376 
2377  refdobj = findObjectByCatalogId(refobjId);
2378  if (refdobj == NULL)
2379  continue;
2380 
2381  Assert(refdobj->objType == DO_TABLE);
2382  reftbinfo = (TableInfo *) refdobj;
2383  Assert(reftbinfo->relkind == RELKIND_MATVIEW);
2384  refdobj = (DumpableObject *) reftbinfo->dataObj;
2385  if (refdobj == NULL)
2386  continue;
2387  Assert(refdobj->objType == DO_REFRESH_MATVIEW);
2388 
2389  addObjectDependency(dobj, refdobj->dumpId);
2390 
2391  if (!reftbinfo->relispopulated)
2392  tbinfo->relispopulated = false;
2393  }
2394 
2395  PQclear(res);
2396 
2397  destroyPQExpBuffer(query);
2398 }
char relkind
Definition: pg_dump.h:268
Oid tableoid
Definition: pg_backup.h:231
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
DumpId dumpId
Definition: pg_dump.h:133
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:651
#define atooid(x)
Definition: postgres_ext.h:42
#define CppAsString2(x)
Definition: c.h:224
struct _tableDataInfo * dataObj
Definition: pg_dump.h:334
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:699
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:805
int i
bool relispopulated
Definition: pg_dump.h:270
DumpableObjectType objType
Definition: pg_dump.h:131
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ checkExtensionMembership()

static bool checkExtensionMembership ( DumpableObject dobj,
Archive fout 
)
static

Definition at line 1366 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().

1367 {
1368  ExtensionInfo *ext = findOwningExtension(dobj->catId);
1369 
1370  if (ext == NULL)
1371  return false;
1372 
1373  dobj->ext_member = true;
1374 
1375  /* Record dependency so that getDependencies needn't deal with that */
1376  addObjectDependency(dobj, ext->dobj.dumpId);
1377 
1378  /*
1379  * In 9.6 and above, mark the member object to have any non-initial ACL,
1380  * policies, and security labels dumped.
1381  *
1382  * Note that any initial ACLs (see pg_init_privs) will be removed when we
1383  * extract the information about the object. We don't provide support for
1384  * initial policies and security labels and it seems unlikely for those to
1385  * ever exist, but we may have to revisit this later.
1386  *
1387  * Prior to 9.6, we do not include any extension member components.
1388  *
1389  * In binary upgrades, we still dump all components of the members
1390  * individually, since the idea is to exactly reproduce the database
1391  * contents rather than replace the extension contents with something
1392  * different.
1393  */
1394  if (fout->dopt->binary_upgrade)
1395  dobj->dump = ext->dobj.dump;
1396  else
1397  {
1398  if (fout->remoteVersion < 90600)
1399  dobj->dump = DUMP_COMPONENT_NONE;
1400  else
1401  dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL |
1404  }
1405 
1406  return true;
1407 }
DumpableObject dobj
Definition: pg_dump.h:156
DumpComponents dump
Definition: pg_dump.h:135
DumpId dumpId
Definition: pg_dump.h:133
bool ext_member
Definition: pg_dump.h:138
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:92
int binary_upgrade
Definition: pg_backup.h:136
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition: common.c:957
DumpOptions * dopt
Definition: pg_backup.h:183
DumpComponents dump_contains
Definition: pg_dump.h:137
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:96
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:805
CatalogId catId
Definition: pg_dump.h:132
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:98
int remoteVersion
Definition: pg_backup.h:188

◆ collectComments()

static int collectComments ( Archive fout,
CommentItem **  items 
)
static

Definition at line 9613 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().

9614 {
9615  PGresult *res;
9616  PQExpBuffer query;
9617  int i_description;
9618  int i_classoid;
9619  int i_objoid;
9620  int i_objsubid;
9621  int ntups;
9622  int i;
9623  CommentItem *comments;
9624 
9625  query = createPQExpBuffer();
9626 
9627  appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
9628  "FROM pg_catalog.pg_description "
9629  "ORDER BY classoid, objoid, objsubid");
9630 
9631  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9632 
9633  /* Construct lookup table containing OIDs in numeric form */
9634 
9635  i_description = PQfnumber(res, "description");
9636  i_classoid = PQfnumber(res, "classoid");
9637  i_objoid = PQfnumber(res, "objoid");
9638  i_objsubid = PQfnumber(res, "objsubid");
9639 
9640  ntups = PQntuples(res);
9641 
9642  comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
9643 
9644  for (i = 0; i < ntups; i++)
9645  {
9646  comments[i].descr = PQgetvalue(res, i, i_description);
9647  comments[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
9648  comments[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
9649  comments[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
9650  }
9651 
9652  /* Do NOT free the PGresult since we are keeping pointers into it */
9653  destroyPQExpBuffer(query);
9654 
9655  *items = comments;
9656  return ntups;
9657 }
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:72
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:69
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:71
Oid classoid
Definition: pg_dump.c:70
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405

◆ collectSecLabels()

static int collectSecLabels ( Archive fout,
SecLabelItem **  items 
)
static

Definition at line 15031 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().

15032 {
15033  PGresult *res;
15034  PQExpBuffer query;
15035  int i_label;
15036  int i_provider;
15037  int i_classoid;
15038  int i_objoid;
15039  int i_objsubid;
15040  int ntups;
15041  int i;
15042  SecLabelItem *labels;
15043 
15044  query = createPQExpBuffer();
15045 
15046  appendPQExpBufferStr(query,
15047  "SELECT label, provider, classoid, objoid, objsubid "
15048  "FROM pg_catalog.pg_seclabel "
15049  "ORDER BY classoid, objoid, objsubid");
15050 
15051  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
15052 
15053  /* Construct lookup table containing OIDs in numeric form */
15054  i_label = PQfnumber(res, "label");
15055  i_provider = PQfnumber(res, "provider");
15056  i_classoid = PQfnumber(res, "classoid");
15057  i_objoid = PQfnumber(res, "objoid");
15058  i_objsubid = PQfnumber(res, "objsubid");
15059 
15060  ntups = PQntuples(res);
15061 
15062  labels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
15063 
15064  for (i = 0; i < ntups; i++)
15065  {
15066  labels[i].label = PQgetvalue(res, i, i_label);
15067  labels[i].provider = PQgetvalue(res, i, i_provider);
15068  labels[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
15069  labels[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
15070  labels[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
15071  }
15072 
15073  /* Do NOT free the PGresult since we are keeping pointers into it */
15074  destroyPQExpBuffer(query);
15075 
15076  *items = labels;
15077  return ntups;
15078 }
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:80
const char * provider
Definition: pg_dump.c:77
#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:81
int i
Oid classoid
Definition: pg_dump.c:79
const char * label
Definition: pg_dump.c:78
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405

◆ convertRegProcReference()

static char * convertRegProcReference ( Archive fout,
const char *  proc 
)
static

Definition at line 12448 of file pg_dump.c.

References name, and pg_strdup().

Referenced by dumpOpr().

12449 {
12450  char *name;
12451  char *paren;
12452  bool inquote;
12453 
12454  /* In all cases "-" means a null reference */
12455  if (strcmp(proc, "-") == 0)
12456  return NULL;
12457 
12458  name = pg_strdup(proc);
12459  /* find non-double-quoted left paren */
12460  inquote = false;
12461  for (paren = name; *paren; paren++)
12462  {
12463  if (*paren == '(' && !inquote)
12464  {
12465  *paren = '\0';
12466  break;
12467  }
12468  if (*paren == '"')
12469  inquote = !inquote;
12470  }
12471  return name;
12472 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
const char * name
Definition: encode.c:521

◆ convertTSFunction()

static char * convertTSFunction ( Archive fout,
Oid  funcOid 
)
static

Definition at line 12519 of file pg_dump.c.

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

Referenced by dumpTSParser(), and dumpTSTemplate().

12520 {
12521  char *result;
12522  char query[128];
12523  PGresult *res;
12524 
12525  snprintf(query, sizeof(query),
12526  "SELECT '%u'::pg_catalog.regproc", funcOid);
12527  res = ExecuteSqlQueryForSingleRow(fout, query);
12528 
12529  result = pg_strdup(PQgetvalue(res, 0, 0));
12530 
12531  PQclear(res);
12532 
12533  return result;
12534 }
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
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:420
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void PQclear(PGresult *res)
Definition: fe-exec.c:671

◆ createBoundaryObjects()

static DumpableObject * createBoundaryObjects ( void  )
static

Definition at line 17764 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().

17765 {
17766  DumpableObject *dobjs;
17767 
17768  dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject));
17769 
17770  dobjs[0].objType = DO_PRE_DATA_BOUNDARY;
17771  dobjs[0].catId = nilCatalogId;
17772  AssignDumpId(dobjs + 0);
17773  dobjs[0].name = pg_strdup("PRE-DATA BOUNDARY");
17774 
17775  dobjs[1].objType = DO_POST_DATA_BOUNDARY;
17776  dobjs[1].catId = nilCatalogId;
17777  AssignDumpId(dobjs + 1);
17778  dobjs[1].name = pg_strdup("POST-DATA BOUNDARY");
17779 
17780  return dobjs;
17781 }
char * name
Definition: pg_dump.h:134
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
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:132
static const CatalogId nilCatalogId
Definition: pg_dump.c:134
DumpableObjectType objType
Definition: pg_dump.h:131

◆ createDummyViewAsClause()

static PQExpBuffer createDummyViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

Definition at line 15269 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), _tableInfo::attcollation, _tableInfo::attnames, _tableInfo::atttypnames, createPQExpBuffer(), findCollationByOid(), fmtId(), fmtQualifiedDumpable, _tableInfo::numatts, and OidIsValid.

Referenced by dumpRule(), and dumpTableSchema().

15270 {
15271  PQExpBuffer result = createPQExpBuffer();
15272  int j;
15273 
15274  appendPQExpBufferStr(result, "SELECT");
15275 
15276  for (j = 0; j < tbinfo->numatts; j++)
15277  {
15278  if (j > 0)
15279  appendPQExpBufferChar(result, ',');
15280  appendPQExpBufferStr(result, "\n ");
15281 
15282  appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]);
15283 
15284  /*
15285  * Must add collation if not default for the type, because CREATE OR
15286  * REPLACE VIEW won't change it
15287  */
15288  if (OidIsValid(tbinfo->attcollation[j]))
15289  {
15290  CollInfo *coll;
15291 
15292  coll = findCollationByOid(tbinfo->attcollation[j]);
15293  if (coll)
15294  appendPQExpBuffer(result, " COLLATE %s",
15295  fmtQualifiedDumpable(coll));
15296  }
15297 
15298  appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j]));
15299  }
15300 
15301  return result;
15302 }
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:306
char ** attnames
Definition: pg_dump.h:305
#define OidIsValid(objectId)
Definition: c.h:605
Oid * attcollation
Definition: pg_dump.h:317
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
int numatts
Definition: pg_dump.h:304
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:140
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:896

◆ createViewAsClause()

static PQExpBuffer createViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

Definition at line 15220 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().

15221 {
15222  PQExpBuffer query = createPQExpBuffer();
15223  PQExpBuffer result = createPQExpBuffer();
15224  PGresult *res;
15225  int len;
15226 
15227  /* Fetch the view definition */
15228  appendPQExpBuffer(query,
15229  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
15230  tbinfo->dobj.catId.oid);
15231 
15232  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
15233 
15234  if (PQntuples(res) != 1)
15235  {
15236  if (PQntuples(res) < 1)
15237  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned no data\n",
15238  tbinfo->dobj.name);
15239  else
15240  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned more than one definition\n",
15241  tbinfo->dobj.name);
15242  }
15243 
15244  len = PQgetlength(res, 0, 0);
15245 
15246  if (len == 0)
15247  exit_horribly(NULL, "definition of view \"%s\" appears to be empty (length zero)\n",
15248  tbinfo->dobj.name);
15249 
15250  /* Strip off the trailing semicolon so that other things may follow. */
15251  Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
15252  appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
15253 
15254  PQclear(res);
15255  destroyPQExpBuffer(query);
15256 
15257  return result;
15258 }
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3129
char * name
Definition: pg_dump.h:134
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:262
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:699
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:132
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:405

◆ dumpAccessMethod()

static void dumpAccessMethod ( Archive fout,
AccessMethodInfo oprinfo 
)
static

Definition at line 12541 of file pg_dump.c.

References _accessMethodInfo::amhandler, _accessMethodInfo::amtype, 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(), free, _dumpableObject::name, pg_strdup(), SECTION_PRE_DATA, and write_msg().

Referenced by dumpDumpableObject().

12542 {
12543  DumpOptions *dopt = fout->dopt;
12544  PQExpBuffer q;
12545  PQExpBuffer delq;
12546  char *qamname;
12547 
12548  /* Skip if not to be dumped */
12549  if (!aminfo->dobj.dump || dopt->dataOnly)
12550  return;
12551 
12552  q = createPQExpBuffer();
12553  delq = createPQExpBuffer();
12554 
12555  qamname = pg_strdup(fmtId(aminfo->dobj.name));
12556 
12557  appendPQExpBuffer(q, "CREATE ACCESS METHOD %s ", qamname);
12558 
12559  switch (aminfo->amtype)
12560  {
12561  case AMTYPE_INDEX:
12562  appendPQExpBuffer(q, "TYPE INDEX ");
12563  break;
12564  default:
12565  write_msg(NULL, "WARNING: invalid type \"%c\" of access method \"%s\"\n",
12566  aminfo->amtype, qamname);
12567  destroyPQExpBuffer(q);
12568  destroyPQExpBuffer(delq);
12569  free(qamname);
12570  return;
12571  }
12572 
12573  appendPQExpBuffer(q, "HANDLER %s;\n", aminfo->amhandler);
12574 
12575  appendPQExpBuffer(delq, "DROP ACCESS METHOD %s;\n",
12576  qamname);
12577 
12578  if (dopt->binary_upgrade)
12579  binary_upgrade_extension_member(q, &aminfo->dobj,
12580  "ACCESS METHOD", qamname, NULL);
12581 
12582  if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
12583  ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
12584  aminfo->dobj.name,
12585  NULL,
12586  NULL,
12587  "",
12588  false, "ACCESS METHOD", SECTION_PRE_DATA,
12589  q->data, delq->data, NULL,
12590  NULL, 0,
12591  NULL, NULL);
12592 
12593  /* Dump Access Method Comments */
12594  if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT)
12595  dumpComment(fout, "ACCESS METHOD", qamname,
12596  NULL, "",
12597  aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
12598 
12599  destroyPQExpBuffer(q);
12600  destroyPQExpBuffer(delq);
12601  free(qamname);
12602 }
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:136
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:95
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define free(a)
Definition: header.h:65
void write_msg(const char *modulename, const char *fmt,...)
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4401
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 dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9355

◆ dumpACL()

static void dumpACL ( Archive fout,
CatalogId  objCatId,
DumpId  objDumpId,
const char *  type,
const char *  name,
const char *  subname,
const char *  nspname,
const char *  owner,
const char *  acls,
const char *  racls,
const char *  initacls,
const char *  initracls 
)
static

Definition at line 14700 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(), dumpDatabase(), dumpDomain(), dumpEnumType(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpNamespace(), dumpProcLang(), dumpRangeType(), dumpTable(), and dumpUndefinedType().

14705 {
14706  DumpOptions *dopt = fout->dopt;
14707  PQExpBuffer sql;
14708 
14709  /* Do nothing if ACL dump is not enabled */
14710  if (dopt->aclsSkip)
14711  return;
14712 
14713  /* --data-only skips ACLs *except* BLOB ACLs */
14714  if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
14715  return;
14716 
14717  sql = createPQExpBuffer();
14718 
14719  /*
14720  * Check to see if this object has had any initial ACLs included for it.
14721  * If so, we are in binary upgrade mode and these are the ACLs to turn
14722  * into GRANT and REVOKE statements to set and record the initial
14723  * privileges for an extension object. Let the backend know that these
14724  * are to be recorded by calling binary_upgrade_set_record_init_privs()
14725  * before and after.
14726  */
14727  if (strlen(initacls) != 0 || strlen(initracls) != 0)
14728  {
14729  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
14730  if (!buildACLCommands(name, subname, nspname, type,
14731  initacls, initracls, owner,
14732  "", fout->remoteVersion, sql))
14733  exit_horribly(NULL,
14734  "could not parse initial GRANT ACL list (%s) or initial REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14735  initacls, initracls, name, type);
14736  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
14737  }
14738 
14739  if (!buildACLCommands(name, subname, nspname, type,
14740  acls, racls, owner,
14741  "", fout->remoteVersion, sql))
14742  exit_horribly(NULL,
14743  "could not parse GRANT ACL list (%s) or REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14744  acls, racls, name, type);
14745 
14746  if (sql->len > 0)
14747  {
14749 
14750  if (subname)
14751  appendPQExpBuffer(tag, "COLUMN %s.%s", name, subname);
14752  else
14753  appendPQExpBuffer(tag, "%s %s", type, name);
14754 
14756  tag->data, nspname,
14757  NULL,
14758  owner ? owner : "",
14759  false, "ACL", SECTION_NONE,
14760  sql->data, "", NULL,
14761  &(objDumpId), 1,
14762  NULL, NULL);
14763  destroyPQExpBuffer(tag);
14764  }
14765 
14766  destroyPQExpBuffer(sql);
14767 }
NameData subname
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
bool aclsSkip
Definition: pg_backup.h:142
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
bool buildACLCommands(const char *name, const char *subname, const char *nspname, const char *type, const char *acls, const char *racls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql)
Definition: dumputils.c:56
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:134
DumpId createDumpId(void)
Definition: common.c:613
int remoteVersion
Definition: pg_backup.h:188

◆ dumpAgg()

static void dumpAgg ( Archive fout,
AggInfo agginfo 
)
static

Definition at line 13523 of file pg_dump.c.

References _aggInfo::aggfn, appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), _dumpableObject::catId, 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, getFormattedOperatorName(), _funcInfo::initproacl, _funcInfo::initrproacl, _dumpableObject::name, CatalogId::oid, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), _funcInfo::proacl, Archive::remoteVersion, _funcInfo::rolname, _funcInfo::rproacl, SECTION_PRE_DATA, and write_msg().

Referenced by dumpDumpableObject().

13524 {
13525  DumpOptions *dopt = fout->dopt;
13526  PQExpBuffer query;
13527  PQExpBuffer q;
13528  PQExpBuffer delq;
13529  PQExpBuffer details;
13530  char *aggsig; /* identity signature */
13531  char *aggfullsig = NULL; /* full signature */
13532  char *aggsig_tag;
13533  PGresult *res;
13534  int i_aggtransfn;
13535  int i_aggfinalfn;
13536  int i_aggcombinefn;
13537  int i_aggserialfn;
13538  int i_aggdeserialfn;
13539  int i_aggmtransfn;
13540  int i_aggminvtransfn;
13541  int i_aggmfinalfn;
13542  int i_aggfinalextra;
13543  int i_aggmfinalextra;
13544  int i_aggfinalmodify;
13545  int i_aggmfinalmodify;
13546  int i_aggsortop;
13547  int i_aggkind;
13548  int i_aggtranstype;
13549  int i_aggtransspace;
13550  int i_aggmtranstype;
13551  int i_aggmtransspace;
13552  int i_agginitval;
13553  int i_aggminitval;
13554  int i_convertok;
13555  int i_proparallel;
13556  const char *aggtransfn;
13557  const char *aggfinalfn;
13558  const char *aggcombinefn;
13559  const char *aggserialfn;
13560  const char *aggdeserialfn;
13561  const char *aggmtransfn;
13562  const char *aggminvtransfn;
13563  const char *aggmfinalfn;
13564  bool aggfinalextra;
13565  bool aggmfinalextra;
13566  char aggfinalmodify;
13567  char aggmfinalmodify;
13568  const char *aggsortop;
13569  char *aggsortconvop;
13570  char aggkind;
13571  const char *aggtranstype;
13572  const char *aggtransspace;
13573  const char *aggmtranstype;
13574  const char *aggmtransspace;
13575  const char *agginitval;
13576  const char *aggminitval;
13577  bool convertok;
13578  const char *proparallel;
13579  char defaultfinalmodify;
13580 
13581  /* Skip if not to be dumped */
13582  if (!agginfo->aggfn.dobj.dump || dopt->dataOnly)
13583  return;
13584 
13585  query = createPQExpBuffer();
13586  q = createPQExpBuffer();
13587  delq = createPQExpBuffer();
13588  details = createPQExpBuffer();
13589 
13590  /* Get aggregate-specific details */
13591  if (fout->remoteVersion >= 110000)
13592  {
13593  appendPQExpBuffer(query, "SELECT aggtransfn, "
13594  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13595  "aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, "
13596  "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13597  "aggfinalextra, aggmfinalextra, "
13598  "aggfinalmodify, aggmfinalmodify, "
13599  "aggsortop, "
13600  "aggkind, "
13601  "aggtransspace, agginitval, "
13602  "aggmtransspace, aggminitval, "
13603  "true AS convertok, "
13604  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13605  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, "
13606  "p.proparallel "
13607  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13608  "WHERE a.aggfnoid = p.oid "
13609  "AND p.oid = '%u'::pg_catalog.oid",
13610  agginfo->aggfn.dobj.catId.oid);
13611  }
13612  else if (fout->remoteVersion >= 90600)
13613  {
13614  appendPQExpBuffer(query, "SELECT aggtransfn, "
13615  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13616  "aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, "
13617  "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13618  "aggfinalextra, aggmfinalextra, "
13619  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13620  "aggsortop, "
13621  "aggkind, "
13622  "aggtransspace, agginitval, "
13623  "aggmtransspace, aggminitval, "
13624  "true AS convertok, "
13625  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13626  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, "
13627  "p.proparallel "
13628  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13629  "WHERE a.aggfnoid = p.oid "
13630  "AND p.oid = '%u'::pg_catalog.oid",
13631  agginfo->aggfn.dobj.catId.oid);
13632  }
13633  else if (fout->remoteVersion >= 90400)
13634  {
13635  appendPQExpBuffer(query, "SELECT aggtransfn, "
13636  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13637  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13638  "'-' AS aggdeserialfn, aggmtransfn, aggminvtransfn, "
13639  "aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13640  "aggfinalextra, aggmfinalextra, "
13641  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13642  "aggsortop, "
13643  "aggkind, "
13644  "aggtransspace, agginitval, "
13645  "aggmtransspace, aggminitval, "
13646  "true AS convertok, "
13647  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13648  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13649  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13650  "WHERE a.aggfnoid = p.oid "
13651  "AND p.oid = '%u'::pg_catalog.oid",
13652  agginfo->aggfn.dobj.catId.oid);
13653  }
13654  else if (fout->remoteVersion >= 80400)
13655  {
13656  appendPQExpBuffer(query, "SELECT aggtransfn, "
13657  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13658  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13659  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13660  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13661  "0 AS aggmtranstype, false AS aggfinalextra, "
13662  "false AS aggmfinalextra, "
13663  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13664  "aggsortop, "
13665  "'n' AS aggkind, "
13666  "0 AS aggtransspace, agginitval, "
13667  "0 AS aggmtransspace, NULL AS aggminitval, "
13668  "true AS convertok, "
13669  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13670  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13671  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13672  "WHERE a.aggfnoid = p.oid "
13673  "AND p.oid = '%u'::pg_catalog.oid",
13674  agginfo->aggfn.dobj.catId.oid);
13675  }
13676  else if (fout->remoteVersion >= 80100)
13677  {
13678  appendPQExpBuffer(query, "SELECT aggtransfn, "
13679  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13680  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13681  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13682  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13683  "0 AS aggmtranstype, false AS aggfinalextra, "
13684  "false AS aggmfinalextra, "
13685  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13686  "aggsortop, "
13687  "'n' AS aggkind, "
13688  "0 AS aggtransspace, agginitval, "
13689  "0 AS aggmtransspace, NULL AS aggminitval, "
13690  "true AS convertok "
13691  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13692  "WHERE a.aggfnoid = p.oid "
13693  "AND p.oid = '%u'::pg_catalog.oid",
13694  agginfo->aggfn.dobj.catId.oid);
13695  }
13696  else
13697  {
13698  appendPQExpBuffer(query, "SELECT aggtransfn, "
13699  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13700  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13701  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13702  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13703  "0 AS aggmtranstype, false AS aggfinalextra, "
13704  "false AS aggmfinalextra, "
13705  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13706  "0 AS aggsortop, "
13707  "'n' AS aggkind, "
13708  "0 AS aggtransspace, agginitval, "
13709  "0 AS aggmtransspace, NULL AS aggminitval, "
13710  "true AS convertok "
13711  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13712  "WHERE a.aggfnoid = p.oid "
13713  "AND p.oid = '%u'::pg_catalog.oid",
13714  agginfo->aggfn.dobj.catId.oid);
13715  }
13716 
13717  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13718 
13719  i_aggtransfn = PQfnumber(res, "aggtransfn");
13720  i_aggfinalfn = PQfnumber(res, "aggfinalfn");
13721  i_aggcombinefn = PQfnumber(res, "aggcombinefn");
13722  i_aggserialfn = PQfnumber(res, "aggserialfn");
13723  i_aggdeserialfn = PQfnumber(res, "aggdeserialfn");
13724  i_aggmtransfn = PQfnumber(res, "aggmtransfn");
13725  i_aggminvtransfn = PQfnumber(res, "aggminvtransfn");
13726  i_aggmfinalfn = PQfnumber(res, "aggmfinalfn");
13727  i_aggfinalextra = PQfnumber(res, "aggfinalextra");
13728  i_aggmfinalextra = PQfnumber(res, "aggmfinalextra");
13729  i_aggfinalmodify = PQfnumber(res, "aggfinalmodify");
13730  i_aggmfinalmodify = PQfnumber(res, "aggmfinalmodify");
13731  i_aggsortop = PQfnumber(res, "aggsortop");
13732  i_aggkind = PQfnumber(res, "aggkind");
13733  i_aggtranstype = PQfnumber(res, "aggtranstype");
13734  i_aggtransspace = PQfnumber(res, "aggtransspace");
13735  i_aggmtranstype = PQfnumber(res, "aggmtranstype");
13736  i_aggmtransspace = PQfnumber(res, "aggmtransspace");
13737  i_agginitval = PQfnumber(res, "agginitval");
13738  i_aggminitval = PQfnumber(res, "aggminitval");
13739  i_convertok = PQfnumber(res, "convertok");
13740  i_proparallel = PQfnumber(res, "proparallel");
13741 
13742  aggtransfn = PQgetvalue(res, 0, i_aggtransfn);
13743  aggfinalfn = PQgetvalue(res, 0, i_aggfinalfn);
13744  aggcombinefn = PQgetvalue(res, 0, i_aggcombinefn);
13745  aggserialfn = PQgetvalue(res, 0, i_aggserialfn);
13746  aggdeserialfn = PQgetvalue(res, 0, i_aggdeserialfn);
13747  aggmtransfn = PQgetvalue(res, 0, i_aggmtransfn);
13748  aggminvtransfn = PQgetvalue(res, 0, i_aggminvtransfn);
13749  aggmfinalfn = PQgetvalue(res, 0, i_aggmfinalfn);
13750  aggfinalextra = (PQgetvalue(res, 0, i_aggfinalextra)[0] == 't');
13751  aggmfinalextra = (PQgetvalue(res, 0, i_aggmfinalextra)[0] == 't');
13752  aggfinalmodify = PQgetvalue(res, 0, i_aggfinalmodify)[0];
13753  aggmfinalmodify = PQgetvalue(res, 0, i_aggmfinalmodify)[0];
13754  aggsortop = PQgetvalue(res, 0, i_aggsortop);
13755  aggkind = PQgetvalue(res, 0, i_aggkind)[0];
13756  aggtranstype = PQgetvalue(res, 0, i_aggtranstype);
13757  aggtransspace = PQgetvalue(res, 0, i_aggtransspace);
13758  aggmtranstype = PQgetvalue(res, 0, i_aggmtranstype);
13759  aggmtransspace = PQgetvalue(res, 0, i_aggmtransspace);
13760  agginitval = PQgetvalue(res, 0, i_agginitval);
13761  aggminitval = PQgetvalue(res, 0, i_aggminitval);
13762  convertok = (PQgetvalue(res, 0, i_convertok)[0] == 't');
13763 
13764  if (fout->remoteVersion >= 80400)
13765  {
13766  /* 8.4 or later; we rely on server-side code for most of the work */
13767  char *funcargs;
13768  char *funciargs;
13769 
13770  funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs"));
13771  funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs"));
13772  aggfullsig = format_function_arguments(&agginfo->aggfn, funcargs, true);
13773  aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true);
13774  }
13775  else
13776  /* pre-8.4, do it ourselves */
13777  aggsig = format_aggregate_signature(agginfo, fout, true);
13778 
13779  aggsig_tag = format_aggregate_signature(agginfo, fout, false);
13780 
13781  if (i_proparallel != -1)
13782  proparallel = PQgetvalue(res, 0, PQfnumber(res, "proparallel"));
13783  else
13784  proparallel = NULL;
13785 
13786  if (!convertok)
13787  {
13788  write_msg(NULL, "WARNING: aggregate function %s could not be dumped correctly for this database version; ignored\n",
13789  aggsig);
13790 
13791  if (aggfullsig)
13792  free(aggfullsig);
13793 
13794  free(aggsig);
13795 
13796  return;
13797  }
13798 
13799  /* identify default modify flag for aggkind (must match DefineAggregate) */
13800  defaultfinalmodify = (aggkind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
13801  /* replace omitted flags for old versions */
13802  if (aggfinalmodify == '0')
13803  aggfinalmodify = defaultfinalmodify;
13804  if (aggmfinalmodify == '0')
13805  aggmfinalmodify = defaultfinalmodify;
13806 
13807  /* regproc and regtype output is already sufficiently quoted */
13808  appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
13809  aggtransfn, aggtranstype);
13810 
13811  if (strcmp(aggtransspace, "0") != 0)
13812  {
13813  appendPQExpBuffer(details, ",\n SSPACE = %s",
13814  aggtransspace);
13815  }
13816 
13817  if (!PQgetisnull(res, 0, i_agginitval))
13818  {
13819  appendPQExpBufferStr(details, ",\n INITCOND = ");
13820  appendStringLiteralAH(details, agginitval, fout);
13821  }
13822 
13823  if (strcmp(aggfinalfn, "-") != 0)
13824  {
13825  appendPQExpBuffer(details, ",\n FINALFUNC = %s",
13826  aggfinalfn);
13827  if (aggfinalextra)
13828  appendPQExpBufferStr(details, ",\n FINALFUNC_EXTRA");
13829  if (aggfinalmodify != defaultfinalmodify)
13830  {
13831  switch (aggfinalmodify)
13832  {
13833  case AGGMODIFY_READ_ONLY:
13834  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = READ_ONLY");
13835  break;
13836  case AGGMODIFY_SHARABLE:
13837  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = SHARABLE");
13838  break;
13839  case AGGMODIFY_READ_WRITE:
13840  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = READ_WRITE");
13841  break;
13842  default:
13843  exit_horribly(NULL, "unrecognized aggfinalmodify value for aggregate \"%s\"\n",
13844  agginfo->aggfn.dobj.name);
13845  break;
13846  }
13847  }
13848  }
13849 
13850  if (strcmp(aggcombinefn, "-") != 0)
13851  appendPQExpBuffer(details, ",\n COMBINEFUNC = %s", aggcombinefn);
13852 
13853  if (strcmp(aggserialfn, "-") != 0)
13854  appendPQExpBuffer(details, ",\n SERIALFUNC = %s", aggserialfn);
13855 
13856  if (strcmp(aggdeserialfn, "-") != 0)
13857  appendPQExpBuffer(details, ",\n DESERIALFUNC = %s", aggdeserialfn);
13858 
13859  if (strcmp(aggmtransfn, "-") != 0)
13860  {
13861  appendPQExpBuffer(details, ",\n MSFUNC = %s,\n MINVFUNC = %s,\n MSTYPE = %s",
13862  aggmtransfn,
13863  aggminvtransfn,
13864  aggmtranstype);
13865  }
13866 
13867  if (strcmp(aggmtransspace, "0") != 0)
13868  {
13869  appendPQExpBuffer(details, ",\n MSSPACE = %s",
13870  aggmtransspace);
13871  }
13872 
13873  if (!PQgetisnull(res, 0, i_aggminitval))
13874  {
13875  appendPQExpBufferStr(details, ",\n MINITCOND = ");
13876  appendStringLiteralAH(details, aggminitval, fout);
13877  }
13878 
13879  if (strcmp(aggmfinalfn, "-") != 0)
13880  {
13881  appendPQExpBuffer(details, ",\n MFINALFUNC = %s",
13882  aggmfinalfn);
13883  if (aggmfinalextra)
13884  appendPQExpBufferStr(details, ",\n MFINALFUNC_EXTRA");
13885  if (aggmfinalmodify != defaultfinalmodify)
13886  {
13887  switch (aggmfinalmodify)
13888  {
13889  case AGGMODIFY_READ_ONLY:
13890  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = READ_ONLY");
13891  break;
13892  case AGGMODIFY_SHARABLE:
13893  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = SHARABLE");
13894  break;
13895  case AGGMODIFY_READ_WRITE:
13896  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = READ_WRITE");
13897  break;
13898  default:
13899  exit_horribly(NULL, "unrecognized aggmfinalmodify value for aggregate \"%s\"\n",
13900  agginfo->aggfn.dobj.name);
13901  break;
13902  }
13903  }
13904  }
13905 
13906  aggsortconvop = getFormattedOperatorName(fout, aggsortop);
13907  if (aggsortconvop)
13908  {
13909  appendPQExpBuffer(details, ",\n SORTOP = %s",
13910  aggsortconvop);
13911  free(aggsortconvop);
13912  }
13913 
13914  if (aggkind == AGGKIND_HYPOTHETICAL)
13915  appendPQExpBufferStr(details, ",\n HYPOTHETICAL");
13916 
13917  if (proparallel != NULL && proparallel[0] != PROPARALLEL_UNSAFE)
13918  {
13919  if (proparallel[0] == PROPARALLEL_SAFE)
13920  appendPQExpBufferStr(details, ",\n PARALLEL = safe");
13921  else if (proparallel[0] == PROPARALLEL_RESTRICTED)
13922  appendPQExpBufferStr(details, ",\n PARALLEL = restricted");
13923  else if (proparallel[0] != PROPARALLEL_UNSAFE)
13924  exit_horribly(NULL, "unrecognized proparallel value for function \"%s\"\n",
13925  agginfo->aggfn.dobj.name);
13926  }
13927 
13928  appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n",
13929  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
13930  aggsig);
13931 
13932  appendPQExpBuffer(q, "CREATE AGGREGATE %s.%s (\n%s\n);\n",
13933  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
13934  aggfullsig ? aggfullsig : aggsig, details->data);
13935 
13936  if (dopt->binary_upgrade)
13938  "AGGREGATE", aggsig,
13939  agginfo->aggfn.dobj.namespace->dobj.name);
13940 
13941  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_DEFINITION)
13942  ArchiveEntry(fout, agginfo->aggfn.dobj.catId,
13943  agginfo->aggfn.dobj.dumpId,
13944  aggsig_tag,
13945  agginfo->aggfn.dobj.namespace->dobj.name,
13946  NULL,
13947  agginfo->aggfn.rolname,
13948  false, "AGGREGATE", SECTION_PRE_DATA,
13949  q->data, delq->data, NULL,
13950  NULL, 0,
13951  NULL, NULL);
13952 
13953  /* Dump Aggregate Comments */
13954  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_COMMENT)
13955  dumpComment(fout, "AGGREGATE", aggsig,
13956  agginfo->aggfn.dobj.namespace->dobj.name,
13957  agginfo->aggfn.rolname,
13958  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13959 
13960  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_SECLABEL)
13961  dumpSecLabel(fout, "AGGREGATE", aggsig,
13962  agginfo->aggfn.dobj.namespace->dobj.name,
13963  agginfo->aggfn.rolname,
13964  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13965 
13966  /*
13967  * Since there is no GRANT ON AGGREGATE syntax, we have to make the ACL
13968  * command look like a function's GRANT; in particular this affects the
13969  * syntax for zero-argument aggregates and ordered-set aggregates.
13970  */
13971  free(aggsig);
13972 
13973  aggsig = format_function_signature(fout, &agginfo->aggfn, true);
13974 
13975  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_ACL)
13976  dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
13977  "FUNCTION", aggsig, NULL,
13978  agginfo->aggfn.dobj.namespace->dobj.name,
13979  agginfo->aggfn.rolname, agginfo->aggfn.proacl,
13980  agginfo->aggfn.rproacl,
13981  agginfo->aggfn.initproacl, agginfo->aggfn.initrproacl);
13982 
13983  free(aggsig);
13984  if (aggfullsig)
13985  free(aggfullsig);
13986  free(aggsig_tag);
13987 
13988  PQclear(res);
13989 
13990  destroyPQExpBuffer(query);
13991  destroyPQExpBuffer(q);
13992  destroyPQExpBuffer(delq);
13993  destroyPQExpBuffer(details);
13994 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
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:208
DumpableObject dobj
Definition: pg_dump.h:199
DumpId dumpId
Definition: pg_dump.h:133
static void dumpSecLabel(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14788
static char * format_function_arguments(FuncInfo *finfo, char *funcargs, bool is_agg)
Definition: pg_dump.c:11328
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14700
FuncInfo aggfn
Definition: pg_dump.h:214
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:420
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
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:95
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:304
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define free(a)
Definition: header.h:65
void write_msg(const char *modulename, const char *fmt,...)
char * initproacl
Definition: pg_dump.h:207
static char * format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11423
char * rolname
Definition: pg_dump.h:200
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:96
char * proacl
Definition: pg_dump.h:205
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4401
char * rproacl
Definition: pg_dump.h:206
static char * getFormattedOperatorName(Archive *fout, const char *oproid)
Definition: pg_dump.c:12489
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:132
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
static char * format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
Definition: pg_dump.c:13485
static void dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9355
int remoteVersion
Definition: pg_backup.h:188

◆ dumpAttrDef()

static void dumpAttrDef ( Archive fout,
AttrDefInfo adinfo 
)
static

Definition at line 16025 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(), fmtQualifiedDumpable, free, _dumpableObject::name, pg_strdup(), psprintf(), _tableInfo::rolname, SECTION_PRE_DATA, and _attrDefInfo::separate.

Referenced by dumpDumpableObject().

16026 {
16027  DumpOptions *dopt = fout->dopt;
16028  TableInfo *tbinfo = adinfo->adtable;
16029  int adnum = adinfo->adnum;
16030  PQExpBuffer q;
16031  PQExpBuffer delq;
16032  char *qualrelname;
16033  char *tag;
16034 
16035  /* Skip if table definition not to be dumped */
16036  if (!tbinfo->dobj.dump || dopt->dataOnly)
16037  return;
16038 
16039  /* Skip if not "separate"; it was dumped in the table's definition */
16040  if (!adinfo->separate)
16041  return;
16042 
16043  q = createPQExpBuffer();
16044  delq = createPQExpBuffer();
16045 
16046  qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo));
16047 
16048  appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
16049  qualrelname);
16050  appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n",
16051  fmtId(tbinfo->attnames[adnum - 1]),
16052  adinfo->adef_expr);
16053 
16054  appendPQExpBuffer(delq, "ALTER TABLE %s ",
16055  qualrelname);
16056  appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n",
16057  fmtId(tbinfo->attnames[adnum - 1]));
16058 
16059  tag = psprintf("%s %s", tbinfo->dobj.name, tbinfo->attnames[adnum - 1]);
16060 
16061  if (adinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16062  ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
16063  tag,
16064  tbinfo->dobj.namespace->dobj.name,
16065  NULL,
16066  tbinfo->rolname,
16067  false, "DEFAULT", SECTION_PRE_DATA,
16068  q->data, delq->data, NULL,
16069  NULL, 0,
16070  NULL, NULL);
16071 
16072  free(tag);
16073  destroyPQExpBuffer(q);
16074  destroyPQExpBuffer(delq);
16075  free(qualrelname);
16076 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
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:263
DumpId dumpId
Definition: pg_dump.h:133
char ** attnames
Definition: pg_dump.h:305
DumpableObject dobj
Definition: pg_dump.h:262
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
bool separate
Definition: pg_dump.h:345
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
TableInfo * adtable
Definition: pg_dump.h:342
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:341
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:140
CatalogId catId
Definition: pg_dump.h:132
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:344

◆ dumpBaseType()

static void dumpBaseType ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10364 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(), fmtQualifiedDumpable, 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, _typeInfo::typacl, typalign, typbyval, typcategory, _typeInfo::typelem, typlen, and zeroAsOpaque.

Referenced by dumpType().

10365 {
10366  DumpOptions *dopt = fout->dopt;
10368  PQExpBuffer delq = createPQExpBuffer();
10369  PQExpBuffer query = createPQExpBuffer();
10370  PGresult *res;
10371  char *qtypname;
10372  char *qualtypname;
10373  char *typlen;
10374  char *typinput;
10375  char *typoutput;
10376  char *typreceive;
10377  char *typsend;
10378  char *typmodin;
10379  char *typmodout;
10380  char *typanalyze;
10381  Oid typreceiveoid;
10382  Oid typsendoid;
10383  Oid typmodinoid;
10384  Oid typmodoutoid;
10385  Oid typanalyzeoid;
10386  char *typcategory;
10387  char *typispreferred;
10388  char *typdelim;
10389  char *typbyval;
10390  char *typalign;
10391  char *typstorage;
10392  char *typcollatable;
10393  char *typdefault;
10394  bool typdefault_is_literal = false;
10395 
10396  /* Fetch type-specific details */
10397  if (fout->remoteVersion >= 90100)
10398  {
10399  appendPQExpBuffer(query, "SELECT typlen, "
10400  "typinput, typoutput, typreceive, typsend, "
10401  "typmodin, typmodout, typanalyze, "
10402  "typreceive::pg_catalog.oid AS typreceiveoid, "
10403  "typsend::pg_catalog.oid AS typsendoid, "
10404  "typmodin::pg_catalog.oid AS typmodinoid, "
10405  "typmodout::pg_catalog.oid AS typmodoutoid, "
10406  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10407  "typcategory, typispreferred, "
10408  "typdelim, typbyval, typalign, typstorage, "
10409  "(typcollation <> 0) AS typcollatable, "
10410  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10411  "FROM pg_catalog.pg_type "
10412  "WHERE oid = '%u'::pg_catalog.oid",
10413  tyinfo->dobj.catId.oid);
10414  }
10415  else if (fout->remoteVersion >= 80400)
10416  {
10417  appendPQExpBuffer(query, "SELECT typlen, "
10418  "typinput, typoutput, typreceive, typsend, "
10419  "typmodin, typmodout, typanalyze, "
10420  "typreceive::pg_catalog.oid AS typreceiveoid, "
10421  "typsend::pg_catalog.oid AS typsendoid, "
10422  "typmodin::pg_catalog.oid AS typmodinoid, "
10423  "typmodout::pg_catalog.oid AS typmodoutoid, "
10424  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10425  "typcategory, typispreferred, "
10426  "typdelim, typbyval, typalign, typstorage, "
10427  "false AS typcollatable, "
10428  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10429  "FROM pg_catalog.pg_type "
10430  "WHERE oid = '%u'::pg_catalog.oid",
10431  tyinfo->dobj.catId.oid);
10432  }
10433  else if (fout->remoteVersion >= 80300)
10434  {
10435  /* Before 8.4, pg_get_expr does not allow 0 for its second arg */
10436  appendPQExpBuffer(query, "SELECT typlen, "
10437  "typinput, typoutput, typreceive, typsend, "
10438  "typmodin, typmodout, typanalyze, "
10439  "typreceive::pg_catalog.oid AS typreceiveoid, "
10440  "typsend::pg_catalog.oid AS typsendoid, "
10441  "typmodin::pg_catalog.oid AS typmodinoid, "
10442  "typmodout::pg_catalog.oid AS typmodoutoid, "
10443  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10444  "'U' AS typcategory, false AS typispreferred, "
10445  "typdelim, typbyval, typalign, typstorage, "
10446  "false AS typcollatable, "
10447  "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10448  "FROM pg_catalog.pg_type "
10449  "WHERE oid = '%u'::pg_catalog.oid",
10450  tyinfo->dobj.catId.oid);
10451  }
10452  else
10453  {
10454  appendPQExpBuffer(query, "SELECT typlen, "
10455  "typinput, typoutput, typreceive, typsend, "
10456  "'-' AS typmodin, '-' AS typmodout, "
10457  "typanalyze, "
10458  "typreceive::pg_catalog.oid AS typreceiveoid, "
10459  "typsend::pg_catalog.oid AS typsendoid, "
10460  "0 AS typmodinoid, 0 AS typmodoutoid, "
10461  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10462  "'U' AS typcategory, false AS typispreferred, "
10463  "typdelim, typbyval, typalign, typstorage, "
10464  "false AS typcollatable, "
10465  "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10466  "FROM pg_catalog.pg_type "
10467  "WHERE oid = '%u'::pg_catalog.oid",
10468  tyinfo->dobj.catId.oid);
10469  }
10470 
10471  res = ExecuteSqlQueryForSingleRow(fout, query->data);
10472 
10473  typlen = PQgetvalue(res, 0, PQfnumber(res, "typlen"));
10474  typinput = PQgetvalue(res, 0, PQfnumber(res, "typinput"));
10475  typoutput = PQgetvalue(res, 0, PQfnumber(res, "typoutput"));
10476  typreceive = PQgetvalue(res, 0, PQfnumber(res, "typreceive"));
10477  typsend = PQgetvalue(res, 0, PQfnumber(res, "typsend"));
10478  typmodin = PQgetvalue(res, 0, PQfnumber(res, "typmodin"));
10479  typmodout = PQgetvalue(res, 0, PQfnumber(res, "typmodout"));
10480  typanalyze = PQgetvalue(res, 0, PQfnumber(res, "typanalyze"));
10481  typreceiveoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typreceiveoid")));
10482  typsendoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typsendoid")));
10483  typmodinoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodinoid")));
10484  typmodoutoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodoutoid")));
10485  typanalyzeoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typanalyzeoid")));
10486  typcategory = PQgetvalue(res, 0, PQfnumber(res, "typcategory"));
10487  typispreferred = PQgetvalue(res, 0, PQfnumber(res, "typispreferred"));
10488  typdelim = PQgetvalue(res, 0, PQfnumber(res, "typdelim"));
10489  typbyval = PQgetvalue(res, 0, PQfnumber(res, "typbyval"));
10490  typalign = PQgetvalue(res, 0, PQfnumber(res, "typalign"));
10491  typstorage = PQgetvalue(res, 0, PQfnumber(res, "typstorage"));
10492  typcollatable = PQgetvalue(res, 0, PQfnumber(res, "typcollatable"));
10493  if (!PQgetisnull(res, 0, PQfnumber(res, "typdefaultbin")))
10494  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefaultbin"));
10495  else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
10496  {
10497  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault"));
10498  typdefault_is_literal = true; /* it needs quotes */
10499  }
10500  else
10501  typdefault = NULL;
10502 
10503  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
10504  qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo));
10505 
10506  /*
10507  * The reason we include CASCADE is that the circular dependency between
10508  * the type and its I/O functions makes it impossible to drop the type any
10509  * other way.
10510  */
10511  appendPQExpBuffer(delq, "DROP TYPE %s CASCADE;\n", qualtypname);
10512 
10513  /*
10514  * We might already have a shell type, but setting pg_type_oid is
10515  * harmless, and in any case we'd better set the array type OID.
10516  */
10517  if (dopt->binary_upgrade)
10519  tyinfo->dobj.catId.oid,
10520  false);
10521 
10523  "CREATE TYPE %s (\n"
10524  " INTERNALLENGTH = %s",
10525  qualtypname,
10526  (strcmp(typlen, "-1") == 0) ? "variable" : typlen);
10527 
10528  /* regproc result is sufficiently quoted already */
10529  appendPQExpBuffer(q, ",\n INPUT = %s", typinput);
10530  appendPQExpBuffer(q, ",\n OUTPUT = %s", typoutput);
10531  if (OidIsValid(typreceiveoid))
10532  appendPQExpBuffer(q, ",\n RECEIVE = %s", typreceive);
10533  if (OidIsValid(typsendoid))
10534  appendPQExpBuffer(q, ",\n SEND = %s", typsend);
10535  if (OidIsValid(typmodinoid))
10536  appendPQExpBuffer(q, ",\n TYPMOD_IN = %s", typmodin);
10537  if (OidIsValid(typmodoutoid))
10538  appendPQExpBuffer(q, ",\n TYPMOD_OUT = %s", typmodout);
10539  if (OidIsValid(typanalyzeoid))
10540  appendPQExpBuffer(q, ",\n ANALYZE = %s", typanalyze);
10541 
10542  if (strcmp(typcollatable, "t") == 0)
10543  appendPQExpBufferStr(q, ",\n COLLATABLE = true");
10544 
10545  if (typdefault != NULL)
10546  {
10547  appendPQExpBufferStr(q, ",\n DEFAULT = ");
10548  if (typdefault_is_literal)
10549  appendStringLiteralAH(q, typdefault, fout);
10550  else
10551  appendPQExpBufferStr(q, typdefault);
10552  }
10553 
10554  if (OidIsValid(tyinfo->typelem))
10555  {
10556  char *elemType;
10557 
10558  elemType = getFormattedTypeName(fout, tyinfo->typelem, zeroAsOpaque);
10559  appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType);
10560  free(elemType);
10561  }
10562 
10563  if (strcmp(typcategory, "U") != 0)
10564  {
10565  appendPQExpBufferStr(q, ",\n CATEGORY = ");
10566  appendStringLiteralAH(q, typcategory, fout);
10567  }
10568 
10569  if (strcmp(typispreferred, "t") == 0)
10570  appendPQExpBufferStr(q, ",\n PREFERRED = true");
10571 
10572  if (typdelim && strcmp(typdelim, ",") != 0)
10573  {
10574  appendPQExpBufferStr(q, ",\n DELIMITER = ");
10575  appendStringLiteralAH(q, typdelim, fout);
10576  }
10577 
10578  if (strcmp(typalign, "c") == 0)
10579  appendPQExpBufferStr(q, ",\n ALIGNMENT = char");
10580  else if (strcmp(typalign, "s") == 0)
10581  appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
10582  else if (strcmp(typalign, "i") == 0)
10583  appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
10584  else if (strcmp(typalign, "d") == 0)
10585  appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
10586 
10587  if (strcmp(typstorage, "p") == 0)
10588  appendPQExpBufferStr(q, ",\n STORAGE = plain");
10589  else if (strcmp(typstorage, "e") == 0)
10590  appendPQExpBufferStr(q, ",\n STORAGE = external");
10591  else if (strcmp(typstorage, "x") == 0)
10592  appendPQExpBufferStr(q, ",\n STORAGE = extended");
10593  else if (strcmp(typstorage, "m") == 0)
10594  appendPQExpBufferStr(q, ",\n STORAGE = main");
10595 
10596  if (strcmp(typbyval, "t") == 0)
10597  appendPQExpBufferStr(q, ",\n PASSEDBYVALUE");
10598 
10599  appendPQExpBufferStr(q, "\n);\n");
10600 
10601  if (dopt->binary_upgrade)
10603  "TYPE", qtypname,
10604  tyinfo->dobj.namespace->dobj.name);
10605 
10606  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
10607  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
10608  tyinfo->dobj.name,
10609  tyinfo->dobj.namespace->dobj.name,
10610  NULL,
10611  tyinfo->rolname, false,
10612  "TYPE", SECTION_PRE_DATA,
10613  q->data, delq->data, NULL,
10614  NULL, 0,
10615  NULL, NULL);
10616 
10617  /* Dump Type Comments and Security Labels */
10618  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10619  dumpComment(fout, "TYPE", qtypname,
10620  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10621  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10622 
10623  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
10624  dumpSecLabel(fout, "TYPE", qtypname,
10625  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10626  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10627 
10628  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
10629  dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
10630  qtypname, NULL,
10631  tyinfo->dobj.namespace->dobj.name,
10632  tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl,
10633  tyinfo->inittypacl, tyinfo->initrtypacl);
10634 
10635  PQclear(res);
10636  destroyPQExpBuffer(q);
10637  destroyPQExpBuffer(delq);
10638  destroyPQExpBuffer(query);
10639  free(qtypname);
10640  free(qualtypname);
10641 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:18005
char typcategory
Definition: pg_type.h:84
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
int16 typlen
Definition: pg_type.h:55
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
char * inittypacl
Definition: pg_dump.h:175
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:176
char * typacl
Definition: pg_dump.h:173
DumpId dumpId
Definition: pg_dump.h:133
unsigned int Oid
Definition: postgres_ext.h:31
static void dumpSecLabel(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14788
#define OidIsValid(objectId)
Definition: c.h:605
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14700
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:420
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
char typalign
Definition: pg_type.h:167
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
Oid typelem
Definition: pg_dump.h:177
#define atooid(x)
Definition: postgres_ext.h:42
DumpableObject dobj
Definition: pg_dump.h:166
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:4216
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:95
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:304
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:140
char * rtypacl
Definition: pg_dump.h:174
char * rolname
Definition: pg_dump.h:172
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:96
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4401
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
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
static void dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9355
int remoteVersion
Definition: pg_backup.h:188
bool typbyval
Definition: pg_type.h:65

◆ dumpBlob()

static void dumpBlob ( Archive fout,
BlobInfo binfo 
)
static

Definition at line 3312 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, _blobInfo::rolname, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

3313 {
3314  PQExpBuffer cquery = createPQExpBuffer();
3315  PQExpBuffer dquery = createPQExpBuffer();
3316 
3317  appendPQExpBuffer(cquery,
3318  "SELECT pg_catalog.lo_create('%s');\n",
3319  binfo->dobj.name);
3320 
3321  appendPQExpBuffer(dquery,
3322  "SELECT pg_catalog.lo_unlink('%s');\n",
3323  binfo->dobj.name);
3324 
3325  if (binfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
3326  ArchiveEntry(fout, binfo->dobj.catId, binfo->dobj.dumpId,
3327  binfo->dobj.name,
3328  NULL, NULL,
3329  binfo->rolname, false,
3330  "BLOB", SECTION_PRE_DATA,
3331  cquery->data, dquery->data, NULL,
3332  NULL, 0,
3333  NULL, NULL);
3334 
3335  /* Dump comment if any */
3336  if (binfo->dobj.dump & DUMP_COMPONENT_COMMENT)
3337  dumpComment(fout, "LARGE OBJECT", binfo->dobj.name,
3338  NULL, binfo->rolname,
3339  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3340 
3341  /* Dump security label if any */
3342  if (binfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
3343  dumpSecLabel(fout, "LARGE OBJECT", binfo->dobj.name,
3344  NULL, binfo->rolname,
3345  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3346 
3347  /* Dump ACL if any */
3348  if (binfo->blobacl && (binfo->dobj.dump & DUMP_COMPONENT_ACL))
3349  dumpACL(fout, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT",
3350  binfo->dobj.name, NULL,
3351  NULL, binfo->rolname, binfo->blobacl, binfo->rblobacl,
3352  binfo->initblobacl, binfo->initrblobacl);
3353 
3354  destroyPQExpBuffer(cquery);
3355  destroyPQExpBuffer(dquery);
3356 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
DumpId dumpId
Definition: pg_dump.h:133
static void dumpSecLabel(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14788
char * initblobacl
Definition: pg_dump.h:567
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14700
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:563
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
char * rolname
Definition: pg_dump.h:564
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:95
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:96
char * blobacl
Definition: pg_dump.h:565
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
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:566
char * initrblobacl
Definition: pg_dump.h:568
static void dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9355

◆ dumpBlobs()

static int dumpBlobs ( Archive fout,
void *  arg 
)
static

Definition at line 3363 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, StartBlob(), write_msg(), and WriteData().

Referenced by dumpDumpableObject().

3364 {
3365  const char *blobQry;
3366  const char *blobFetchQry;
3367  PGconn *conn = GetConnection(fout);
3368  PGresult *res;
3369  char buf[LOBBUFSIZE];
3370  int ntups;
3371  int i;
3372  int cnt;
3373 
3374  if (g_verbose)
3375  write_msg(NULL, "saving large objects\n");
3376 
3377  /*
3378  * Currently, we re-fetch all BLOB OIDs using a cursor. Consider scanning
3379  * the already-in-memory dumpable objects instead...
3380  */
3381  if (fout->remoteVersion >= 90000)
3382  blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_largeobject_metadata";
3383  else
3384  blobQry = "DECLARE bloboid CURSOR FOR SELECT DISTINCT loid FROM pg_largeobject";
3385 
3386  ExecuteSqlStatement(fout, blobQry);
3387 
3388  /* Command to fetch from cursor */
3389  blobFetchQry = "FETCH 1000 IN bloboid";
3390 
3391  do
3392  {
3393  /* Do a fetch */
3394  res = ExecuteSqlQuery(fout, blobFetchQry, PGRES_TUPLES_OK);
3395 
3396  /* Process the tuples, if any */
3397  ntups = PQntuples(res);
3398  for (i = 0; i < ntups; i++)
3399  {
3400  Oid blobOid;
3401  int loFd;
3402 
3403  blobOid = atooid(PQgetvalue(res, i, 0));
3404  /* Open the BLOB */
3405  loFd = lo_open(conn, blobOid, INV_READ);
3406  if (loFd == -1)
3407  exit_horribly(NULL, "could not open large object %u: %s",
3408  blobOid, PQerrorMessage(conn));
3409 
3410  StartBlob(fout, blobOid);
3411 
3412  /* Now read it in chunks, sending data to archive */
3413  do
3414  {
3415  cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
3416  if (cnt < 0)
3417  exit_horribly(NULL, "error reading large object %u: %s",
3418  blobOid, PQerrorMessage(conn));
3419 
3420  WriteData(fout, buf, cnt);
3421  } while (cnt > 0);
3422 
3423  lo_close(conn, loFd);
3424 
3425  EndBlob(fout, blobOid);
3426  }
3427 
3428  PQclear(res);
3429  } while (ntups > 0);
3430 
3431  return 1;
3432 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6116
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:55
static char * buf
Definition: pg_test_fsync.c:67
int lo_read(int fd, char *buf, int len)
Definition: be-fsstubs.c:142
void WriteData(Archive *AH, const void *data, size_t dLen)
#define atooid(x)
Definition: postgres_ext.h:42
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:393
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:93
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ dumpCast()

static void dumpCast ( Archive fout,
CastInfo cast 
)
static

Definition at line 11990 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, 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, write_msg(), and zeroAsNone.

Referenced by dumpDumpableObject().

11991 {
11992  DumpOptions *dopt = fout->dopt;
11993  PQExpBuffer defqry;
11994  PQExpBuffer delqry;
11995  PQExpBuffer labelq;
11996  PQExpBuffer castargs;
11997  FuncInfo *funcInfo = NULL;
11998  char *sourceType;
11999  char *targetType;
12000 
12001  /* Skip if not to be dumped */
12002  if (!cast->dobj.dump || dopt->dataOnly)
12003  return;
12004 
12005  /* Cannot dump if we don't have the cast function's info */
12006  if (OidIsValid(cast->castfunc))
12007  {
12008  funcInfo = findFuncByOid(cast->castfunc);
12009  if (funcInfo == NULL)
12010  exit_horribly(NULL, "could not find function definition for function with OID %u\n",
12011  cast->castfunc);
12012  }
12013 
12014  defqry = createPQExpBuffer();
12015  delqry = createPQExpBuffer();
12016  labelq = createPQExpBuffer();
12017  castargs = createPQExpBuffer();
12018 
12019  sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone);
12020  targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone);
12021  appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
12022  sourceType, targetType);
12023 
12024  appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
12025  sourceType, targetType);
12026 
12027  switch (cast->castmethod)
12028  {
12029  case COERCION_METHOD_BINARY:
12030  appendPQExpBufferStr(defqry, "WITHOUT FUNCTION");
12031  break;
12032  case COERCION_METHOD_INOUT:
12033  appendPQExpBufferStr(defqry, "WITH INOUT");
12034  break;
12035  case COERCION_METHOD_FUNCTION:
12036  if (funcInfo)
12037  {
12038  char *fsig = format_function_signature(fout, funcInfo, true);
12039 
12040  /*
12041  * Always qualify the function name (format_function_signature
12042  * won't qualify it).
12043  */
12044  appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
12045  fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
12046  free(fsig);
12047  }
12048  else
12049  write_msg(NULL, "WARNING: bogus value in pg_cast.castfunc or pg_cast.castmethod field\n");
12050  break;
12051  default:
12052  write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
12053  }
12054 
12055  if (cast->castcontext == 'a')
12056  appendPQExpBufferStr(defqry, " AS ASSIGNMENT");
12057  else if (cast->castcontext == 'i')
12058  appendPQExpBufferStr(defqry, " AS IMPLICIT");
12059  appendPQExpBufferStr(defqry, ";\n");
12060 
12061  appendPQExpBuffer(labelq, "CAST (%s AS %s)",
12062  sourceType, targetType);
12063 
12064  appendPQExpBuffer(castargs, "(%s AS %s)",
12065  sourceType, targetType);
12066 
12067  if (dopt->binary_upgrade)
12068  binary_upgrade_extension_member(defqry, &cast->dobj,
12069  "CAST", castargs->data, NULL);
12070 
12071  if (cast->dobj.dump & DUMP_COMPONENT_DEFINITION)
12072  ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
12073  labelq->data,
12074  NULL, NULL, "",
12075  false, "CAST", SECTION_PRE_DATA,
12076  defqry->data, delqry->data, NULL,
12077  NULL, 0,
12078  NULL, NULL);
12079 
12080  /* Dump Cast Comments */
12081  if (cast->dobj.dump & DUMP_COMPONENT_COMMENT)
12082  dumpComment(fout, "CAST", castargs->data,
12083  NULL, "",
12084  cast->dobj.catId, 0, cast->dobj.dumpId);
12085 
12086  free(sourceType);
12087  free(targetType);
12088 
12089  destroyPQExpBuffer(defqry);
12090  destroyPQExpBuffer(delqry);
12091  destroyPQExpBuffer(labelq);
12092  destroyPQExpBuffer(castargs);
12093 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:18005
char * name
Definition: pg_dump.h:134
Oid castsource
Definition: pg_dump.h:468
DumpComponents dump
Definition: pg_dump.h:135
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:199
DumpId dumpId
Definition: pg_dump.h:133
Oid castfunc
Definition: pg_dump.h:470
#define OidIsValid(objectId)
Definition: c.h:605
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
DumpableObject dobj
Definition: pg_dump.h:467
Oid casttarget
Definition: pg_dump.h:469
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
FuncInfo * findFuncByOid(Oid oid)
Definition: common.c:874
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:95
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#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:11423
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4401
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:132
char castmethod
Definition: pg_dump.h:472
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:471
static void dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9355

◆ dumpCollation()

static void dumpCollation ( Archive fout,
CollInfo collinfo 
)
static

Definition at line 13246 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(), fmtQualifiedDumpable, free, _dumpableObject::name, CatalogId::oid, pg_strdup(), PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), Archive::remoteVersion, _collInfo::rolname, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

13247 {
13248  DumpOptions *dopt = fout->dopt;
13249  PQExpBuffer query;
13250  PQExpBuffer q;
13251  PQExpBuffer delq;
13252  char *qcollname;
13253  PGresult *res;
13254  int i_collprovider;
13255  int i_collcollate;
13256  int i_collctype;
13257  const char *collprovider;
13258  const char *collcollate;
13259  const char *collctype;
13260 
13261  /* Skip if not to be dumped */
13262  if (!collinfo->dobj.dump || dopt->dataOnly)
13263  return;
13264 
13265  query = createPQExpBuffer();
13266  q = createPQExpBuffer();
13267  delq = createPQExpBuffer();
13268 
13269  qcollname = pg_strdup(fmtId(collinfo->dobj.name));
13270 
13271  /* Get collation-specific details */
13272  if (fout->remoteVersion >= 100000)
13273  appendPQExpBuffer(query, "SELECT "
13274  "collprovider, "
13275  "collcollate, "
13276  "collctype, "
13277  "collversion "
13278  "FROM pg_catalog.pg_collation c "
13279  "WHERE c.oid = '%u'::pg_catalog.oid",
13280  collinfo->dobj.catId.oid);
13281  else
13282  appendPQExpBuffer(query, "SELECT "
13283  "'c' AS collprovider, "
13284  "collcollate, "
13285  "collctype, "
13286  "NULL AS collversion "
13287  "FROM pg_catalog.pg_collation c "
13288  "WHERE c.oid = '%u'::pg_catalog.oid",
13289  collinfo->dobj.catId.oid);
13290 
13291  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13292 
13293  i_collprovider = PQfnumber(res, "collprovider");
13294  i_collcollate = PQfnumber(res, "collcollate");
13295  i_collctype = PQfnumber(res, "collctype");
13296 
13297  collprovider = PQgetvalue(res, 0, i_collprovider);
13298  collcollate = PQgetvalue(res, 0, i_collcollate);
13299  collctype = PQgetvalue(res, 0, i_collctype);
13300 
13301  appendPQExpBuffer(delq, "DROP COLLATION %s;\n",
13302  fmtQualifiedDumpable(collinfo));
13303 
13304  appendPQExpBuffer(q, "CREATE COLLATION %s (",
13305  fmtQualifiedDumpable(collinfo));
13306 
13307  appendPQExpBufferStr(q, "provider = ");
13308  if (collprovider[0] == 'c')
13309  appendPQExpBufferStr(q, "libc");
13310  else if (collprovider[0] == 'i')
13311  appendPQExpBufferStr(q, "icu");
13312  else if (collprovider[0] == 'd')
13313  /* to allow dumping pg_catalog; not accepted on input */
13314  appendPQExpBufferStr(q, "default");
13315  else
13316  exit_horribly(NULL,
13317  "unrecognized collation provider: %s\n",
13318  collprovider);
13319 
13320  if (strcmp(collcollate, collctype) == 0)
13321  {
13322  appendPQExpBufferStr(q, ", locale = ");
13323  appendStringLiteralAH(q, collcollate, fout);
13324  }
13325  else
13326  {
13327  appendPQExpBufferStr(q, ", lc_collate = ");
13328  appendStringLiteralAH(q, collcollate, fout);
13329  appendPQExpBufferStr(q, ", lc_ctype = ");
13330  appendStringLiteralAH(q, collctype, fout);
13331  }
13332 
13333  /*
13334  * For binary upgrade, carry over the collation version. For normal
13335  * dump/restore, omit the version, so that it is computed upon restore.
13336  */
13337  if (dopt->binary_upgrade)
13338  {
13339  int i_collversion;
13340 
13341  i_collversion = PQfnumber(res, "collversion");
13342  if (!PQgetisnull(res, 0, i_collversion))
13343  {
13344  appendPQExpBufferStr(q, ", version = ");
13346  PQgetvalue(res, 0, i_collversion),
13347  fout);
13348  }
13349  }
13350 
13351  appendPQExpBufferStr(q, ");\n");
13352 
13353  if (dopt->binary_upgrade)
13354  binary_upgrade_extension_member(q, &collinfo->dobj,
13355  "COLLATION", qcollname,
13356  collinfo->dobj.namespace->dobj.name);
13357 
13358  if (collinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13359  ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId,
13360  collinfo->dobj.name,
13361  collinfo->dobj.namespace->dobj.name,
13362  NULL,
13363  collinfo->rolname,
13364  false, "COLLATION", SECTION_PRE_DATA,
13365  q->data, delq->data, NULL,
13366  NULL, 0,
13367  NULL, NULL);
13368 
13369  /* Dump Collation Comments */
13370  if (collinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13371  dumpComment(fout, "COLLATION", qcollname,
13372  collinfo->dobj.namespace->dobj.name, collinfo->rolname,
13373  collinfo->dobj.catId, 0, collinfo->dobj.dumpId);
13374 
13375  PQclear(res);
13376 
13377  destroyPQExpBuffer(query);
13378  destroyPQExpBuffer(q);
13379  destroyPQExpBuffer(delq);
13380  free(qcollname);
13381 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
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:133
DumpableObject dobj
Definition: pg_dump.h:247
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:420
char * rolname
Definition: pg_dump.h:248
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
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:95
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:304
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:140
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4401
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:132
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
static void dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9355
int remoteVersion
Definition: pg_backup.h:188

◆ dumpComment()

static void dumpComment ( Archive fout,
const char *  type,
const char *  name,
const char *  namespace,
const char *  owner,
CatalogId  catalogId,
int  subid,
DumpId  dumpId 
)
static

Definition at line 9355 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(), fmtId(), _dumpOptions::no_comments, 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().

9358 {
9359  DumpOptions *dopt = fout->dopt;
9360  CommentItem *comments;
9361  int ncomments;
9362 
9363  /* do nothing, if --no-comments is supplied */
9364  if (dopt->no_comments)
9365  return;
9366 
9367  /* Comments are schema not data ... except blob comments are data */
9368  if (strcmp(type, "LARGE OBJECT") != 0)
9369  {
9370  if (dopt->dataOnly)
9371  return;
9372  }
9373  else
9374  {
9375  /* We do dump blob comments in binary-upgrade mode */
9376  if (dopt->schemaOnly && !dopt->binary_upgrade)
9377  return;
9378  }
9379 
9380  /* Search for comments associated with catalogId, using table */
9381  ncomments = findComments(fout, catalogId.tableoid, catalogId.oid,
9382  &comments);
9383 
9384  /* Is there one matching the subid? */
9385  while (ncomments > 0)
9386  {
9387  if (comments->objsubid == subid)
9388  break;
9389  comments++;
9390  ncomments--;
9391  }
9392 
9393  /* If a comment exists, build COMMENT ON statement */
9394  if (ncomments > 0)
9395  {
9396  PQExpBuffer query = createPQExpBuffer();
9398 
9399  appendPQExpBuffer(query, "COMMENT ON %s ", type);
9400  if (namespace && *namespace)
9401  appendPQExpBuffer(query, "%s.", fmtId(namespace));
9402  appendPQExpBuffer(query, "%s IS ", name);
9403  appendStringLiteralAH(query, comments->descr, fout);
9404  appendPQExpBufferStr(query, ";\n");
9405 
9406  appendPQExpBuffer(tag, "%s %s", type, name);
9407 
9408  /*
9409  * We mark comments as SECTION_NONE because they really belong in the
9410  * same section as their parent, whether that is pre-data or
9411  * post-data.
9412  */
9414  tag->data, namespace, NULL, owner,
9415  false, "COMMENT", SECTION_NONE,
9416  query->data, "", NULL,
9417  &(dumpId), 1,
9418  NULL, NULL);
9419 
9420  destroyPQExpBuffer(query);
9421  destroyPQExpBuffer(tag);
9422  }
9423 }
Oid tableoid
Definition: pg_backup.h:231
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
bool schemaOnly
Definition: pg_backup.h:139
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:72
static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9529
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
const char * descr
Definition: pg_dump.c:69
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:304
int no_comments
Definition: pg_backup.h:150
const char * name
Definition: encode.c:521
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:134
DumpId createDumpId(void)
Definition: common.c:613

◆ dumpCompositeType()

static void dumpCompositeType ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10823 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), atooid, attalign, attcollation, attlen, attname, _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, 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(), fmtQualifiedDumpable, free, 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, _typeInfo::typacl, and _typeInfo::typrelid.

Referenced by dumpType().

10824 {
10825  DumpOptions *dopt = fout->dopt;
10827  PQExpBuffer dropped = createPQExpBuffer();
10828  PQExpBuffer delq = createPQExpBuffer();
10829  PQExpBuffer query = createPQExpBuffer();
10830  PGresult *res;
10831  char *qtypname;
10832  char *qualtypname;
10833  int ntups;
10834  int i_attname;
10835  int i_atttypdefn;
10836  int i_attlen;
10837  int i_attalign;
10838  int i_attisdropped;
10839  int i_attcollation;
10840  int i;
10841  int actual_atts;
10842 
10843  /* Fetch type specific details */
10844  if (fout->remoteVersion >= 90100)
10845  {
10846  /*
10847  * attcollation is new in 9.1. Since we only want to dump COLLATE
10848  * clauses for attributes whose collation is different from their
10849  * type's default, we use a CASE here to suppress uninteresting
10850  * attcollations cheaply. atttypid will be 0 for dropped columns;
10851  * collation does not matter for those.
10852  */
10853  appendPQExpBuffer(query, "SELECT a.attname, "
10854  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
10855  "a.attlen, a.attalign, a.attisdropped, "
10856  "CASE WHEN a.attcollation <> at.typcollation "
10857  "THEN a.attcollation ELSE 0 END AS attcollation "
10858  "FROM pg_catalog.pg_type ct "
10859  "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
10860  "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
10861  "WHERE ct.oid = '%u'::pg_catalog.oid "
10862  "ORDER BY a.attnum ",
10863  tyinfo->dobj.catId.oid);
10864  }
10865  else
10866  {
10867  /*
10868  * Since ALTER TYPE could not drop columns until 9.1, attisdropped
10869  * should always be false.
10870  */
10871  appendPQExpBuffer(query, "SELECT a.attname, "
10872  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
10873  "a.attlen, a.attalign, a.attisdropped, "
10874  "0 AS attcollation "
10875  "FROM pg_catalog.pg_type ct, pg_catalog.pg_attribute a "
10876  "WHERE ct.oid = '%u'::pg_catalog.oid "
10877  "AND a.attrelid = ct.typrelid "
10878  "ORDER BY a.attnum ",
10879  tyinfo->dobj.catId.oid);
10880  }
10881 
10882  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10883 
10884  ntups = PQntuples(res);
10885 
10886  i_attname = PQfnumber(res, "attname");
10887  i_atttypdefn = PQfnumber(res, "atttypdefn");
10888  i_attlen = PQfnumber(res, "attlen");
10889  i_attalign = PQfnumber(res, "attalign");
10890  i_attisdropped = PQfnumber(res, "attisdropped");
10891  i_attcollation = PQfnumber(res, "attcollation");
10892 
10893  if (dopt->binary_upgrade)
10894  {
10896  tyinfo->dobj.catId.oid,
10897  false);
10898  binary_upgrade_set_pg_class_oids(fout, q, tyinfo->typrelid, false);
10899  }
10900 
10901  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
10902  qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo));
10903 
10904  appendPQExpBuffer(q, "CREATE TYPE %s AS (",
10905  qualtypname);
10906 
10907  actual_atts = 0;
10908  for (i = 0; i < ntups; i++)
10909  {
10910  char *attname;
10911  char *atttypdefn;
10912  char *attlen;
10913  char *attalign;
10914  bool attisdropped;
10915  Oid attcollation;
10916 
10917  attname = PQgetvalue(res, i, i_attname);
10918  atttypdefn = PQgetvalue(res, i, i_atttypdefn);
10919  attlen = PQgetvalue(res, i, i_attlen);
10920  attalign = PQgetvalue(res, i, i_attalign);
10921  attisdropped = (PQgetvalue(res, i, i_attisdropped)[0] == 't');
10922  attcollation = atooid(PQgetvalue(res, i, i_attcollation));
10923 
10924  if (attisdropped && !dopt->binary_upgrade)
10925  continue;
10926 
10927  /* Format properly if not first attr */
10928  if (actual_atts++ > 0)
10929  appendPQExpBufferChar(q, ',');
10930  appendPQExpBufferStr(q, "\n\t");
10931 
10932  if (!attisdropped)
10933  {
10934  appendPQExpBuffer(q, "%s %s", fmtId(attname), atttypdefn);
10935 
10936  /* Add collation if not default for the column type */
10937  if (OidIsValid(attcollation))
10938  {
10939  CollInfo *coll;
10940 
10941  coll = findCollationByOid(attcollation);
10942  if (coll)
10943  appendPQExpBuffer(q, " COLLATE %s",
10944  fmtQualifiedDumpable(coll));
10945  }
10946  }
10947  else
10948  {
10949  /*
10950  * This is a dropped attribute and we're in binary_upgrade mode.
10951  * Insert a placeholder for it in the CREATE TYPE command, and set
10952  * length and alignment with direct UPDATE to the catalogs
10953  * afterwards. See similar code in dumpTableSchema().
10954  */
10955  appendPQExpBuffer(q, "%s INTEGER /* dummy */", fmtId(attname));
10956 
10957  /* stash separately for insertion after the CREATE TYPE */
10958  appendPQExpBufferStr(dropped,
10959  "\n-- For binary upgrade, recreate dropped column.\n");
10960  appendPQExpBuffer(dropped, "UPDATE pg_catalog.pg_attribute\n"
10961  "SET attlen = %s, "
10962  "attalign = '%s', attbyval = false\n"
10963  "WHERE attname = ", attlen, attalign);
10964  appendStringLiteralAH(dropped, attname, fout);
10965  appendPQExpBufferStr(dropped, "\n AND attrelid = ");
10966  appendStringLiteralAH(dropped, qualtypname, fout);
10967  appendPQExpBufferStr(dropped, "::pg_catalog.regclass;\n");
10968 
10969  appendPQExpBuffer(dropped, "ALTER TYPE %s ",
10970  qualtypname);
10971  appendPQExpBuffer(dropped, "DROP ATTRIBUTE %s;\n",
10972  fmtId(attname));
10973  }
10974  }
10975  appendPQExpBufferStr(q, "\n);\n");
10976  appendPQExpBufferStr(q, dropped->data);
10977 
10978  appendPQExpBuffer(delq, "DROP TYPE %s;\n", qualtypname);
10979 
10980  if (dopt->binary_upgrade)
10982  "TYPE", qtypname,
10983  tyinfo->dobj.namespace->dobj.name);
10984 
10985  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
10986  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
10987  tyinfo->dobj.name,
10988  tyinfo->dobj.namespace->dobj.name,
10989  NULL,
10990  tyinfo->rolname, false,
10991  "TYPE", SECTION_PRE_DATA,
10992  q->data, delq->data, NULL,
10993  NULL, 0,
10994  NULL, NULL);
10995 
10996 
10997  /* Dump Type Comments and Security Labels */
10998  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10999  dumpComment(fout, "TYPE", qtypname,
11000  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
11001  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
11002 
11003  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
11004  dumpSecLabel(fout, "TYPE", qtypname,
11005  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
11006  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
11007 
11008  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
11009  dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
11010  qtypname, NULL,
11011  tyinfo->dobj.namespace->dobj.name,
11012  tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl,
11013  tyinfo->inittypacl, tyinfo->initrtypacl);
11014 
11015  PQclear(res);
11016  destroyPQExpBuffer(q);
11017  destroyPQExpBuffer(dropped);
11018  destroyPQExpBuffer(delq);
11019  destroyPQExpBuffer(query);
11020  free(qtypname);
11021  free(qualtypname);
11022 
11023  /* Dump any per-column comments */
11024  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
11025  dumpCompositeTypeColComments(fout, tyinfo);
11026 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
char * inittypacl
Definition: pg_dump.h:175
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
Oid typrelid
Definition: pg_dump.h:178
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * initrtypacl
Definition: pg_dump.h:176
static void dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
Definition: pg_dump.c:11034
char * typacl
Definition: pg_dump.h:173
DumpId dumpId
Definition: pg_dump.h:133
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
static void dumpSecLabel(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14788
#define OidIsValid(objectId)
Definition: c.h:605
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14700
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
NameData attname
Definition: pg_attribute.h:40
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
Oid attcollation
Definition: pg_attribute.h:161
char attalign
Definition: pg_attribute.h:129
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
Definition: pg_dump.c:4331
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define atooid(x)
Definition: postgres_ext.h:42
int16 attlen
Definition: pg_attribute.h:64
DumpableObject dobj
Definition: pg_dump.h:166
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:4216
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:95
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:304
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:140
char * rtypacl
Definition: pg_dump.h:174
char * rolname
Definition: pg_dump.h:172
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:896
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:96
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4401
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:97
CatalogId catId
Definition: pg_dump.h:132
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 void dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9355
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
int remoteVersion
Definition: pg_backup.h:188

◆ dumpCompositeTypeColComments()

static void dumpCompositeTypeColComments ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 11034 of file pg_dump.c.

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

Referenced by dumpCompositeType().

11035 {
11036  CommentItem *comments;
11037  int ncomments;
11038  PGresult *res;
11039  PQExpBuffer query;
11040  PQExpBuffer target;
11041  Oid pgClassOid;
11042  int i;
11043  int ntups;
11044  int i_attname;
11045  int i_attnum;
11046 
11047  /* do nothing, if --no-comments is supplied */
11048  if (fout->dopt->no_comments)
11049  return;
11050 
11051  query = createPQExpBuffer();
11052 
11053  appendPQExpBuffer(query,
11054  "SELECT c.tableoid, a.attname, a.attnum "
11055  "FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
11056  "WHERE c.oid = '%u' AND c.oid = a.attrelid "
11057  " AND NOT a.attisdropped "
11058  "ORDER BY a.attnum ",
11059  tyinfo->typrelid);
11060 
11061  /* Fetch column attnames */
11062  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
11063 
11064  ntups = PQntuples(res);
11065  if (ntups < 1)
11066  {
11067  PQclear(res);
11068  destroyPQExpBuffer(query);
11069  return;
11070  }
11071 
11072  pgClassOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "tableoid")));
11073 
11074  /* Search for comments associated with type's pg_class OID */
11075  ncomments = findComments(fout,
11076  pgClassOid,
11077  tyinfo->typrelid,
11078  &comments);
11079 
11080  /* If no comments exist, we're done */
11081  if (ncomments <= 0)
11082  {
11083  PQclear(res);
11084  destroyPQExpBuffer(query);
11085  return;
11086  }
11087 
11088  /* Build COMMENT ON statements */
11089  target = createPQExpBuffer();
11090 
11091  i_attnum = PQfnumber(res, "attnum");
11092  i_attname = PQfnumber(res, "attname");
11093  while (ncomments > 0)
11094  {
11095  const char *attname;
11096 
11097  attname = NULL;
11098  for (i = 0; i < ntups; i++)
11099  {
11100  if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid)
11101  {
11102  attname = PQgetvalue(res, i, i_attname);
11103  break;
11104  }
11105  }
11106  if (attname) /* just in case we don't find it */
11107  {
11108  const char *descr = comments->descr;
11109 
11110  resetPQExpBuffer(target);
11111  appendPQExpBuffer(target, "COLUMN %s.",
11112  fmtId(tyinfo->dobj.name));
11113  appendPQExpBufferStr(target, fmtId(attname));
11114 
11115  resetPQExpBuffer(query);
11116  appendPQExpBuffer(query, "COMMENT ON COLUMN %s.",
11117  fmtQualifiedDumpable(tyinfo));
11118  appendPQExpBuffer(query, "%s IS ", fmtId(attname));
11119  appendStringLiteralAH(query, descr, fout);
11120  appendPQExpBufferStr(query, ";\n");
11121 
11123  target->data,
11124  tyinfo->dobj.namespace->dobj.name,
11125  NULL, tyinfo->rolname,
11126  false, "COMMENT", SECTION_NONE,
11127  query->data, "", NULL,
11128  &(tyinfo->dobj.dumpId), 1,
11129  NULL, NULL);
11130  }
11131 
11132  comments++;
11133  ncomments--;
11134  }
11135 
11136  PQclear(res);
11137  destroyPQExpBuffer(query);
11138  destroyPQExpBuffer(target);
11139 }
char * name
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
Oid typrelid
Definition: pg_dump.h:178
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:72
DumpId dumpId
Definition: pg_dump.h:133
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:9529
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
NameData attname
Definition: pg_attribute.h:40
DumpOptions * dopt
Definition: pg_backup.h:183
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:69
DumpableObject dobj
Definition: pg_dump.h:166
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:304
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:140
char * rolname
Definition: pg_dump.h:172
int no_comments
Definition: pg_backup.h:150
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:134
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:405
DumpId createDumpId(void)
Definition: common.c:613

◆ dumpConstraint()

static void dumpConstraint ( Archive fout,
ConstraintInfo coninfo 
)
static

Definition at line 16302 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendReloptionsArrayAH(), ArchiveEntry(), attname, _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(), fmtQualifiedDumpable, free, getAttrName(), _indxInfo::indisclustered, _indxInfo::indkeys, _indxInfo::indnattrs, _indxInfo::indnkeyattrs, _indxInfo::indreloptions, InvalidAttrNumber, _dumpableObject::name, nonemptyReloptions(), CatalogId::oid, psprintf(), _tableInfo::relkind, _typeInfo::rolname, _tableInfo::rolname, SECTION_POST_DATA, _constraintInfo::separate, and _indxInfo::tablespace.

Referenced by dumpDumpableObject().

16303 {
16304  DumpOptions *dopt = fout->dopt;
16305  TableInfo *tbinfo = coninfo->contable;
16306  PQExpBuffer q;
16307  PQExpBuffer delq;
16308  char *tag = NULL;
16309 
16310  /* Skip if not to be dumped */
16311  if (!coninfo->dobj.dump || dopt->dataOnly)
16312  return;
16313 
16314  q = createPQExpBuffer();
16315  delq = createPQExpBuffer();
16316 
16317  if (coninfo->contype == 'p' ||
16318  coninfo->contype == 'u' ||
16319  coninfo->contype == 'x')
16320  {
16321  /* Index-related constraint */
16322  IndxInfo *indxinfo;
16323  int k;
16324 
16325  indxinfo = (IndxInfo *) findObjectByDumpId(coninfo->conindex);
16326 
16327  if (indxinfo == NULL)
16328  exit_horribly(NULL, "missing index for constraint \"%s\"\n",
16329  coninfo->dobj.name);
16330 
16331  if (dopt->binary_upgrade)
16333  indxinfo->dobj.catId.oid, true);
16334 
16335  appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
16336  fmtQualifiedDumpable(tbinfo));
16337  appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
16338  fmtId(coninfo->dobj.name));
16339 
16340  if (coninfo->condef)
16341  {
16342  /* pg_get_constraintdef should have provided everything */
16343  appendPQExpBuffer(q, "%s;\n", coninfo->condef);
16344  }
16345  else
16346  {
16347  appendPQExpBuffer(q, "%s (",
16348  coninfo->contype == 'p' ? "PRIMARY KEY" : "UNIQUE");
16349  for (k = 0; k < indxinfo->indnkeyattrs; k++)
16350  {
16351  int indkey = (int) indxinfo->indkeys[k];
16352  const char *attname;
16353 
16354  if (indkey == InvalidAttrNumber)
16355  break;
16356  attname = getAttrName(indkey, tbinfo);
16357 
16358  appendPQExpBuffer(q, "%s%s",
16359  (k == 0) ? "" : ", ",
16360  fmtId(attname));
16361  }
16362 
16363  if (indxinfo->indnkeyattrs < indxinfo->indnattrs)
16364  appendPQExpBuffer(q, ") INCLUDE (");
16365 
16366  for (k = indxinfo->indnkeyattrs; k < indxinfo->indnattrs; k++)
16367  {
16368  int indkey = (int) indxinfo->indkeys[k];
16369  const char *attname;
16370 
16371  if (indkey == InvalidAttrNumber)
16372  break;
16373  attname = getAttrName(indkey, tbinfo);
16374 
16375  appendPQExpBuffer(q, "%s%s",
16376  (k == indxinfo->indnkeyattrs) ? "" : ", ",
16377  fmtId(attname));
16378  }
16379 
16380  appendPQExpBufferChar(q, ')');
16381 
16382  if (nonemptyReloptions(indxinfo->indreloptions))
16383  {
16384  appendPQExpBufferStr(q, " WITH (");
16385  appendReloptionsArrayAH(q, indxinfo->indreloptions, "", fout);
16386  appendPQExpBufferChar(q, ')');
16387  }
16388 
16389  if (coninfo->condeferrable)
16390  {
16391  appendPQExpBufferStr(q, " DEFERRABLE");
16392  if (coninfo->condeferred)
16393  appendPQExpBufferStr(q, " INITIALLY DEFERRED");
16394  }
16395 
16396  appendPQExpBufferStr(q, ";\n");
16397  }
16398 
16399  /* If the index is clustered, we need to record that. */
16400  if (indxinfo->indisclustered)
16401  {
16402  appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER",
16403  fmtQualifiedDumpable(tbinfo));
16404  /* index name is not qualified in this syntax */
16405  appendPQExpBuffer(q, " ON %s;\n",
16406  fmtId(indxinfo->dobj.name));
16407  }
16408 
16409  appendPQExpBuffer(delq, "ALTER TABLE ONLY %s ",
16410  fmtQualifiedDumpable(tbinfo));
16411  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16412  fmtId(coninfo->dobj.name));
16413 
16414  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16415 
16416  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16417  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16418  tag,
16419  tbinfo->dobj.namespace->dobj.name,
16420  indxinfo->tablespace,
16421  tbinfo->rolname, false,
16422  "CONSTRAINT", SECTION_POST_DATA,
16423  q->data, delq->data, NULL,
16424  NULL, 0,
16425  NULL, NULL);
16426  }
16427  else if (coninfo->contype == 'f')
16428  {
16429  char *only;
16430 
16431  /*
16432  * Foreign keys on partitioned tables are always declared as
16433  * inheriting to partitions; for all other cases, emit them as
16434  * applying ONLY directly to the named table, because that's how they
16435  * work for regular inherited tables.
16436  */
16437  only = tbinfo->relkind == RELKIND_PARTITIONED_TABLE ? "" : "ONLY ";
16438 
16439  /*
16440  * XXX Potentially wrap in a 'SET CONSTRAINTS OFF' block so that the
16441  * current table data is not processed
16442  */
16443  appendPQExpBuffer(q, "ALTER TABLE %s%s\n",
16444  only, fmtQualifiedDumpable(tbinfo));
16445  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16446  fmtId(coninfo->dobj.name),
16447  coninfo->condef);
16448 
16449  appendPQExpBuffer(delq, "ALTER TABLE %s%s ",
16450  only, fmtQualifiedDumpable(tbinfo));
16451  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16452  fmtId(coninfo->dobj.name));
16453 
16454  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16455 
16456  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16457  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16458  tag,
16459  tbinfo->dobj.namespace->dobj.name,
16460  NULL,
16461  tbinfo->rolname, false,
16462  "FK CONSTRAINT", SECTION_POST_DATA,
16463  q->data, delq->data, NULL,
16464  NULL, 0,
16465  NULL, NULL);
16466  }
16467  else if (coninfo->contype == 'c' && tbinfo)
16468  {
16469  /* CHECK constraint on a table */
16470 
16471  /* Ignore if not to be dumped separately, or if it was inherited */
16472  if (coninfo->separate && coninfo->conislocal)
16473  {
16474  /* not ONLY since we want it to propagate to children */
16475  appendPQExpBuffer(q, "ALTER TABLE %s\n",
16476  fmtQualifiedDumpable(tbinfo));
16477  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16478  fmtId(coninfo->dobj.name),
16479  coninfo->condef);
16480 
16481  appendPQExpBuffer(delq, "ALTER TABLE %s ",
16482  fmtQualifiedDumpable(tbinfo));
16483  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16484  fmtId(coninfo->dobj.name));
16485 
16486  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16487 
16488  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16489  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16490  tag,
16491  tbinfo->dobj.namespace->dobj.name,
16492  NULL,
16493  tbinfo->rolname, false,
16494  "CHECK CONSTRAINT", SECTION_POST_DATA,
16495  q->data, delq->data, NULL,
16496  NULL, 0,
16497  NULL, NULL);
16498  }
16499  }
16500  else if (coninfo->contype == 'c' && tbinfo == NULL)
16501  {
16502  /* CHECK constraint on a domain */
16503  TypeInfo *tyinfo = coninfo->condomain;
16504 
16505  /* Ignore if not to be dumped separately */
16506  if (coninfo->separate)
16507  {
16508  appendPQExpBuffer(q, "ALTER DOMAIN %s\n",
16509  fmtQualifiedDumpable(tyinfo));
16510  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16511  fmtId(coninfo->dobj.name),
16512  coninfo->condef);
16513 
16514  appendPQExpBuffer(delq, "ALTER DOMAIN %s ",
16515  fmtQualifiedDumpable(tyinfo));
16516  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16517  fmtId(coninfo->dobj.name));
16518 
16519  tag = psprintf("%s %s", tyinfo->dobj.name, coninfo->dobj.name);
16520 
16521  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16522  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16523  tag,
16524  tyinfo->dobj.namespace->dobj.name,
16525  NULL,
16526  tyinfo->rolname, false,
16527  "CHECK CONSTRAINT", SECTION_POST_DATA,
16528  q->data, delq->data, NULL,
16529  NULL, 0,
16530  NULL, NULL);
16531  }
16532  }
16533  else
16534  {
16535  exit_horribly(NULL, "unrecognized constraint type: %c\n",
16536  coninfo->contype);
16537  }
16538 
16539  /* Dump Constraint Comments --- only works for table constraints */
16540  if (tbinfo && coninfo->separate &&
16541  coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
16542  dumpTableConstraintComment(fout, coninfo);
16543 
16544  free(tag);
16545  destroyPQExpBuffer(q);
16546  destroyPQExpBuffer(delq);
16547 }
char * tablespace
Definition: pg_dump.h:361
char * name
Definition: pg_dump.h:134
char relkind
Definition: pg_dump.h:268
DumpComponents dump
Definition: pg_dump.h:135
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:18088
char * rolname
Definition: pg_dump.h:263
DumpId dumpId
Definition: pg_dump.h:133
DumpId conindex
Definition: pg_dump.h:444
DumpableObject dobj
Definition: pg_dump.h:262
char * condef
Definition: pg_dump.h:442
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
NameData attname
Definition: pg_attribute.h:40
int binary_upgrade
Definition: pg_backup.h:136
DumpableObject dobj
Definition: pg_dump.h:438
DumpOptions * dopt
Definition: pg_backup.h:183
static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
Definition: pg_dump.c:16557
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:633
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
Oid * indkeys
Definition: pg_dump.h:365
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
Definition: pg_dump.c:4331
static const char * getAttrName(int attrnum, TableInfo *tblInfo)
Definition: pg_dump.c:16086
bool condeferrable
Definition: pg_dump.h:445
static bool nonemptyReloptions(const char *reloptions)
Definition: pg_dump.c:18076
char * indreloptions
Definition: pg_dump.h:362
DumpableObject dobj
Definition: pg_dump.h:166
TypeInfo * condomain
Definition: pg_dump.h:440
bool conislocal
Definition: pg_dump.h:447
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
TableInfo * contable
Definition: pg_dump.h:439
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:95
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define free(a)
Definition: header.h:65
bool condeferred
Definition: pg_dump.h:446
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:140
char * rolname
Definition: pg_dump.h:172
#define InvalidAttrNumber
Definition: attnum.h:23
int indnkeyattrs
Definition: pg_dump.h:363
void exit_horribly(const char *modulename, const char *fmt,...)
int indnattrs
Definition: pg_dump.h:364
CatalogId catId
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:358
bool indisclustered
Definition: pg_dump.h:367
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)

◆ dumpConversion()

static void dumpConversion ( Archive fout,
ConvInfo convinfo 
)
static

Definition at line 13388 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(), fmtQualifiedDumpable, free, _dumpableObject::name, CatalogId::oid, pg_strdup(), PQclear(), PQfnumber(), PQgetvalue(), _convInfo::rolname, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

13389 {
13390  DumpOptions *dopt = fout->dopt;
13391  PQExpBuffer query;
13392  PQExpBuffer q;
13393  PQExpBuffer delq;
13394  char *qconvname;
13395  PGresult *res;
13396  int i_conforencoding;
13397  int i_contoencoding;
13398  int i_conproc;
13399  int i_condefault;
13400  const char *conforencoding;
13401  const char *contoencoding;
13402  const char *conproc;
13403  bool condefault;
13404 
13405  /* Skip if not to be dumped */
13406  if (!convinfo->dobj.dump || dopt->dataOnly)
13407  return;
13408 
13409  query = createPQExpBuffer();
13410  q = createPQExpBuffer();
13411  delq = createPQExpBuffer();
13412 
13413  qconvname = pg_strdup(fmtId(convinfo->dobj.name));
13414 
13415  /* Get conversion-specific details */
13416  appendPQExpBuffer(query, "SELECT "
13417  "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
13418  "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
13419  "conproc, condefault "
13420  "FROM pg_catalog.pg_conversion c "
13421  "WHERE c.oid = '%u'::pg_catalog.oid",
13422  convinfo->dobj.catId.oid);
13423 
13424  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13425 
13426  i_conforencoding = PQfnumber(res, "conforencoding");
13427  i_contoencoding = PQfnumber(res, "contoencoding");
13428  i_conproc = PQfnumber(res, "conproc");
13429  i_condefault = PQfnumber(res, "condefault");
13430 
13431  conforencoding = PQgetvalue(res, 0, i_conforencoding);
13432  contoencoding = PQgetvalue(res, 0, i_contoencoding);
13433  conproc = PQgetvalue(res, 0, i_conproc);
13434  condefault = (PQgetvalue(res, 0, i_condefault)[0] == 't');
13435 
13436  appendPQExpBuffer(delq, "DROP CONVERSION %s;\n",
13437  fmtQualifiedDumpable(convinfo));
13438 
13439  appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ",
13440  (condefault) ? "DEFAULT " : "",
13441  fmtQualifiedDumpable(convinfo));
13442  appendStringLiteralAH(q, conforencoding, fout);
13443  appendPQExpBufferStr(q, " TO ");
13444  appendStringLiteralAH(q, contoencoding, fout);
13445  /* regproc output is already sufficiently quoted */
13446  appendPQExpBuffer(q, " FROM %s;\n", conproc);
13447 
13448  if (dopt->binary_upgrade)
13449  binary_upgrade_extension_member(q, &convinfo->dobj,
13450  "CONVERSION", qconvname,
13451  convinfo->dobj.namespace->dobj.name);
13452 
13453  if (convinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13454  ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
13455  convinfo->dobj.name,
13456  convinfo->dobj.namespace->dobj.name,
13457  NULL,
13458  convinfo->rolname,
13459  false, "CONVERSION", SECTION_PRE_DATA,
13460  q->data, delq->data, NULL,
13461  NULL, 0,
13462  NULL, NULL);
13463 
13464  /* Dump Conversion Comments */
13465  if (convinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13466  dumpComment(fout, "CONVERSION", qconvname,
13467  convinfo->dobj.namespace->dobj.name, convinfo->rolname,
13468  convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
13469 
13470  PQclear(res);
13471 
13472  destroyPQExpBuffer(query);
13473  destroyPQExpBuffer(q);
13474  destroyPQExpBuffer(delq);
13475  free(qconvname);
13476 }
char * name
Definition: pg_dump.h:134
DumpComponents dump
Definition: pg_dump.h:135
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:254
DumpId dumpId
Definition: pg_dump.h:133
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:420
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:136
DumpOptions * dopt
Definition: pg_backup.h:183
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:140
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
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:95
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:304
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:93
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:140
DumpableObject dobj
Definition: pg_dump.h:253
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4401
CatalogId catId
Definition: pg_dump.h:132
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 dumpComment(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9355

◆ dumpDatabase()

static void dumpDatabase ( Archive AH)
static

Definition at line 2529 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), atooid, _dumpOptions::binary_upgrade, buildShSecLabelQuery(), conn, createDumpId(), createPQExpBuffer(), PQExpBufferData::data, datconnlimit, datistemplate, destroyPQExpBuffer(), Archive::dopt, dumpACL(), dumpComment(), dumpDatabaseConfig(), emitShSecLabels(), encoding, ExecuteSqlQuery(), ExecuteSqlQueryForSingleRow(), fmtId(), free, g_verbose, GetConnection(), PQExpBufferData::len, _dumpOptions::no_comments, _dumpOptions::no_security_labels, CatalogId::oid, _dumpOptions::outputNoTablespaces, pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), Archive::remoteVersion, resetPQExpBuffer(), SECTION_NONE, SECTION_PRE_DATA, CatalogId::tableoid, tablespace, username_subquery, and write_msg().

Referenced by main().

2530 {
2531  DumpOptions *dopt = fout->dopt;
2532  PQExpBuffer dbQry = createPQExpBuffer();
2533  PQExpBuffer delQry = createPQExpBuffer();
2534  PQExpBuffer creaQry = createPQExpBuffer();
2535  PQExpBuffer labelq = createPQExpBuffer();
2536  PGconn *conn = GetConnection(fout);
2537  PGresult *res;
2538  int i_tableoid,
2539  i_oid,
2540  i_datname,
2541  i_dba,
2542  i_encoding,
2543  i_collate,
2544  i_ctype,
2545  i_frozenxid,
2546  i_minmxid,
2547  i_datacl,
2548  i_rdatacl,
2549  i_datistemplate,
2550  i_datconnlimit,
2551  i_tablespace;
2552  CatalogId dbCatId;
2553  DumpId dbDumpId;
2554  const char *datname,
2555  *dba,
2556  *encoding,
2557  *collate,
2558  *ctype,
2559  *datacl,
2560  *rdatacl,
2561  *datistemplate,
2562  *datconnlimit,
2563  *tablespace;
2564  uint32 frozenxid,
2565  minmxid;
2566  char *qdatname;
2567 
2568  if (g_verbose)
2569  write_msg(NULL, "saving database definition\n");
2570 
2571  /* Fetch the database-level properties for this database */
2572  if (fout->remoteVersion >= 90600)
2573  {
2574  appendPQExpBuffer(dbQry, "SELECT tableoid, oid, datname, "
2575  "(%s datdba) AS dba, "
2576  "pg_encoding_to_char(encoding) AS encoding, "
2577  "datcollate, datctype, datfrozenxid, datminmxid, "
2578  "(SELECT array_agg(acl ORDER BY acl::text COLLATE \"C\") FROM ( "
2579  " SELECT unnest(coalesce(datacl,acldefault('d',datdba))) AS acl "
2580  " EXCEPT SELECT unnest(acldefault('d',datdba))) as datacls)"
2581  " AS datacl, "
2582  "(SELECT array_agg(acl ORDER BY acl::text COLLATE \"C\") FROM ( "
2583  " SELECT unnest(acldefault('d',datdba)) AS acl "
2584  " EXCEPT SELECT unnest(coalesce(datacl,acldefault('d',datdba)))) as rdatacls)"
2585  " AS rdatacl, "
2586  "datistemplate, datconnlimit, "
2587  "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2588  "shobj_description(oid, 'pg_database') AS description "
2589 
2590  "FROM pg_database "
2591  "WHERE datnam