PostgreSQL Source Code  git master
pg_dump.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <ctype.h>
#include <limits.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 "storage/block.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 DUMP_DEFAULT_ROWS_PER_INSERT   1
 
#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, char relkind)
 
static void makeTableDataInfo (DumpOptions *dopt, TableInfo *tbinfo)
 
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

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}
 
static bool have_extra_float_digits = false
 
static int extra_float_digits
 

Macro Definition Documentation

◆ DUMP_DEFAULT_ROWS_PER_INSERT

#define DUMP_DEFAULT_ROWS_PER_INSERT   1

Definition at line 144 of file pg_dump.c.

Referenced by main().

◆ fmtQualifiedDumpable

Typedef Documentation

◆ OidOptions

typedef enum OidOptions OidOptions

Enumeration Type Documentation

◆ OidOptions

enum OidOptions
Enumerator
zeroAsOpaque 
zeroAsAny 
zeroAsStar 
zeroAsNone 

Definition at line 86 of file pg_dump.c.

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

Function Documentation

◆ addBoundaryDependencies()

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

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

18132 {
18133  DumpableObject *preDataBound = boundaryObjs + 0;
18134  DumpableObject *postDataBound = boundaryObjs + 1;
18135  int i;
18136 
18137  for (i = 0; i < numObjs; i++)
18138  {
18139  DumpableObject *dobj = dobjs[i];
18140 
18141  /*
18142  * The classification of object types here must match the SECTION_xxx
18143  * values assigned during subsequent ArchiveEntry calls!
18144  */
18145  switch (dobj->objType)
18146  {
18147  case DO_NAMESPACE:
18148  case DO_EXTENSION:
18149  case DO_TYPE:
18150  case DO_SHELL_TYPE:
18151  case DO_FUNC:
18152  case DO_AGG:
18153  case DO_OPERATOR:
18154  case DO_ACCESS_METHOD:
18155  case DO_OPCLASS:
18156  case DO_OPFAMILY:
18157  case DO_COLLATION:
18158  case DO_CONVERSION:
18159  case DO_TABLE:
18160  case DO_ATTRDEF:
18161  case DO_PROCLANG:
18162  case DO_CAST:
18163  case DO_DUMMY_TYPE:
18164  case DO_TSPARSER:
18165  case DO_TSDICT:
18166  case DO_TSTEMPLATE:
18167  case DO_TSCONFIG:
18168  case DO_FDW:
18169  case DO_FOREIGN_SERVER:
18170  case DO_TRANSFORM:
18171  case DO_BLOB:
18172  /* Pre-data objects: must come before the pre-data boundary */
18173  addObjectDependency(preDataBound, dobj->dumpId);
18174  break;
18175  case DO_TABLE_DATA:
18176  case DO_SEQUENCE_SET:
18177  case DO_BLOB_DATA:
18178  /* Data objects: must come between the boundaries */
18179  addObjectDependency(dobj, preDataBound->dumpId);
18180  addObjectDependency(postDataBound, dobj->dumpId);
18181  break;
18182  case DO_INDEX:
18183  case DO_INDEX_ATTACH:
18184  case DO_STATSEXT:
18185  case DO_REFRESH_MATVIEW:
18186  case DO_TRIGGER:
18187  case DO_EVENT_TRIGGER:
18188  case DO_DEFAULT_ACL:
18189  case DO_POLICY:
18190  case DO_PUBLICATION:
18191  case DO_PUBLICATION_REL:
18192  case DO_SUBSCRIPTION:
18193  /* Post-data objects: must come after the post-data boundary */
18194  addObjectDependency(dobj, postDataBound->dumpId);
18195  break;
18196  case DO_RULE:
18197  /* Rules are post-data, but only if dumped separately */
18198  if (((RuleInfo *) dobj)->separate)
18199  addObjectDependency(dobj, postDataBound->dumpId);
18200  break;
18201  case DO_CONSTRAINT:
18202  case DO_FK_CONSTRAINT:
18203  /* Constraints are post-data, but only if dumped separately */
18204  if (((ConstraintInfo *) dobj)->separate)
18205  addObjectDependency(dobj, postDataBound->dumpId);
18206  break;
18207  case DO_PRE_DATA_BOUNDARY:
18208  /* nothing to do */
18209  break;
18210  case DO_POST_DATA_BOUNDARY:
18211  /* must come after the pre-data boundary */
18212  addObjectDependency(dobj, preDataBound->dumpId);
18213  break;
18214  }
18215  }
18216 }
DumpId dumpId
Definition: pg_dump.h:129
Definition: pg_dump.h:45
Definition: pg_dump.h:70
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:783
int i
DumpableObjectType objType
Definition: pg_dump.h:127

◆ appendReloptionsArrayAH()

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

Definition at line 18433 of file pg_dump.c.

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

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

18435 {
18436  bool res;
18437 
18438  res = appendReloptionsArray(buffer, reloptions, prefix, fout->encoding,
18439  fout->std_strings);
18440  if (!res)
18441  pg_log_warning("could not parse reloptions array");
18442 }
int encoding
Definition: pg_backup.h:197
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
Definition: string_utils.c:743
#define pg_log_warning(...)
Definition: pgfnames.c:24
bool std_strings
Definition: pg_backup.h:198

◆ 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 4473 of file pg_dump.c.

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

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

4478 {
4479  DumpableObject *extobj = NULL;
4480  int i;
4481 
4482  if (!dobj->ext_member)
4483  return;
4484 
4485  /*
4486  * Find the parent extension. We could avoid this search if we wanted to
4487  * add a link field to DumpableObject, but the space costs of that would
4488  * be considerable. We assume that member objects could only have a
4489  * direct dependency on their own extension, not any others.
4490  */
4491  for (i = 0; i < dobj->nDeps; i++)
4492  {
4493  extobj = findObjectByDumpId(dobj->dependencies[i]);
4494  if (extobj && extobj->objType == DO_EXTENSION)
4495  break;
4496  extobj = NULL;
4497  }
4498  if (extobj == NULL)
4499  fatal("could not find parent extension for %s %s",
4500  objtype, objname);
4501 
4502  appendPQExpBufferStr(upgrade_buffer,
4503  "\n-- For binary upgrade, handle extension membership the hard way\n");
4504  appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s ",
4505  fmtId(extobj->name),
4506  objtype);
4507  if (objnamespace && *objnamespace)
4508  appendPQExpBuffer(upgrade_buffer, "%s.", fmtId(objnamespace));
4509  appendPQExpBuffer(upgrade_buffer, "%s;\n", objname);
4510 }
char * name
Definition: pg_dump.h:130
DumpId * dependencies
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:369
bool ext_member
Definition: pg_dump.h:134
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:611
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
#define fatal(...)
int i
DumpableObjectType objType
Definition: pg_dump.h:127

◆ 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 4403 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().

4406 {
4407  PQExpBuffer upgrade_query = createPQExpBuffer();
4408  PGresult *upgrade_res;
4409  Oid pg_class_reltoastrelid;
4410  Oid pg_index_indexrelid;
4411 
4412  appendPQExpBuffer(upgrade_query,
4413  "SELECT c.reltoastrelid, i.indexrelid "
4414  "FROM pg_catalog.pg_class c LEFT JOIN "
4415  "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
4416  "WHERE c.oid = '%u'::pg_catalog.oid;",
4417  pg_class_oid);
4418 
4419  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4420 
4421  pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
4422  pg_index_indexrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "indexrelid")));
4423 
4424  appendPQExpBufferStr(upgrade_buffer,
4425  "\n-- For binary upgrade, must preserve pg_class oids\n");
4426 
4427  if (!is_index)
4428  {
4429  appendPQExpBuffer(upgrade_buffer,
4430  "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
4431  pg_class_oid);
4432  /* only tables have toast tables, not indexes */
4433  if (OidIsValid(pg_class_reltoastrelid))
4434  {
4435  /*
4436  * One complexity is that the table definition might not require
4437  * the creation of a TOAST table, and the TOAST table might have
4438  * been created long after table creation, when the table was
4439  * loaded with wide data. By setting the TOAST oid we force
4440  * creation of the TOAST heap and TOAST index by the backend so we
4441  * can cleanly copy the files during binary upgrade.
4442  */
4443 
4444  appendPQExpBuffer(upgrade_buffer,
4445  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
4446  pg_class_reltoastrelid);
4447 
4448  /* every toast table has an index */
4449  appendPQExpBuffer(upgrade_buffer,
4450  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4451  pg_index_indexrelid);
4452  }
4453  }
4454  else
4455  appendPQExpBuffer(upgrade_buffer,
4456  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4457  pg_class_oid);
4458 
4459  appendPQExpBufferChar(upgrade_buffer, '\n');
4460 
4461  PQclear(upgrade_res);
4462  destroyPQExpBuffer(upgrade_query);
4463 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:418
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
void PQclear(PGresult *res)
Definition: fe-exec.c:695

◆ 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 4351 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().

4354 {
4355  PQExpBuffer upgrade_query = createPQExpBuffer();
4356  PGresult *upgrade_res;
4357  Oid pg_type_oid;
4358  bool toast_set = false;
4359 
4360  /*
4361  * We only support old >= 8.3 for binary upgrades.
4362  *
4363  * We purposefully ignore toast OIDs for partitioned tables; the reason is
4364  * that versions 10 and 11 have them, but 12 does not, so emitting them
4365  * causes the upgrade to fail.
4366  */
4367  appendPQExpBuffer(upgrade_query,
4368  "SELECT c.reltype AS crel, t.reltype AS trel "
4369  "FROM pg_catalog.pg_class c "
4370  "LEFT JOIN pg_catalog.pg_class t ON "
4371  " (c.reltoastrelid = t.oid AND c.relkind <> '%c') "
4372  "WHERE c.oid = '%u'::pg_catalog.oid;",
4373  RELKIND_PARTITIONED_TABLE, pg_rel_oid);
4374 
4375  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4376 
4377  pg_type_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "crel")));
4378 
4379  binary_upgrade_set_type_oids_by_type_oid(fout, upgrade_buffer,
4380  pg_type_oid, false);
4381 
4382  if (!PQgetisnull(upgrade_res, 0, PQfnumber(upgrade_res, "trel")))
4383  {
4384  /* Toast tables do not have pg_type array rows */
4385  Oid pg_type_toast_oid = atooid(PQgetvalue(upgrade_res, 0,
4386  PQfnumber(upgrade_res, "trel")));
4387 
4388  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
4389  appendPQExpBuffer(upgrade_buffer,
4390  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4391  pg_type_toast_oid);
4392 
4393  toast_set = true;
4394  }
4395 
4396  PQclear(upgrade_res);
4397  destroyPQExpBuffer(upgrade_query);
4398 
4399  return toast_set;
4400 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
unsigned int Oid
Definition: postgres_ext.h:31
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:418
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
#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:4282
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
void PQclear(PGresult *res)
Definition: fe-exec.c:695
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3189

◆ 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 4282 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().

4286 {
4287  PQExpBuffer upgrade_query = createPQExpBuffer();
4288  PGresult *res;
4289  Oid pg_type_array_oid;
4290 
4291  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
4292  appendPQExpBuffer(upgrade_buffer,
4293  "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4294  pg_type_oid);
4295 
4296  /* we only support old >= 8.3 for binary upgrades */
4297  appendPQExpBuffer(upgrade_query,
4298  "SELECT typarray "
4299  "FROM pg_catalog.pg_type "
4300  "WHERE oid = '%u'::pg_catalog.oid;",
4301  pg_type_oid);
4302 
4303  res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4304 
4305  pg_type_array_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typarray")));
4306 
4307  PQclear(res);
4308 
4309  if (!OidIsValid(pg_type_array_oid) && force_array_type)
4310  {
4311  /*
4312  * If the old version didn't assign an array type, but the new version
4313  * does, we must select an unused type OID to assign. This currently
4314  * only happens for domains, when upgrading pre-v11 to v11 and up.
4315  *
4316  * Note: local state here is kind of ugly, but we must have some,
4317  * since we mustn't choose the same unused OID more than once.
4318  */
4319  static Oid next_possible_free_oid = FirstNormalObjectId;
4320  bool is_dup;
4321 
4322  do
4323  {
4324  ++next_possible_free_oid;
4325  printfPQExpBuffer(upgrade_query,
4326  "SELECT EXISTS(SELECT 1 "
4327  "FROM pg_catalog.pg_type "
4328  "WHERE oid = '%u'::pg_catalog.oid);",
4329  next_possible_free_oid);
4330  res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4331  is_dup = (PQgetvalue(res, 0, 0)[0] == 't');
4332  PQclear(res);
4333  } while (is_dup);
4334 
4335  pg_type_array_oid = next_possible_free_oid;
4336  }
4337 
4338  if (OidIsValid(pg_type_array_oid))
4339  {
4340  appendPQExpBufferStr(upgrade_buffer,
4341  "\n-- For binary upgrade, must preserve pg_type array oid\n");
4342  appendPQExpBuffer(upgrade_buffer,
4343  "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4344  pg_type_array_oid);
4345  }
4346 
4347  destroyPQExpBuffer(upgrade_query);
4348 }
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
#define FirstNormalObjectId
Definition: transam.h:141
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:418
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
void PQclear(PGresult *res)
Definition: fe-exec.c:695

◆ BuildArchiveDependencies()

static void BuildArchiveDependencies ( Archive fout)
static

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

18244 {
18245  ArchiveHandle *AH = (ArchiveHandle *) fout;
18246  TocEntry *te;
18247 
18248  /* Scan all TOC entries in the archive */
18249  for (te = AH->toc->next; te != AH->toc; te = te->next)
18250  {
18251  DumpableObject *dobj;
18252  DumpId *dependencies;
18253  int nDeps;
18254  int allocDeps;
18255 
18256  /* No need to process entries that will not be dumped */
18257  if (te->reqs == 0)
18258  continue;
18259  /* Ignore entries that already have "special" dependencies */
18260  if (te->nDeps > 0)
18261  continue;
18262  /* Otherwise, look up the item's original DumpableObject, if any */
18263  dobj = findObjectByDumpId(te->dumpId);
18264  if (dobj == NULL)
18265  continue;
18266  /* No work if it has no dependencies */
18267  if (dobj->nDeps <= 0)
18268  continue;
18269  /* Set up work array */
18270  allocDeps = 64;
18271  dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(DumpId));
18272  nDeps = 0;
18273  /* Recursively find all dumpable dependencies */
18274  findDumpableDependencies(AH, dobj,
18275  &dependencies, &nDeps, &allocDeps);
18276  /* And save 'em ... */
18277  if (nDeps > 0)
18278  {
18279  dependencies = (DumpId *) pg_realloc(dependencies,
18280  nDeps * sizeof(DumpId));
18281  te->dependencies = dependencies;
18282  te->nDeps = nDeps;
18283  }
18284  else
18285  free(dependencies);
18286  }
18287 }
struct _tocEntry * next
int DumpId
Definition: pg_backup.h:234
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:611
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:18291
#define free(a)
Definition: header.h:65

◆ buildMatViewRefreshDependencies()

static void buildMatViewRefreshDependencies ( Archive fout)
static

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

2397 {
2398  PQExpBuffer query;
2399  PGresult *res;
2400  int ntups,
2401  i;
2402  int i_classid,
2403  i_objid,
2404  i_refobjid;
2405 
2406  /* No Mat Views before 9.3. */
2407  if (fout->remoteVersion < 90300)
2408  return;
2409 
2410  query = createPQExpBuffer();
2411 
2412  appendPQExpBufferStr(query, "WITH RECURSIVE w AS "
2413  "( "
2414  "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2415  "FROM pg_depend d1 "
2416  "JOIN pg_class c1 ON c1.oid = d1.objid "
2417  "AND c1.relkind = " CppAsString2(RELKIND_MATVIEW)
2418  " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2419  "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2420  "AND d2.objid = r1.oid "
2421  "AND d2.refobjid <> d1.objid "
2422  "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2423  "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2424  CppAsString2(RELKIND_VIEW) ") "
2425  "WHERE d1.classid = 'pg_class'::regclass "
2426  "UNION "
2427  "SELECT w.objid, d3.refobjid, c3.relkind "
2428  "FROM w "
2429  "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2430  "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2431  "AND d3.objid = r3.oid "
2432  "AND d3.refobjid <> w.refobjid "
2433  "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2434  "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2435  CppAsString2(RELKIND_VIEW) ") "
2436  ") "
2437  "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2438  "FROM w "
2439  "WHERE refrelkind = " CppAsString2(RELKIND_MATVIEW));
2440 
2441  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
2442 
2443  ntups = PQntuples(res);
2444 
2445  i_classid = PQfnumber(res, "classid");
2446  i_objid = PQfnumber(res, "objid");
2447  i_refobjid = PQfnumber(res, "refobjid");
2448 
2449  for (i = 0; i < ntups; i++)
2450  {
2451  CatalogId objId;
2452  CatalogId refobjId;
2453  DumpableObject *dobj;
2454  DumpableObject *refdobj;
2455  TableInfo *tbinfo;
2456  TableInfo *reftbinfo;
2457 
2458  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
2459  objId.oid = atooid(PQgetvalue(res, i, i_objid));
2460  refobjId.tableoid = objId.tableoid;
2461  refobjId.oid = atooid(PQgetvalue(res, i, i_refobjid));
2462 
2463  dobj = findObjectByCatalogId(objId);
2464  if (dobj == NULL)
2465  continue;
2466 
2467  Assert(dobj->objType == DO_TABLE);
2468  tbinfo = (TableInfo *) dobj;
2469  Assert(tbinfo->relkind == RELKIND_MATVIEW);
2470  dobj = (DumpableObject *) tbinfo->dataObj;
2471  if (dobj == NULL)
2472  continue;
2473  Assert(dobj->objType == DO_REFRESH_MATVIEW);
2474 
2475  refdobj = findObjectByCatalogId(refobjId);
2476  if (refdobj == NULL)
2477  continue;
2478 
2479  Assert(refdobj->objType == DO_TABLE);
2480  reftbinfo = (TableInfo *) refdobj;
2481  Assert(reftbinfo->relkind == RELKIND_MATVIEW);
2482  refdobj = (DumpableObject *) reftbinfo->dataObj;
2483  if (refdobj == NULL)
2484  continue;
2485  Assert(refdobj->objType == DO_REFRESH_MATVIEW);
2486 
2487  addObjectDependency(dobj, refdobj->dumpId);
2488 
2489  if (!reftbinfo->relispopulated)
2490  tbinfo->relispopulated = false;
2491  }
2492 
2493  PQclear(res);
2494 
2495  destroyPQExpBuffer(query);
2496 }
char relkind
Definition: pg_dump.h:264
Oid tableoid
Definition: pg_backup.h:230
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
DumpId dumpId
Definition: pg_dump.h:129
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2770
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:629
#define atooid(x)
Definition: postgres_ext.h:42
#define CppAsString2(x)
Definition: c.h:224
struct _tableDataInfo * dataObj
Definition: pg_dump.h:333
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define Assert(condition)
Definition: c.h:732
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:783
int i
bool relispopulated
Definition: pg_dump.h:266
DumpableObjectType objType
Definition: pg_dump.h:127
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:403
int remoteVersion
Definition: pg_backup.h:187

◆ checkExtensionMembership()

static bool checkExtensionMembership ( DumpableObject dobj,
Archive fout 
)
static

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

1417 {
1418  ExtensionInfo *ext = findOwningExtension(dobj->catId);
1419 
1420  if (ext == NULL)
1421  return false;
1422 
1423  dobj->ext_member = true;
1424 
1425  /* Record dependency so that getDependencies needn't deal with that */
1426  addObjectDependency(dobj, ext->dobj.dumpId);
1427 
1428  /*
1429  * In 9.6 and above, mark the member object to have any non-initial ACL,
1430  * policies, and security labels dumped.
1431  *
1432  * Note that any initial ACLs (see pg_init_privs) will be removed when we
1433  * extract the information about the object. We don't provide support for
1434  * initial policies and security labels and it seems unlikely for those to
1435  * ever exist, but we may have to revisit this later.
1436  *
1437  * Prior to 9.6, we do not include any extension member components.
1438  *
1439  * In binary upgrades, we still dump all components of the members
1440  * individually, since the idea is to exactly reproduce the database
1441  * contents rather than replace the extension contents with something
1442  * different.
1443  */
1444  if (fout->dopt->binary_upgrade)
1445  dobj->dump = ext->dobj.dump;
1446  else
1447  {
1448  if (fout->remoteVersion < 90600)
1449  dobj->dump = DUMP_COMPONENT_NONE;
1450  else
1451  dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL |
1454  }
1455 
1456  return true;
1457 }
DumpableObject dobj
Definition: pg_dump.h:152
DumpComponents dump
Definition: pg_dump.h:131
DumpId dumpId
Definition: pg_dump.h:129
bool ext_member
Definition: pg_dump.h:134
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:88
int binary_upgrade
Definition: pg_backup.h:135
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition: common.c:935
DumpOptions * dopt
Definition: pg_backup.h:182
DumpComponents dump_contains
Definition: pg_dump.h:133
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:92
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:783
CatalogId catId
Definition: pg_dump.h:128
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:94
int remoteVersion
Definition: pg_backup.h:187

◆ collectComments()

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

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

9770 {
9771  PGresult *res;
9772  PQExpBuffer query;
9773  int i_description;
9774  int i_classoid;
9775  int i_objoid;
9776  int i_objsubid;
9777  int ntups;
9778  int i;
9779  CommentItem *comments;
9780 
9781  query = createPQExpBuffer();
9782 
9783  appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
9784  "FROM pg_catalog.pg_description "
9785  "ORDER BY classoid, objoid, objsubid");
9786 
9787  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9788 
9789  /* Construct lookup table containing OIDs in numeric form */
9790 
9791  i_description = PQfnumber(res, "description");
9792  i_classoid = PQfnumber(res, "classoid");
9793  i_objoid = PQfnumber(res, "objoid");
9794  i_objsubid = PQfnumber(res, "objsubid");
9795 
9796  ntups = PQntuples(res);
9797 
9798  comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
9799 
9800  for (i = 0; i < ntups; i++)
9801  {
9802  comments[i].descr = PQgetvalue(res, i, i_description);
9803  comments[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
9804  comments[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
9805  comments[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
9806  }
9807 
9808  /* Do NOT free the PGresult since we are keeping pointers into it */
9809  destroyPQExpBuffer(query);
9810 
9811  *items = comments;
9812  return ntups;
9813 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int objsubid
Definition: pg_dump.c:74
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2770
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
#define atooid(x)
Definition: postgres_ext.h:42
const char * descr
Definition: pg_dump.c:71
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
Oid objoid
Definition: pg_dump.c:73
Oid classoid
Definition: pg_dump.c:72
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:403

◆ collectSecLabels()

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

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

15245 {
15246  PGresult *res;
15247  PQExpBuffer query;
15248  int i_label;
15249  int i_provider;
15250  int i_classoid;
15251  int i_objoid;
15252  int i_objsubid;
15253  int ntups;
15254  int i;
15255  SecLabelItem *labels;
15256 
15257  query = createPQExpBuffer();
15258 
15259  appendPQExpBufferStr(query,
15260  "SELECT label, provider, classoid, objoid, objsubid "
15261  "FROM pg_catalog.pg_seclabel "
15262  "ORDER BY classoid, objoid, objsubid");
15263 
15264  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
15265 
15266  /* Construct lookup table containing OIDs in numeric form */
15267  i_label = PQfnumber(res, "label");
15268  i_provider = PQfnumber(res, "provider");
15269  i_classoid = PQfnumber(res, "classoid");
15270  i_objoid = PQfnumber(res, "objoid");
15271  i_objsubid = PQfnumber(res, "objsubid");
15272 
15273  ntups = PQntuples(res);
15274 
15275  labels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
15276 
15277  for (i = 0; i < ntups; i++)
15278  {
15279  labels[i].label = PQgetvalue(res, i, i_label);
15280  labels[i].provider = PQgetvalue(res, i, i_provider);
15281  labels[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
15282  labels[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
15283  labels[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
15284  }
15285 
15286  /* Do NOT free the PGresult since we are keeping pointers into it */
15287  destroyPQExpBuffer(query);
15288 
15289  *items = labels;
15290  return ntups;
15291 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2770
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
Oid objoid
Definition: pg_dump.c:82
const char * provider
Definition: pg_dump.c:79
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
int objsubid
Definition: pg_dump.c:83
int i
Oid classoid
Definition: pg_dump.c:81
const char * label
Definition: pg_dump.c:80
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:403

◆ convertRegProcReference()

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

Definition at line 12666 of file pg_dump.c.

References name, and pg_strdup().

Referenced by dumpOpr().

12667 {
12668  char *name;
12669  char *paren;
12670  bool inquote;
12671 
12672  /* In all cases "-" means a null reference */
12673  if (strcmp(proc, "-") == 0)
12674  return NULL;
12675 
12676  name = pg_strdup(proc);
12677  /* find non-double-quoted left paren */
12678  inquote = false;
12679  for (paren = name; *paren; paren++)
12680  {
12681  if (*paren == '(' && !inquote)
12682  {
12683  *paren = '\0';
12684  break;
12685  }
12686  if (*paren == '"')
12687  inquote = !inquote;
12688  }
12689  return name;
12690 }
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 12737 of file pg_dump.c.

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

Referenced by dumpTSParser(), and dumpTSTemplate().

12738 {
12739  char *result;
12740  char query[128];
12741  PGresult *res;
12742 
12743  snprintf(query, sizeof(query),
12744  "SELECT '%u'::pg_catalog.regproc", funcOid);
12745  res = ExecuteSqlQueryForSingleRow(fout, query);
12746 
12747  result = pg_strdup(PQgetvalue(res, 0, 0));
12748 
12749  PQclear(res);
12750 
12751  return result;
12752 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:418
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define snprintf
Definition: port.h:192

◆ createBoundaryObjects()

static DumpableObject * createBoundaryObjects ( void  )
static

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

18107 {
18108  DumpableObject *dobjs;
18109 
18110  dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject));
18111 
18112  dobjs[0].objType = DO_PRE_DATA_BOUNDARY;
18113  dobjs[0].catId = nilCatalogId;
18114  AssignDumpId(dobjs + 0);
18115  dobjs[0].name = pg_strdup("PRE-DATA BOUNDARY");
18116 
18117  dobjs[1].objType = DO_POST_DATA_BOUNDARY;
18118  dobjs[1].catId = nilCatalogId;
18119  AssignDumpId(dobjs + 1);
18120  dobjs[1].name = pg_strdup("POST-DATA BOUNDARY");
18121 
18122  return dobjs;
18123 }
char * name
Definition: pg_dump.h:130
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:547
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:128
static const CatalogId nilCatalogId
Definition: pg_dump.c:134
DumpableObjectType objType
Definition: pg_dump.h:127

◆ createDummyViewAsClause()

static PQExpBuffer createDummyViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

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

15483 {
15484  PQExpBuffer result = createPQExpBuffer();
15485  int j;
15486 
15487  appendPQExpBufferStr(result, "SELECT");
15488 
15489  for (j = 0; j < tbinfo->numatts; j++)
15490  {
15491  if (j > 0)
15492  appendPQExpBufferChar(result, ',');
15493  appendPQExpBufferStr(result, "\n ");
15494 
15495  appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]);
15496 
15497  /*
15498  * Must add collation if not default for the type, because CREATE OR
15499  * REPLACE VIEW won't change it
15500  */
15501  if (OidIsValid(tbinfo->attcollation[j]))
15502  {
15503  CollInfo *coll;
15504 
15505  coll = findCollationByOid(tbinfo->attcollation[j]);
15506  if (coll)
15507  appendPQExpBuffer(result, " COLLATE %s",
15508  fmtQualifiedDumpable(coll));
15509  }
15510 
15511  appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j]));
15512  }
15513 
15514  return result;
15515 }
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
char ** atttypnames
Definition: pg_dump.h:302
char ** attnames
Definition: pg_dump.h:301
#define OidIsValid(objectId)
Definition: c.h:638
Oid * attcollation
Definition: pg_dump.h:314
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
int numatts
Definition: pg_dump.h:300
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:149
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:874

◆ createViewAsClause()

static PQExpBuffer createViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

Definition at line 15433 of file pg_dump.c.

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

Referenced by dumpRule(), and dumpTableSchema().

15434 {
15435  PQExpBuffer query = createPQExpBuffer();
15436  PQExpBuffer result = createPQExpBuffer();
15437  PGresult *res;
15438  int len;
15439 
15440  /* Fetch the view definition */
15441  appendPQExpBuffer(query,
15442  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
15443  tbinfo->dobj.catId.oid);
15444 
15445  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
15446 
15447  if (PQntuples(res) != 1)
15448  {
15449  if (PQntuples(res) < 1)
15450  fatal("query to obtain definition of view \"%s\" returned no data",
15451  tbinfo->dobj.name);
15452  else
15453  fatal("query to obtain definition of view \"%s\" returned more than one definition",
15454  tbinfo->dobj.name);
15455  }
15456 
15457  len = PQgetlength(res, 0, 0);
15458 
15459  if (len == 0)
15460  fatal("definition of view \"%s\" appears to be empty (length zero)",
15461  tbinfo->dobj.name);
15462 
15463  /* Strip off the trailing semicolon so that other things may follow. */
15464  Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
15465  appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
15466 
15467  PQclear(res);
15468  destroyPQExpBuffer(query);
15469 
15470  return result;
15471 }
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3175
char * name
Definition: pg_dump.h:130
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2770
DumpableObject dobj
Definition: pg_dump.h:258
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define Assert(condition)
Definition: c.h:732
#define fatal(...)
CatalogId catId
Definition: pg_dump.h:128
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:399
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:403

◆ dumpAccessMethod()

static void dumpAccessMethod ( Archive fout,
AccessMethodInfo oprinfo 
)
static

Definition at line 12759 of file pg_dump.c.

References _accessMethodInfo::amhandler, _accessMethodInfo::amtype, appendPQExpBuffer(), appendPQExpBufferStr(), ARCHIVE_OPTS, 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_log_warning, pg_strdup(), and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

12760 {
12761  DumpOptions *dopt = fout->dopt;
12762  PQExpBuffer q;
12763  PQExpBuffer delq;
12764  char *qamname;
12765 
12766  /* Skip if not to be dumped */
12767  if (!aminfo->dobj.dump || dopt->dataOnly)
12768  return;
12769 
12770  q = createPQExpBuffer();
12771  delq = createPQExpBuffer();
12772 
12773  qamname = pg_strdup(fmtId(aminfo->dobj.name));
12774 
12775  appendPQExpBuffer(q, "CREATE ACCESS METHOD %s ", qamname);
12776 
12777  switch (aminfo->amtype)
12778  {
12779  case AMTYPE_INDEX:
12780  appendPQExpBufferStr(q, "TYPE INDEX ");
12781  break;
12782  case AMTYPE_TABLE:
12783  appendPQExpBufferStr(q, "TYPE TABLE ");
12784  break;
12785  default:
12786  pg_log_warning("invalid type \"%c\" of access method \"%s\"",
12787  aminfo->amtype, qamname);
12788  destroyPQExpBuffer(q);
12789  destroyPQExpBuffer(delq);
12790  free(qamname);
12791  return;
12792  }
12793 
12794  appendPQExpBuffer(q, "HANDLER %s;\n", aminfo->amhandler);
12795 
12796  appendPQExpBuffer(delq, "DROP ACCESS METHOD %s;\n",
12797  qamname);
12798 
12799  if (dopt->binary_upgrade)
12800  binary_upgrade_extension_member(q, &aminfo->dobj,
12801  "ACCESS METHOD", qamname, NULL);
12802 
12803  if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
12804  ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
12805  ARCHIVE_OPTS(.tag = aminfo->dobj.name,
12806  .description = "ACCESS METHOD",
12807  .section = SECTION_PRE_DATA,
12808  .createStmt = q->data,
12809  .dropStmt = delq->data));
12810 
12811  /* Dump Access Method Comments */
12812  if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT)
12813  dumpComment(fout, "ACCESS METHOD", qamname,
12814  NULL, "",
12815  aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
12816 
12817  destroyPQExpBuffer(q);
12818  destroyPQExpBuffer(delq);
12819  free(qamname);
12820 }
#define ARCHIVE_OPTS(...)
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4473
#define pg_log_warning(...)
Definition: pgfnames.c:24
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:9506

◆ 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 14910 of file pg_dump.c.

References _dumpOptions::aclsSkip, appendPQExpBuffer(), appendPQExpBufferStr(), ARCHIVE_OPTS, ArchiveEntry(), buildACLCommands(), createDumpId(), createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), Archive::dopt, fatal, 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().

14915 {
14916  DumpOptions *dopt = fout->dopt;
14917  PQExpBuffer sql;
14918 
14919  /* Do nothing if ACL dump is not enabled */
14920  if (dopt->aclsSkip)
14921  return;
14922 
14923  /* --data-only skips ACLs *except* BLOB ACLs */
14924  if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
14925  return;
14926 
14927  sql = createPQExpBuffer();
14928 
14929  /*
14930  * Check to see if this object has had any initial ACLs included for it.
14931  * If so, we are in binary upgrade mode and these are the ACLs to turn
14932  * into GRANT and REVOKE statements to set and record the initial
14933  * privileges for an extension object. Let the backend know that these
14934  * are to be recorded by calling binary_upgrade_set_record_init_privs()
14935  * before and after.
14936  */
14937  if (strlen(initacls) != 0 || strlen(initracls) != 0)
14938  {
14939  appendPQExpBufferStr(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
14940  if (!buildACLCommands(name, subname, nspname, type,
14941  initacls, initracls, owner,
14942  "", fout->remoteVersion, sql))
14943  fatal("could not parse initial GRANT ACL list (%s) or initial REVOKE ACL list (%s) for object \"%s\" (%s)",
14944  initacls, initracls, name, type);
14945  appendPQExpBufferStr(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
14946  }
14947 
14948  if (!buildACLCommands(name, subname, nspname, type,
14949  acls, racls, owner,
14950  "", fout->remoteVersion, sql))
14951  fatal("could not parse GRANT ACL list (%s) or REVOKE ACL list (%s) for object \"%s\" (%s)",
14952  acls, racls, name, type);
14953 
14954  if (sql->len > 0)
14955  {
14957 
14958  if (subname)
14959  appendPQExpBuffer(tag, "COLUMN %s.%s", name, subname);
14960  else
14961  appendPQExpBuffer(tag, "%s %s", type, name);
14962 
14964  ARCHIVE_OPTS(.tag = tag->data,
14965  .namespace = nspname,
14966  .owner = owner,
14967  .description = "ACL",
14968  .section = SECTION_NONE,
14969  .createStmt = sql->data,
14970  .deps = &objDumpId,
14971  .nDeps = 1));
14972  destroyPQExpBuffer(tag);
14973  }
14974 
14975  destroyPQExpBuffer(sql);
14976 }
#define ARCHIVE_OPTS(...)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
NameData subname
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
bool aclsSkip
Definition: pg_backup.h:141
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
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:58
#define fatal(...)
const char * name
Definition: encode.c:521
static const CatalogId nilCatalogId
Definition: pg_dump.c:134
DumpId createDumpId(void)
Definition: common.c:591
int remoteVersion
Definition: pg_backup.h:187

◆ dumpAgg()

static void dumpAgg ( Archive fout,
AggInfo agginfo 
)
static

Definition at line 13747 of file pg_dump.c.

References _aggInfo::aggfn, appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, 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(), fatal, fmtId(), format_aggregate_signature(), format_function_arguments(), format_function_signature(), free, getFormattedOperatorName(), _funcInfo::initproacl, _funcInfo::initrproacl, _dumpableObject::name, CatalogId::oid, pg_log_warning, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), _funcInfo::proacl, Archive::remoteVersion, _funcInfo::rolname, _funcInfo::rproacl, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

13748 {
13749  DumpOptions *dopt = fout->dopt;
13750  PQExpBuffer query;
13751  PQExpBuffer q;
13752  PQExpBuffer delq;
13753  PQExpBuffer details;
13754  char *aggsig; /* identity signature */
13755  char *aggfullsig = NULL; /* full signature */
13756  char *aggsig_tag;
13757  PGresult *res;
13758  int i_aggtransfn;
13759  int i_aggfinalfn;
13760  int i_aggcombinefn;
13761  int i_aggserialfn;
13762  int i_aggdeserialfn;
13763  int i_aggmtransfn;
13764  int i_aggminvtransfn;
13765  int i_aggmfinalfn;
13766  int i_aggfinalextra;
13767  int i_aggmfinalextra;
13768  int i_aggfinalmodify;
13769  int i_aggmfinalmodify;
13770  int i_aggsortop;
13771  int i_aggkind;
13772  int i_aggtranstype;
13773  int i_aggtransspace;
13774  int i_aggmtranstype;
13775  int i_aggmtransspace;
13776  int i_agginitval;
13777  int i_aggminitval;
13778  int i_convertok;
13779  int i_proparallel;
13780  const char *aggtransfn;
13781  const char *aggfinalfn;
13782  const char *aggcombinefn;
13783  const char *aggserialfn;
13784  const char *aggdeserialfn;
13785  const char *aggmtransfn;
13786  const char *aggminvtransfn;
13787  const char *aggmfinalfn;
13788  bool aggfinalextra;
13789  bool aggmfinalextra;
13790  char aggfinalmodify;
13791  char aggmfinalmodify;
13792  const char *aggsortop;
13793  char *aggsortconvop;
13794  char aggkind;
13795  const char *aggtranstype;
13796  const char *aggtransspace;
13797  const char *aggmtranstype;
13798  const char *aggmtransspace;
13799  const char *agginitval;
13800  const char *aggminitval;
13801  bool convertok;
13802  const char *proparallel;
13803  char defaultfinalmodify;
13804 
13805  /* Skip if not to be dumped */
13806  if (!agginfo->aggfn.dobj.dump || dopt->dataOnly)
13807  return;
13808 
13809  query = createPQExpBuffer();
13810  q = createPQExpBuffer();
13811  delq = createPQExpBuffer();
13812  details = createPQExpBuffer();
13813 
13814  /* Get aggregate-specific details */
13815  if (fout->remoteVersion >= 110000)
13816  {
13817  appendPQExpBuffer(query, "SELECT aggtransfn, "
13818  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13819  "aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, "
13820  "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13821  "aggfinalextra, aggmfinalextra, "
13822  "aggfinalmodify, aggmfinalmodify, "
13823  "aggsortop, "
13824  "aggkind, "
13825  "aggtransspace, agginitval, "
13826  "aggmtransspace, aggminitval, "
13827  "true AS convertok, "
13828  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13829  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, "
13830  "p.proparallel "
13831  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13832  "WHERE a.aggfnoid = p.oid "
13833  "AND p.oid = '%u'::pg_catalog.oid",
13834  agginfo->aggfn.dobj.catId.oid);
13835  }
13836  else if (fout->remoteVersion >= 90600)
13837  {
13838  appendPQExpBuffer(query, "SELECT aggtransfn, "
13839  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13840  "aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, "
13841  "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13842  "aggfinalextra, aggmfinalextra, "
13843  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13844  "aggsortop, "
13845  "aggkind, "
13846  "aggtransspace, agginitval, "
13847  "aggmtransspace, aggminitval, "
13848  "true AS convertok, "
13849  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13850  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, "
13851  "p.proparallel "
13852  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13853  "WHERE a.aggfnoid = p.oid "
13854  "AND p.oid = '%u'::pg_catalog.oid",
13855  agginfo->aggfn.dobj.catId.oid);
13856  }
13857  else if (fout->remoteVersion >= 90400)
13858  {
13859  appendPQExpBuffer(query, "SELECT aggtransfn, "
13860  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13861  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13862  "'-' AS aggdeserialfn, aggmtransfn, aggminvtransfn, "
13863  "aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13864  "aggfinalextra, aggmfinalextra, "
13865  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13866  "aggsortop, "
13867  "aggkind, "
13868  "aggtransspace, agginitval, "
13869  "aggmtransspace, aggminitval, "
13870  "true AS convertok, "
13871  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13872  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13873  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13874  "WHERE a.aggfnoid = p.oid "
13875  "AND p.oid = '%u'::pg_catalog.oid",
13876  agginfo->aggfn.dobj.catId.oid);
13877  }
13878  else if (fout->remoteVersion >= 80400)
13879  {
13880  appendPQExpBuffer(query, "SELECT aggtransfn, "
13881  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13882  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13883  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13884  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13885  "0 AS aggmtranstype, false AS aggfinalextra, "
13886  "false AS aggmfinalextra, "
13887  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13888  "aggsortop, "
13889  "'n' AS aggkind, "
13890  "0 AS aggtransspace, agginitval, "
13891  "0 AS aggmtransspace, NULL AS aggminitval, "
13892  "true AS convertok, "
13893  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13894  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13895  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13896  "WHERE a.aggfnoid = p.oid "
13897  "AND p.oid = '%u'::pg_catalog.oid",
13898  agginfo->aggfn.dobj.catId.oid);
13899  }
13900  else if (fout->remoteVersion >= 80100)
13901  {
13902  appendPQExpBuffer(query, "SELECT aggtransfn, "
13903  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13904  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13905  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13906  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13907  "0 AS aggmtranstype, false AS aggfinalextra, "
13908  "false AS aggmfinalextra, "
13909  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13910  "aggsortop, "
13911  "'n' AS aggkind, "
13912  "0 AS aggtransspace, agginitval, "
13913  "0 AS aggmtransspace, NULL AS aggminitval, "
13914  "true AS convertok "
13915  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13916  "WHERE a.aggfnoid = p.oid "
13917  "AND p.oid = '%u'::pg_catalog.oid",
13918  agginfo->aggfn.dobj.catId.oid);
13919  }
13920  else
13921  {
13922  appendPQExpBuffer(query, "SELECT aggtransfn, "
13923  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13924  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13925  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13926  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13927  "0 AS aggmtranstype, false AS aggfinalextra, "
13928  "false AS aggmfinalextra, "
13929  "'0' AS aggfinalmodify, '0' AS aggmfinalmodify, "
13930  "0 AS aggsortop, "
13931  "'n' AS aggkind, "
13932  "0 AS aggtransspace, agginitval, "
13933  "0 AS aggmtransspace, NULL AS aggminitval, "
13934  "true AS convertok "
13935  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13936  "WHERE a.aggfnoid = p.oid "
13937  "AND p.oid = '%u'::pg_catalog.oid",
13938  agginfo->aggfn.dobj.catId.oid);
13939  }
13940 
13941  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13942 
13943  i_aggtransfn = PQfnumber(res, "aggtransfn");
13944  i_aggfinalfn = PQfnumber(res, "aggfinalfn");
13945  i_aggcombinefn = PQfnumber(res, "aggcombinefn");
13946  i_aggserialfn = PQfnumber(res, "aggserialfn");
13947  i_aggdeserialfn = PQfnumber(res, "aggdeserialfn");
13948  i_aggmtransfn = PQfnumber(res, "aggmtransfn");
13949  i_aggminvtransfn = PQfnumber(res, "aggminvtransfn");
13950  i_aggmfinalfn = PQfnumber(res, "aggmfinalfn");
13951  i_aggfinalextra = PQfnumber(res, "aggfinalextra");
13952  i_aggmfinalextra = PQfnumber(res, "aggmfinalextra");
13953  i_aggfinalmodify = PQfnumber(res, "aggfinalmodify");
13954  i_aggmfinalmodify = PQfnumber(res, "aggmfinalmodify");
13955  i_aggsortop = PQfnumber(res, "aggsortop");
13956  i_aggkind = PQfnumber(res, "aggkind");
13957  i_aggtranstype = PQfnumber(res, "aggtranstype");
13958  i_aggtransspace = PQfnumber(res, "aggtransspace");
13959  i_aggmtranstype = PQfnumber(res, "aggmtranstype");
13960  i_aggmtransspace = PQfnumber(res, "aggmtransspace");
13961  i_agginitval = PQfnumber(res, "agginitval");
13962  i_aggminitval = PQfnumber(res, "aggminitval");
13963  i_convertok = PQfnumber(res, "convertok");
13964  i_proparallel = PQfnumber(res, "proparallel");
13965 
13966  aggtransfn = PQgetvalue(res, 0, i_aggtransfn);
13967  aggfinalfn = PQgetvalue(res, 0, i_aggfinalfn);
13968  aggcombinefn = PQgetvalue(res, 0, i_aggcombinefn);
13969  aggserialfn = PQgetvalue(res, 0, i_aggserialfn);
13970  aggdeserialfn = PQgetvalue(res, 0, i_aggdeserialfn);
13971  aggmtransfn = PQgetvalue(res, 0, i_aggmtransfn);
13972  aggminvtransfn = PQgetvalue(res, 0, i_aggminvtransfn);
13973  aggmfinalfn = PQgetvalue(res, 0, i_aggmfinalfn);
13974  aggfinalextra = (PQgetvalue(res, 0, i_aggfinalextra)[0] == 't');
13975  aggmfinalextra = (PQgetvalue(res, 0, i_aggmfinalextra)[0] == 't');
13976  aggfinalmodify = PQgetvalue(res, 0, i_aggfinalmodify)[0];
13977  aggmfinalmodify = PQgetvalue(res, 0, i_aggmfinalmodify)[0];
13978  aggsortop = PQgetvalue(res, 0, i_aggsortop);
13979  aggkind = PQgetvalue(res, 0, i_aggkind)[0];
13980  aggtranstype = PQgetvalue(res, 0, i_aggtranstype);
13981  aggtransspace = PQgetvalue(res, 0, i_aggtransspace);
13982  aggmtranstype = PQgetvalue(res, 0, i_aggmtranstype);
13983  aggmtransspace = PQgetvalue(res, 0, i_aggmtransspace);
13984  agginitval = PQgetvalue(res, 0, i_agginitval);
13985  aggminitval = PQgetvalue(res, 0, i_aggminitval);
13986  convertok = (PQgetvalue(res, 0, i_convertok)[0] == 't');
13987 
13988  if (fout->remoteVersion >= 80400)
13989  {
13990  /* 8.4 or later; we rely on server-side code for most of the work */
13991  char *funcargs;
13992  char *funciargs;
13993 
13994  funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs"));
13995  funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs"));
13996  aggfullsig = format_function_arguments(&agginfo->aggfn, funcargs, true);
13997  aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true);
13998  }
13999  else
14000  /* pre-8.4, do it ourselves */
14001  aggsig = format_aggregate_signature(agginfo, fout, true);
14002 
14003  aggsig_tag = format_aggregate_signature(agginfo, fout, false);
14004 
14005  if (i_proparallel != -1)
14006  proparallel = PQgetvalue(res, 0, PQfnumber(res, "proparallel"));
14007  else
14008  proparallel = NULL;
14009 
14010  if (!convertok)
14011  {
14012  pg_log_warning("aggregate function %s could not be dumped correctly for this database version; ignored",
14013  aggsig);
14014 
14015  if (aggfullsig)
14016  free(aggfullsig);
14017 
14018  free(aggsig);
14019 
14020  return;
14021  }
14022 
14023  /* identify default modify flag for aggkind (must match DefineAggregate) */
14024  defaultfinalmodify = (aggkind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
14025  /* replace omitted flags for old versions */
14026  if (aggfinalmodify == '0')
14027  aggfinalmodify = defaultfinalmodify;
14028  if (aggmfinalmodify == '0')
14029  aggmfinalmodify = defaultfinalmodify;
14030 
14031  /* regproc and regtype output is already sufficiently quoted */
14032  appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
14033  aggtransfn, aggtranstype);
14034 
14035  if (strcmp(aggtransspace, "0") != 0)
14036  {
14037  appendPQExpBuffer(details, ",\n SSPACE = %s",
14038  aggtransspace);
14039  }
14040 
14041  if (!PQgetisnull(res, 0, i_agginitval))
14042  {
14043  appendPQExpBufferStr(details, ",\n INITCOND = ");
14044  appendStringLiteralAH(details, agginitval, fout);
14045  }
14046 
14047  if (strcmp(aggfinalfn, "-") != 0)
14048  {
14049  appendPQExpBuffer(details, ",\n FINALFUNC = %s",
14050  aggfinalfn);
14051  if (aggfinalextra)
14052  appendPQExpBufferStr(details, ",\n FINALFUNC_EXTRA");
14053  if (aggfinalmodify != defaultfinalmodify)
14054  {
14055  switch (aggfinalmodify)
14056  {
14057  case AGGMODIFY_READ_ONLY:
14058  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = READ_ONLY");
14059  break;
14060  case AGGMODIFY_SHAREABLE:
14061  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = SHAREABLE");
14062  break;
14063  case AGGMODIFY_READ_WRITE:
14064  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = READ_WRITE");
14065  break;
14066  default:
14067  fatal("unrecognized aggfinalmodify value for aggregate \"%s\"",
14068  agginfo->aggfn.dobj.name);
14069  break;
14070  }
14071  }
14072  }
14073 
14074  if (strcmp(aggcombinefn, "-") != 0)
14075  appendPQExpBuffer(details, ",\n COMBINEFUNC = %s", aggcombinefn);
14076 
14077  if (strcmp(aggserialfn, "-") != 0)
14078  appendPQExpBuffer(details, ",\n SERIALFUNC = %s", aggserialfn);
14079 
14080  if (strcmp(aggdeserialfn, "-") != 0)
14081  appendPQExpBuffer(details, ",\n DESERIALFUNC = %s", aggdeserialfn);
14082 
14083  if (strcmp(aggmtransfn, "-") != 0)
14084  {
14085  appendPQExpBuffer(details, ",\n MSFUNC = %s,\n MINVFUNC = %s,\n MSTYPE = %s",
14086  aggmtransfn,
14087  aggminvtransfn,
14088  aggmtranstype);
14089  }
14090 
14091  if (strcmp(aggmtransspace, "0") != 0)
14092  {
14093  appendPQExpBuffer(details, ",\n MSSPACE = %s",
14094  aggmtransspace);
14095  }
14096 
14097  if (!PQgetisnull(res, 0, i_aggminitval))
14098  {
14099  appendPQExpBufferStr(details, ",\n MINITCOND = ");
14100  appendStringLiteralAH(details, aggminitval, fout);
14101  }
14102 
14103  if (strcmp(aggmfinalfn, "-") != 0)
14104  {
14105  appendPQExpBuffer(details, ",\n MFINALFUNC = %s",
14106  aggmfinalfn);
14107  if (aggmfinalextra)
14108  appendPQExpBufferStr(details, ",\n MFINALFUNC_EXTRA");
14109  if (aggmfinalmodify != defaultfinalmodify)
14110  {
14111  switch (aggmfinalmodify)
14112  {
14113  case AGGMODIFY_READ_ONLY:
14114  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = READ_ONLY");
14115  break;
14116  case AGGMODIFY_SHAREABLE:
14117  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = SHAREABLE");
14118  break;
14119  case AGGMODIFY_READ_WRITE:
14120  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = READ_WRITE");
14121  break;
14122  default:
14123  fatal("unrecognized aggmfinalmodify value for aggregate \"%s\"",
14124  agginfo->aggfn.dobj.name);
14125  break;
14126  }
14127  }
14128  }
14129 
14130  aggsortconvop = getFormattedOperatorName(fout, aggsortop);
14131  if (aggsortconvop)
14132  {
14133  appendPQExpBuffer(details, ",\n SORTOP = %s",
14134  aggsortconvop);
14135  free(aggsortconvop);
14136  }
14137 
14138  if (aggkind == AGGKIND_HYPOTHETICAL)
14139  appendPQExpBufferStr(details, ",\n HYPOTHETICAL");
14140 
14141  if (proparallel != NULL && proparallel[0] != PROPARALLEL_UNSAFE)
14142  {
14143  if (proparallel[0] == PROPARALLEL_SAFE)
14144  appendPQExpBufferStr(details, ",\n PARALLEL = safe");
14145  else if (proparallel[0] == PROPARALLEL_RESTRICTED)
14146  appendPQExpBufferStr(details, ",\n PARALLEL = restricted");
14147  else if (proparallel[0] != PROPARALLEL_UNSAFE)
14148  fatal("unrecognized proparallel value for function \"%s\"",
14149  agginfo->aggfn.dobj.name);
14150  }
14151 
14152  appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n",
14153  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
14154  aggsig);
14155 
14156  appendPQExpBuffer(q, "CREATE AGGREGATE %s.%s (\n%s\n);\n",
14157  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
14158  aggfullsig ? aggfullsig : aggsig, details->data);
14159 
14160  if (dopt->binary_upgrade)
14162  "AGGREGATE", aggsig,
14163  agginfo->aggfn.dobj.namespace->dobj.name);
14164 
14165  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_DEFINITION)
14166  ArchiveEntry(fout, agginfo->aggfn.dobj.catId,
14167  agginfo->aggfn.dobj.dumpId,
14168  ARCHIVE_OPTS(.tag = aggsig_tag,
14169  .namespace = agginfo->aggfn.dobj.namespace->dobj.name,
14170  .owner = agginfo->aggfn.rolname,
14171  .description = "AGGREGATE",
14172  .section = SECTION_PRE_DATA,
14173  .createStmt = q->data,
14174  .dropStmt = delq->data));
14175 
14176  /* Dump Aggregate Comments */
14177  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_COMMENT)
14178  dumpComment(fout, "AGGREGATE", aggsig,
14179  agginfo->aggfn.dobj.namespace->dobj.name,
14180  agginfo->aggfn.rolname,
14181  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
14182 
14183  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_SECLABEL)
14184  dumpSecLabel(fout, "AGGREGATE", aggsig,
14185  agginfo->aggfn.dobj.namespace->dobj.name,
14186  agginfo->aggfn.rolname,
14187  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
14188 
14189  /*
14190  * Since there is no GRANT ON AGGREGATE syntax, we have to make the ACL
14191  * command look like a function's GRANT; in particular this affects the
14192  * syntax for zero-argument aggregates and ordered-set aggregates.
14193  */
14194  free(aggsig);
14195 
14196  aggsig = format_function_signature(fout, &agginfo->aggfn, true);
14197 
14198  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_ACL)
14199  dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
14200  "FUNCTION", aggsig, NULL,
14201  agginfo->aggfn.dobj.namespace->dobj.name,
14202  agginfo->aggfn.rolname, agginfo->aggfn.proacl,
14203  agginfo->aggfn.rproacl,
14204  agginfo->aggfn.initproacl, agginfo->aggfn.initrproacl);
14205 
14206  free(aggsig);
14207  if (aggfullsig)
14208  free(aggfullsig);
14209  free(aggsig_tag);
14210 
14211  PQclear(res);
14212 
14213  destroyPQExpBuffer(query);
14214  destroyPQExpBuffer(q);
14215  destroyPQExpBuffer(delq);
14216  destroyPQExpBuffer(details);
14217 }
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
char * initrproacl
Definition: pg_dump.h:204
DumpableObject dobj
Definition: pg_dump.h:195
DumpId dumpId
Definition: pg_dump.h:129
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:14997
static char * format_function_arguments(FuncInfo *finfo, char *funcargs, bool is_agg)
Definition: pg_dump.c:11493
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:14910
FuncInfo aggfn
Definition: pg_dump.h:210
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:418
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:291
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
char * initproacl
Definition: pg_dump.h:203
static char * format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11588
char * rolname
Definition: pg_dump.h:196
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:92
#define fatal(...)
char * proacl
Definition: pg_dump.h:201
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4473
char * rproacl
Definition: pg_dump.h:202
static char * getFormattedOperatorName(Archive *fout, const char *oproid)
Definition: pg_dump.c:12707
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
#define pg_log_warning(...)
Definition: pgfnames.c:24
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3189
static char * format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
Definition: pg_dump.c:13709
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:9506
int remoteVersion
Definition: pg_backup.h:187

◆ dumpAttrDef()

static void dumpAttrDef ( Archive fout,
AttrDefInfo adinfo 
)
static

Definition at line 16270 of file pg_dump.c.

References _attrDefInfo::adef_expr, _attrDefInfo::adnum, _attrDefInfo::adtable, appendPQExpBuffer(), ARCHIVE_OPTS, 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().

16271 {
16272  DumpOptions *dopt = fout->dopt;
16273  TableInfo *tbinfo = adinfo->adtable;
16274  int adnum = adinfo->adnum;
16275  PQExpBuffer q;
16276  PQExpBuffer delq;
16277  char *qualrelname;
16278  char *tag;
16279 
16280  /* Skip if table definition not to be dumped */
16281  if (!tbinfo->dobj.dump || dopt->dataOnly)
16282  return;
16283 
16284  /* Skip if not "separate"; it was dumped in the table's definition */
16285  if (!adinfo->separate)
16286  return;
16287 
16288  q = createPQExpBuffer();
16289  delq = createPQExpBuffer();
16290 
16291  qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo));
16292 
16293  appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
16294  qualrelname);
16295  appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n",
16296  fmtId(tbinfo->attnames[adnum - 1]),
16297  adinfo->adef_expr);
16298 
16299  appendPQExpBuffer(delq, "ALTER TABLE %s ",
16300  qualrelname);
16301  appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n",
16302  fmtId(tbinfo->attnames[adnum - 1]));
16303 
16304  tag = psprintf("%s %s", tbinfo->dobj.name, tbinfo->attnames[adnum - 1]);
16305 
16306  if (adinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16307  ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
16308  ARCHIVE_OPTS(.tag = tag,
16309  .namespace = tbinfo->dobj.namespace->dobj.name,
16310  .owner = tbinfo->rolname,
16311  .description = "DEFAULT",
16312  .section = SECTION_PRE_DATA,
16313  .createStmt = q->data,
16314  .dropStmt = delq->data));
16315 
16316  free(tag);
16317  destroyPQExpBuffer(q);
16318  destroyPQExpBuffer(delq);
16319  free(qualrelname);
16320 }
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
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:259
DumpId dumpId
Definition: pg_dump.h:129
char ** attnames
Definition: pg_dump.h:301
DumpableObject dobj
Definition: pg_dump.h:258
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
bool separate
Definition: pg_dump.h:344
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
TableInfo * adtable
Definition: pg_dump.h:341
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
DumpableObject dobj
Definition: pg_dump.h:340
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:149
CatalogId catId
Definition: pg_dump.h:128
char * adef_expr
Definition: pg_dump.h:343

◆ dumpBaseType()

static void dumpBaseType ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10532 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, 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, _typeInfo::typelem, and zeroAsOpaque.

Referenced by dumpType().

10533 {
10534  DumpOptions *dopt = fout->dopt;
10536  PQExpBuffer delq = createPQExpBuffer();
10537  PQExpBuffer query = createPQExpBuffer();
10538  PGresult *res;
10539  char *qtypname;
10540  char *qualtypname;
10541  char *typlen;
10542  char *typinput;
10543  char *typoutput;
10544  char *typreceive;
10545  char *typsend;
10546  char *typmodin;
10547  char *typmodout;
10548  char *typanalyze;
10549  Oid typreceiveoid;
10550  Oid typsendoid;
10551  Oid typmodinoid;
10552  Oid typmodoutoid;
10553  Oid typanalyzeoid;
10554  char *typcategory;
10555  char *typispreferred;
10556  char *typdelim;
10557  char *typbyval;
10558  char *typalign;
10559  char *typstorage;
10560  char *typcollatable;
10561  char *typdefault;
10562  bool typdefault_is_literal = false;
10563 
10564  /* Fetch type-specific details */
10565  if (fout->remoteVersion >= 90100)
10566  {
10567  appendPQExpBuffer(query, "SELECT typlen, "
10568  "typinput, typoutput, typreceive, typsend, "
10569  "typmodin, typmodout, typanalyze, "
10570  "typreceive::pg_catalog.oid AS typreceiveoid, "
10571  "typsend::pg_catalog.oid AS typsendoid, "
10572  "typmodin::pg_catalog.oid AS typmodinoid, "
10573  "typmodout::pg_catalog.oid AS typmodoutoid, "
10574  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10575  "typcategory, typispreferred, "
10576  "typdelim, typbyval, typalign, typstorage, "
10577  "(typcollation <> 0) AS typcollatable, "
10578  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10579  "FROM pg_catalog.pg_type "
10580  "WHERE oid = '%u'::pg_catalog.oid",
10581  tyinfo->dobj.catId.oid);
10582  }
10583  else if (fout->remoteVersion >= 80400)
10584  {
10585  appendPQExpBuffer(query, "SELECT typlen, "
10586  "typinput, typoutput, typreceive, typsend, "
10587  "typmodin, typmodout, typanalyze, "
10588  "typreceive::pg_catalog.oid AS typreceiveoid, "
10589  "typsend::pg_catalog.oid AS typsendoid, "
10590  "typmodin::pg_catalog.oid AS typmodinoid, "
10591  "typmodout::pg_catalog.oid AS typmodoutoid, "
10592  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10593  "typcategory, typispreferred, "
10594  "typdelim, typbyval, typalign, typstorage, "
10595  "false AS typcollatable, "
10596  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10597  "FROM pg_catalog.pg_type "
10598  "WHERE oid = '%u'::pg_catalog.oid",
10599  tyinfo->dobj.catId.oid);
10600  }
10601  else if (fout->remoteVersion >= 80300)
10602  {
10603  /* Before 8.4, pg_get_expr does not allow 0 for its second arg */
10604  appendPQExpBuffer(query, "SELECT typlen, "
10605  "typinput, typoutput, typreceive, typsend, "
10606  "typmodin, typmodout, typanalyze, "
10607  "typreceive::pg_catalog.oid AS typreceiveoid, "
10608  "typsend::pg_catalog.oid AS typsendoid, "
10609  "typmodin::pg_catalog.oid AS typmodinoid, "
10610  "typmodout::pg_catalog.oid AS typmodoutoid, "
10611  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10612  "'U' AS typcategory, false AS typispreferred, "
10613  "typdelim, typbyval, typalign, typstorage, "
10614  "false AS typcollatable, "
10615  "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10616  "FROM pg_catalog.pg_type "
10617  "WHERE oid = '%u'::pg_catalog.oid",
10618  tyinfo->dobj.catId.oid);
10619  }
10620  else
10621  {
10622  appendPQExpBuffer(query, "SELECT typlen, "
10623  "typinput, typoutput, typreceive, typsend, "
10624  "'-' AS typmodin, '-' AS typmodout, "
10625  "typanalyze, "
10626  "typreceive::pg_catalog.oid AS typreceiveoid, "
10627  "typsend::pg_catalog.oid AS typsendoid, "
10628  "0 AS typmodinoid, 0 AS typmodoutoid, "
10629  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10630  "'U' AS typcategory, false AS typispreferred, "
10631  "typdelim, typbyval, typalign, typstorage, "
10632  "false AS typcollatable, "
10633  "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10634  "FROM pg_catalog.pg_type "
10635  "WHERE oid = '%u'::pg_catalog.oid",
10636  tyinfo->dobj.catId.oid);
10637  }
10638 
10639  res = ExecuteSqlQueryForSingleRow(fout, query->data);
10640 
10641  typlen = PQgetvalue(res, 0, PQfnumber(res, "typlen"));
10642  typinput = PQgetvalue(res, 0, PQfnumber(res, "typinput"));
10643  typoutput = PQgetvalue(res, 0, PQfnumber(res, "typoutput"));
10644  typreceive = PQgetvalue(res, 0, PQfnumber(res, "typreceive"));
10645  typsend = PQgetvalue(res, 0, PQfnumber(res, "typsend"));
10646  typmodin = PQgetvalue(res, 0, PQfnumber(res, "typmodin"));
10647  typmodout = PQgetvalue(res, 0, PQfnumber(res, "typmodout"));
10648  typanalyze = PQgetvalue(res, 0, PQfnumber(res, "typanalyze"));
10649  typreceiveoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typreceiveoid")));
10650  typsendoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typsendoid")));
10651  typmodinoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodinoid")));
10652  typmodoutoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodoutoid")));
10653  typanalyzeoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typanalyzeoid")));
10654  typcategory = PQgetvalue(res, 0, PQfnumber(res, "typcategory"));
10655  typispreferred = PQgetvalue(res, 0, PQfnumber(res, "typispreferred"));
10656  typdelim = PQgetvalue(res, 0, PQfnumber(res, "typdelim"));
10657  typbyval = PQgetvalue(res, 0, PQfnumber(res, "typbyval"));
10658  typalign = PQgetvalue(res, 0, PQfnumber(res, "typalign"));
10659  typstorage = PQgetvalue(res, 0, PQfnumber(res, "typstorage"));
10660  typcollatable = PQgetvalue(res, 0, PQfnumber(res, "typcollatable"));
10661  if (!PQgetisnull(res, 0, PQfnumber(res, "typdefaultbin")))
10662  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefaultbin"));
10663  else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
10664  {
10665  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault"));
10666  typdefault_is_literal = true; /* it needs quotes */
10667  }
10668  else
10669  typdefault = NULL;
10670 
10671  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
10672  qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo));
10673 
10674  /*
10675  * The reason we include CASCADE is that the circular dependency between
10676  * the type and its I/O functions makes it impossible to drop the type any
10677  * other way.
10678  */
10679  appendPQExpBuffer(delq, "DROP TYPE %s CASCADE;\n", qualtypname);
10680 
10681  /*
10682  * We might already have a shell type, but setting pg_type_oid is
10683  * harmless, and in any case we'd better set the array type OID.
10684  */
10685  if (dopt->binary_upgrade)
10687  tyinfo->dobj.catId.oid,
10688  false);
10689 
10691  "CREATE TYPE %s (\n"
10692  " INTERNALLENGTH = %s",
10693  qualtypname,
10694  (strcmp(typlen, "-1") == 0) ? "variable" : typlen);
10695 
10696  /* regproc result is sufficiently quoted already */
10697  appendPQExpBuffer(q, ",\n INPUT = %s", typinput);
10698  appendPQExpBuffer(q, ",\n OUTPUT = %s", typoutput);
10699  if (OidIsValid(typreceiveoid))
10700  appendPQExpBuffer(q, ",\n RECEIVE = %s", typreceive);
10701  if (OidIsValid(typsendoid))
10702  appendPQExpBuffer(q, ",\n SEND = %s", typsend);
10703  if (OidIsValid(typmodinoid))
10704  appendPQExpBuffer(q, ",\n TYPMOD_IN = %s", typmodin);
10705  if (OidIsValid(typmodoutoid))
10706  appendPQExpBuffer(q, ",\n TYPMOD_OUT = %s", typmodout);
10707  if (OidIsValid(typanalyzeoid))
10708  appendPQExpBuffer(q, ",\n ANALYZE = %s", typanalyze);
10709 
10710  if (strcmp(typcollatable, "t") == 0)
10711  appendPQExpBufferStr(q, ",\n COLLATABLE = true");
10712 
10713  if (typdefault != NULL)
10714  {
10715  appendPQExpBufferStr(q, ",\n DEFAULT = ");
10716  if (typdefault_is_literal)
10717  appendStringLiteralAH(q, typdefault, fout);
10718  else
10719  appendPQExpBufferStr(q, typdefault);
10720  }
10721 
10722  if (OidIsValid(tyinfo->typelem))
10723  {
10724  char *elemType;
10725 
10726  elemType = getFormattedTypeName(fout, tyinfo->typelem, zeroAsOpaque);
10727  appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType);
10728  free(elemType);
10729  }
10730 
10731  if (strcmp(typcategory, "U") != 0)
10732  {
10733  appendPQExpBufferStr(q, ",\n CATEGORY = ");
10734  appendStringLiteralAH(q, typcategory, fout);
10735  }
10736 
10737  if (strcmp(typispreferred, "t") == 0)
10738  appendPQExpBufferStr(q, ",\n PREFERRED = true");
10739 
10740  if (typdelim && strcmp(typdelim, ",") != 0)
10741  {
10742  appendPQExpBufferStr(q, ",\n DELIMITER = ");
10743  appendStringLiteralAH(q, typdelim, fout);
10744  }
10745 
10746  if (strcmp(typalign, "c") == 0)
10747  appendPQExpBufferStr(q, ",\n ALIGNMENT = char");
10748  else if (strcmp(typalign, "s") == 0)
10749  appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
10750  else if (strcmp(typalign, "i") == 0)
10751  appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
10752  else if (strcmp(typalign, "d") == 0)
10753  appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
10754 
10755  if (strcmp(typstorage, "p") == 0)
10756  appendPQExpBufferStr(q, ",\n STORAGE = plain");
10757  else if (strcmp(typstorage, "e") == 0)
10758  appendPQExpBufferStr(q, ",\n STORAGE = external");
10759  else if (strcmp(typstorage, "x") == 0)
10760  appendPQExpBufferStr(q, ",\n STORAGE = extended");
10761  else if (strcmp(typstorage, "m") == 0)
10762  appendPQExpBufferStr(q, ",\n STORAGE = main");
10763 
10764  if (strcmp(typbyval, "t") == 0)
10765  appendPQExpBufferStr(q, ",\n PASSEDBYVALUE");
10766 
10767  appendPQExpBufferStr(q, "\n);\n");
10768 
10769  if (dopt->binary_upgrade)
10771  "TYPE", qtypname,
10772  tyinfo->dobj.namespace->dobj.name);
10773 
10774  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
10775  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
10776  ARCHIVE_OPTS(.tag = tyinfo->dobj.name,
10777  .namespace = tyinfo->dobj.namespace->dobj.name,
10778  .owner = tyinfo->rolname,
10779  .description = "TYPE",
10780  .section = SECTION_PRE_DATA,
10781  .createStmt = q->data,
10782  .dropStmt = delq->data));
10783 
10784  /* Dump Type Comments and Security Labels */
10785  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10786  dumpComment(fout, "TYPE", qtypname,
10787  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10788  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10789 
10790  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
10791  dumpSecLabel(fout, "TYPE", qtypname,
10792  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10793  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10794 
10795  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
10796  dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
10797  qtypname, NULL,
10798  tyinfo->dobj.namespace->dobj.name,
10799  tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl,
10800  tyinfo->inittypacl, tyinfo->initrtypacl);
10801 
10802  PQclear(res);
10803  destroyPQExpBuffer(q);
10804  destroyPQExpBuffer(delq);
10805  destroyPQExpBuffer(query);
10806  free(qtypname);
10807  free(qualtypname);
10808 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:18347
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
char * inittypacl
Definition: pg_dump.h:171
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
char * initrtypacl
Definition: pg_dump.h:172
char * typacl
Definition: pg_dump.h:169
DumpId dumpId
Definition: pg_dump.h:129
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:14997
#define OidIsValid(objectId)
Definition: c.h:638
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:14910
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:418
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
char typalign
Definition: pg_type.h:170
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
Oid typelem
Definition: pg_dump.h:173
#define atooid(x)
Definition: postgres_ext.h:42
DumpableObject dobj
Definition: pg_dump.h:162
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:4282
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:291
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:149
char * rtypacl
Definition: pg_dump.h:170
char * rolname
Definition: pg_dump.h:168
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:92
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4473
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3189
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:9506
int remoteVersion
Definition: pg_backup.h:187

◆ dumpBlob()

static void dumpBlob ( Archive fout,
BlobInfo binfo 
)
static

Definition at line 3382 of file pg_dump.c.

References appendPQExpBuffer(), ARCHIVE_OPTS, 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().

3383 {
3384  PQExpBuffer cquery = createPQExpBuffer();
3385  PQExpBuffer dquery = createPQExpBuffer();
3386 
3387  appendPQExpBuffer(cquery,
3388  "SELECT pg_catalog.lo_create('%s');\n",
3389  binfo->dobj.name);
3390 
3391  appendPQExpBuffer(dquery,
3392  "SELECT pg_catalog.lo_unlink('%s');\n",
3393  binfo->dobj.name);
3394 
3395  if (binfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
3396  ArchiveEntry(fout, binfo->dobj.catId, binfo->dobj.dumpId,
3397  ARCHIVE_OPTS(.tag = binfo->dobj.name,
3398  .owner = binfo->rolname,
3399  .description = "BLOB",
3400  .section = SECTION_PRE_DATA,
3401  .createStmt = cquery->data,
3402  .dropStmt = dquery->data));
3403 
3404  /* Dump comment if any */
3405  if (binfo->dobj.dump & DUMP_COMPONENT_COMMENT)
3406  dumpComment(fout, "LARGE OBJECT", binfo->dobj.name,
3407  NULL, binfo->rolname,
3408  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3409 
3410  /* Dump security label if any */
3411  if (binfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
3412  dumpSecLabel(fout, "LARGE OBJECT", binfo->dobj.name,
3413  NULL, binfo->rolname,
3414  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3415 
3416  /* Dump ACL if any */
3417  if (binfo->blobacl && (binfo->dobj.dump & DUMP_COMPONENT_ACL))
3418  dumpACL(fout, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT",
3419  binfo->dobj.name, NULL,
3420  NULL, binfo->rolname, binfo->blobacl, binfo->rblobacl,
3421  binfo->initblobacl, binfo->initrblobacl);
3422 
3423  destroyPQExpBuffer(cquery);
3424  destroyPQExpBuffer(dquery);
3425 }
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
DumpId dumpId
Definition: pg_dump.h:129
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:14997
char * initblobacl
Definition: pg_dump.h:569
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:14910
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
DumpableObject dobj
Definition: pg_dump.h:565
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
char * rolname
Definition: pg_dump.h:566
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:92
char * blobacl
Definition: pg_dump.h:567
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
char * rblobacl
Definition: pg_dump.h:568
char * initrblobacl
Definition: pg_dump.h:570
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:9506

◆ dumpBlobs()

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

Definition at line 3432 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

3433 {
3434  const char *blobQry;
3435  const char *blobFetchQry;
3436  PGconn *conn = GetConnection(fout);
3437  PGresult *res;
3438  char buf[LOBBUFSIZE];
3439  int ntups;
3440  int i;
3441  int cnt;
3442 
3443  pg_log_info("saving large objects");
3444 
3445  /*
3446  * Currently, we re-fetch all BLOB OIDs using a cursor. Consider scanning
3447  * the already-in-memory dumpable objects instead...
3448  */
3449  if (fout->remoteVersion >= 90000)
3450  blobQry =
3451  "DECLARE bloboid CURSOR FOR "
3452  "SELECT oid FROM pg_largeobject_metadata ORDER BY 1";
3453  else
3454  blobQry =
3455  "DECLARE bloboid CURSOR FOR "
3456  "SELECT DISTINCT loid FROM pg_largeobject ORDER BY 1";
3457 
3458  ExecuteSqlStatement(fout, blobQry);
3459 
3460  /* Command to fetch from cursor */
3461  blobFetchQry = "FETCH 1000 IN bloboid";
3462 
3463  do
3464  {
3465  /* Do a fetch */
3466  res = ExecuteSqlQuery(fout, blobFetchQry, PGRES_TUPLES_OK);
3467 
3468  /* Process the tuples, if any */
3469  ntups = PQntuples(res);
3470  for (i = 0; i < ntups; i++)
3471  {
3472  Oid blobOid;
3473  int loFd;
3474 
3475  blobOid = atooid(PQgetvalue(res, i, 0));
3476  /* Open the BLOB */
3477  loFd = lo_open(conn, blobOid, INV_READ);
3478  if (loFd == -1)
3479  fatal("could not open large object %u: %s",
3480  blobOid, PQerrorMessage(conn));
3481 
3482  StartBlob(fout, blobOid);
3483 
3484  /* Now read it in chunks, sending data to archive */
3485  do
3486  {
3487  cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
3488  if (cnt < 0)
3489  fatal("error reading large object %u: %s",
3490  blobOid, PQerrorMessage(conn));
3491 
3492  WriteData(fout, buf, cnt);
3493  } while (cnt > 0);
3494 
3495  lo_close(conn, loFd);
3496 
3497  EndBlob(fout, blobOid);
3498  }
3499 
3500  PQclear(res);
3501  } while (ntups > 0);
3502 
3503  return 1;
3504 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6596
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2770
#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:56
static char * buf
Definition: pg_test_fsync.c:68
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:695
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt)
Definition: connection.c:107
void ExecuteSqlStatement(Archive *AHX, const char *query)
Definition: pg_backup_db.c:391
#define fatal(...)
int EndBlob(Archive *AH, Oid oid)
int i
#define LOBBUFSIZE
#define pg_log_info(...)
Definition: logging.h:87
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:403
int remoteVersion
Definition: pg_backup.h:187

◆ dumpCast()

static void dumpCast ( Archive fout,
CastInfo cast 
)
static

Definition at line 12209 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), ARCHIVE_OPTS, 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, fatal, findFuncByOid(), fmtId(), format_function_signature(), free, getFormattedTypeName(), _dumpableObject::name, OidIsValid, pg_log_warning, SECTION_PRE_DATA, and zeroAsNone.

Referenced by dumpDumpableObject().

12210 {
12211  DumpOptions *dopt = fout->dopt;
12212  PQExpBuffer defqry;
12213  PQExpBuffer delqry;
12214  PQExpBuffer labelq;
12215  PQExpBuffer castargs;
12216  FuncInfo *funcInfo = NULL;
12217  char *sourceType;
12218  char *targetType;
12219 
12220  /* Skip if not to be dumped */
12221  if (!cast->dobj.dump || dopt->dataOnly)
12222  return;
12223 
12224  /* Cannot dump if we don't have the cast function's info */
12225  if (OidIsValid(cast->castfunc))
12226  {
12227  funcInfo = findFuncByOid(cast->castfunc);
12228  if (funcInfo == NULL)
12229  fatal("could not find function definition for function with OID %u",
12230  cast->castfunc);
12231  }
12232 
12233  defqry = createPQExpBuffer();
12234  delqry = createPQExpBuffer();
12235  labelq = createPQExpBuffer();
12236  castargs = createPQExpBuffer();
12237 
12238  sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone);
12239  targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone);
12240  appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
12241  sourceType, targetType);
12242 
12243  appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
12244  sourceType, targetType);
12245 
12246  switch (cast->castmethod)
12247  {
12248  case COERCION_METHOD_BINARY:
12249  appendPQExpBufferStr(defqry, "WITHOUT FUNCTION");
12250  break;
12251  case COERCION_METHOD_INOUT:
12252  appendPQExpBufferStr(defqry, "WITH INOUT");
12253  break;
12254  case COERCION_METHOD_FUNCTION:
12255  if (funcInfo)
12256  {
12257  char *fsig = format_function_signature(fout, funcInfo, true);
12258 
12259  /*
12260  * Always qualify the function name (format_function_signature
12261  * won't qualify it).
12262  */
12263  appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
12264  fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
12265  free(fsig);
12266  }
12267  else
12268  pg_log_warning("bogus value in pg_cast.castfunc or pg_cast.castmethod field");
12269  break;
12270  default:
12271  pg_log_warning("bogus value in pg_cast.castmethod field");
12272  }
12273 
12274  if (cast->castcontext == 'a')
12275  appendPQExpBufferStr(defqry, " AS ASSIGNMENT");
12276  else if (cast->castcontext == 'i')
12277  appendPQExpBufferStr(defqry, " AS IMPLICIT");
12278  appendPQExpBufferStr(defqry, ";\n");
12279 
12280  appendPQExpBuffer(labelq, "CAST (%s AS %s)",
12281  sourceType, targetType);
12282 
12283  appendPQExpBuffer(castargs, "(%s AS %s)",
12284  sourceType, targetType);
12285 
12286  if (dopt->binary_upgrade)
12287  binary_upgrade_extension_member(defqry, &cast->dobj,
12288  "CAST", castargs->data, NULL);
12289 
12290  if (cast->dobj.dump & DUMP_COMPONENT_DEFINITION)
12291  ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
12292  ARCHIVE_OPTS(.tag = labelq->data,
12293  .description = "CAST",
12294  .section = SECTION_PRE_DATA,
12295  .createStmt = defqry->data,
12296  .dropStmt = delqry->data));
12297 
12298  /* Dump Cast Comments */
12299  if (cast->dobj.dump & DUMP_COMPONENT_COMMENT)
12300  dumpComment(fout, "CAST", castargs->data,
12301  NULL, "",
12302  cast->dobj.catId, 0, cast->dobj.dumpId);
12303 
12304  free(sourceType);
12305  free(targetType);
12306 
12307  destroyPQExpBuffer(defqry);
12308  destroyPQExpBuffer(delqry);
12309  destroyPQExpBuffer(labelq);
12310  destroyPQExpBuffer(castargs);
12311 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:18347
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
Oid castsource
Definition: pg_dump.h:470
DumpComponents dump
Definition: pg_dump.h:131
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
DumpableObject dobj
Definition: pg_dump.h:195
DumpId dumpId
Definition: pg_dump.h:129
Oid castfunc
Definition: pg_dump.h:472
#define OidIsValid(objectId)
Definition: c.h:638
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpableObject dobj
Definition: pg_dump.h:469
Oid casttarget
Definition: pg_dump.h:471
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
FuncInfo * findFuncByOid(Oid oid)
Definition: common.c:852
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
static char * format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11588
#define fatal(...)
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4473
CatalogId catId
Definition: pg_dump.h:128
char castmethod
Definition: pg_dump.h:474
#define pg_log_warning(...)
Definition: pgfnames.c:24
char castcontext
Definition: pg_dump.h:473
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:9506

◆ dumpCollation()

static void dumpCollation ( Archive fout,
CollInfo collinfo 
)
static

Definition at line 13462 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, 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(), fatal, fmtId(), fmtQualifiedDumpable, free, _dumpableObject::name, CatalogId::oid, pg_strdup(), PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), Archive::remoteVersion, _collInfo::rolname, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

13463 {
13464  DumpOptions *dopt = fout->dopt;
13465  PQExpBuffer query;
13466  PQExpBuffer q;
13467  PQExpBuffer delq;
13468  char *qcollname;
13469  PGresult *res;
13470  int i_collprovider;
13471  int i_collisdeterministic;
13472  int i_collcollate;
13473  int i_collctype;
13474  const char *collprovider;
13475  const char *collcollate;
13476  const char *collctype;
13477 
13478  /* Skip if not to be dumped */
13479  if (!collinfo->dobj.dump || dopt->dataOnly)
13480  return;
13481 
13482  query = createPQExpBuffer();
13483  q = createPQExpBuffer();
13484  delq = createPQExpBuffer();
13485 
13486  qcollname = pg_strdup(fmtId(collinfo->dobj.name));
13487 
13488  /* Get collation-specific details */
13489  appendPQExpBufferStr(query, "SELECT ");
13490 
13491  if (fout->remoteVersion >= 100000)
13492  appendPQExpBufferStr(query,
13493  "collprovider, "
13494  "collversion, ");
13495  else
13496  appendPQExpBufferStr(query,
13497  "'c' AS collprovider, "
13498  "NULL AS collversion, ");
13499 
13500  if (fout->remoteVersion >= 120000)
13501  appendPQExpBufferStr(query,
13502  "collisdeterministic, ");
13503  else
13504  appendPQExpBufferStr(query,
13505  "true AS collisdeterministic, ");
13506 
13507  appendPQExpBuffer(query,
13508  "collcollate, "
13509  "collctype "
13510  "FROM pg_catalog.pg_collation c "
13511  "WHERE c.oid = '%u'::pg_catalog.oid",
13512  collinfo->dobj.catId.oid);
13513 
13514  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13515 
13516  i_collprovider = PQfnumber(res, "collprovider");
13517  i_collisdeterministic = PQfnumber(res, "collisdeterministic");
13518  i_collcollate = PQfnumber(res, "collcollate");
13519  i_collctype = PQfnumber(res, "collctype");
13520 
13521  collprovider = PQgetvalue(res, 0, i_collprovider);
13522  collcollate = PQgetvalue(res, 0, i_collcollate);
13523  collctype = PQgetvalue(res, 0, i_collctype);
13524 
13525  appendPQExpBuffer(delq, "DROP COLLATION %s;\n",
13526  fmtQualifiedDumpable(collinfo));
13527 
13528  appendPQExpBuffer(q, "CREATE COLLATION %s (",
13529  fmtQualifiedDumpable(collinfo));
13530 
13531  appendPQExpBufferStr(q, "provider = ");
13532  if (collprovider[0] == 'c')
13533  appendPQExpBufferStr(q, "libc");
13534  else if (collprovider[0] == 'i')
13535  appendPQExpBufferStr(q, "icu");
13536  else if (collprovider[0] == 'd')
13537  /* to allow dumping pg_catalog; not accepted on input */
13538  appendPQExpBufferStr(q, "default");
13539  else
13540  fatal("unrecognized collation provider: %s",
13541  collprovider);
13542 
13543  if (strcmp(PQgetvalue(res, 0, i_collisdeterministic), "f") == 0)
13544  appendPQExpBufferStr(q, ", deterministic = false");
13545 
13546  if (strcmp(collcollate, collctype) == 0)
13547  {
13548  appendPQExpBufferStr(q, ", locale = ");
13549  appendStringLiteralAH(q, collcollate, fout);
13550  }
13551  else
13552  {
13553  appendPQExpBufferStr(q, ", lc_collate = ");
13554  appendStringLiteralAH(q, collcollate, fout);
13555  appendPQExpBufferStr(q, ", lc_ctype = ");
13556  appendStringLiteralAH(q, collctype, fout);
13557  }
13558 
13559  /*
13560  * For binary upgrade, carry over the collation version. For normal
13561  * dump/restore, omit the version, so that it is computed upon restore.
13562  */
13563  if (dopt->binary_upgrade)
13564  {
13565  int i_collversion;
13566 
13567  i_collversion = PQfnumber(res, "collversion");
13568  if (!PQgetisnull(res, 0, i_collversion))
13569  {
13570  appendPQExpBufferStr(q, ", version = ");
13572  PQgetvalue(res, 0, i_collversion),
13573  fout);
13574  }
13575  }
13576 
13577  appendPQExpBufferStr(q, ");\n");
13578 
13579  if (dopt->binary_upgrade)
13580  binary_upgrade_extension_member(q, &collinfo->dobj,
13581  "COLLATION", qcollname,
13582  collinfo->dobj.namespace->dobj.name);
13583 
13584  if (collinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13585  ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId,
13586  ARCHIVE_OPTS(.tag = collinfo->dobj.name,
13587  .namespace = collinfo->dobj.namespace->dobj.name,
13588  .owner = collinfo->rolname,
13589  .description = "COLLATION",
13590  .section = SECTION_PRE_DATA,
13591  .createStmt = q->data,
13592  .dropStmt = delq->data));
13593 
13594  /* Dump Collation Comments */
13595  if (collinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13596  dumpComment(fout, "COLLATION", qcollname,
13597  collinfo->dobj.namespace->dobj.name, collinfo->rolname,
13598  collinfo->dobj.catId, 0, collinfo->dobj.dumpId);
13599 
13600  PQclear(res);
13601 
13602  destroyPQExpBuffer(query);
13603  destroyPQExpBuffer(q);
13604  destroyPQExpBuffer(delq);
13605  free(qcollname);
13606 }
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
DumpId dumpId
Definition: pg_dump.h:129
DumpableObject dobj
Definition: pg_dump.h:243
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:418
char * rolname
Definition: pg_dump.h:244
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:291
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:149
#define fatal(...)
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4473
CatalogId catId
Definition: pg_dump.h:128
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3189
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:9506
int remoteVersion
Definition: pg_backup.h:187

◆ 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 9506 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, 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().

9509 {
9510  DumpOptions *dopt = fout->dopt;
9511  CommentItem *comments;
9512  int ncomments;
9513 
9514  /* do nothing, if --no-comments is supplied */
9515  if (dopt->no_comments)
9516  return;
9517 
9518  /* Comments are schema not data ... except blob comments are data */
9519  if (strcmp(type, "LARGE OBJECT") != 0)
9520  {
9521  if (dopt->dataOnly)
9522  return;
9523  }
9524  else
9525  {
9526  /* We do dump blob comments in binary-upgrade mode */
9527  if (dopt->schemaOnly && !dopt->binary_upgrade)
9528  return;
9529  }
9530 
9531  /* Search for comments associated with catalogId, using table */
9532  ncomments = findComments(fout, catalogId.tableoid, catalogId.oid,
9533  &comments);
9534 
9535  /* Is there one matching the subid? */
9536  while (ncomments > 0)
9537  {
9538  if (comments->objsubid == subid)
9539  break;
9540  comments++;
9541  ncomments--;
9542  }
9543 
9544  /* If a comment exists, build COMMENT ON statement */
9545  if (ncomments > 0)
9546  {
9547  PQExpBuffer query = createPQExpBuffer();
9549 
9550  appendPQExpBuffer(query, "COMMENT ON %s ", type);
9551  if (namespace && *namespace)
9552  appendPQExpBuffer(query, "%s.", fmtId(namespace));
9553  appendPQExpBuffer(query, "%s IS ", name);
9554  appendStringLiteralAH(query, comments->descr, fout);
9555  appendPQExpBufferStr(query, ";\n");
9556 
9557  appendPQExpBuffer(tag, "%s %s", type, name);
9558 
9559  /*
9560  * We mark comments as SECTION_NONE because they really belong in the
9561  * same section as their parent, whether that is pre-data or
9562  * post-data.
9563  */
9565  ARCHIVE_OPTS(.tag = tag->data,
9566  .namespace = namespace,
9567  .owner = owner,
9568  .description = "COMMENT",
9569  .section = SECTION_NONE,
9570  .createStmt = query->data,
9571  .deps = &dumpId,
9572  .nDeps = 1));
9573 
9574  destroyPQExpBuffer(query);
9575  destroyPQExpBuffer(tag);
9576  }
9577 }
#define ARCHIVE_OPTS(...)
Oid tableoid
Definition: pg_backup.h:230
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
bool schemaOnly
Definition: pg_backup.h:138
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int objsubid
Definition: pg_dump.c:74
static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9685
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
const char * descr
Definition: pg_dump.c:71
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:291
int no_comments
Definition: pg_backup.h:149
const char * name
Definition: encode.c:521
static const CatalogId nilCatalogId
Definition: pg_dump.c:134
DumpId createDumpId(void)
Definition: common.c:591

◆ dumpCompositeType()

static void dumpCompositeType ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10989 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, 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().

10990 {
10991  DumpOptions *dopt = fout->dopt;
10993  PQExpBuffer dropped = createPQExpBuffer();
10994  PQExpBuffer delq = createPQExpBuffer();
10995  PQExpBuffer query = createPQExpBuffer();
10996  PGresult *res;
10997  char *qtypname;
10998  char *qualtypname;
10999  int ntups;
11000  int i_attname;
11001  int i_atttypdefn;
11002  int i_attlen;
11003  int i_attalign;
11004  int i_attisdropped;
11005  int i_attcollation;
11006  int i;
11007  int actual_atts;
11008 
11009  /* Fetch type specific details */
11010  if (fout->remoteVersion >= 90100)
11011  {
11012  /*
11013  * attcollation is new in 9.1. Since we only want to dump COLLATE
11014  * clauses for attributes whose collation is different from their
11015  * type's default, we use a CASE here to suppress uninteresting
11016  * attcollations cheaply. atttypid will be 0 for dropped columns;
11017  * collation does not matter for those.
11018  */
11019  appendPQExpBuffer(query, "SELECT a.attname, "
11020  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
11021  "a.attlen, a.attalign, a.attisdropped, "
11022  "CASE WHEN a.attcollation <> at.typcollation "
11023  "THEN a.attcollation ELSE 0 END AS attcollation "
11024  "FROM pg_catalog.pg_type ct "
11025  "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
11026  "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
11027  "WHERE ct.oid = '%u'::pg_catalog.oid "
11028  "ORDER BY a.attnum ",
11029  tyinfo->dobj.catId.oid);
11030  }
11031  else
11032  {
11033  /*
11034  * Since ALTER TYPE could not drop columns until 9.1, attisdropped
11035  * should always be false.
11036  */
11037  appendPQExpBuffer(query, "SELECT a.attname, "
11038  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
11039  "a.attlen, a.attalign, a.attisdropped, "
11040  "0 AS attcollation "
11041  "FROM pg_catalog.pg_type ct, pg_catalog.pg_attribute a "
11042  "WHERE ct.oid = '%u'::pg_catalog.oid "
11043  "AND a.attrelid = ct.typrelid "
11044  "ORDER BY a.attnum ",
11045  tyinfo->dobj.catId.oid);
11046  }
11047 
11048  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
11049 
11050  ntups = PQntuples(res);
11051 
11052  i_attname = PQfnumber(res, "attname");
11053  i_atttypdefn = PQfnumber(res, "atttypdefn");
11054  i_attlen = PQfnumber(res, "attlen");
11055  i_attalign = PQfnumber(res, "attalign");
11056  i_attisdropped = PQfnumber(res, "attisdropped");
11057  i_attcollation = PQfnumber(res, "attcollation");
11058 
11059  if (dopt->binary_upgrade)
11060  {
11062  tyinfo->dobj.catId.oid,
11063  false);
11064  binary_upgrade_set_pg_class_oids(fout, q, tyinfo->typrelid, false);
11065  }
11066 
11067  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
11068  qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo));
11069 
11070  appendPQExpBuffer(q, "CREATE TYPE %s AS (",
11071  qualtypname);
11072 
11073  actual_atts = 0;
11074  for (i = 0; i < ntups; i++)
11075  {
11076  char *attname;
11077  char *atttypdefn;
11078  char *attlen;
11079  char *attalign;
11080  bool attisdropped;
11081  Oid attcollation;
11082 
11083  attname = PQgetvalue(res, i, i_attname);
11084  atttypdefn = PQgetvalue(res, i, i_atttypdefn);
11085  attlen = PQgetvalue(res, i, i_attlen);
11086  attalign = PQgetvalue(res, i, i_attalign);
11087  attisdropped = (PQgetvalue(res, i, i_attisdropped)[0] == 't');
11088  attcollation = atooid(PQgetvalue(res, i, i_attcollation));
11089 
11090  if (attisdropped && !dopt->binary_upgrade)
11091  continue;
11092 
11093  /* Format properly if not first attr */
11094  if (actual_atts++ > 0)
11095  appendPQExpBufferChar(q, ',');
11096  appendPQExpBufferStr(q, "\n\t");
11097 
11098  if (!attisdropped)
11099  {
11100  appendPQExpBuffer(q, "%s %s", fmtId(attname), atttypdefn);
11101 
11102  /* Add collation if not default for the column type */
11103  if (OidIsValid(attcollation))
11104  {
11105  CollInfo *coll;
11106 
11107  coll = findCollationByOid(attcollation);
11108  if (coll)
11109  appendPQExpBuffer(q, " COLLATE %s",
11110  fmtQualifiedDumpable(coll));
11111  }
11112  }
11113  else
11114  {
11115  /*
11116  * This is a dropped attribute and we're in binary_upgrade mode.
11117  * Insert a placeholder for it in the CREATE TYPE command, and set
11118  * length and alignment with direct UPDATE to the catalogs
11119  * afterwards. See similar code in dumpTableSchema().
11120  */
11121  appendPQExpBuffer(q, "%s INTEGER /* dummy */", fmtId(attname));
11122 
11123  /* stash separately for insertion after the CREATE TYPE */
11124  appendPQExpBufferStr(dropped,
11125  "\n-- For binary upgrade, recreate dropped column.\n");
11126  appendPQExpBuffer(dropped, "UPDATE pg_catalog.pg_attribute\n"
11127  "SET attlen = %s, "
11128  "attalign = '%s', attbyval = false\n"
11129  "WHERE attname = ", attlen, attalign);
11130  appendStringLiteralAH(dropped, attname, fout);
11131  appendPQExpBufferStr(dropped, "\n AND attrelid = ");
11132  appendStringLiteralAH(dropped, qualtypname, fout);
11133  appendPQExpBufferStr(dropped, "::pg_catalog.regclass;\n");
11134 
11135  appendPQExpBuffer(dropped, "ALTER TYPE %s ",
11136  qualtypname);
11137  appendPQExpBuffer(dropped, "DROP ATTRIBUTE %s;\n",
11138  fmtId(attname));
11139  }
11140  }
11141  appendPQExpBufferStr(q, "\n);\n");
11142  appendPQExpBufferStr(q, dropped->data);
11143 
11144  appendPQExpBuffer(delq, "DROP TYPE %s;\n", qualtypname);
11145 
11146  if (dopt->binary_upgrade)
11148  "TYPE", qtypname,
11149  tyinfo->dobj.namespace->dobj.name);
11150 
11151  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
11152  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
11153  ARCHIVE_OPTS(.tag = tyinfo->dobj.name,
11154  .namespace = tyinfo->dobj.namespace->dobj.name,
11155  .owner = tyinfo->rolname,
11156  .description = "TYPE",
11157  .section = SECTION_PRE_DATA,
11158  .createStmt = q->data,
11159  .dropStmt = delq->data));
11160 
11161 
11162  /* Dump Type Comments and Security Labels */
11163  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
11164  dumpComment(fout, "TYPE", qtypname,
11165  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
11166  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
11167 
11168  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
11169  dumpSecLabel(fout, "TYPE", qtypname,
11170  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
11171  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
11172 
11173  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
11174  dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
11175  qtypname, NULL,
11176  tyinfo->dobj.namespace->dobj.name,
11177  tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl,
11178  tyinfo->inittypacl, tyinfo->initrtypacl);
11179 
11180  PQclear(res);
11181  destroyPQExpBuffer(q);
11182  destroyPQExpBuffer(dropped);
11183  destroyPQExpBuffer(delq);
11184  destroyPQExpBuffer(query);
11185  free(qtypname);
11186  free(qualtypname);
11187 
11188  /* Dump any per-column comments */
11189  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
11190  dumpCompositeTypeColComments(fout, tyinfo);
11191 }
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
char * inittypacl
Definition: pg_dump.h:171
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
Oid typrelid
Definition: pg_dump.h:174
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
char * initrtypacl
Definition: pg_dump.h:172
static void dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
Definition: pg_dump.c:11199
char * typacl
Definition: pg_dump.h:169
DumpId dumpId
Definition: pg_dump.h:129
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2770
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:14997
#define OidIsValid(objectId)
Definition: c.h:638
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:14910
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
NameData attname
Definition: pg_attribute.h:40
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
Oid attcollation
Definition: pg_attribute.h:164
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
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:4403
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:162
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:4282
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:291
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:149
char * rtypacl
Definition: pg_dump.h:170
char * rolname
Definition: pg_dump.h:168
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:874
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:92
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4473
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:93
CatalogId catId
Definition: pg_dump.h:128
int i
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:9506
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:403
int remoteVersion
Definition: pg_backup.h:187

◆ dumpCompositeTypeColComments()

static void dumpCompositeTypeColComments ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 11199 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, 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().

11200 {
11201  CommentItem *comments;
11202  int ncomments;
11203  PGresult *res;
11204  PQExpBuffer query;
11205  PQExpBuffer target;
11206  Oid pgClassOid;
11207  int i;
11208  int ntups;
11209  int i_attname;
11210  int i_attnum;
11211 
11212  /* do nothing, if --no-comments is supplied */
11213  if (fout->dopt->no_comments)
11214  return;
11215 
11216  query = createPQExpBuffer();
11217 
11218  appendPQExpBuffer(query,
11219  "SELECT c.tableoid, a.attname, a.attnum "
11220  "FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
11221  "WHERE c.oid = '%u' AND c.oid = a.attrelid "
11222  " AND NOT a.attisdropped "
11223  "ORDER BY a.attnum ",
11224  tyinfo->typrelid);
11225 
11226  /* Fetch column attnames */
11227  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
11228 
11229  ntups = PQntuples(res);
11230  if (ntups < 1)
11231  {
11232  PQclear(res);
11233  destroyPQExpBuffer(query);
11234  return;
11235  }
11236 
11237  pgClassOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "tableoid")));
11238 
11239  /* Search for comments associated with type's pg_class OID */
11240  ncomments = findComments(fout,
11241  pgClassOid,
11242  tyinfo->typrelid,
11243  &comments);
11244 
11245  /* If no comments exist, we're done */
11246  if (ncomments <= 0)
11247  {
11248  PQclear(res);
11249  destroyPQExpBuffer(query);
11250  return;
11251  }
11252 
11253  /* Build COMMENT ON statements */
11254  target = createPQExpBuffer();
11255 
11256  i_attnum = PQfnumber(res, "attnum");
11257  i_attname = PQfnumber(res, "attname");
11258  while (ncomments > 0)
11259  {
11260  const char *attname;
11261 
11262  attname = NULL;
11263  for (i = 0; i < ntups; i++)
11264  {
11265  if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid)
11266  {
11267  attname = PQgetvalue(res, i, i_attname);
11268  break;
11269  }
11270  }
11271  if (attname) /* just in case we don't find it */
11272  {
11273  const char *descr = comments->descr;
11274 
11275  resetPQExpBuffer(target);
11276  appendPQExpBuffer(target, "COLUMN %s.",
11277  fmtId(tyinfo->dobj.name));
11278  appendPQExpBufferStr(target, fmtId(attname));
11279 
11280  resetPQExpBuffer(query);
11281  appendPQExpBuffer(query, "COMMENT ON COLUMN %s.",
11282  fmtQualifiedDumpable(tyinfo));
11283  appendPQExpBuffer(query, "%s IS ", fmtId(attname));
11284  appendStringLiteralAH(query, descr, fout);
11285  appendPQExpBufferStr(query, ";\n");
11286 
11288  ARCHIVE_OPTS(.tag = target->data,
11289  .namespace = tyinfo->dobj.namespace->dobj.name,
11290  .owner = tyinfo->rolname,
11291  .description = "COMMENT",
11292  .section = SECTION_NONE,
11293  .createStmt = query->data,
11294  .deps = &(tyinfo->dobj.dumpId),
11295  .nDeps = 1));
11296  }
11297 
11298  comments++;
11299  ncomments--;
11300  }
11301 
11302  PQclear(res);
11303  destroyPQExpBuffer(query);
11304  destroyPQExpBuffer(target);
11305 }
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
Oid typrelid
Definition: pg_dump.h:174
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
int objsubid
Definition: pg_dump.c:74
DumpId dumpId
Definition: pg_dump.h:129
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2770
static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9685
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
NameData attname
Definition: pg_attribute.h:40
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
#define atooid(x)
Definition: postgres_ext.h:42
const char * descr
Definition: pg_dump.c:71
DumpableObject dobj
Definition: pg_dump.h:162
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:291
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:149
char * rolname
Definition: pg_dump.h:168
int no_comments
Definition: pg_backup.h:149
int i
static const CatalogId nilCatalogId
Definition: pg_dump.c:134
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:403
DumpId createDumpId(void)
Definition: common.c:591

◆ dumpConstraint()

static void dumpConstraint ( Archive fout,
ConstraintInfo coninfo 
)
static

Definition at line 16598 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendReloptionsArrayAH(), ARCHIVE_OPTS, 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(), fatal, findObjectByDumpId(), fmtId(), fmtQualifiedDumpable, free, getAttrName(), _indxInfo::indisclustered, _indxInfo::indisreplident, _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().

16599 {
16600  DumpOptions *dopt = fout->dopt;
16601  TableInfo *tbinfo = coninfo->contable;
16602  PQExpBuffer q;
16603  PQExpBuffer delq;
16604  char *tag = NULL;
16605 
16606  /* Skip if not to be dumped */
16607  if (!coninfo->dobj.dump || dopt->dataOnly)
16608  return;
16609 
16610  q = createPQExpBuffer();
16611  delq = createPQExpBuffer();
16612 
16613  if (coninfo->contype == 'p' ||
16614  coninfo->contype == 'u' ||
16615  coninfo->contype == 'x')
16616  {
16617  /* Index-related constraint */
16618  IndxInfo *indxinfo;
16619  int k;
16620 
16621  indxinfo = (IndxInfo *) findObjectByDumpId(coninfo->conindex);
16622 
16623  if (indxinfo == NULL)
16624  fatal("missing index for constraint \"%s\"",
16625  coninfo->dobj.name);
16626 
16627  if (dopt->binary_upgrade)
16629  indxinfo->dobj.catId.oid, true);
16630 
16631  appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
16632  fmtQualifiedDumpable(tbinfo));
16633  appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
16634  fmtId(coninfo->dobj.name));
16635 
16636  if (coninfo->condef)
16637  {
16638  /* pg_get_constraintdef should have provided everything */
16639  appendPQExpBuffer(q, "%s;\n", coninfo->condef);
16640  }
16641  else
16642  {
16643  appendPQExpBuffer(q, "%s (",
16644  coninfo->contype == 'p' ? "PRIMARY KEY" : "UNIQUE");
16645  for (k = 0; k < indxinfo->indnkeyattrs; k++)
16646  {
16647  int indkey = (int) indxinfo->indkeys[k];
16648  const char *attname;
16649 
16650  if (indkey == InvalidAttrNumber)
16651  break;
16652  attname = getAttrName(indkey, tbinfo);
16653 
16654  appendPQExpBuffer(q, "%s%s",
16655  (k == 0) ? "" : ", ",
16656  fmtId(attname));
16657  }
16658 
16659  if (indxinfo->indnkeyattrs < indxinfo->indnattrs)
16660  appendPQExpBufferStr(q, ") INCLUDE (");
16661 
16662  for (k = indxinfo->indnkeyattrs; k < indxinfo->indnattrs; k++)
16663  {
16664  int indkey = (int) indxinfo->indkeys[k];
16665  const char *attname;
16666 
16667  if (indkey == InvalidAttrNumber)
16668  break;
16669  attname = getAttrName(indkey, tbinfo);
16670 
16671  appendPQExpBuffer(q, "%s%s",
16672  (k == indxinfo->indnkeyattrs) ? "" : ", ",
16673  fmtId(attname));
16674  }
16675 
16676  appendPQExpBufferChar(q, ')');
16677 
16678  if (nonemptyReloptions(indxinfo->indreloptions))
16679  {
16680  appendPQExpBufferStr(q, " WITH (");
16681  appendReloptionsArrayAH(q, indxinfo->indreloptions, "", fout);
16682  appendPQExpBufferChar(q, ')');
16683  }
16684 
16685  if (coninfo->condeferrable)
16686  {
16687  appendPQExpBufferStr(q, " DEFERRABLE");
16688  if (coninfo->condeferred)
16689  appendPQExpBufferStr(q, " INITIALLY DEFERRED");
16690  }
16691 
16692  appendPQExpBufferStr(q, ";\n");
16693  }
16694 
16695  /*
16696  * Append ALTER TABLE commands as needed to set properties that we
16697  * only have ALTER TABLE syntax for. Keep this in sync with the
16698  * similar code in dumpIndex!
16699  */
16700 
16701  /* If the index is clustered, we need to record that. */
16702  if (indxinfo->indisclustered)
16703  {
16704  appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER",
16705  fmtQualifiedDumpable(tbinfo));
16706  /* index name is not qualified in this syntax */
16707  appendPQExpBuffer(q, " ON %s;\n",
16708  fmtId(indxinfo->dobj.name));
16709  }
16710 
16711  /* If the index defines identity, we need to record that. */
16712  if (indxinfo->indisreplident)
16713  {
16714  appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY USING",
16715  fmtQualifiedDumpable(tbinfo));
16716  /* index name is not qualified in this syntax */
16717  appendPQExpBuffer(q, " INDEX %s;\n",
16718  fmtId(indxinfo->dobj.name));
16719  }
16720 
16721  appendPQExpBuffer(delq, "ALTER TABLE ONLY %s ",
16722  fmtQualifiedDumpable(tbinfo));
16723  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16724  fmtId(coninfo->dobj.name));
16725 
16726  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16727 
16728  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16729  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16730  ARCHIVE_OPTS(.tag = tag,
16731  .namespace = tbinfo->dobj.namespace->dobj.name,
16732  .tablespace = indxinfo->tablespace,
16733  .owner = tbinfo->rolname,
16734  .description = "CONSTRAINT",
16735  .section = SECTION_POST_DATA,
16736  .createStmt = q->data,
16737  .dropStmt = delq->data));
16738  }
16739  else if (coninfo->contype == 'f')
16740  {
16741  char *only;
16742 
16743  /*
16744  * Foreign keys on partitioned tables are always declared as
16745  * inheriting to partitions; for all other cases, emit them as
16746  * applying ONLY directly to the named table, because that's how they
16747  * work for regular inherited tables.
16748  */
16749  only = tbinfo->relkind == RELKIND_PARTITIONED_TABLE ? "" : "ONLY ";
16750 
16751  /*
16752  * XXX Potentially wrap in a 'SET CONSTRAINTS OFF' block so that the
16753  * current table data is not processed
16754  */
16755  appendPQExpBuffer(q, "ALTER TABLE %s%s\n",
16756  only, fmtQualifiedDumpable(tbinfo));
16757  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16758  fmtId(coninfo->dobj.name),
16759  coninfo->condef);
16760 
16761  appendPQExpBuffer(delq, "ALTER TABLE %s%s ",
16762  only, fmtQualifiedDumpable(tbinfo));
16763  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16764  fmtId(coninfo->dobj.name));
16765 
16766  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16767 
16768  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16769  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16770  ARCHIVE_OPTS(.tag = tag,
16771  .namespace = tbinfo->dobj.namespace->dobj.name,
16772  .owner = tbinfo->rolname,
16773  .description = "FK CONSTRAINT",
16774  .section = SECTION_POST_DATA,
16775  .createStmt = q->data,
16776  .dropStmt = delq->data));
16777  }
16778  else if (coninfo->contype == 'c' && tbinfo)
16779  {
16780  /* CHECK constraint on a table */
16781 
16782  /* Ignore if not to be dumped separately, or if it was inherited */
16783  if (coninfo->separate && coninfo->conislocal)
16784  {
16785  /* not ONLY since we want it to propagate to children */
16786  appendPQExpBuffer(q, "ALTER TABLE %s\n",
16787  fmtQualifiedDumpable(tbinfo));
16788  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16789  fmtId(coninfo->dobj.name),
16790  coninfo->condef);
16791 
16792  appendPQExpBuffer(delq, "ALTER TABLE %s ",
16793  fmtQualifiedDumpable(tbinfo));
16794  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16795  fmtId(coninfo->dobj.name));
16796 
16797  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16798 
16799  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16800  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16801  ARCHIVE_OPTS(.tag = tag,
16802  .namespace = tbinfo->dobj.namespace->dobj.name,
16803  .owner = tbinfo->rolname,
16804  .description = "CHECK CONSTRAINT",
16805  .section = SECTION_POST_DATA,
16806  .createStmt = q->data,
16807  .dropStmt = delq->data));
16808  }
16809  }
16810  else if (coninfo->contype == 'c' && tbinfo == NULL)
16811  {
16812  /* CHECK constraint on a domain */
16813  TypeInfo *tyinfo = coninfo->condomain;
16814 
16815  /* Ignore if not to be dumped separately */
16816  if (coninfo->separate)
16817  {
16818  appendPQExpBuffer(q, "ALTER DOMAIN %s\n",
16819  fmtQualifiedDumpable(tyinfo));
16820  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16821  fmtId(coninfo->dobj.name),
16822  coninfo->condef);
16823 
16824  appendPQExpBuffer(delq, "ALTER DOMAIN %s ",
16825  fmtQualifiedDumpable(tyinfo));
16826  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16827  fmtId(coninfo->dobj.name));
16828 
16829  tag = psprintf("%s %s", tyinfo->dobj.name, coninfo->dobj.name);
16830 
16831  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16832  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16833  ARCHIVE_OPTS(.tag = tag,
16834  .namespace = tyinfo->dobj.namespace->dobj.name,
16835  .owner = tyinfo->rolname,
16836  .description = "CHECK CONSTRAINT",
16837  .section = SECTION_POST_DATA,
16838  .createStmt = q->data,
16839  .dropStmt = delq->data));
16840  }
16841  }
16842  else
16843  {
16844  fatal("unrecognized constraint type: %c",
16845  coninfo->contype);
16846  }
16847 
16848  /* Dump Constraint Comments --- only works for table constraints */
16849  if (tbinfo && coninfo->separate &&
16850  coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
16851  dumpTableConstraintComment(fout, coninfo);
16852 
16853  free(tag);
16854  destroyPQExpBuffer(q);
16855  destroyPQExpBuffer(delq);
16856 }
char * tablespace
Definition: pg_dump.h:359
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
char relkind
Definition: pg_dump.h:264
DumpComponents dump
Definition: pg_dump.h:131
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
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:18433
char * rolname
Definition: pg_dump.h:259
DumpId dumpId
Definition: pg_dump.h:129
DumpId conindex
Definition: pg_dump.h:446
DumpableObject dobj
Definition: pg_dump.h:258
char * condef
Definition: pg_dump.h:444
bool indisreplident
Definition: pg_dump.h:368
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
NameData attname
Definition: pg_attribute.h:40
int binary_upgrade
Definition: pg_backup.h:135
DumpableObject dobj
Definition: pg_dump.h:440
DumpOptions * dopt
Definition: pg_backup.h:182
static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
Definition: pg_dump.c:16866
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:611
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
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:4403
static const char * getAttrName(int attrnum, TableInfo *tblInfo)
Definition: pg_dump.c:16330
bool condeferrable
Definition: pg_dump.h:447
static bool nonemptyReloptions(const char *reloptions)
Definition: pg_dump.c:18421
char * indreloptions
Definition: pg_dump.h:360
DumpableObject dobj
Definition: pg_dump.h:162
TypeInfo * condomain
Definition: pg_dump.h:442
bool conislocal
Definition: pg_dump.h:449
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
TableInfo * contable
Definition: pg_dump.h:441
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
bool condeferred
Definition: pg_dump.h:448
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:149
char * rolname
Definition: pg_dump.h:168
#define fatal(...)
#define InvalidAttrNumber
Definition: attnum.h:23
int indnkeyattrs
Definition: pg_dump.h:363
int indnattrs
Definition: pg_dump.h:364
CatalogId catId
Definition: pg_dump.h:128
DumpableObject dobj
Definition: pg_dump.h:356
bool indisclustered
Definition: pg_dump.h:367

◆ dumpConversion()

static void dumpConversion ( Archive fout,
ConvInfo convinfo 
)
static

Definition at line 13613 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, 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().

13614 {
13615  DumpOptions *dopt = fout->dopt;
13616  PQExpBuffer query;
13617  PQExpBuffer q;
13618  PQExpBuffer delq;
13619  char *qconvname;
13620  PGresult *res;
13621  int i_conforencoding;
13622  int i_contoencoding;
13623  int i_conproc;
13624  int i_condefault;
13625  const char *conforencoding;
13626  const char *contoencoding;
13627  const char *conproc;
13628  bool condefault;
13629 
13630  /* Skip if not to be dumped */
13631  if (!convinfo->dobj.dump || dopt->dataOnly)
13632  return;
13633 
13634  query = createPQExpBuffer();
13635  q = createPQExpBuffer();
13636  delq = createPQExpBuffer();
13637 
13638  qconvname = pg_strdup(fmtId(convinfo->dobj.name));
13639 
13640  /* Get conversion-specific details */
13641  appendPQExpBuffer(query, "SELECT "
13642  "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
13643  "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
13644  "conproc, condefault "
13645  "FROM pg_catalog.pg_conversion c "
13646  "WHERE c.oid = '%u'::pg_catalog.oid",
13647  convinfo->dobj.catId.oid);
13648 
13649  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13650 
13651  i_conforencoding = PQfnumber(res, "conforencoding");
13652  i_contoencoding = PQfnumber(res, "contoencoding");
13653  i_conproc = PQfnumber(res, "conproc");
13654  i_condefault = PQfnumber(res, "condefault");
13655 
13656  conforencoding = PQgetvalue(res, 0, i_conforencoding);
13657  contoencoding = PQgetvalue(res, 0, i_contoencoding);
13658  conproc = PQgetvalue(res, 0, i_conproc);
13659  condefault = (PQgetvalue(res, 0, i_condefault)[0] == 't');
13660 
13661  appendPQExpBuffer(delq, "DROP CONVERSION %s;\n",
13662  fmtQualifiedDumpable(convinfo));
13663 
13664  appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ",
13665  (condefault) ? "DEFAULT " : "",
13666  fmtQualifiedDumpable(convinfo));
13667  appendStringLiteralAH(q, conforencoding, fout);
13668  appendPQExpBufferStr(q, " TO ");
13669  appendStringLiteralAH(q, contoencoding, fout);
13670  /* regproc output is already sufficiently quoted */
13671  appendPQExpBuffer(q, " FROM %s;\n", conproc);
13672 
13673  if (dopt->binary_upgrade)
13674  binary_upgrade_extension_member(q, &convinfo->dobj,
13675  "CONVERSION", qconvname,
13676  convinfo->dobj.namespace->dobj.name);
13677 
13678  if (convinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13679  ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
13680  ARCHIVE_OPTS(.tag = convinfo->dobj.name,
13681  .namespace = convinfo->dobj.namespace->dobj.name,
13682  .owner = convinfo->rolname,
13683  .description = "CONVERSION",
13684  .section = SECTION_PRE_DATA,
13685  .createStmt = q->data,
13686  .dropStmt = delq->data));
13687 
13688  /* Dump Conversion Comments */
13689  if (convinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13690  dumpComment(fout, "CONVERSION", qconvname,
13691  convinfo->dobj.namespace->dobj.name, convinfo->rolname,
13692  convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
13693 
13694  PQclear(res);
13695 
13696  destroyPQExpBuffer(query);
13697  destroyPQExpBuffer(q);
13698  destroyPQExpBuffer(delq);
13699  free(qconvname);
13700 }
#define ARCHIVE_OPTS(...)
char * name
Definition: pg_dump.h:130
DumpComponents dump
Definition: pg_dump.h:131
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3164
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
char * rolname
Definition: pg_dump.h:250
DumpId dumpId
Definition: pg_dump.h:129
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:418
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:182
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
bool dataOnly
Definition: pg_backup.h:139
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2878
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:91
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:291
void PQclear(PGresult *res)
Definition: fe-exec.c:695
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:89
#define free(a)
Definition: header.h:65
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:149
DumpableObject dobj
Definition: pg_dump.h:249
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4473
CatalogId catId
Definition: pg_dump.h:128
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:9506

◆ dumpDatabase()