PostgreSQL Source Code  git master
pg_dump.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <ctype.h>
#include <limits.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_authid_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_subscription.h"
#include "catalog/pg_trigger_d.h"
#include "catalog/pg_type_d.h"
#include "common/connect.h"
#include "dumputils.h"
#include "fe_utils/option_utils.h"
#include "fe_utils/string_utils.h"
#include "getopt_long.h"
#include "libpq/libpq-fs.h"
#include "parallel.h"
#include "pg_backup_db.h"
#include "pg_backup_utils.h"
#include "pg_dump.h"
#include "storage/block.h"
Include dependency graph for pg_dump.c:

Go to the source code of this file.

Data Structures

struct  RoleNameItem
 
struct  CommentItem
 
struct  SecLabelItem
 

Macros

#define DUMP_DEFAULT_ROWS_PER_INSERT   1
 
#define fmtQualifiedDumpable(obj)
 

Typedefs

typedef enum OidOptions OidOptions
 

Enumerations

enum  OidOptions { zeroIsError = 1 , zeroAsStar = 2 , zeroAsNone = 4 }
 

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_extension_name_patterns (Archive *fout, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names)
 
static void expand_foreign_server_name_patterns (Archive *fout, SimpleStringList *patterns, SimpleOidList *oids)
 
static void expand_table_name_patterns (Archive *fout, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names)
 
static void prohibit_crossdb_refs (PGconn *conn, const char *dbname, const char *pattern)
 
static NamespaceInfofindNamespace (Oid nsoid)
 
static void dumpTableData (Archive *fout, const TableDataInfo *tdinfo)
 
static void refreshMatViewData (Archive *fout, const TableDataInfo *tdinfo)
 
static const char * getRoleName (const char *roleoid_str)
 
static void collectRoleNames (Archive *fout)
 
static void getAdditionalACLs (Archive *fout)
 
static void dumpCommentExtended (Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId, const char *initdb_comment)
 
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 (Oid classoid, Oid objoid, CommentItem **items)
 
static void collectComments (Archive *fout)
 
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 (Oid classoid, Oid objoid, SecLabelItem **items)
 
static void collectSecLabels (Archive *fout)
 
static void dumpDumpableObject (Archive *fout, DumpableObject *dobj)
 
static void dumpNamespace (Archive *fout, const NamespaceInfo *nspinfo)
 
static void dumpExtension (Archive *fout, const ExtensionInfo *extinfo)
 
static void dumpType (Archive *fout, const TypeInfo *tyinfo)
 
static void dumpBaseType (Archive *fout, const TypeInfo *tyinfo)
 
static void dumpEnumType (Archive *fout, const TypeInfo *tyinfo)
 
static void dumpRangeType (Archive *fout, const TypeInfo *tyinfo)
 
static void dumpUndefinedType (Archive *fout, const TypeInfo *tyinfo)
 
static void dumpDomain (Archive *fout, const TypeInfo *tyinfo)
 
static void dumpCompositeType (Archive *fout, const TypeInfo *tyinfo)
 
static void dumpCompositeTypeColComments (Archive *fout, const TypeInfo *tyinfo, PGresult *res)
 
static void dumpShellType (Archive *fout, const ShellTypeInfo *stinfo)
 
static void dumpProcLang (Archive *fout, const ProcLangInfo *plang)
 
static void dumpFunc (Archive *fout, const FuncInfo *finfo)
 
static void dumpCast (Archive *fout, const CastInfo *cast)
 
static void dumpTransform (Archive *fout, const TransformInfo *transform)
 
static void dumpOpr (Archive *fout, const OprInfo *oprinfo)
 
static void dumpAccessMethod (Archive *fout, const AccessMethodInfo *oprinfo)
 
static void dumpOpclass (Archive *fout, const OpclassInfo *opcinfo)
 
static void dumpOpfamily (Archive *fout, const OpfamilyInfo *opfinfo)
 
static void dumpCollation (Archive *fout, const CollInfo *collinfo)
 
static void dumpConversion (Archive *fout, const ConvInfo *convinfo)
 
static void dumpRule (Archive *fout, const RuleInfo *rinfo)
 
static void dumpAgg (Archive *fout, const AggInfo *agginfo)
 
static void dumpTrigger (Archive *fout, const TriggerInfo *tginfo)
 
static void dumpEventTrigger (Archive *fout, const EventTriggerInfo *evtinfo)
 
static void dumpTable (Archive *fout, const TableInfo *tbinfo)
 
static void dumpTableSchema (Archive *fout, const TableInfo *tbinfo)
 
static void dumpTableAttach (Archive *fout, const TableAttachInfo *tbinfo)
 
static void dumpAttrDef (Archive *fout, const AttrDefInfo *adinfo)
 
static void dumpSequence (Archive *fout, const TableInfo *tbinfo)
 
static void dumpSequenceData (Archive *fout, const TableDataInfo *tdinfo)
 
static void dumpIndex (Archive *fout, const IndxInfo *indxinfo)
 
static void dumpIndexAttach (Archive *fout, const IndexAttachInfo *attachinfo)
 
static void dumpStatisticsExt (Archive *fout, const StatsExtInfo *statsextinfo)
 
static void dumpConstraint (Archive *fout, const ConstraintInfo *coninfo)
 
static void dumpTableConstraintComment (Archive *fout, const ConstraintInfo *coninfo)
 
static void dumpTSParser (Archive *fout, const TSParserInfo *prsinfo)
 
static void dumpTSDictionary (Archive *fout, const TSDictInfo *dictinfo)
 
static void dumpTSTemplate (Archive *fout, const TSTemplateInfo *tmplinfo)
 
static void dumpTSConfig (Archive *fout, const TSConfigInfo *cfginfo)
 
static void dumpForeignDataWrapper (Archive *fout, const FdwInfo *fdwinfo)
 
static void dumpForeignServer (Archive *fout, const 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, const DefaultACLInfo *daclinfo)
 
static DumpId dumpACL (Archive *fout, DumpId objDumpId, DumpId altDumpId, const char *type, const char *name, const char *subname, const char *nspname, const char *owner, const DumpableAcl *dacl)
 
static void getDependencies (Archive *fout)
 
static void BuildArchiveDependencies (Archive *fout)
 
static void findDumpableDependencies (ArchiveHandle *AH, const DumpableObject *dobj, DumpId **dependencies, int *nDeps, int *allocDeps)
 
static DumpableObjectcreateBoundaryObjects (void)
 
static void addBoundaryDependencies (DumpableObject **dobjs, int numObjs, DumpableObject *boundaryObjs)
 
static void addConstrChildIdxDeps (DumpableObject *dobj, const IndxInfo *refidx)
 
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 (const FuncInfo *finfo, const char *funcargs, bool is_agg)
 
static char * format_function_signature (Archive *fout, const FuncInfo *finfo, bool honor_quotes)
 
static char * convertRegProcReference (const char *proc)
 
static char * getFormattedOperatorName (const char *oproid)
 
static char * convertTSFunction (Archive *fout, Oid funcOid)
 
static const char * getFormattedTypeName (Archive *fout, Oid oid, OidOptions opts)
 
static void getBlobs (Archive *fout)
 
static void dumpBlob (Archive *fout, const BlobInfo *binfo)
 
static int dumpBlobs (Archive *fout, const void *arg)
 
static void dumpPolicy (Archive *fout, const PolicyInfo *polinfo)
 
static void dumpPublication (Archive *fout, const PublicationInfo *pubinfo)
 
static void dumpPublicationTable (Archive *fout, const PublicationRelInfo *pubrinfo)
 
static void dumpSubscription (Archive *fout, const 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, bool include_multirange_type)
 
static void binary_upgrade_set_type_oids_by_rel (Archive *fout, PQExpBuffer upgrade_buffer, const TableInfo *tbinfo)
 
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, const DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
 
static const char * getAttrName (int attrnum, const 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 (const 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 selectDumpablePublicationObject (DumpableObject *dobj, Archive *fout)
 
static void selectDumpableObject (DumpableObject *dobj, Archive *fout)
 
static int dumpTableData_copy (Archive *fout, const void *dcontext)
 
static int dumpTableData_insert (Archive *fout, const void *dcontext)
 
void getPolicies (Archive *fout, TableInfo tblinfo[], int numTables)
 
PublicationInfogetPublications (Archive *fout, int *numPublications)
 
void getPublicationNamespaces (Archive *fout)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
static void dumpPublicationNamespace (Archive *fout, const PublicationSchemaInfo *pubsinfo)
 
static bool is_superuser (Archive *fout)
 
void getSubscriptions (Archive *fout)
 
static void append_depends_on_extension (Archive *fout, PQExpBuffer create, const DumpableObject *dobj, const char *catalog, const char *keyword, const char *objname)
 
static Oid get_next_possible_free_pg_type_oid (Archive *fout, PQExpBuffer upgrade_query)
 
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 (const DumpOptions *dopt, const 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, const TableInfo *tbinfo, const char *reltypename)
 
static char * format_aggregate_signature (const AggInfo *agginfo, Archive *fout, bool honor_quotes)
 
static void dumpTableSecLabel (Archive *fout, const TableInfo *tbinfo, const char *reltypename)
 
static PQExpBuffer createViewAsClause (Archive *fout, const TableInfo *tbinfo)
 
static PQExpBuffer createDummyViewAsClause (Archive *fout, const TableInfo *tbinfo)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 

Variables

static bool dosync = true
 
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}
 
static SimpleStringList foreign_servers_include_patterns = {NULL, NULL}
 
static SimpleOidList foreign_servers_include_oids = {NULL, NULL}
 
static SimpleStringList extension_include_patterns = {NULL, NULL}
 
static SimpleOidList extension_include_oids = {NULL, NULL}
 
static const CatalogId nilCatalogId = {0, 0}
 
static bool have_extra_float_digits = false
 
static int extra_float_digits
 
static RoleNameItemrolenames = NULL
 
static int nrolenames = 0
 
static CommentItemcomments = NULL
 
static int ncomments = 0
 
static SecLabelItemseclabels = NULL
 
static int nseclabels = 0
 

Macro Definition Documentation

◆ DUMP_DEFAULT_ROWS_PER_INSERT

#define DUMP_DEFAULT_ROWS_PER_INSERT   1

Definition at line 152 of file pg_dump.c.

◆ fmtQualifiedDumpable

#define fmtQualifiedDumpable (   obj)
Value:
fmtQualifiedId((obj)->dobj.namespace->dobj.name, \
(obj)->dobj.name)
const char * fmtQualifiedId(const char *schema, const char *id)
Definition: string_utils.c:145

Definition at line 157 of file pg_dump.c.

Typedef Documentation

◆ OidOptions

typedef enum OidOptions OidOptions

Enumeration Type Documentation

◆ OidOptions

enum OidOptions
Enumerator
zeroIsError 
zeroAsStar 
zeroAsNone 

Definition at line 92 of file pg_dump.c.

93 {
94  zeroIsError = 1,
95  zeroAsStar = 2,
96  zeroAsNone = 4
97 } OidOptions;
OidOptions
Definition: pg_dump.c:93
@ zeroIsError
Definition: pg_dump.c:94
@ zeroAsStar
Definition: pg_dump.c:95
@ zeroAsNone
Definition: pg_dump.c:96

Function Documentation

◆ addBoundaryDependencies()

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

Definition at line 17810 of file pg_dump.c.

17812 {
17813  DumpableObject *preDataBound = boundaryObjs + 0;
17814  DumpableObject *postDataBound = boundaryObjs + 1;
17815  int i;
17816 
17817  for (i = 0; i < numObjs; i++)
17818  {
17819  DumpableObject *dobj = dobjs[i];
17820 
17821  /*
17822  * The classification of object types here must match the SECTION_xxx
17823  * values assigned during subsequent ArchiveEntry calls!
17824  */
17825  switch (dobj->objType)
17826  {
17827  case DO_NAMESPACE:
17828  case DO_EXTENSION:
17829  case DO_TYPE:
17830  case DO_SHELL_TYPE:
17831  case DO_FUNC:
17832  case DO_AGG:
17833  case DO_OPERATOR:
17834  case DO_ACCESS_METHOD:
17835  case DO_OPCLASS:
17836  case DO_OPFAMILY:
17837  case DO_COLLATION:
17838  case DO_CONVERSION:
17839  case DO_TABLE:
17840  case DO_TABLE_ATTACH:
17841  case DO_ATTRDEF:
17842  case DO_PROCLANG:
17843  case DO_CAST:
17844  case DO_DUMMY_TYPE:
17845  case DO_TSPARSER:
17846  case DO_TSDICT:
17847  case DO_TSTEMPLATE:
17848  case DO_TSCONFIG:
17849  case DO_FDW:
17850  case DO_FOREIGN_SERVER:
17851  case DO_TRANSFORM:
17852  case DO_BLOB:
17853  /* Pre-data objects: must come before the pre-data boundary */
17854  addObjectDependency(preDataBound, dobj->dumpId);
17855  break;
17856  case DO_TABLE_DATA:
17857  case DO_SEQUENCE_SET:
17858  case DO_BLOB_DATA:
17859  /* Data objects: must come between the boundaries */
17860  addObjectDependency(dobj, preDataBound->dumpId);
17861  addObjectDependency(postDataBound, dobj->dumpId);
17862  break;
17863  case DO_INDEX:
17864  case DO_INDEX_ATTACH:
17865  case DO_STATSEXT:
17866  case DO_REFRESH_MATVIEW:
17867  case DO_TRIGGER:
17868  case DO_EVENT_TRIGGER:
17869  case DO_DEFAULT_ACL:
17870  case DO_POLICY:
17871  case DO_PUBLICATION:
17872  case DO_PUBLICATION_REL:
17874  case DO_SUBSCRIPTION:
17875  /* Post-data objects: must come after the post-data boundary */
17876  addObjectDependency(dobj, postDataBound->dumpId);
17877  break;
17878  case DO_RULE:
17879  /* Rules are post-data, but only if dumped separately */
17880  if (((RuleInfo *) dobj)->separate)
17881  addObjectDependency(dobj, postDataBound->dumpId);
17882  break;
17883  case DO_CONSTRAINT:
17884  case DO_FK_CONSTRAINT:
17885  /* Constraints are post-data, but only if dumped separately */
17886  if (((ConstraintInfo *) dobj)->separate)
17887  addObjectDependency(dobj, postDataBound->dumpId);
17888  break;
17889  case DO_PRE_DATA_BOUNDARY:
17890  /* nothing to do */
17891  break;
17892  case DO_POST_DATA_BOUNDARY:
17893  /* must come after the pre-data boundary */
17894  addObjectDependency(dobj, preDataBound->dumpId);
17895  break;
17896  }
17897  }
17898 }
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:720
int i
Definition: isn.c:73
@ DO_EVENT_TRIGGER
Definition: pg_dump.h:79
@ DO_REFRESH_MATVIEW
Definition: pg_dump.h:80
@ DO_POLICY
Definition: pg_dump.h:81
@ DO_CAST
Definition: pg_dump.h:63
@ DO_FOREIGN_SERVER
Definition: pg_dump.h:72
@ DO_PRE_DATA_BOUNDARY
Definition: pg_dump.h:77
@ DO_PROCLANG
Definition: pg_dump.h:62
@ DO_TYPE
Definition: pg_dump.h:42
@ DO_INDEX
Definition: pg_dump.h:55
@ DO_COLLATION
Definition: pg_dump.h:50
@ DO_BLOB
Definition: pg_dump.h:75
@ DO_TSCONFIG
Definition: pg_dump.h:70
@ DO_OPERATOR
Definition: pg_dump.h:46
@ DO_FK_CONSTRAINT
Definition: pg_dump.h:61
@ DO_CONSTRAINT
Definition: pg_dump.h:60
@ DO_SUBSCRIPTION
Definition: pg_dump.h:85
@ DO_DEFAULT_ACL
Definition: pg_dump.h:73
@ DO_FDW
Definition: pg_dump.h:71
@ DO_SEQUENCE_SET
Definition: pg_dump.h:65
@ DO_ATTRDEF
Definition: pg_dump.h:54
@ DO_BLOB_DATA
Definition: pg_dump.h:76
@ DO_PUBLICATION_REL
Definition: pg_dump.h:83
@ DO_TABLE_ATTACH
Definition: pg_dump.h:53
@ DO_OPCLASS
Definition: pg_dump.h:48
@ DO_INDEX_ATTACH
Definition: pg_dump.h:56
@ DO_TSTEMPLATE
Definition: pg_dump.h:69
@ DO_STATSEXT
Definition: pg_dump.h:57
@ DO_FUNC
Definition: pg_dump.h:44
@ DO_POST_DATA_BOUNDARY
Definition: pg_dump.h:78
@ DO_OPFAMILY
Definition: pg_dump.h:49
@ DO_TRANSFORM
Definition: pg_dump.h:74
@ DO_ACCESS_METHOD
Definition: pg_dump.h:47
@ DO_PUBLICATION_TABLE_IN_SCHEMA
Definition: pg_dump.h:84
@ DO_CONVERSION
Definition: pg_dump.h:51
@ DO_TRIGGER
Definition: pg_dump.h:59
@ DO_RULE
Definition: pg_dump.h:58
@ DO_DUMMY_TYPE
Definition: pg_dump.h:66
@ DO_TSDICT
Definition: pg_dump.h:68
@ DO_TSPARSER
Definition: pg_dump.h:67
@ DO_EXTENSION
Definition: pg_dump.h:41
@ DO_TABLE_DATA
Definition: pg_dump.h:64
@ DO_PUBLICATION
Definition: pg_dump.h:82
@ DO_TABLE
Definition: pg_dump.h:52
@ DO_NAMESPACE
Definition: pg_dump.h:40
@ DO_AGG
Definition: pg_dump.h:45
@ DO_SHELL_TYPE
Definition: pg_dump.h:43
DumpId dumpId
Definition: pg_dump.h:136
DumpableObjectType objType
Definition: pg_dump.h:134

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_PUBLICATION_TABLE_IN_SCHEMA, DO_REFRESH_MATVIEW, DO_RULE, DO_SEQUENCE_SET, DO_SHELL_TYPE, DO_STATSEXT, DO_SUBSCRIPTION, DO_TABLE, DO_TABLE_ATTACH, 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().

◆ addConstrChildIdxDeps()

static void addConstrChildIdxDeps ( DumpableObject dobj,
const IndxInfo refidx 
)
static

Definition at line 7182 of file pg_dump.c.

7183 {
7184  SimplePtrListCell *cell;
7185 
7186  Assert(dobj->objType == DO_FK_CONSTRAINT);
7187 
7188  for (cell = refidx->partattaches.head; cell; cell = cell->next)
7189  {
7190  IndexAttachInfo *attach = (IndexAttachInfo *) cell->ptr;
7191 
7192  addObjectDependency(dobj, attach->dobj.dumpId);
7193 
7194  if (attach->partitionIdx->partattaches.head != NULL)
7195  addConstrChildIdxDeps(dobj, attach->partitionIdx);
7196  }
7197 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition: pg_dump.c:7182
struct SimplePtrListCell * next
Definition: simple_list.h:48
SimplePtrListCell * head
Definition: simple_list.h:54
IndxInfo * partitionIdx
Definition: pg_dump.h:413
DumpableObject dobj
Definition: pg_dump.h:411
SimplePtrList partattaches
Definition: pg_dump.h:403

References addObjectDependency(), Assert(), DO_FK_CONSTRAINT, _indexAttachInfo::dobj, _dumpableObject::dumpId, SimplePtrList::head, SimplePtrListCell::next, _dumpableObject::objType, _indxInfo::partattaches, _indexAttachInfo::partitionIdx, and SimplePtrListCell::ptr.

Referenced by getConstraints().

◆ append_depends_on_extension()

static void append_depends_on_extension ( Archive fout,
PQExpBuffer  create,
const DumpableObject dobj,
const char *  catalog,
const char *  keyword,
const char *  objname 
)
static

Definition at line 4630 of file pg_dump.c.

4636 {
4637  if (dobj->depends_on_ext)
4638  {
4639  char *nm;
4640  PGresult *res;
4641  PQExpBuffer query;
4642  int ntups;
4643  int i_extname;
4644  int i;
4645 
4646  /* dodge fmtId() non-reentrancy */
4647  nm = pg_strdup(objname);
4648 
4649  query = createPQExpBuffer();
4650  appendPQExpBuffer(query,
4651  "SELECT e.extname "
4652  "FROM pg_catalog.pg_depend d, pg_catalog.pg_extension e "
4653  "WHERE d.refobjid = e.oid AND classid = '%s'::pg_catalog.regclass "
4654  "AND objid = '%u'::pg_catalog.oid AND deptype = 'x' "
4655  "AND refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass",
4656  catalog,
4657  dobj->catId.oid);
4658  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4659  ntups = PQntuples(res);
4660  i_extname = PQfnumber(res, "extname");
4661  for (i = 0; i < ntups; i++)
4662  {
4663  appendPQExpBuffer(create, "ALTER %s %s DEPENDS ON EXTENSION %s;\n",
4664  keyword, nm,
4665  fmtId(PQgetvalue(res, i, i_extname)));
4666  }
4667 
4668  PQclear(res);
4669  destroyPQExpBuffer(query);
4670  pg_free(nm);
4671  }
4672 }
void PQclear(PGresult *res)
Definition: fe-exec.c:718
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3340
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3735
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3448
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void pg_free(void *ptr)
Definition: fe_memutils.c:105
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:100
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:291
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
const char * fmtId(const char *rawid)
Definition: string_utils.c:64
CatalogId catId
Definition: pg_dump.h:135
bool depends_on_ext
Definition: pg_dump.h:143

References appendPQExpBuffer(), _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, _dumpableObject::depends_on_ext, destroyPQExpBuffer(), ExecuteSqlQuery(), fmtId(), i, CatalogId::oid, pg_free(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), and res.

Referenced by dumpConstraint(), dumpFunc(), dumpIndex(), dumpTableSchema(), and dumpTrigger().

◆ appendReloptionsArrayAH()

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

Definition at line 18126 of file pg_dump.c.

18128 {
18129  bool res;
18130 
18131  res = appendReloptionsArray(buffer, reloptions, prefix, fout->encoding,
18132  fout->std_strings);
18133  if (!res)
18134  pg_log_warning("could not parse %s array", "reloptions");
18135 }
#define pg_log_warning(...)
Definition: pgfnames.c:24
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
Definition: string_utils.c:804
bool std_strings
Definition: pg_backup.h:225
int encoding
Definition: pg_backup.h:224

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

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

◆ binary_upgrade_extension_member()

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

Definition at line 4919 of file pg_dump.c.

4924 {
4925  DumpableObject *extobj = NULL;
4926  int i;
4927 
4928  if (!dobj->ext_member)
4929  return;
4930 
4931  /*
4932  * Find the parent extension. We could avoid this search if we wanted to
4933  * add a link field to DumpableObject, but the space costs of that would
4934  * be considerable. We assume that member objects could only have a
4935  * direct dependency on their own extension, not any others.
4936  */
4937  for (i = 0; i < dobj->nDeps; i++)
4938  {
4939  extobj = findObjectByDumpId(dobj->dependencies[i]);
4940  if (extobj && extobj->objType == DO_EXTENSION)
4941  break;
4942  extobj = NULL;
4943  }
4944  if (extobj == NULL)
4945  pg_fatal("could not find parent extension for %s %s",
4946  objtype, objname);
4947 
4948  appendPQExpBufferStr(upgrade_buffer,
4949  "\n-- For binary upgrade, handle extension membership the hard way\n");
4950  appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s ",
4951  fmtId(extobj->name),
4952  objtype);
4953  if (objnamespace && *objnamespace)
4954  appendPQExpBuffer(upgrade_buffer, "%s.", fmtId(objnamespace));
4955  appendPQExpBuffer(upgrade_buffer, "%s;\n", objname);
4956 }
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:666
#define pg_fatal(...)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
char * name
Definition: pg_dump.h:137
DumpId * dependencies
Definition: pg_dump.h:144
bool ext_member
Definition: pg_dump.h:142

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

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

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

4806 {
4807  PQExpBuffer upgrade_query = createPQExpBuffer();
4808  PGresult *upgrade_res;
4809  Oid relfilenode;
4810  Oid toast_oid;
4811  Oid toast_relfilenode;
4812  char relkind;
4813  Oid toast_index_oid;
4814  Oid toast_index_relfilenode;
4815 
4816  /*
4817  * Preserve the OID and relfilenode of the table, table's index, table's
4818  * toast table and toast table's index if any.
4819  *
4820  * One complexity is that the current table definition might not require
4821  * the creation of a TOAST table, but the old database might have a TOAST
4822  * table that was created earlier, before some wide columns were dropped.
4823  * By setting the TOAST oid we force creation of the TOAST heap and index
4824  * by the new backend, so we can copy the files during binary upgrade
4825  * without worrying about this case.
4826  */
4827  appendPQExpBuffer(upgrade_query,
4828  "SELECT c.relkind, c.relfilenode, c.reltoastrelid, ct.relfilenode AS toast_relfilenode, i.indexrelid, cti.relfilenode AS toast_index_relfilenode "
4829  "FROM pg_catalog.pg_class c LEFT JOIN "
4830  "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
4831  "LEFT JOIN pg_catalog.pg_class ct ON (c.reltoastrelid = ct.oid) "
4832  "LEFT JOIN pg_catalog.pg_class AS cti ON (i.indexrelid = cti.oid) "
4833  "WHERE c.oid = '%u'::pg_catalog.oid;",
4834  pg_class_oid);
4835 
4836  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4837 
4838  relkind = *PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "relkind"));
4839 
4840  relfilenode = atooid(PQgetvalue(upgrade_res, 0,
4841  PQfnumber(upgrade_res, "relfilenode")));
4842  toast_oid = atooid(PQgetvalue(upgrade_res, 0,
4843  PQfnumber(upgrade_res, "reltoastrelid")));
4844  toast_relfilenode = atooid(PQgetvalue(upgrade_res, 0,
4845  PQfnumber(upgrade_res, "toast_relfilenode")));
4846  toast_index_oid = atooid(PQgetvalue(upgrade_res, 0,
4847  PQfnumber(upgrade_res, "indexrelid")));
4848  toast_index_relfilenode = atooid(PQgetvalue(upgrade_res, 0,
4849  PQfnumber(upgrade_res, "toast_index_relfilenode")));
4850 
4851  appendPQExpBufferStr(upgrade_buffer,
4852  "\n-- For binary upgrade, must preserve pg_class oids and relfilenodes\n");
4853 
4854  if (!is_index)
4855  {
4856  appendPQExpBuffer(upgrade_buffer,
4857  "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
4858  pg_class_oid);
4859 
4860  /*
4861  * Not every relation has storage. Also, in a pre-v12 database,
4862  * partitioned tables have a relfilenode, which should not be
4863  * preserved when upgrading.
4864  */
4865  if (OidIsValid(relfilenode) && relkind != RELKIND_PARTITIONED_TABLE)
4866  appendPQExpBuffer(upgrade_buffer,
4867  "SELECT pg_catalog.binary_upgrade_set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
4868  relfilenode);
4869 
4870  /*
4871  * In a pre-v12 database, partitioned tables might be marked as having
4872  * toast tables, but we should ignore them if so.
4873  */
4874  if (OidIsValid(toast_oid) &&
4875  relkind != RELKIND_PARTITIONED_TABLE)
4876  {
4877  appendPQExpBuffer(upgrade_buffer,
4878  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
4879  toast_oid);
4880  appendPQExpBuffer(upgrade_buffer,
4881  "SELECT pg_catalog.binary_upgrade_set_next_toast_relfilenode('%u'::pg_catalog.oid);\n",
4882  toast_relfilenode);
4883 
4884  /* every toast table has an index */
4885  appendPQExpBuffer(upgrade_buffer,
4886  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4887  toast_index_oid);
4888  appendPQExpBuffer(upgrade_buffer,
4889  "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
4890  toast_index_relfilenode);
4891  }
4892 
4893  PQclear(upgrade_res);
4894  }
4895  else
4896  {
4897  /* Preserve the OID and relfilenode of the index */
4898  appendPQExpBuffer(upgrade_buffer,
4899  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4900  pg_class_oid);
4901  appendPQExpBuffer(upgrade_buffer,
4902  "SELECT pg_catalog.binary_upgrade_set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
4903  relfilenode);
4904  }
4905 
4906  appendPQExpBufferChar(upgrade_buffer, '\n');
4907 
4908  destroyPQExpBuffer(upgrade_query);
4909 }
#define OidIsValid(objectId)
Definition: c.h:710
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)
Definition: pg_backup_db.c:306
unsigned int Oid
Definition: postgres_ext.h:31
#define atooid(x)
Definition: postgres_ext.h:42
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380

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

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

◆ binary_upgrade_set_type_oids_by_rel()

static void binary_upgrade_set_type_oids_by_rel ( Archive fout,
PQExpBuffer  upgrade_buffer,
const TableInfo tbinfo 
)
static

Definition at line 4791 of file pg_dump.c.

4794 {
4795  Oid pg_type_oid = tbinfo->reltype;
4796 
4797  if (OidIsValid(pg_type_oid))
4798  binary_upgrade_set_type_oids_by_type_oid(fout, upgrade_buffer,
4799  pg_type_oid, false, false);
4800 }
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid, bool force_array_type, bool include_multirange_type)
Definition: pg_dump.c:4706
Oid reltype
Definition: pg_dump.h:307

References binary_upgrade_set_type_oids_by_type_oid(), OidIsValid, and _tableInfo::reltype.

Referenced by dumpTableSchema().

◆ 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,
bool  include_multirange_type 
)
static

Definition at line 4706 of file pg_dump.c.

4711 {
4712  PQExpBuffer upgrade_query = createPQExpBuffer();
4713  PGresult *res;
4714  Oid pg_type_array_oid;
4715  Oid pg_type_multirange_oid;
4716  Oid pg_type_multirange_array_oid;
4717 
4718  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
4719  appendPQExpBuffer(upgrade_buffer,
4720  "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4721  pg_type_oid);
4722 
4723  appendPQExpBuffer(upgrade_query,
4724  "SELECT typarray "
4725  "FROM pg_catalog.pg_type "
4726  "WHERE oid = '%u'::pg_catalog.oid;",
4727  pg_type_oid);
4728 
4729  res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4730 
4731  pg_type_array_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typarray")));
4732 
4733  PQclear(res);
4734 
4735  if (!OidIsValid(pg_type_array_oid) && force_array_type)
4736  pg_type_array_oid = get_next_possible_free_pg_type_oid(fout, upgrade_query);
4737 
4738  if (OidIsValid(pg_type_array_oid))
4739  {
4740  appendPQExpBufferStr(upgrade_buffer,
4741  "\n-- For binary upgrade, must preserve pg_type array oid\n");
4742  appendPQExpBuffer(upgrade_buffer,
4743  "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4744  pg_type_array_oid);
4745  }
4746 
4747  /*
4748  * Pre-set the multirange type oid and its own array type oid.
4749  */
4750  if (include_multirange_type)
4751  {
4752  if (fout->remoteVersion >= 140000)
4753  {
4754  printfPQExpBuffer(upgrade_query,
4755  "SELECT t.oid, t.typarray "
4756  "FROM pg_catalog.pg_type t "
4757  "JOIN pg_catalog.pg_range r "
4758  "ON t.oid = r.rngmultitypid "
4759  "WHERE r.rngtypid = '%u'::pg_catalog.oid;",
4760  pg_type_oid);
4761 
4762  res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4763 
4764  pg_type_multirange_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "oid")));
4765  pg_type_multirange_array_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typarray")));
4766 
4767  PQclear(res);
4768  }
4769  else
4770  {
4771  pg_type_multirange_oid = get_next_possible_free_pg_type_oid(fout, upgrade_query);
4772  pg_type_multirange_array_oid = get_next_possible_free_pg_type_oid(fout, upgrade_query);
4773  }
4774 
4775  appendPQExpBufferStr(upgrade_buffer,
4776  "\n-- For binary upgrade, must preserve multirange pg_type oid\n");
4777  appendPQExpBuffer(upgrade_buffer,
4778  "SELECT pg_catalog.binary_upgrade_set_next_multirange_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4779  pg_type_multirange_oid);
4780  appendPQExpBufferStr(upgrade_buffer,
4781  "\n-- For binary upgrade, must preserve multirange pg_type array oid\n");
4782  appendPQExpBuffer(upgrade_buffer,
4783  "SELECT pg_catalog.binary_upgrade_set_next_multirange_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4784  pg_type_multirange_array_oid);
4785  }
4786 
4787  destroyPQExpBuffer(upgrade_query);
4788 }
static Oid get_next_possible_free_pg_type_oid(Archive *fout, PQExpBuffer upgrade_query)
Definition: pg_dump.c:4675
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:237
int remoteVersion
Definition: pg_backup.h:214

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

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

◆ BuildArchiveDependencies()

static void BuildArchiveDependencies ( Archive fout)
static

Definition at line 17925 of file pg_dump.c.

17926 {
17927  ArchiveHandle *AH = (ArchiveHandle *) fout;
17928  TocEntry *te;
17929 
17930  /* Scan all TOC entries in the archive */
17931  for (te = AH->toc->next; te != AH->toc; te = te->next)
17932  {
17933  DumpableObject *dobj;
17934  DumpId *dependencies;
17935  int nDeps;
17936  int allocDeps;
17937 
17938  /* No need to process entries that will not be dumped */
17939  if (te->reqs == 0)
17940  continue;
17941  /* Ignore entries that already have "special" dependencies */
17942  if (te->nDeps > 0)
17943  continue;
17944  /* Otherwise, look up the item's original DumpableObject, if any */
17945  dobj = findObjectByDumpId(te->dumpId);
17946  if (dobj == NULL)
17947  continue;
17948  /* No work if it has no dependencies */
17949  if (dobj->nDeps <= 0)
17950  continue;
17951  /* Set up work array */
17952  allocDeps = 64;
17953  dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(DumpId));
17954  nDeps = 0;
17955  /* Recursively find all dumpable dependencies */
17956  findDumpableDependencies(AH, dobj,
17957  &dependencies, &nDeps, &allocDeps);
17958  /* And save 'em ... */
17959  if (nDeps > 0)
17960  {
17961  dependencies = (DumpId *) pg_realloc(dependencies,
17962  nDeps * sizeof(DumpId));
17963  te->dependencies = dependencies;
17964  te->nDeps = nDeps;
17965  }
17966  else
17967  free(dependencies);
17968  }
17969 }
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define free(a)
Definition: header.h:65
int DumpId
Definition: pg_backup.h:265
static void findDumpableDependencies(ArchiveHandle *AH, const DumpableObject *dobj, DumpId **dependencies, int *nDeps, int *allocDeps)
Definition: pg_dump.c:17973
struct _tocEntry * toc
struct _tocEntry * next
DumpId * dependencies

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

Referenced by main().

◆ buildMatViewRefreshDependencies()

static void buildMatViewRefreshDependencies ( Archive fout)
static

Definition at line 2637 of file pg_dump.c.

2638 {
2639  PQExpBuffer query;
2640  PGresult *res;
2641  int ntups,
2642  i;
2643  int i_classid,
2644  i_objid,
2645  i_refobjid;
2646 
2647  /* No Mat Views before 9.3. */
2648  if (fout->remoteVersion < 90300)
2649  return;
2650 
2651  query = createPQExpBuffer();
2652 
2653  appendPQExpBufferStr(query, "WITH RECURSIVE w AS "
2654  "( "
2655  "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2656  "FROM pg_depend d1 "
2657  "JOIN pg_class c1 ON c1.oid = d1.objid "
2658  "AND c1.relkind = " CppAsString2(RELKIND_MATVIEW)
2659  " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2660  "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2661  "AND d2.objid = r1.oid "
2662  "AND d2.refobjid <> d1.objid "
2663  "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2664  "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2665  CppAsString2(RELKIND_VIEW) ") "
2666  "WHERE d1.classid = 'pg_class'::regclass "
2667  "UNION "
2668  "SELECT w.objid, d3.refobjid, c3.relkind "
2669  "FROM w "
2670  "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2671  "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2672  "AND d3.objid = r3.oid "
2673  "AND d3.refobjid <> w.refobjid "
2674  "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2675  "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2676  CppAsString2(RELKIND_VIEW) ") "
2677  ") "
2678  "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2679  "FROM w "
2680  "WHERE refrelkind = " CppAsString2(RELKIND_MATVIEW));
2681 
2682  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
2683 
2684  ntups = PQntuples(res);
2685 
2686  i_classid = PQfnumber(res, "classid");
2687  i_objid = PQfnumber(res, "objid");
2688  i_refobjid = PQfnumber(res, "refobjid");
2689 
2690  for (i = 0; i < ntups; i++)
2691  {
2692  CatalogId objId;
2693  CatalogId refobjId;
2694  DumpableObject *dobj;
2695  DumpableObject *refdobj;
2696  TableInfo *tbinfo;
2697  TableInfo *reftbinfo;
2698 
2699  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
2700  objId.oid = atooid(PQgetvalue(res, i, i_objid));
2701  refobjId.tableoid = objId.tableoid;
2702  refobjId.oid = atooid(PQgetvalue(res, i, i_refobjid));
2703 
2704  dobj = findObjectByCatalogId(objId);
2705  if (dobj == NULL)
2706  continue;
2707 
2708  Assert(dobj->objType == DO_TABLE);
2709  tbinfo = (TableInfo *) dobj;
2710  Assert(tbinfo->relkind == RELKIND_MATVIEW);
2711  dobj = (DumpableObject *) tbinfo->dataObj;
2712  if (dobj == NULL)
2713  continue;
2714  Assert(dobj->objType == DO_REFRESH_MATVIEW);
2715 
2716  refdobj = findObjectByCatalogId(refobjId);
2717  if (refdobj == NULL)
2718  continue;
2719 
2720  Assert(refdobj->objType == DO_TABLE);
2721  reftbinfo = (TableInfo *) refdobj;
2722  Assert(reftbinfo->relkind == RELKIND_MATVIEW);
2723  refdobj = (DumpableObject *) reftbinfo->dataObj;
2724  if (refdobj == NULL)
2725  continue;
2726  Assert(refdobj->objType == DO_REFRESH_MATVIEW);
2727 
2728  addObjectDependency(dobj, refdobj->dumpId);
2729 
2730  if (!reftbinfo->relispopulated)
2731  tbinfo->relispopulated = false;
2732  }
2733 
2734  PQclear(res);
2735 
2736  destroyPQExpBuffer(query);
2737 }
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition: common.c:679
#define CppAsString2(x)
Definition: c.h:289
Oid tableoid
Definition: pg_backup.h:261
bool relispopulated
Definition: pg_dump.h:288
struct _tableDataInfo * dataObj
Definition: pg_dump.h:358
char relkind
Definition: pg_dump.h:286

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

Referenced by main().

◆ checkExtensionMembership()

static bool checkExtensionMembership ( DumpableObject dobj,
Archive fout 
)
static

Definition at line 1565 of file pg_dump.c.

1566 {
1567  ExtensionInfo *ext = findOwningExtension(dobj->catId);
1568 
1569  if (ext == NULL)
1570  return false;
1571 
1572  dobj->ext_member = true;
1573 
1574  /* Record dependency so that getDependencies needn't deal with that */
1575  addObjectDependency(dobj, ext->dobj.dumpId);
1576 
1577  /*
1578  * In 9.6 and above, mark the member object to have any non-initial ACL,
1579  * policies, and security labels dumped.
1580  *
1581  * Note that any initial ACLs (see pg_init_privs) will be removed when we
1582  * extract the information about the object. We don't provide support for
1583  * initial policies and security labels and it seems unlikely for those to
1584  * ever exist, but we may have to revisit this later.
1585  *
1586  * Prior to 9.6, we do not include any extension member components.
1587  *
1588  * In binary upgrades, we still dump all components of the members
1589  * individually, since the idea is to exactly reproduce the database
1590  * contents rather than replace the extension contents with something
1591  * different.
1592  */
1593  if (fout->dopt->binary_upgrade)
1594  dobj->dump = ext->dobj.dump;
1595  else
1596  {
1597  if (fout->remoteVersion < 90600)
1598  dobj->dump = DUMP_COMPONENT_NONE;
1599  else
1600  dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL |
1603  }
1604 
1605  return true;
1606 }
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition: common.c:955
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:101
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:99
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:100
#define DUMP_COMPONENT_NONE
Definition: pg_dump.h:95
DumpOptions * dopt
Definition: pg_backup.h:209
int binary_upgrade
Definition: pg_backup.h:161
DumpComponents dump
Definition: pg_dump.h:138
DumpComponents dump_contains
Definition: pg_dump.h:140
DumpableObject dobj
Definition: pg_dump.h:180

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(), selectDumpablePublicationObject(), selectDumpableTable(), and selectDumpableType().

◆ collectComments()

static void collectComments ( Archive fout)
static

Definition at line 9692 of file pg_dump.c.

9693 {
9694  PGresult *res;
9695  PQExpBuffer query;
9696  int i_description;
9697  int i_classoid;
9698  int i_objoid;
9699  int i_objsubid;
9700  int ntups;
9701  int i;
9702  DumpableObject *dobj;
9703 
9704  query = createPQExpBuffer();
9705 
9706  appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
9707  "FROM pg_catalog.pg_description "
9708  "ORDER BY classoid, objoid, objsubid");
9709 
9710  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9711 
9712  /* Construct lookup table containing OIDs in numeric form */
9713 
9714  i_description = PQfnumber(res, "description");
9715  i_classoid = PQfnumber(res, "classoid");
9716  i_objoid = PQfnumber(res, "objoid");
9717  i_objsubid = PQfnumber(res, "objsubid");
9718 
9719  ntups = PQntuples(res);
9720 
9721  comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
9722  ncomments = 0;
9723  dobj = NULL;
9724 
9725  for (i = 0; i < ntups; i++)
9726  {
9727  CatalogId objId;
9728  int subid;
9729 
9730  objId.tableoid = atooid(PQgetvalue(res, i, i_classoid));
9731  objId.oid = atooid(PQgetvalue(res, i, i_objoid));
9732  subid = atoi(PQgetvalue(res, i, i_objsubid));
9733 
9734  /* We needn't remember comments that don't match any dumpable object */
9735  if (dobj == NULL ||
9736  dobj->catId.tableoid != objId.tableoid ||
9737  dobj->catId.oid != objId.oid)
9738  dobj = findObjectByCatalogId(objId);
9739  if (dobj == NULL)
9740  continue;
9741 
9742  /*
9743  * Comments on columns of composite types are linked to the type's
9744  * pg_class entry, but we need to set the DUMP_COMPONENT_COMMENT flag
9745  * in the type's own DumpableObject.
9746  */
9747  if (subid != 0 && dobj->objType == DO_TABLE &&
9748  ((TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
9749  {
9750  TypeInfo *cTypeInfo;
9751 
9752  cTypeInfo = findTypeByOid(((TableInfo *) dobj)->reltype);
9753  if (cTypeInfo)
9754  cTypeInfo->dobj.components |= DUMP_COMPONENT_COMMENT;
9755  }
9756  else
9757  dobj->components |= DUMP_COMPONENT_COMMENT;
9758 
9759  comments[ncomments].descr = pg_strdup(PQgetvalue(res, i, i_description));
9761  comments[ncomments].objoid = objId.oid;
9762  comments[ncomments].objsubid = subid;
9763  ncomments++;
9764  }
9765 
9766  PQclear(res);
9767  destroyPQExpBuffer(query);
9768 }
TypeInfo * findTypeByOid(Oid oid)
Definition: common.c:803
static int ncomments
Definition: pg_dump.c:142
static CommentItem * comments
Definition: pg_dump.c:141
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:98
Oid classoid
Definition: pg_dump.c:78
Oid objoid
Definition: pg_dump.c:79
int objsubid
Definition: pg_dump.c:80
const char * descr
Definition: pg_dump.c:77
DumpComponents components
Definition: pg_dump.h:141
DumpableObject dobj
Definition: pg_dump.h:190

References appendPQExpBufferStr(), atooid, _dumpableObject::catId, CommentItem::classoid, comments, _dumpableObject::components, createPQExpBuffer(), PQExpBufferData::data, CommentItem::descr, destroyPQExpBuffer(), DO_TABLE, _typeInfo::dobj, DUMP_COMPONENT_COMMENT, ExecuteSqlQuery(), findObjectByCatalogId(), findTypeByOid(), i, ncomments, CommentItem::objoid, CommentItem::objsubid, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), res, and CatalogId::tableoid.

Referenced by main().

◆ collectRoleNames()

static void collectRoleNames ( Archive fout)
static

Definition at line 9237 of file pg_dump.c.

9238 {
9239  PGresult *res;
9240  const char *query;
9241  int i;
9242 
9243  query = "SELECT oid, rolname FROM pg_catalog.pg_roles ORDER BY 1";
9244 
9245  res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK);
9246 
9248 
9250 
9251  for (i = 0; i < nrolenames; i++)
9252  {
9255  }
9256 
9257  PQclear(res);
9258 }
static RoleNameItem * rolenames
Definition: pg_dump.c:137
static int nrolenames
Definition: pg_dump.c:138
const char * rolename
Definition: pg_dump.c:72
Oid roleoid
Definition: pg_dump.c:71

References atooid, ExecuteSqlQuery(), i, nrolenames, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQgetvalue(), PQntuples(), res, RoleNameItem::rolename, rolenames, and RoleNameItem::roleoid.

Referenced by main().

◆ collectSecLabels()

static void collectSecLabels ( Archive fout)
static

Definition at line 14715 of file pg_dump.c.

14716 {
14717  PGresult *res;
14718  PQExpBuffer query;
14719  int i_label;
14720  int i_provider;
14721  int i_classoid;
14722  int i_objoid;
14723  int i_objsubid;
14724  int ntups;
14725  int i;
14726  DumpableObject *dobj;
14727 
14728  query = createPQExpBuffer();
14729 
14730  appendPQExpBufferStr(query,
14731  "SELECT label, provider, classoid, objoid, objsubid "
14732  "FROM pg_catalog.pg_seclabel "
14733  "ORDER BY classoid, objoid, objsubid");
14734 
14735  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
14736 
14737  /* Construct lookup table containing OIDs in numeric form */
14738  i_label = PQfnumber(res, "label");
14739  i_provider = PQfnumber(res, "provider");
14740  i_classoid = PQfnumber(res, "classoid");
14741  i_objoid = PQfnumber(res, "objoid");
14742  i_objsubid = PQfnumber(res, "objsubid");
14743 
14744  ntups = PQntuples(res);
14745 
14746  seclabels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
14747  nseclabels = 0;
14748  dobj = NULL;
14749 
14750  for (i = 0; i < ntups; i++)
14751  {
14752  CatalogId objId;
14753  int subid;
14754 
14755  objId.tableoid = atooid(PQgetvalue(res, i, i_classoid));
14756  objId.oid = atooid(PQgetvalue(res, i, i_objoid));
14757  subid = atoi(PQgetvalue(res, i, i_objsubid));
14758 
14759  /* We needn't remember labels that don't match any dumpable object */
14760  if (dobj == NULL ||
14761  dobj->catId.tableoid != objId.tableoid ||
14762  dobj->catId.oid != objId.oid)
14763  dobj = findObjectByCatalogId(objId);
14764  if (dobj == NULL)
14765  continue;
14766 
14767  /*
14768  * Labels on columns of composite types are linked to the type's
14769  * pg_class entry, but we need to set the DUMP_COMPONENT_SECLABEL flag
14770  * in the type's own DumpableObject.
14771  */
14772  if (subid != 0 && dobj->objType == DO_TABLE &&
14773  ((TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
14774  {
14775  TypeInfo *cTypeInfo;
14776 
14777  cTypeInfo = findTypeByOid(((TableInfo *) dobj)->reltype);
14778  if (cTypeInfo)
14779  cTypeInfo->dobj.components |= DUMP_COMPONENT_SECLABEL;
14780  }
14781  else
14782  dobj->components |= DUMP_COMPONENT_SECLABEL;
14783 
14787  seclabels[nseclabels].objoid = objId.oid;
14788  seclabels[nseclabels].objsubid = subid;
14789  nseclabels++;
14790  }
14791 
14792  PQclear(res);
14793  destroyPQExpBuffer(query);
14794 }
static int nseclabels
Definition: pg_dump.c:146
static SecLabelItem * seclabels
Definition: pg_dump.c:145
const char * provider
Definition: pg_dump.c:85
Oid classoid
Definition: pg_dump.c:87
int objsubid
Definition: pg_dump.c:89
const char * label
Definition: pg_dump.c:86
Oid objoid
Definition: pg_dump.c:88

References appendPQExpBufferStr(), atooid, _dumpableObject::catId, SecLabelItem::classoid, _dumpableObject::components, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TABLE, _typeInfo::dobj, DUMP_COMPONENT_SECLABEL, ExecuteSqlQuery(), findObjectByCatalogId(), findTypeByOid(), i, SecLabelItem::label, nseclabels, SecLabelItem::objoid, SecLabelItem::objsubid, _dumpableObject::objType, CatalogId::oid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), SecLabelItem::provider, res, seclabels, and CatalogId::tableoid.

Referenced by main().

◆ convertRegProcReference()

static char * convertRegProcReference ( const char *  proc)
static

Definition at line 12377 of file pg_dump.c.

12378 {
12379  char *name;
12380  char *paren;
12381  bool inquote;
12382 
12383  /* In all cases "-" means a null reference */
12384  if (strcmp(proc, "-") == 0)
12385  return NULL;
12386 
12387  name = pg_strdup(proc);
12388  /* find non-double-quoted left paren */
12389  inquote = false;
12390  for (paren = name; *paren; paren++)
12391  {
12392  if (*paren == '(' && !inquote)
12393  {
12394  *paren = '\0';
12395  break;
12396  }
12397  if (*paren == '"')
12398  inquote = !inquote;
12399  }
12400  return name;
12401 }
const char * name
Definition: encode.c:561

References name, and pg_strdup().

Referenced by dumpOpr().

◆ convertTSFunction()

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

Definition at line 12448 of file pg_dump.c.

12449 {
12450  char *result;
12451  char query[128];
12452  PGresult *res;
12453 
12454  snprintf(query, sizeof(query),
12455  "SELECT '%u'::pg_catalog.regproc", funcOid);
12456  res = ExecuteSqlQueryForSingleRow(fout, query);
12457 
12458  result = pg_strdup(PQgetvalue(res, 0, 0));
12459 
12460  PQclear(res);
12461 
12462  return result;
12463 }
#define snprintf
Definition: port.h:225

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

Referenced by dumpTSParser(), and dumpTSTemplate().

◆ createBoundaryObjects()

static DumpableObject * createBoundaryObjects ( void  )
static

Definition at line 17786 of file pg_dump.c.

17787 {
17788  DumpableObject *dobjs;
17789 
17790  dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject));
17791 
17792  dobjs[0].objType = DO_PRE_DATA_BOUNDARY;
17793  dobjs[0].catId = nilCatalogId;
17794  AssignDumpId(dobjs + 0);
17795  dobjs[0].name = pg_strdup("PRE-DATA BOUNDARY");
17796 
17797  dobjs[1].objType = DO_POST_DATA_BOUNDARY;
17798  dobjs[1].catId = nilCatalogId;
17799  AssignDumpId(dobjs + 1);
17800  dobjs[1].name = pg_strdup("POST-DATA BOUNDARY");
17801 
17802  return dobjs;
17803 }
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:580
static const CatalogId nilCatalogId
Definition: pg_dump.c:130

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

◆ createDummyViewAsClause()

static PQExpBuffer createDummyViewAsClause ( Archive fout,
const TableInfo tbinfo 
)
static

Definition at line 14990 of file pg_dump.c.

14991 {
14992  PQExpBuffer result = createPQExpBuffer();
14993  int j;
14994 
14995  appendPQExpBufferStr(result, "SELECT");
14996 
14997  for (j = 0; j < tbinfo->numatts; j++)
14998  {
14999  if (j > 0)
15000  appendPQExpBufferChar(result, ',');
15001  appendPQExpBufferStr(result, "\n ");
15002 
15003  appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]);
15004 
15005  /*
15006  * Must add collation if not default for the type, because CREATE OR
15007  * REPLACE VIEW won't change it
15008  */
15009  if (OidIsValid(tbinfo->attcollation[j]))
15010  {
15011  CollInfo *coll;
15012 
15013  coll = findCollationByOid(tbinfo->attcollation[j]);
15014  if (coll)
15015  appendPQExpBuffer(result, " COLLATE %s",
15016  fmtQualifiedDumpable(coll));
15017  }
15018 
15019  appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j]));
15020  }
15021 
15022  return result;
15023 }
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:858
int j
Definition: isn.c:74
#define fmtQualifiedDumpable(obj)
Definition: pg_dump.c:157
int numatts
Definition: pg_dump.h:326
Oid * attcollation
Definition: pg_dump.h:340
char ** atttypnames
Definition: pg_dump.h:328
char ** attnames
Definition: pg_dump.h:327

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

Referenced by dumpRule(), and dumpTableSchema().

◆ createViewAsClause()

static PQExpBuffer createViewAsClause ( Archive fout,
const TableInfo tbinfo 
)
static

Definition at line 14941 of file pg_dump.c.

14942 {
14943  PQExpBuffer query = createPQExpBuffer();
14944  PQExpBuffer result = createPQExpBuffer();
14945  PGresult *res;
14946  int len;
14947 
14948  /* Fetch the view definition */
14949  appendPQExpBuffer(query,
14950  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
14951  tbinfo->dobj.catId.oid);
14952 
14953  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
14954 
14955  if (PQntuples(res) != 1)
14956  {
14957  if (PQntuples(res) < 1)
14958  pg_fatal("query to obtain definition of view \"%s\" returned no data",
14959  tbinfo->dobj.name);
14960  else
14961  pg_fatal("query to obtain definition of view \"%s\" returned more than one definition",
14962  tbinfo->dobj.name);
14963  }
14964 
14965  len = PQgetlength(res, 0, 0);
14966 
14967  if (len == 0)
14968  pg_fatal("definition of view \"%s\" appears to be empty (length zero)",
14969  tbinfo->dobj.name);
14970 
14971  /* Strip off the trailing semicolon so that other things may follow. */
14972  Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
14973  appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
14974 
14975  PQclear(res);
14976  destroyPQExpBuffer(query);
14977 
14978  return result;
14979 }
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3746
const void size_t len
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:399
DumpableObject dobj
Definition: pg_dump.h:283

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

Referenced by dumpRule(), and dumpTableSchema().

◆ dumpAccessMethod()

static void dumpAccessMethod ( Archive fout,
const AccessMethodInfo oprinfo 
)
static

Definition at line 12470 of file pg_dump.c.

12471 {
12472  DumpOptions *dopt = fout->dopt;
12473  PQExpBuffer q;
12474  PQExpBuffer delq;
12475  char *qamname;
12476 
12477  /* Do nothing in data-only dump */
12478  if (dopt->dataOnly)
12479  return;
12480 
12481  q = createPQExpBuffer();
12482  delq = createPQExpBuffer();
12483 
12484  qamname = pg_strdup(fmtId(aminfo->dobj.name));
12485 
12486  appendPQExpBuffer(q, "CREATE ACCESS METHOD %s ", qamname);
12487 
12488  switch (aminfo->amtype)
12489  {
12490  case AMTYPE_INDEX:
12491  appendPQExpBufferStr(q, "TYPE INDEX ");
12492  break;
12493  case AMTYPE_TABLE:
12494  appendPQExpBufferStr(q, "TYPE TABLE ");
12495  break;
12496  default:
12497  pg_log_warning("invalid type \"%c\" of access method \"%s\"",
12498  aminfo->amtype, qamname);
12499  destroyPQExpBuffer(q);
12500  destroyPQExpBuffer(delq);
12501  free(qamname);
12502  return;
12503  }
12504 
12505  appendPQExpBuffer(q, "HANDLER %s;\n", aminfo->amhandler);
12506 
12507  appendPQExpBuffer(delq, "DROP ACCESS METHOD %s;\n",
12508  qamname);
12509 
12510  if (dopt->binary_upgrade)
12511  binary_upgrade_extension_member(q, &aminfo->dobj,
12512  "ACCESS METHOD", qamname, NULL);
12513 
12514  if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
12515  ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
12516  ARCHIVE_OPTS(.tag = aminfo->dobj.name,
12517  .description = "ACCESS METHOD",
12518  .section = SECTION_PRE_DATA,
12519  .createStmt = q->data,
12520  .dropStmt = delq->data));
12521 
12522  /* Dump Access Method Comments */
12523  if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT)
12524  dumpComment(fout, "ACCESS METHOD", qamname,
12525  NULL, "",
12526  aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
12527 
12528  destroyPQExpBuffer(q);
12529  destroyPQExpBuffer(delq);
12530  free(qamname);
12531 }
@ SECTION_PRE_DATA
Definition: pg_backup.h:56
TocEntry * ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
#define ARCHIVE_OPTS(...)
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:9501
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, const DumpableObject *dobj, const char *objtype, const char *objname, const char *objnamespace)
Definition: pg_dump.c:4919
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:96
bool dataOnly
Definition: pg_backup.h:165

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

◆ dumpACL()

static DumpId dumpACL ( Archive fout,
DumpId  objDumpId,
DumpId  altDumpId,
const char *  type,
const char *  name,
const char *  subname,
const char *  nspname,
const char *  owner,
const DumpableAcl dacl 
)
static

Definition at line 14351 of file pg_dump.c.

14355 {
14356  DumpId aclDumpId = InvalidDumpId;
14357  DumpOptions *dopt = fout->dopt;
14358  const char *acls = dacl->acl;
14359  const char *acldefault = dacl->acldefault;
14360  char privtype = dacl->privtype;
14361  const char *initprivs = dacl->initprivs;
14362  const char *baseacls;
14363  PQExpBuffer sql;
14364 
14365  /* Do nothing if ACL dump is not enabled */
14366  if (dopt->aclsSkip)
14367  return InvalidDumpId;
14368 
14369  /* --data-only skips ACLs *except* BLOB ACLs */
14370  if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
14371  return InvalidDumpId;
14372 
14373  sql = createPQExpBuffer();
14374 
14375  /*
14376  * In binary upgrade mode, we don't run an extension's script but instead
14377  * dump out the objects independently and then recreate them. To preserve
14378  * any initial privileges which were set on extension objects, we need to
14379  * compute the set of GRANT and REVOKE commands necessary to get from the
14380  * default privileges of an object to its initial privileges as recorded
14381  * in pg_init_privs.
14382  *
14383  * At restore time, we apply these commands after having called
14384  * binary_upgrade_set_record_init_privs(true). That tells the backend to
14385  * copy the results into pg_init_privs. This is how we preserve the
14386  * contents of that catalog across binary upgrades.
14387  */
14388  if (dopt->binary_upgrade && privtype == 'e' &&
14389  initprivs && *initprivs != '\0')
14390  {
14391  appendPQExpBufferStr(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
14392  if (!buildACLCommands(name, subname, nspname, type,
14393  initprivs, acldefault, owner,
14394  "", fout->remoteVersion, sql))
14395  pg_fatal("could not parse initial ACL list (%s) or default (%s) for object \"%s\" (%s)",
14396  initprivs, acldefault, name, type);
14397  appendPQExpBufferStr(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
14398  }
14399 
14400  /*
14401  * Now figure the GRANT and REVOKE commands needed to get to the object's
14402  * actual current ACL, starting from the initprivs if given, else from the
14403  * object-type-specific default. Also, while buildACLCommands will assume
14404  * that a NULL/empty acls string means it needn't do anything, what that
14405  * actually represents is the object-type-specific default; so we need to
14406  * substitute the acldefault string to get the right results in that case.
14407  */
14408  if (initprivs && *initprivs != '\0')
14409  {
14410  baseacls = initprivs;
14411  if (acls == NULL || *acls == '\0')
14412  acls = acldefault;
14413  }
14414  else
14415  baseacls = acldefault;
14416 
14417  if (!buildACLCommands(name, subname, nspname, type,
14418  acls, baseacls, owner,
14419  "", fout->remoteVersion, sql))
14420  pg_fatal("could not parse ACL list (%s) or default (%s) for object \"%s\" (%s)",
14421  acls, baseacls, name, type);
14422 
14423  if (sql->len > 0)
14424  {
14426  DumpId aclDeps[2];
14427  int nDeps = 0;
14428 
14429  if (subname)
14430  appendPQExpBuffer(tag, "COLUMN %s.%s", name, subname);
14431  else
14432  appendPQExpBuffer(tag, "%s %s", type, name);
14433 
14434  aclDeps[nDeps++] = objDumpId;
14435  if (altDumpId != InvalidDumpId)
14436  aclDeps[nDeps++] = altDumpId;
14437 
14438  aclDumpId = createDumpId();
14439 
14440  ArchiveEntry(fout, nilCatalogId, aclDumpId,
14441  ARCHIVE_OPTS(.tag = tag->data,
14442  .namespace = nspname,
14443  .owner = owner,
14444  .description = "ACL",
14445  .section = SECTION_NONE,
14446  .createStmt = sql->data,
14447  .deps = aclDeps,
14448  .nDeps = nDeps));
14449 
14450  destroyPQExpBuffer(tag);
14451  }
14452 
14453  destroyPQExpBuffer(sql);
14454 
14455  return aclDumpId;
14456 }
Acl * acldefault(ObjectType objtype, Oid ownerId)
Definition: acl.c:743
DumpId createDumpId(void)
Definition: common.c:646
bool buildACLCommands(const char *name, const char *subname, const char *nspname, const char *type, const char *acls, const char *baseacls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql)
Definition: dumputils.c:64
@ SECTION_NONE
Definition: pg_backup.h:55
#define InvalidDumpId
Definition: pg_backup.h:267
NameData subname
bool aclsSkip
Definition: pg_backup.h:167
char privtype
Definition: pg_dump.h:158
char * acldefault
Definition: pg_dump.h:156
char * acl
Definition: pg_dump.h:155
char * initprivs
Definition: pg_dump.h:159

References _dumpableAcl::acl, acldefault(), _dumpableAcl::acldefault, _dumpOptions::aclsSkip, appendPQExpBuffer(), appendPQExpBufferStr(), ARCHIVE_OPTS, ArchiveEntry(), _dumpOptions::binary_upgrade, buildACLCommands(), createDumpId(), createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), Archive::dopt, _dumpableAcl::initprivs, InvalidDumpId, PQExpBufferData::len, name, nilCatalogId, pg_fatal, _dumpableAcl::privtype, Archive::remoteVersion, SECTION_NONE, subname, and generate_unaccent_rules::type.

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

◆ dumpAgg()

static void dumpAgg ( Archive fout,
const AggInfo agginfo 
)
static

Definition at line 13317 of file pg_dump.c.

13318 {
13319  DumpOptions *dopt = fout->dopt;
13320  PQExpBuffer query;
13321  PQExpBuffer q;
13322  PQExpBuffer delq;
13323  PQExpBuffer details;
13324  char *aggsig; /* identity signature */
13325  char *aggfullsig = NULL; /* full signature */
13326  char *aggsig_tag;
13327  PGresult *res;
13328  int i_agginitval;
13329  int i_aggminitval;
13330  const char *aggtransfn;
13331  const char *aggfinalfn;
13332  const char *aggcombinefn;
13333  const char *aggserialfn;
13334  const char *aggdeserialfn;
13335  const char *aggmtransfn;
13336  const char *aggminvtransfn;
13337  const char *aggmfinalfn;
13338  bool aggfinalextra;
13339  bool aggmfinalextra;
13340  char aggfinalmodify;
13341  char aggmfinalmodify;
13342  const char *aggsortop;
13343  char *aggsortconvop;
13344  char aggkind;
13345  const char *aggtranstype;
13346  const char *aggtransspace;
13347  const char *aggmtranstype;
13348  const char *aggmtransspace;
13349  const char *agginitval;
13350  const char *aggminitval;
13351  const char *proparallel;
13352  char defaultfinalmodify;
13353 
13354  /* Do nothing in data-only dump */
13355  if (dopt->dataOnly)
13356  return;
13357 
13358  query = createPQExpBuffer();
13359  q = createPQExpBuffer();
13360  delq = createPQExpBuffer();
13361  details = createPQExpBuffer();
13362 
13363  if (!fout->is_prepared[PREPQUERY_DUMPAGG])
13364  {
13365  /* Set up query for aggregate-specific details */
13366  appendPQExpBufferStr(query,
13367  "PREPARE dumpAgg(pg_catalog.oid) AS\n");
13368 
13369  appendPQExpBufferStr(query,
13370  "SELECT "
13371  "aggtransfn,\n"
13372  "aggfinalfn,\n"
13373  "aggtranstype::pg_catalog.regtype,\n"
13374  "agginitval,\n"
13375  "aggsortop,\n"
13376  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
13377  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
13378 
13379  if (fout->remoteVersion >= 90400)
13380  appendPQExpBufferStr(query,
13381  "aggkind,\n"
13382  "aggmtransfn,\n"
13383  "aggminvtransfn,\n"
13384  "aggmfinalfn,\n"
13385  "aggmtranstype::pg_catalog.regtype,\n"
13386  "aggfinalextra,\n"
13387  "aggmfinalextra,\n"
13388  "aggtransspace,\n"
13389  "aggmtransspace,\n"
13390  "aggminitval,\n");
13391  else
13392  appendPQExpBufferStr(query,
13393  "'n' AS aggkind,\n"
13394  "'-' AS aggmtransfn,\n"
13395  "'-' AS aggminvtransfn,\n"
13396  "'-' AS aggmfinalfn,\n"
13397  "0 AS aggmtranstype,\n"
13398  "false AS aggfinalextra,\n"
13399  "false AS aggmfinalextra,\n"
13400  "0 AS aggtransspace,\n"
13401  "0 AS aggmtransspace,\n"
13402  "NULL AS aggminitval,\n");
13403 
13404  if (fout->remoteVersion >= 90600)
13405  appendPQExpBufferStr(query,
13406  "aggcombinefn,\n"
13407  "aggserialfn,\n"
13408  "aggdeserialfn,\n"
13409  "proparallel,\n");
13410  else
13411  appendPQExpBufferStr(query,
13412  "'-' AS aggcombinefn,\n"
13413  "'-' AS aggserialfn,\n"
13414  "'-' AS aggdeserialfn,\n"
13415  "'u' AS proparallel,\n");
13416 
13417  if (fout->remoteVersion >= 110000)
13418  appendPQExpBufferStr(query,
13419  "aggfinalmodify,\n"
13420  "aggmfinalmodify\n");
13421  else
13422  appendPQExpBufferStr(query,
13423  "'0' AS aggfinalmodify,\n"
13424  "'0' AS aggmfinalmodify\n");
13425 
13426  appendPQExpBufferStr(query,
13427  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13428  "WHERE a.aggfnoid = p.oid "
13429  "AND p.oid = $1");
13430 
13431  ExecuteSqlStatement(fout, query->data);
13432 
13433  fout->is_prepared[PREPQUERY_DUMPAGG] = true;
13434  }
13435 
13436  printfPQExpBuffer(query,
13437  "EXECUTE dumpAgg('%u')",
13438  agginfo->aggfn.dobj.catId.oid);
13439 
13440  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13441 
13442  i_agginitval = PQfnumber(res, "agginitval");
13443  i_aggminitval = PQfnumber(res, "aggminitval");
13444 
13445  aggtransfn = PQgetvalue(res, 0, PQfnumber(res, "aggtransfn"));
13446  aggfinalfn = PQgetvalue(res, 0, PQfnumber(res, "aggfinalfn"));
13447  aggcombinefn = PQgetvalue(res, 0, PQfnumber(res, "aggcombinefn"));
13448  aggserialfn = PQgetvalue(res, 0, PQfnumber(res, "aggserialfn"));
13449  aggdeserialfn = PQgetvalue(res, 0, PQfnumber(res, "aggdeserialfn"));
13450  aggmtransfn = PQgetvalue(res, 0, PQfnumber(res, "aggmtransfn"));
13451  aggminvtransfn = PQgetvalue(res, 0, PQfnumber(res, "aggminvtransfn"));
13452  aggmfinalfn = PQgetvalue(res, 0, PQfnumber(res, "aggmfinalfn"));
13453  aggfinalextra = (PQgetvalue(res, 0, PQfnumber(res, "aggfinalextra"))[0] == 't');
13454  aggmfinalextra = (PQgetvalue(res, 0, PQfnumber(res, "aggmfinalextra"))[0] == 't');
13455  aggfinalmodify = PQgetvalue(res, 0, PQfnumber(res, "aggfinalmodify"))[0];
13456  aggmfinalmodify = PQgetvalue(res, 0, PQfnumber(res, "aggmfinalmodify"))[0];
13457  aggsortop = PQgetvalue(res, 0, PQfnumber(res, "aggsortop"));
13458  aggkind = PQgetvalue(res, 0, PQfnumber(res, "aggkind"))[0];
13459  aggtranstype = PQgetvalue(res, 0, PQfnumber(res, "aggtranstype"));
13460  aggtransspace = PQgetvalue(res, 0, PQfnumber(res, "aggtransspace"));
13461  aggmtranstype = PQgetvalue(res, 0, PQfnumber(res, "aggmtranstype"));
13462  aggmtransspace = PQgetvalue(res, 0, PQfnumber(res, "aggmtransspace"));
13463  agginitval = PQgetvalue(res, 0, i_agginitval);
13464  aggminitval = PQgetvalue(res, 0, i_aggminitval);
13465  proparallel = PQgetvalue(res, 0, PQfnumber(res, "proparallel"));
13466 
13467  {
13468  char *funcargs;
13469  char *funciargs;
13470 
13471  funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs"));
13472  funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs"));
13473  aggfullsig = format_function_arguments(&agginfo->aggfn, funcargs, true);
13474  aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true);
13475  }
13476 
13477  aggsig_tag = format_aggregate_signature(agginfo, fout, false);
13478 
13479  /* identify default modify flag for aggkind (must match DefineAggregate) */
13480  defaultfinalmodify = (aggkind == AGGKIND_NORMAL) ? AGGMODIFY_READ_ONLY : AGGMODIFY_READ_WRITE;
13481  /* replace omitted flags for old versions */
13482  if (aggfinalmodify == '0')
13483  aggfinalmodify = defaultfinalmodify;
13484  if (aggmfinalmodify == '0')
13485  aggmfinalmodify = defaultfinalmodify;
13486 
13487  /* regproc and regtype output is already sufficiently quoted */
13488  appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
13489  aggtransfn, aggtranstype);
13490 
13491  if (strcmp(aggtransspace, "0") != 0)
13492  {
13493  appendPQExpBuffer(details, ",\n SSPACE = %s",
13494  aggtransspace);
13495  }
13496 
13497  if (!PQgetisnull(res, 0, i_agginitval))
13498  {
13499  appendPQExpBufferStr(details, ",\n INITCOND = ");
13500  appendStringLiteralAH(details, agginitval, fout);
13501  }
13502 
13503  if (strcmp(aggfinalfn, "-") != 0)
13504  {
13505  appendPQExpBuffer(details, ",\n FINALFUNC = %s",
13506  aggfinalfn);
13507  if (aggfinalextra)
13508  appendPQExpBufferStr(details, ",\n FINALFUNC_EXTRA");
13509  if (aggfinalmodify != defaultfinalmodify)
13510  {
13511  switch (aggfinalmodify)
13512  {
13513  case AGGMODIFY_READ_ONLY:
13514  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = READ_ONLY");
13515  break;
13516  case AGGMODIFY_SHAREABLE:
13517  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = SHAREABLE");
13518  break;
13519  case AGGMODIFY_READ_WRITE:
13520  appendPQExpBufferStr(details, ",\n FINALFUNC_MODIFY = READ_WRITE");
13521  break;
13522  default:
13523  pg_fatal("unrecognized aggfinalmodify value for aggregate \"%s\"",
13524  agginfo->aggfn.dobj.name);
13525  break;
13526  }
13527  }
13528  }
13529 
13530  if (strcmp(aggcombinefn, "-") != 0)
13531  appendPQExpBuffer(details, ",\n COMBINEFUNC = %s", aggcombinefn);
13532 
13533  if (strcmp(aggserialfn, "-") != 0)
13534  appendPQExpBuffer(details, ",\n SERIALFUNC = %s", aggserialfn);
13535 
13536  if (strcmp(aggdeserialfn, "-") != 0)
13537  appendPQExpBuffer(details, ",\n DESERIALFUNC = %s", aggdeserialfn);
13538 
13539  if (strcmp(aggmtransfn, "-") != 0)
13540  {
13541  appendPQExpBuffer(details, ",\n MSFUNC = %s,\n MINVFUNC = %s,\n MSTYPE = %s",
13542  aggmtransfn,
13543  aggminvtransfn,
13544  aggmtranstype);
13545  }
13546 
13547  if (strcmp(aggmtransspace, "0") != 0)
13548  {
13549  appendPQExpBuffer(details, ",\n MSSPACE = %s",
13550  aggmtransspace);
13551  }
13552 
13553  if (!PQgetisnull(res, 0, i_aggminitval))
13554  {
13555  appendPQExpBufferStr(details, ",\n MINITCOND = ");
13556  appendStringLiteralAH(details, aggminitval, fout);
13557  }
13558 
13559  if (strcmp(aggmfinalfn, "-") != 0)
13560  {
13561  appendPQExpBuffer(details, ",\n MFINALFUNC = %s",
13562  aggmfinalfn);
13563  if (aggmfinalextra)
13564  appendPQExpBufferStr(details, ",\n MFINALFUNC_EXTRA");
13565  if (aggmfinalmodify != defaultfinalmodify)
13566  {
13567  switch (aggmfinalmodify)
13568  {
13569  case AGGMODIFY_READ_ONLY:
13570  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = READ_ONLY");
13571  break;
13572  case AGGMODIFY_SHAREABLE:
13573  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = SHAREABLE");
13574  break;
13575  case AGGMODIFY_READ_WRITE:
13576  appendPQExpBufferStr(details, ",\n MFINALFUNC_MODIFY = READ_WRITE");
13577  break;
13578  default:
13579  pg_fatal("unrecognized aggmfinalmodify value for aggregate \"%s\"",
13580  agginfo->aggfn.dobj.name);
13581  break;
13582  }
13583  }
13584  }
13585 
13586  aggsortconvop = getFormattedOperatorName(aggsortop);
13587  if (aggsortconvop)
13588  {
13589  appendPQExpBuffer(details, ",\n SORTOP = %s",
13590  aggsortconvop);
13591  free(aggsortconvop);
13592  }
13593 
13594  if (aggkind == AGGKIND_HYPOTHETICAL)
13595  appendPQExpBufferStr(details, ",\n HYPOTHETICAL");
13596 
13597  if (proparallel[0] != PROPARALLEL_UNSAFE)
13598  {
13599  if (proparallel[0] == PROPARALLEL_SAFE)
13600  appendPQExpBufferStr(details, ",\n PARALLEL = safe");
13601  else if (proparallel[0] == PROPARALLEL_RESTRICTED)
13602  appendPQExpBufferStr(details, ",\n PARALLEL = restricted");
13603  else if (proparallel[0] != PROPARALLEL_UNSAFE)
13604  pg_fatal("unrecognized proparallel value for function \"%s\"",
13605  agginfo->aggfn.dobj.name);
13606  }
13607 
13608  appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n",
13609  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
13610  aggsig);
13611 
13612  appendPQExpBuffer(q, "CREATE AGGREGATE %s.%s (\n%s\n);\n",
13613  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
13614  aggfullsig ? aggfullsig : aggsig, details->data);
13615 
13616  if (dopt->binary_upgrade)
13617  binary_upgrade_extension_member(q, &agginfo->aggfn.dobj,
13618  "AGGREGATE", aggsig,
13619  agginfo->aggfn.dobj.namespace->dobj.name);
13620 
13621  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_DEFINITION)
13622  ArchiveEntry(fout, agginfo->aggfn.dobj.catId,
13623  agginfo->aggfn.dobj.dumpId,
13624  ARCHIVE_OPTS(.tag = aggsig_tag,
13625  .namespace = agginfo->aggfn.dobj.namespace->dobj.name,
13626  .owner = agginfo->aggfn.rolname,
13627  .description = "AGGREGATE",
13628  .section = SECTION_PRE_DATA,
13629  .createStmt = q->data,
13630  .dropStmt = delq->data));
13631 
13632  /* Dump Aggregate Comments */
13633  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_COMMENT)
13634  dumpComment(fout, "AGGREGATE", aggsig,
13635  agginfo->aggfn.dobj.namespace->dobj.name,
13636  agginfo->aggfn.rolname,
13637  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13638 
13639  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_SECLABEL)
13640  dumpSecLabel(fout, "AGGREGATE", aggsig,
13641  agginfo->aggfn.dobj.namespace->dobj.name,
13642  agginfo->aggfn.rolname,
13643  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13644 
13645  /*
13646  * Since there is no GRANT ON AGGREGATE syntax, we have to make the ACL
13647  * command look like a function's GRANT; in particular this affects the
13648  * syntax for zero-argument aggregates and ordered-set aggregates.
13649  */
13650  free(aggsig);
13651 
13652  aggsig = format_function_signature(fout, &agginfo->aggfn, true);
13653 
13654  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_ACL)
13655  dumpACL(fout, agginfo->aggfn.dobj.dumpId, InvalidDumpId,
13656  "FUNCTION", aggsig, NULL,
13657  agginfo->aggfn.dobj.namespace->dobj.name,
13658  agginfo->aggfn.rolname, &agginfo->aggfn.dacl);
13659 
13660  free(aggsig);
13661  if (aggfullsig)
13662  free(aggfullsig);
13663  free(aggsig_tag);
13664 
13665  PQclear(res);
13666 
13667  destroyPQExpBuffer(query);
13668  destroyPQExpBuffer(q);
13669  destroyPQExpBuffer(delq);
13670  destroyPQExpBuffer(details);
13671 }
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3760
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:325
@ PREPQUERY_DUMPAGG
Definition: pg_backup.h:64
void ExecuteSqlStatement(Archive *AHX, const char *query)
Definition: pg_backup_db.c:279
static char * getFormattedOperatorName(const char *oproid)
Definition: pg_dump.c:12418
static char * format_function_signature(Archive *fout, const FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11477
static char * format_aggregate_signature(const AggInfo *agginfo, Archive *fout, bool honor_quotes)
Definition: pg_dump.c:13285
static DumpId dumpACL(Archive *fout, DumpId objDumpId, DumpId altDumpId, const char *type, const char *name, const char *subname, const char *nspname, const char *owner, const DumpableAcl *dacl)
Definition: pg_dump.c:14351
static char * format_function_arguments(const FuncInfo *finfo, const char *funcargs, bool is_agg)
Definition: pg_dump.c:11454
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:14477
bool * is_prepared
Definition: pg_backup.h:236

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, ArchiveEntry(), _dumpOptions::binary_upgrade, binary_upgrade_extension_member(), createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, destroyPQExpBuffer(), Archive::dopt, DUMP_COMPONENT_ACL, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_SECLABEL, dumpACL(), dumpComment(), dumpSecLabel(), ExecuteSqlQueryForSingleRow(), ExecuteSqlStatement(), fmtId(), format_aggregate_signature(), format_function_arguments(), format_function_signature(), free, getFormattedOperatorName(), InvalidDumpId, Archive::is_prepared, pg_fatal, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PREPQUERY_DUMPAGG, printfPQExpBuffer(), Archive::remoteVersion, res, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

◆ dumpAttrDef()

static void dumpAttrDef ( Archive fout,
const AttrDefInfo adinfo 
)
static

Definition at line 15901 of file pg_dump.c.

15902 {
15903  DumpOptions *dopt = fout->dopt;
15904  TableInfo *tbinfo = adinfo->adtable;
15905  int adnum = adinfo->adnum;
15906  PQExpBuffer q;
15907  PQExpBuffer delq;
15908  char *qualrelname;
15909  char *tag;
15910  char *foreign;
15911 
15912  /* Do nothing in data-only dump */
15913  if (dopt->dataOnly)
15914  return;
15915 
15916  /* Skip if not "separate"; it was dumped in the table's definition */
15917  if (!adinfo->separate)
15918  return;
15919 
15920  q = createPQExpBuffer();
15921  delq = createPQExpBuffer();
15922 
15923  qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo));
15924 
15925  foreign = tbinfo->relkind == RELKIND_FOREIGN_TABLE ? "FOREIGN " : "";
15926 
15928  "ALTER %sTABLE ONLY %s ALTER COLUMN %s SET DEFAULT %s;\n",
15929  foreign, qualrelname, fmtId(tbinfo->attnames[adnum - 1]),
15930  adinfo->adef_expr);
15931 
15932  appendPQExpBuffer(delq, "ALTER %sTABLE %s ALTER COLUMN %s DROP DEFAULT;\n",
15933  foreign, qualrelname,
15934  fmtId(tbinfo->attnames[adnum - 1]));
15935 
15936  tag = psprintf("%s %s", tbinfo->dobj.name, tbinfo->attnames[adnum - 1]);
15937 
15938  if (adinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
15939  ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
15940  ARCHIVE_OPTS(.tag = tag,
15941  .namespace = tbinfo->dobj.namespace->dobj.name,
15942  .owner = tbinfo->rolname,
15943  .description = "DEFAULT",
15944  .section = SECTION_PRE_DATA,
15945  .createStmt = q->data,
15946  .dropStmt = delq->data));
15947 
15948  free(tag);
15949  destroyPQExpBuffer(q);
15950  destroyPQExpBuffer(delq);
15951  free(qualrelname);
15952 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
DumpableObject dobj
Definition: pg_dump.h:372
char * adef_expr
Definition: pg_dump.h:375
TableInfo * adtable
Definition: pg_dump.h:373
bool separate
Definition: pg_dump.h:376
const char * rolname
Definition: pg_dump.h:285

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::relkind, _tableInfo::rolname, SECTION_PRE_DATA, and _attrDefInfo::separate.

Referenced by dumpDumpableObject().

◆ dumpBaseType()

static void dumpBaseType ( Archive fout,
const TypeInfo tyinfo 
)
static

Definition at line 10559 of file pg_dump.c.

10560 {
10561  DumpOptions *dopt = fout->dopt;
10563  PQExpBuffer delq = createPQExpBuffer();
10564  PQExpBuffer query = createPQExpBuffer();
10565  PGresult *res;
10566  char *qtypname;
10567  char *qualtypname;
10568  char *typlen;
10569  char *typinput;
10570  char *typoutput;
10571  char *typreceive;
10572  char *typsend;
10573  char *typmodin;
10574  char *typmodout;
10575  char *typanalyze;
10576  char *typsubscript;
10577  Oid typreceiveoid;
10578  Oid typsendoid;
10579  Oid typmodinoid;
10580  Oid typmodoutoid;
10581  Oid typanalyzeoid;
10582  Oid typsubscriptoid;
10583  char *typcategory;
10584  char *typispreferred;
10585  char *typdelim;
10586  char *typbyval;
10587  char *typalign;
10588  char *typstorage;
10589  char *typcollatable;
10590  char *typdefault;
10591  bool typdefault_is_literal = false;
10592 
10593  if (!fout->is_prepared[PREPQUERY_DUMPBASETYPE])
10594  {
10595  /* Set up query for type-specific details */
10596  appendPQExpBufferStr(query,
10597  "PREPARE dumpBaseType(pg_catalog.oid) AS\n"
10598  "SELECT typlen, "
10599  "typinput, typoutput, typreceive, typsend, "
10600  "typreceive::pg_catalog.oid AS typreceiveoid, "
10601  "typsend::pg_catalog.oid AS typsendoid, "
10602  "typanalyze, "
10603  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10604  "typdelim, typbyval, typalign, typstorage, "
10605  "typmodin, typmodout, "
10606  "typmodin::pg_catalog.oid AS typmodinoid, "
10607  "typmodout::pg_catalog.oid AS typmodoutoid, "
10608  "typcategory, typispreferred, "
10609  "(typcollation <> 0) AS typcollatable, "
10610  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault, ");
10611 
10612  if (fout->remoteVersion >= 140000)
10613  appendPQExpBufferStr(query,
10614  "typsubscript, "
10615  "typsubscript::pg_catalog.oid AS typsubscriptoid ");
10616  else
10617  appendPQExpBufferStr(query,
10618  "'-' AS typsubscript, 0 AS typsubscriptoid ");
10619 
10620  appendPQExpBufferStr(query, "FROM pg_catalog.pg_type "
10621  "WHERE oid = $1");
10622 
10623  ExecuteSqlStatement(fout, query->data);
10624 
10625  fout->is_prepared[PREPQUERY_DUMPBASETYPE] = true;
10626  }
10627 
10628  printfPQExpBuffer(query,
10629  "EXECUTE dumpBaseType('%u')",
10630  tyinfo->dobj.catId.oid);
10631 
10632  res = ExecuteSqlQueryForSingleRow(fout, query->data);
10633 
10634  typlen = PQgetvalue(res, 0, PQfnumber(res, "typlen"));
10635  typinput = PQgetvalue(res, 0, PQfnumber(res, "typinput"));
10636  typoutput = PQgetvalue(res, 0, PQfnumber(res, "typoutput"));
10637  typreceive = PQgetvalue(res, 0, PQfnumber(res, "typreceive"));
10638  typsend = PQgetvalue(res, 0, PQfnumber(res, "typsend"));
10639  typmodin = PQgetvalue(res, 0, PQfnumber(res, "typmodin"));
10640  typmodout = PQgetvalue(res, 0, PQfnumber(res, "typmodout"));
10641  typanalyze = PQgetvalue(res, 0, PQfnumber(res, "typanalyze"));
10642  typsubscript = PQgetvalue(res, 0, PQfnumber(res, "typsubscript"));
10643  typreceiveoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typreceiveoid")));
10644  typsendoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typsendoid")));
10645  typmodinoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodinoid")));
10646  typmodoutoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodoutoid")));
10647  typanalyzeoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typanalyzeoid")));
10648  typsubscriptoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typsubscriptoid")));
10649  typcategory = PQgetvalue(res, 0, PQfnumber(res, "typcategory"));
10650  typispreferred = PQgetvalue(res, 0, PQfnumber(res, "typispreferred"));
10651  typdelim = PQgetvalue(res, 0, PQfnumber(res, "typdelim"));
10652  typbyval = PQgetvalue(res, 0, PQfnumber(res, "typbyval"));
10653  typalign = PQgetvalue(res, 0, PQfnumber(res, "typalign"));
10654  typstorage = PQgetvalue(res, 0, PQfnumber(res, "typstorage"));
10655  typcollatable = PQgetvalue(res, 0, PQfnumber(res, "typcollatable"));
10656  if (!PQgetisnull(res, 0, PQfnumber(res, "typdefaultbin")))
10657  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefaultbin"));
10658  else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
10659  {
10660  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault"));
10661  typdefault_is_literal = true; /* it needs quotes */
10662  }
10663  else
10664  typdefault = NULL;
10665 
10666  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
10667  qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo));
10668 
10669  /*
10670  * The reason we include CASCADE is that the circular dependency between
10671  * the type and its I/O functions makes it impossible to drop the type any
10672  * other way.
10673  */
10674  appendPQExpBuffer(delq, "DROP TYPE %s CASCADE;\n", qualtypname);
10675 
10676  /*
10677  * We might already have a shell type, but setting pg_type_oid is
10678  * harmless, and in any case we'd better set the array type OID.
10679  */
10680  if (dopt->binary_upgrade)
10682  tyinfo->dobj.catId.oid,
10683  false, false);
10684 
10686  "CREATE TYPE %s (\n"
10687  " INTERNALLENGTH = %s",
10688  qualtypname,
10689  (strcmp(typlen, "-1") == 0) ? "variable" : typlen);
10690 
10691  /* regproc result is sufficiently quoted already */
10692  appendPQExpBuffer(q, ",\n INPUT = %s", typinput);
10693  appendPQExpBuffer(q, ",\n OUTPUT = %s", typoutput);
10694  if (OidIsValid(typreceiveoid))
10695  appendPQExpBuffer(q, ",\n RECEIVE = %s", typreceive);
10696  if (OidIsValid(typsendoid))
10697  appendPQExpBuffer(q, ",\n SEND = %s", typsend);
10698  if (OidIsValid(typmodinoid))
10699  appendPQExpBuffer(q, ",\n TYPMOD_IN = %s", typmodin);
10700  if (OidIsValid(typmodoutoid))
10701  appendPQExpBuffer(q, ",\n TYPMOD_OUT = %s", typmodout);
10702  if (OidIsValid(typanalyzeoid))
10703  appendPQExpBuffer(q, ",\n ANALYZE = %s", typanalyze);
10704 
10705  if (strcmp(typcollatable, "t") == 0)
10706  appendPQExpBufferStr(q, ",\n COLLATABLE = true");
10707 
10708  if (typdefault != NULL)
10709  {
10710  appendPQExpBufferStr(q, ",\n DEFAULT = ");
10711  if (typdefault_is_literal)
10712  appendStringLiteralAH(q, typdefault, fout);
10713  else
10714  appendPQExpBufferStr(q, typdefault);
10715  }
10716 
10717  if (OidIsValid(typsubscriptoid))
10718  appendPQExpBuffer(q, ",\n SUBSCRIPT = %s", typsubscript);
10719 
10720  if (OidIsValid(tyinfo->typelem))
10721  appendPQExpBuffer(q, ",\n ELEMENT = %s",
10722  getFormattedTypeName(fout, tyinfo->typelem,
10723  zeroIsError));
10724 
10725  if (strcmp(typcategory, "U") != 0)
10726  {
10727  appendPQExpBufferStr(q, ",\n CATEGORY = ");
10728  appendStringLiteralAH(q, typcategory, fout);
10729  }
10730 
10731  if (strcmp(typispreferred, "t") == 0)
10732  appendPQExpBufferStr(q, ",\n PREFERRED = true");
10733 
10734  if (typdelim && strcmp(typdelim, ",") != 0)
10735  {
10736  appendPQExpBufferStr(q, ",\n DELIMITER = ");
10737  appendStringLiteralAH(q, typdelim, fout);
10738  }
10739 
10740  if (*typalign == TYPALIGN_CHAR)
10741  appendPQExpBufferStr(q, ",\n ALIGNMENT = char");
10742  else if (*typalign == TYPALIGN_SHORT)
10743  appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
10744  else if (*typalign == TYPALIGN_INT)
10745  appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
10746  else if (*typalign == TYPALIGN_DOUBLE)
10747  appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
10748 
10749  if (*typstorage == TYPSTORAGE_PLAIN)
10750  appendPQExpBufferStr(q, ",\n STORAGE = plain");
10751  else if (*typstorage == TYPSTORAGE_EXTERNAL)
10752  appendPQExpBufferStr(q, ",\n STORAGE = external");
10753  else if (*typstorage == TYPSTORAGE_EXTENDED)
10754  appendPQExpBufferStr(q, ",\n STORAGE = extended");
10755  else if (*typstorage == TYPSTORAGE_MAIN)
10756  appendPQExpBufferStr(q, ",\n STORAGE = main");
10757 
10758  if (strcmp(typbyval, "t") == 0)
10759  appendPQExpBufferStr(q, ",\n PASSEDBYVALUE");
10760 
10761  appendPQExpBufferStr(q, "\n);\n");
10762 
10763  if (dopt->binary_upgrade)
10765  "TYPE", qtypname,
10766  tyinfo->dobj.namespace->dobj.name);
10767 
10768  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
10769  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
10770  ARCHIVE_OPTS(.tag = tyinfo->dobj.name,
10771  .namespace = tyinfo->dobj.namespace->dobj.name,
10772  .owner = tyinfo->rolname,
10773  .description = "TYPE",
10774  .section = SECTION_PRE_DATA,
10775  .createStmt = q->data,
10776  .dropStmt = delq->data));
10777 
10778  /* Dump Type Comments and Security Labels */
10779  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10780  dumpComment(fout, "TYPE", qtypname,
10781  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10782  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10783 
10784  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
10785  dumpSecLabel(fout, "TYPE", qtypname,
10786  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10787  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10788 
10789  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
10790  dumpACL(fout, tyinfo->dobj.dumpId, InvalidDumpId, "TYPE",
10791  qtypname, NULL,
10792  tyinfo->dobj.namespace->dobj.name,
10793  tyinfo->rolname, &tyinfo->dacl);
10794 
10795  PQclear(res);
10796  destroyPQExpBuffer(q);
10797  destroyPQExpBuffer(delq);
10798  destroyPQExpBuffer(query);
10799  free(qtypname);
10800  free(qualtypname);
10801 }
@ PREPQUERY_DUMPBASETYPE
Definition: pg_backup.h:65
static const char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:18029
char typalign
Definition: pg_type.h:176
DumpableAcl dacl
Definition: pg_dump.h:191
Oid typelem
Definition: pg_dump.h:200
const char * rolname
Definition: pg_dump.h:199

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(), _typeInfo::dacl, 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(), ExecuteSqlStatement(), fmtId(), fmtQualifiedDumpable, free, getFormattedTypeName(), InvalidDumpId, Archive::is_prepared, _dumpableObject::name, CatalogId::oid, OidIsValid, pg_strdup(), PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PREPQUERY_DUMPBASETYPE, printfPQExpBuffer(), Archive::remoteVersion, res, _typeInfo::rolname, SECTION_PRE_DATA, typalign, _typeInfo::typelem, and zeroIsError.

Referenced by dumpType().

◆ dumpBlob()

static void dumpBlob ( Archive fout,
const BlobInfo binfo 
)
static

Definition at line 3447 of file pg_dump.c.

3448 {
3449  PQExpBuffer cquery = createPQExpBuffer();
3450  PQExpBuffer dquery = createPQExpBuffer();
3451 
3452  appendPQExpBuffer(cquery,
3453  "SELECT pg_catalog.lo_create('%s');\n",
3454  binfo->dobj.name);
3455 
3456  appendPQExpBuffer(dquery,
3457  "SELECT pg_catalog.lo_unlink('%s');\n",
3458  binfo->dobj.name);
3459 
3460  if (binfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
3461  ArchiveEntry(fout, binfo->dobj.catId, binfo->dobj.dumpId,
3462  ARCHIVE_OPTS(.tag = binfo->dobj.name,
3463  .owner = binfo->rolname,
3464  .description = "BLOB",
3465  .section = SECTION_PRE_DATA,
3466  .createStmt = cquery->data,
3467  .dropStmt = dquery->data));
3468 
3469  /* Dump comment if any */
3470  if (binfo->dobj.dump & DUMP_COMPONENT_COMMENT)
3471  dumpComment(fout, "LARGE OBJECT", binfo->dobj.name,
3472  NULL, binfo->rolname,
3473  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3474 
3475  /* Dump security label if any */
3476  if (binfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
3477  dumpSecLabel(fout, "LARGE OBJECT", binfo->dobj.name,
3478  NULL, binfo->rolname,
3479  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3480 
3481  /* Dump ACL if any */
3482  if (binfo->dobj.dump & DUMP_COMPONENT_ACL)
3483  dumpACL(fout, binfo->dobj.dumpId, InvalidDumpId, "LARGE OBJECT",
3484  binfo->dobj.name, NULL,
3485  NULL, binfo->rolname, &binfo->dacl);
3486 
3487  destroyPQExpBuffer(cquery);
3488  destroyPQExpBuffer(dquery);
3489 }
DumpableObject dobj
Definition: pg_dump.h:587
const char * rolname
Definition: pg_dump.h:589
DumpableAcl dacl
Definition: pg_dump.h:588

References appendPQExpBuffer(), ARCHIVE_OPTS, ArchiveEntry(), _dumpableObject::catId, createPQExpBuffer(), _blobInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), _blobInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_COMMENT, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_SECLABEL, dumpACL(), dumpComment(), _dumpableObject::dumpId, dumpSecLabel(), InvalidDumpId, _dumpableObject::name, _blobInfo::rolname, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

◆ dumpBlobs()

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

Definition at line 3496 of file pg_dump.c.

3497 {
3498  const char *blobQry;
3499  const char *blobFetchQry;
3500  PGconn *conn = GetConnection(fout);
3501  PGresult *res;
3502  char buf[LOBBUFSIZE];
3503  int ntups;
3504  int i;
3505  int cnt;
3506 
3507  pg_log_info("saving large objects");
3508 
3509  /*
3510  * Currently, we re-fetch all BLOB OIDs using a cursor. Consider scanning
3511  * the already-in-memory dumpable objects instead...
3512  */
3513  blobQry =
3514  "DECLARE bloboid CURSOR FOR "
3515  "SELECT oid FROM pg_largeobject_metadata ORDER BY 1";
3516 
3517  ExecuteSqlStatement(fout, blobQry);
3518 
3519  /* Command to fetch from cursor */
3520  blobFetchQry = "FETCH 1000 IN bloboid";
3521 
3522  do
3523  {
3524  /* Do a fetch */
3525  res = ExecuteSqlQuery(fout, blobFetchQry, PGRES_TUPLES_OK);
3526 
3527  /* Process the tuples, if any */
3528  ntups = PQntuples(res);
3529  for (i = 0; i < ntups; i++)
3530  {
3531  Oid blobOid;
3532  int loFd;
3533 
3534  blobOid = atooid(PQgetvalue(res, i, 0));
3535  /* Open the BLOB */
3536  loFd = lo_open(conn, blobOid, INV_READ);
3537  if (loFd == -1)
3538  pg_fatal("could not open large object %u: %s",
3539  blobOid, PQerrorMessage(conn));
3540 
3541  StartBlob(fout, blobOid);
3542 
3543  /* Now read it in chunks, sending data to archive */
3544  do
3545  {
3546  cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
3547  if (cnt < 0)
3548  pg_fatal("error reading large object %u: %s",
3549  blobOid, PQerrorMessage(conn));
3550 
3551  WriteData(fout, buf, cnt);
3552  } while (cnt > 0);
3553 
3554  lo_close(conn, loFd);
3555 
3556  EndBlob(fout, blobOid);
3557  }
3558 
3559  PQclear(res);
3560  } while (ntups > 0);
3561 
3562  return 1;
3563 }
int lo_read(int fd, char *buf, int len)
Definition: be-fsstubs.c:149
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt, PgFdwConnState **state)
Definition: connection.c:134
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6908
int lo_close(PGconn *conn, int fd)
Definition: fe-lobj.c:96
int lo_open(PGconn *conn, Oid lobjId, int mode)
Definition: fe-lobj.c:57
#define INV_READ
Definition: libpq-fs.h:22
#define pg_log_info(...)
Definition: logging.h:124
int StartBlob(Archive *AH, Oid oid)
void WriteData(Archive *AH, const void *data, size_t dLen)
int EndBlob(Archive *AH, Oid oid)
#define LOBBUFSIZE
static char * buf
Definition: pg_test_fsync.c:67
PGconn * conn
Definition: streamutil.c:54

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

Referenced by dumpDumpableObject().

◆ dumpCast()

static void dumpCast ( Archive fout,
const CastInfo cast 
)
static

Definition at line 11924 of file pg_dump.c.

11925 {
11926  DumpOptions *dopt = fout->dopt;
11927  PQExpBuffer defqry;
11928  PQExpBuffer delqry;
11929  PQExpBuffer labelq;
11930  PQExpBuffer castargs;
11931  FuncInfo *funcInfo = NULL;
11932  const char *sourceType;
11933  const char *targetType;
11934 
11935  /* Do nothing in data-only dump */
11936  if (dopt->dataOnly)
11937  return;
11938 
11939  /* Cannot dump if we don't have the cast function's info */
11940  if (OidIsValid(cast->castfunc))
11941  {
11942  funcInfo = findFuncByOid(cast->castfunc);
11943  if (funcInfo == NULL)
11944  pg_fatal("could not find function definition for function with OID %u",
11945  cast->castfunc);
11946  }
11947 
11948  defqry = createPQExpBuffer();
11949  delqry = createPQExpBuffer();
11950  labelq = createPQExpBuffer();
11951  castargs = createPQExpBuffer();
11952 
11953  sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone);
11954  targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone);
11955  appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
11956  sourceType, targetType);
11957 
11958  appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
11959  sourceType, targetType);
11960 
11961  switch (cast->castmethod)
11962  {
11963  case COERCION_METHOD_BINARY:
11964  appendPQExpBufferStr(defqry, "WITHOUT FUNCTION");
11965  break;
11966  case COERCION_METHOD_INOUT:
11967  appendPQExpBufferStr(defqry, "WITH INOUT");
11968  break;
11969  case COERCION_METHOD_FUNCTION:
11970  if (funcInfo)
11971  {
11972  char *fsig = format_function_signature(fout, funcInfo, true);
11973 
11974  /*
11975  * Always qualify the function name (format_function_signature
11976  * won't qualify it).
11977  */
11978  appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
11979  fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
11980  free(fsig);
11981  }
11982  else
11983  pg_log_warning("bogus value in pg_cast.castfunc or pg_cast.castmethod field");
11984  break;
11985  default:
11986  pg_log_warning("bogus value in pg_cast.castmethod field");
11987  }
11988 
11989  if (cast->castcontext == 'a')
11990  appendPQExpBufferStr(defqry, " AS ASSIGNMENT");
11991  else if (cast->castcontext == 'i')
11992  appendPQExpBufferStr(defqry, " AS IMPLICIT");
11993  appendPQExpBufferStr(defqry, ";\n");
11994 
11995  appendPQExpBuffer(labelq, "CAST (%s AS %s)",
11996  sourceType, targetType);
11997 
11998  appendPQExpBuffer(castargs, "(%s AS %s)",
11999  sourceType, targetType);
12000 
12001  if (dopt->binary_upgrade)
12002  binary_upgrade_extension_member(defqry, &cast->dobj,
12003  "CAST", castargs->data, NULL);
12004 
12005  if (cast->dobj.dump & DUMP_COMPONENT_DEFINITION)
12006  ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
12007  ARCHIVE_OPTS(.tag = labelq->data,
12008  .description = "CAST",
12009  .section = SECTION_PRE_DATA,
12010  .createStmt = defqry->data,
12011  .dropStmt = delqry->data));
12012 
12013  /* Dump Cast Comments */
12014  if (cast->dobj.dump & DUMP_COMPONENT_COMMENT)
12015  dumpComment(fout, "CAST", castargs->data,
12016  NULL, "",
12017  cast->dobj.catId, 0, cast->dobj.dumpId);
12018 
12019  destroyPQExpBuffer(defqry);
12020  destroyPQExpBuffer(delqry);
12021  destroyPQExpBuffer(labelq);
12022  destroyPQExpBuffer(castargs);
12023 }
FuncInfo * findFuncByOid(Oid oid)
Definition: common.c:822
char castmethod
Definition: pg_dump.h:505
Oid casttarget
Definition: pg_dump.h:502
char castcontext
Definition: pg_dump.h:504
DumpableObject dobj
Definition: pg_dump.h:500
Oid castsource
Definition: pg_dump.h:501
Oid castfunc
Definition: pg_dump.h:503
DumpableObject dobj
Definition: pg_dump.h:223

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

Referenced by dumpDumpableObject().

◆ dumpCollation()

static void dumpCollation ( Archive fout,
const CollInfo collinfo 
)
static

Definition at line 13038 of file pg_dump.c.

13039 {
13040  DumpOptions *dopt = fout->dopt;
13041  PQExpBuffer query;
13042  PQExpBuffer q;
13043  PQExpBuffer delq;
13044  char *qcollname;
13045  PGresult *res;
13046  int i_collprovider;
13047  int i_collisdeterministic;
13048  int i_collcollate;
13049  int i_collctype;
13050  const char *collprovider;
13051  const char *collcollate;
13052  const char *collctype;
13053 
13054  /* Do nothing in data-only dump */
13055  if (dopt->dataOnly)
13056  return;
13057 
13058  query = createPQExpBuffer();
13059  q = createPQExpBuffer();
13060  delq = createPQExpBuffer();
13061 
13062  qcollname = pg_strdup(fmtId(collinfo->dobj.name));
13063 
13064  /* Get collation-specific details */
13065  appendPQExpBufferStr(query, "SELECT ");
13066 
13067  if (fout->remoteVersion >= 100000)
13068  appendPQExpBufferStr(query,
13069  "collprovider, "
13070  "collversion, ");
13071  else
13072  appendPQExpBufferStr(query,
13073  "'c' AS collprovider, "
13074  "NULL AS collversion, ");
13075 
13076  if (fout->remoteVersion >= 120000)
13077  appendPQExpBufferStr(query,
13078  "collisdeterministic, ");
13079  else
13080  appendPQExpBufferStr(query,
13081  "true AS collisdeterministic, ");
13082 
13083  appendPQExpBuffer(query,
13084  "collcollate, "
13085  "collctype "
13086  "FROM pg_catalog.pg_collation c "
13087  "WHERE c.oid = '%u'::pg_catalog.oid",
13088  collinfo->dobj.catId.oid);
13089 
13090  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13091 
13092  i_collprovider = PQfnumber(res, "collprovider");
13093  i_collisdeterministic = PQfnumber(res, "collisdeterministic");
13094  i_collcollate = PQfnumber(res, "collcollate");
13095  i_collctype = PQfnumber(res, "collctype");
13096 
13097  collprovider = PQgetvalue(res, 0, i_collprovider);
13098  collcollate = PQgetvalue(res, 0, i_collcollate);
13099  collctype = PQgetvalue(res, 0, i_collctype);
13100 
13101  appendPQExpBuffer(delq, "DROP COLLATION %s;\n",
13102  fmtQualifiedDumpable(collinfo));
13103 
13104  appendPQExpBuffer(q, "CREATE COLLATION %s (",
13105  fmtQualifiedDumpable(collinfo));
13106 
13107  appendPQExpBufferStr(q, "provider = ");
13108  if (collprovider[0] == 'c')
13109  appendPQExpBufferStr(q, "libc");
13110  else if (collprovider[0] == 'i')
13111  appendPQExpBufferStr(q, "icu");
13112  else if (collprovider[0] == 'd')
13113  /* to allow dumping pg_catalog; not accepted on input */
13114  appendPQExpBufferStr(q, "default");
13115  else
13116  pg_fatal("unrecognized collation provider: %s",
13117  collprovider);
13118 
13119  if (strcmp(PQgetvalue(res, 0, i_collisdeterministic), "f") == 0)
13120  appendPQExpBufferStr(q, ", deterministic = false");
13121 
13122  if (strcmp(collcollate, collctype) == 0)
13123  {
13124  appendPQExpBufferStr(q, ", locale = ");
13125  appendStringLiteralAH(q, collcollate, fout);
13126  }
13127  else
13128  {
13129  appendPQExpBufferStr(q, ", lc_collate = ");
13130  appendStringLiteralAH(q, collcollate, fout);
13131  appendPQExpBufferStr(q, ", lc_ctype = ");
13132  appendStringLiteralAH(q, collctype, fout);
13133  }
13134 
13135  /*
13136  * For binary upgrade, carry over the collation version. For normal
13137  * dump/restore, omit the version, so that it is computed upon restore.
13138  */
13139  if (dopt->binary_upgrade)
13140  {
13141  int i_collversion;
13142 
13143  i_collversion = PQfnumber(res, "collversion");
13144  if (!PQgetisnull(res, 0, i_collversion))
13145  {
13146  appendPQExpBufferStr(q, ", version = ");
13148  PQgetvalue(res, 0, i_collversion),
13149  fout);
13150  }
13151  }
13152 
13153  appendPQExpBufferStr(q, ");\n");
13154 
13155  if (dopt->binary_upgrade)
13156  binary_upgrade_extension_member(q, &collinfo->dobj,
13157  "COLLATION", qcollname,
13158  collinfo->dobj.namespace->dobj.name);
13159 
13160  if (collinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13161  ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId,
13162  ARCHIVE_OPTS(.tag = collinfo->dobj.name,
13163  .namespace = collinfo->dobj.namespace->dobj.name,
13164  .owner = collinfo->rolname,
13165  .description = "COLLATION",
13166  .section = SECTION_PRE_DATA,
13167  .createStmt = q->data,
13168  .dropStmt = delq->data));
13169 
13170  /* Dump Collation Comments */
13171  if (collinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13172  dumpComment(fout, "COLLATION", qcollname,
13173  collinfo->dobj.namespace->dobj.name, collinfo->rolname,
13174  collinfo->dobj.catId, 0, collinfo->dobj.dumpId);
13175 
13176  PQclear(res);
13177 
13178  destroyPQExpBuffer(query);
13179  destroyPQExpBuffer(q);
13180  destroyPQExpBuffer(delq);
13181  free(qcollname);
13182 }
const char * rolname
Definition: pg_dump.h:269
DumpableObject dobj
Definition: pg_dump.h:268

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

Referenced by dumpDumpableObject().

◆ dumpComment()

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

Definition at line 9501 of file pg_dump.c.

9505 {
9506  dumpCommentExtended(fout, type, name, namespace, owner,
9507  catalogId, subid, dumpId, NULL);
9508 }
static void dumpCommentExtended(Archive *fout, const char *type, const char *name, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId, const char *initdb_comment)
Definition: pg_dump.c:9401

References dumpCommentExtended(), name, and generate_unaccent_rules::type.

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

◆ dumpCommentExtended()

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

Definition at line 9401 of file pg_dump.c.

9406 {
9407  DumpOptions *dopt = fout->dopt;
9409  int ncomments;
9410 
9411  /* do nothing, if --no-comments is supplied */
9412  if (dopt->no_comments)
9413  return;
9414 
9415  /* Comments are schema not data ... except blob comments are data */
9416  if (strcmp(type, "LARGE OBJECT") != 0)
9417  {
9418  if (dopt->dataOnly)
9419  return;
9420  }
9421  else
9422  {
9423  /* We do dump blob comments in binary-upgrade mode */
9424  if (dopt->schemaOnly && !dopt->binary_upgrade)
9425  return;
9426  }
9427 
9428  /* Search for comments associated with catalogId, using table */
9429  ncomments = findComments(catalogId.tableoid, catalogId.oid,
9430  &comments);
9431 
9432  /* Is there one matching the subid? */
9433  while (ncomments > 0)
9434  {
9435  if (comments->objsubid == subid)
9436  break;
9437  comments++;
9438  ncomments--;
9439  }
9440 
9441  if (initdb_comment != NULL)
9442  {
9443  static CommentItem empty_comment = {.descr = ""};
9444 
9445  /*
9446  * initdb creates this object with a comment. Skip dumping the
9447  * initdb-provided comment, which would complicate matters for
9448  * non-superuser use of pg_dump. When the DBA has removed initdb's
9449  * comment, replicate that.
9450  */
9451  if (ncomments == 0)
9452  {
9453  comments = &empty_comment;
9454  ncomments = 1;
9455  }
9456  else if (strcmp(comments->descr, initdb_comment) == 0)
9457  ncomments = 0;
9458  }
9459 
9460  /* If a comment exists, build COMMENT ON statement */
9461  if (ncomments > 0)
9462  {
9463  PQExpBuffer query = createPQExpBuffer();
9465 
9466  appendPQExpBuffer(query, "COMMENT ON %s ", type);
9467  if (namespace && *namespace)
9468  appendPQExpBuffer(query, "%s.", fmtId(namespace));
9469  appendPQExpBuffer(query, "%s IS ", name);
9470  appendStringLiteralAH(query, comments->descr, fout);
9471  appendPQExpBufferStr(query, ";\n");
9472 
9473  appendPQExpBuffer(tag, "%s %s", type, name);
9474 
9475  /*
9476  * We mark comments as SECTION_NONE because they really belong in the
9477  * same section as their parent, whether that is pre-data or
9478  * post-data.
9479  */
9481  ARCHIVE_OPTS(.tag = tag->data,
9482  .namespace = namespace,
9483  .owner = owner,
9484  .description = "COMMENT",
9485  .section = SECTION_NONE,
9486  .createStmt = query->data,
9487  .deps = &dumpId,
9488  .nDeps = 1));
9489 
9490  destroyPQExpBuffer(query);
9491  destroyPQExpBuffer(tag);
9492  }
9493 }
static int findComments(Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9615
int no_comments
Definition: pg_backup.h:175
bool schemaOnly
Definition: pg_backup.h:164

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, ArchiveEntry(), _dumpOptions::binary_upgrade, comments, createDumpId(), createPQExpBuffer(), PQExpBufferData::data, _dumpOptions::dataOnly, CommentItem::descr, destroyPQExpBuffer(), Archive::dopt, findComments(), fmtId(), name, ncomments, nilCatalogId, _dumpOptions::no_comments, CommentItem::objsubid, CatalogId::oid, _dumpOptions::schemaOnly, SECTION_NONE, CatalogId::tableoid, and generate_unaccent_rules::type.

Referenced by dumpComment(), and dumpNamespace().

◆ dumpCompositeType()

static void dumpCompositeType ( Archive fout,
const TypeInfo tyinfo 
)
static

Definition at line 10981 of file pg_dump.c.

10982 {
10983  DumpOptions *dopt = fout->dopt;
10985  PQExpBuffer dropped = createPQExpBuffer();
10986  PQExpBuffer delq = createPQExpBuffer();
10987  PQExpBuffer query = createPQExpBuffer();
10988  PGresult *res;
10989  char *qtypname;
10990  char *qualtypname;
10991  int ntups;
10992  int i_attname;
10993  int i_atttypdefn;
10994  int i_attlen;
10995  int i_attalign;
10996  int i_attisdropped;
10997  int i_attcollation;
10998  int i;
10999  int actual_atts;
11000 
11002  {
11003  /*
11004  * Set up query for type-specific details.
11005  *
11006  * Since we only want to dump COLLATE clauses for attributes whose
11007  * collation is different from their type's default, we use a CASE
11008  * here to suppress uninteresting attcollations cheaply. atttypid
11009  * will be 0 for dropped columns; collation does not matter for those.
11010  */
11011  appendPQExpBufferStr(query,
11012  "PREPARE dumpCompositeType(pg_catalog.oid) AS\n"
11013  "SELECT a.attname, a.attnum, "
11014  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
11015  "a.attlen, a.attalign, a.attisdropped, "
11016  "CASE WHEN a.attcollation <> at.typcollation "
11017  "THEN a.attcollation ELSE 0 END AS attcollation "
11018  "FROM pg_catalog.pg_type ct "
11019  "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
11020  "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
11021  "WHERE ct.oid = $1 "
11022  "ORDER BY a.attnum");
11023 
11024  ExecuteSqlStatement(fout, query->data);
11025 
11027  }
11028 
11029  printfPQExpBuffer(query,
11030  "EXECUTE dumpCompositeType('%u')",
11031  tyinfo->dobj.catId.oid);
11032 
11033  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
11034 
11035  ntups = PQntuples(res);
11036 
11037  i_attname = PQfnumber(res, "attname");
11038  i_atttypdefn = PQfnumber(res, "atttypdefn");
11039  i_attlen = PQfnumber(res, "attlen");
11040  i_attalign = PQfnumber(res, "attalign");
11041  i_attisdropped = PQfnumber(res, "attisdropped");
11042  i_attcollation = PQfnumber(res, "attcollation");
11043 
11044  if (dopt->binary_upgrade)
11045  {
11047  tyinfo->dobj.catId.oid,
11048  false, false);
11049  binary_upgrade_set_pg_class_oids(fout, q, tyinfo->typrelid, false);
11050  }
11051 
11052  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
11053  qualtypname = pg_strdup(fmtQualifiedDumpable(tyinfo));
11054 
11055  appendPQExpBuffer(q, "CREATE TYPE %s AS (",
11056  qualtypname);
11057 
11058  actual_atts = 0;
11059  for (i = 0; i < ntups; i++)
11060  {
11061  char *attname;
11062  char *atttypdefn;
11063  char *attlen;
11064  char *attalign;
11065  bool attisdropped;
11066  Oid attcollation;
11067 
11068  attname = PQgetvalue(res, i, i_attname);
11069  atttypdefn = PQgetvalue(res, i, i_atttypdefn);
11070  attlen = PQgetvalue(res, i, i_attlen);
11071  attalign = PQgetvalue(res, i, i_attalign);
11072  attisdropped = (PQgetvalue(res, i, i_attisdropped)[0] == 't');
11073  attcollation = atooid(PQgetvalue(res, i, i_attcollation));
11074 
11075  if (attisdropped && !dopt->binary_upgrade)
11076  continue;
11077 
11078  /* Format properly if not first attr */
11079  if (actual_atts++ > 0)
11080  appendPQExpBufferChar(q, ',');
11081  appendPQExpBufferStr(q, "\n\t");
11082 
11083  if (!attisdropped)
11084  {
11085  appendPQExpBuffer(q, "%s %s", fmtId(attname), atttypdefn);
11086 
11087  /* Add collation if not default for the column type */
11088  if (OidIsValid(attcollation))
11089  {
11090  CollInfo *coll;
11091 
11092  coll = findCollationByOid(attcollation);
11093  if (coll)
11094  appendPQExpBuffer(q, " COLLATE %s",
11095  fmtQualifiedDumpable(coll));
11096  }
11097  }
11098  else
11099  {
11100  /*
11101  * This is a dropped attribute and we're in binary_upgrade mode.
11102  * Insert a placeholder for it in the CREATE TYPE command, and set
11103  * length and alignment with direct UPDATE to the catalogs
11104  * afterwards. See similar code in dumpTableSchema().
11105  */
11106  appendPQExpBuffer(q, "%s INTEGER /* dummy */", fmtId(attname));
11107 
11108  /* stash separately for insertion after the CREATE TYPE */
11109  appendPQExpBufferStr(dropped,
11110  "\n-- For binary upgrade, recreate dropped column.\n");
11111  appendPQExpBuffer(dropped, "UPDATE pg_catalog.pg_attribute\n"
11112  "SET attlen = %s, "
11113  "attalign = '%s', attbyval = false\n"
11114  "WHERE attname = ", attlen, attalign);
11115  appendStringLiteralAH(dropped, attname, fout);
11116  appendPQExpBufferStr(dropped, "\n AND attrelid = ");
11117  appendStringLiteralAH(dropped, qualtypname, fout);
11118  appendPQExpBufferStr(dropped, "::pg_catalog.regclass;\n");
11119 
11120  appendPQExpBuffer(dropped, "ALTER TYPE %s ",
11121  qualtypname);
11122  appendPQExpBuffer(dropped, "DROP ATTRIBUTE %s;\n",
11123  fmtId(attname));
11124  }
11125  }
11126  appendPQExpBufferStr(q, "\n);\n");
11127  appendPQExpBufferStr(q, dropped->data);
11128 
11129  appendPQExpBuffer(delq, "DROP TYPE %s;\n", qualtypname);
11130 
11131  if (dopt->binary_upgrade)
11133  "TYPE", qtypname,
11134  tyinfo->dobj.namespace->dobj.name);
11135 
11136  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
11137  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
11138  ARCHIVE_OPTS(.tag = tyinfo->dobj.name,
11139  .namespace = tyinfo->dobj.namespace->dobj.name,
11140  .owner = tyinfo->rolname,
11141  .description = "TYPE",
11142  .section = SECTION_PRE_DATA,
11143  .createStmt = q->data,
11144  .dropStmt = delq->data));
11145 
11146 
11147  /* Dump Type Comments and Security Labels */
11148  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
11149  dumpComment(fout, "TYPE", qtypname,
11150  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
11151  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
11152 
11153  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
11154  dumpSecLabel(fout, "TYPE", qtypname,
11155  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
11156  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
11157 
11158  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
11159  dumpACL(fout, tyinfo->dobj.dumpId, InvalidDumpId, "TYPE",
11160  qtypname, NULL,
11161  tyinfo->dobj.namespace->dobj.name,
11162  tyinfo->rolname, &tyinfo->dacl);
11163 
11164  /* Dump any per-column comments */
11165  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
11166  dumpCompositeTypeColComments(fout, tyinfo, res);
11167 
11168  PQclear(res);
11169  destroyPQExpBuffer(q);
11170  destroyPQExpBuffer(dropped);
11171  destroyPQExpBuffer(delq);
11172  destroyPQExpBuffer(query);
11173  free(qtypname);
11174  free(qualtypname);
11175 }
NameData attname
Definition: pg_attribute.h:41
char attalign
Definition: pg_attribute.h:118
int16 attlen
Definition: pg_attribute.h:68
@ PREPQUERY_DUMPCOMPOSITETYPE
Definition: pg_backup.h:66
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
Definition: pg_dump.c:4803
static void dumpCompositeTypeColComments(Archive *fout, const TypeInfo *tyinfo, PGresult *res)
Definition: pg_dump.c:11187
Oid typrelid
Definition: pg_dump.h:201

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, ArchiveEntry(), atooid, attalign, 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(), _typeInfo::dacl, 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(), ExecuteSqlStatement(), findCollationByOid(), fmtId(), fmtQualifiedDumpable, free, i, InvalidDumpId, Archive::is_prepared, _dumpableObject::name, CatalogId::oid, OidIsValid, pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), PREPQUERY_DUMPCOMPOSITETYPE, printfPQExpBuffer(), res, _typeInfo::rolname, SECTION_PRE_DATA, and _typeInfo::typrelid.

Referenced by dumpType().

◆ dumpCompositeTypeColComments()

static void dumpCompositeTypeColComments ( Archive fout,
const TypeInfo tyinfo,
PGresult res 
)
static

Definition at line 11187 of file pg_dump.c.

11189 {
11191  int ncomments;
11192  PQExpBuffer query;
11193  PQExpBuffer target;
11194  int i;
11195  int ntups;
11196  int i_attname;
11197  int i_attnum;
11198  int i_attisdropped;
11199 
11200  /* do nothing, if --no-comments is supplied */
11201  if (fout->dopt->no_comments)
11202  return;
11203 
11204  /* Search for comments associated with type's pg_class OID */
11205  ncomments = findComments(RelationRelationId, tyinfo->typrelid,
11206  &comments);
11207 
11208  /* If no comments exist, we're done */
11209  if (ncomments <= 0)
11210  return;
11211 
11212  /* Build COMMENT ON statements */
11213  query = createPQExpBuffer();
11214  target = createPQExpBuffer();
11215 
11216  ntups = PQntuples(res);
11217  i_attnum = PQfnumber(res, "attnum");
11218  i_attname = PQfnumber(res, "attname");
11219  i_attisdropped = PQfnumber(res, "attisdropped");
11220  while (ncomments > 0)
11221  {
11222  const char *attname;
11223 
11224  attname = NULL;
11225  for (i = 0; i < ntups; i++)
11226  {
11227  if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid &&
11228  PQgetvalue(res, i, i_attisdropped)[0] != 't')
11229  {
11230  attname = PQgetvalue(res, i, i_attname);
11231  break;
11232  }
11233  }
11234  if (attname) /* just in case we don't find it */
11235  {
11236  const char *descr = comments->descr;
11237 
11238  resetPQExpBuffer(target);
11239  appendPQExpBuffer(target, "COLUMN %s.",
11240  fmtId(tyinfo->dobj.name));
11242 
11243  resetPQExpBuffer(query);
11244  appendPQExpBuffer(query, "COMMENT ON COLUMN %s.",
11245  fmtQualifiedDumpable(tyinfo));
11246  appendPQExpBuffer(query, "%s IS ", fmtId(attname));
11247  appendStringLiteralAH(query, descr, fout);
11248  appendPQExpBufferStr(query, ";\n");
11249 
11251  ARCHIVE_OPTS(.tag = target->data,
11252  .namespace = tyinfo->dobj.namespace->dobj.name,
11253  .owner = tyinfo->rolname,
11254  .description = "COMMENT",
11255  .section = SECTION_NONE,
11256  .createStmt = query->data,
11257  .deps = &(tyinfo->dobj.dumpId),
11258  .nDeps = 1));
11259  }
11260 
11261  comments++;
11262  ncomments--;
11263  }
11264 
11265  destroyPQExpBuffer(query);
11266  destroyPQExpBuffer(target);
11267 }
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148

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

Referenced by dumpCompositeType().

◆ dumpConstraint()

static void dumpConstraint ( Archive fout,
const ConstraintInfo coninfo 
)
static

Definition at line 16251 of file pg_dump.c.

16252 {
16253  DumpOptions *dopt = fout->dopt;
16254  TableInfo *tbinfo = coninfo->contable;
16255  PQExpBuffer q;
16256  PQExpBuffer delq;
16257  char *tag = NULL;
16258  char *foreign;
16259 
16260  /* Do nothing in data-only dump */
16261  if (dopt->dataOnly)
16262  return;
16263 
16264  q = createPQExpBuffer();
16265  delq = createPQExpBuffer();
16266 
16267  foreign = tbinfo &&
16268  tbinfo->relkind == RELKIND_FOREIGN_TABLE ? "FOREIGN " : "";
16269 
16270  if (coninfo->contype == 'p' ||
16271  coninfo->contype == 'u' ||
16272  coninfo->contype == 'x')
16273  {
16274  /* Index-related constraint */
16275  IndxInfo *indxinfo;
16276  int k;
16277 
16278  indxinfo = (IndxInfo *) findObjectByDumpId(coninfo->conindex);
16279 
16280  if (indxinfo == NULL)
16281  pg_fatal("missing index for constraint \"%s\"",
16282  coninfo->dobj.name);
16283 
16284  if (dopt->binary_upgrade)
16286  indxinfo->dobj.catId.oid, true);
16287 
16288  appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s\n", foreign,
16289  fmtQualifiedDumpable(tbinfo));
16290  appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
16291  fmtId(coninfo->dobj.name));
16292 
16293  if (coninfo->condef)
16294  {
16295  /* pg_get_constraintdef should have provided everything */
16296  appendPQExpBuffer(q, "%s;\n", coninfo->condef);
16297  }
16298  else
16299  {
16300  appendPQExpBuffer(q, "%s",
16301  coninfo->contype == 'p' ? "PRIMARY KEY" : "UNIQUE");
16302  if (indxinfo->indnullsnotdistinct)
16303  appendPQExpBuffer(q, " NULLS NOT DISTINCT");
16304  appendPQExpBuffer(q, " (");
16305  for (k = 0; k < indxinfo->indnkeyattrs; k++)
16306  {
16307  int indkey = (int) indxinfo->indkeys[k];
16308  const char *attname;
16309 
16310  if (indkey == InvalidAttrNumber)
16311  break;
16312  attname = getAttrName(indkey, tbinfo);
16313 
16314  appendPQExpBuffer(q, "%s%s",
16315  (k == 0) ? "" : ", ",
16316  fmtId(attname));
16317  }
16318 
16319  if (indxinfo->indnkeyattrs < indxinfo->indnattrs)
16320  appendPQExpBufferStr(q, ") INCLUDE (");
16321 
16322  for (k = indxinfo->indnkeyattrs; k < indxinfo->indnattrs; k++)
16323  {
16324  int indkey = (int) indxinfo->indkeys[k];
16325  const char *attname;
16326 
16327  if (indkey == InvalidAttrNumber)
16328  break;
16329  attname = getAttrName(indkey, tbinfo);
16330 
16331  appendPQExpBuffer(q, "%s%s",
16332  (k == indxinfo->indnkeyattrs) ? "" : ", ",
16333  fmtId(attname));
16334  }
16335 
16336  appendPQExpBufferChar(q, ')');
16337 
16338  if (nonemptyReloptions(indxinfo->indreloptions))
16339  {
16340  appendPQExpBufferStr(q, " WITH (");
16341  appendReloptionsArrayAH(q, indxinfo->indreloptions, "", fout);
16342  appendPQExpBufferChar(q, ')');
16343  }
16344 
16345  if (coninfo->condeferrable)
16346  {
16347  appendPQExpBufferStr(q, " DEFERRABLE");
16348  if (coninfo->condeferred)
16349  appendPQExpBufferStr(q, " INITIALLY DEFERRED");
16350  }
16351 
16352  appendPQExpBufferStr(q, ";\n");
16353  }
16354 
16355  /*
16356  * Append ALTER TABLE commands as needed to set properties that we
16357  * only have ALTER TABLE syntax for. Keep this in sync with the
16358  * similar code in dumpIndex!
16359  */
16360 
16361  /* If the index is clustered, we need to record that. */
16362  if (indxinfo->indisclustered)
16363  {
16364  appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER",
16365  fmtQualifiedDumpable(tbinfo));
16366  /* index name is not qualified in this syntax */
16367  appendPQExpBuffer(q, " ON %s;\n",
16368  fmtId(indxinfo->dobj.name));
16369  }
16370 
16371  /* If the index defines identity, we need to record that. */
16372  if (indxinfo->indisreplident)
16373  {
16374  appendPQExpBuffer(q, "\nALTER TABLE ONLY %s REPLICA IDENTITY USING",
16375  fmtQualifiedDumpable(tbinfo));
16376  /* index name is not qualified in this syntax */
16377  appendPQExpBuffer(q, " INDEX %s;\n",
16378  fmtId(indxinfo->dobj.name));
16379  }
16380 
16381  /* Indexes can depend on extensions */
16382  append_depends_on_extension(fout, q, &indxinfo->dobj,
16383  "pg_catalog.pg_class", "INDEX",
16384  fmtQualifiedDumpable(indxinfo));
16385 
16386  appendPQExpBuffer(delq, "ALTER %sTABLE ONLY %s ", foreign,
16387  fmtQualifiedDumpable(tbinfo));
16388  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16389  fmtId(coninfo->dobj.name));
16390 
16391  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16392 
16393  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16394  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16395  ARCHIVE_OPTS(.tag = tag,
16396  .namespace = tbinfo->dobj.namespace->dobj.name,
16397  .tablespace = indxinfo->tablespace,
16398  .owner = tbinfo->rolname,
16399  .description = "CONSTRAINT",
16400  .section = SECTION_POST_DATA,
16401  .createStmt = q->data,
16402  .dropStmt = delq->data));
16403  }
16404  else if (coninfo->contype == 'f')
16405  {
16406  char *only;
16407 
16408  /*
16409  * Foreign keys on partitioned tables are always declared as
16410  * inheriting to partitions; for all other cases, emit them as
16411  * applying ONLY directly to the named table, because that's how they
16412  * work for regular inherited tables.
16413  */
16414  only = tbinfo->relkind == RELKIND_PARTITIONED_TABLE ? "" : "ONLY ";
16415 
16416  /*
16417  * XXX Potentially wrap in a 'SET CONSTRAINTS OFF' block so that the
16418  * current table data is not processed
16419  */
16420  appendPQExpBuffer(q, "ALTER %sTABLE %s%s\n", foreign,
16421  only, fmtQualifiedDumpable(tbinfo));
16422  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16423  fmtId(coninfo->dobj.name),
16424  coninfo->condef);
16425 
16426  appendPQExpBuffer(delq, "ALTER %sTABLE %s%s ", foreign,
16427  only, fmtQualifiedDumpable(tbinfo));
16428  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16429  fmtId(coninfo->dobj.name));
16430 
16431  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16432 
16433  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16434  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16435  ARCHIVE_OPTS(.tag = tag,
16436  .namespace = tbinfo->dobj.namespace->dobj.name,
16437  .owner = tbinfo->rolname,
16438  .description = "FK CONSTRAINT",
16439  .section = SECTION_POST_DATA,
16440  .createStmt = q->data,
16441  .dropStmt = delq->data));
16442  }
16443  else if (coninfo->contype == 'c' && tbinfo)
16444  {
16445  /* CHECK constraint on a table */
16446 
16447  /* Ignore if not to be dumped separately, or if it was inherited */
16448  if (coninfo->separate && coninfo->conislocal)
16449  {
16450  /* not ONLY since we want it to propagate to children */
16451  appendPQExpBuffer(q, "ALTER %sTABLE %s\n", foreign,
16452  fmtQualifiedDumpable(tbinfo));
16453  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16454  fmtId(coninfo->dobj.name),
16455  coninfo->condef);
16456 
16457  appendPQExpBuffer(delq, "ALTER %sTABLE %s ", foreign,
16458  fmtQualifiedDumpable(tbinfo));
16459  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16460  fmtId(coninfo->dobj.name));
16461 
16462  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16463 
16464  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16465  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16466  ARCHIVE_OPTS(.tag = tag,
16467  .namespace = tbinfo->dobj.namespace->dobj.name,
16468  .owner = tbinfo->rolname,
16469  .description = "CHECK CONSTRAINT",
16470  .section = SECTION_POST_DATA,
16471  .createStmt = q->data,
16472  .dropStmt = delq->data));
16473  }
16474  }
16475  else if (coninfo->contype == 'c' && tbinfo == NULL)
16476  {
16477  /* CHECK constraint on a domain */
16478  TypeInfo *tyinfo = coninfo->condomain;
16479 
16480  /* Ignore if not to be dumped separately */
16481  if (coninfo->separate)
16482  {
16483  appendPQExpBuffer(q, "ALTER DOMAIN %s\n",
16484  fmtQualifiedDumpable(tyinfo));
16485  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16486  fmtId(coninfo->dobj.name),
16487  coninfo->condef);
16488 
16489  appendPQExpBuffer(delq, "ALTER DOMAIN %s ",
16490  fmtQualifiedDumpable(tyinfo));
16491  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16492  fmtId(coninfo->dobj.name));
16493 
16494  tag = psprintf("%s %s", tyinfo->dobj.name, coninfo->dobj.name);
16495 
16496  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16497  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16498  ARCHIVE_OPTS(.tag = tag,
16499  .namespace = tyinfo->dobj.namespace->dobj.name,
16500  .owner = tyinfo->rolname,
16501  .description = "CHECK CONSTRAINT",
16502  .section = SECTION_POST_DATA,
16503  .createStmt = q->data,
16504  .dropStmt = delq->data));
16505  }
16506  }
16507  else
16508  {
16509  pg_fatal("unrecognized constraint type: %c",
16510  coninfo->contype);
16511  }
16512 
16513  /* Dump Constraint Comments --- only works for table constraints */
16514  if (tbinfo && coninfo->separate &&
16515  coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
16516  dumpTableConstraintComment(fout, coninfo);
16517 
16518  free(tag);
16519  destroyPQExpBuffer(q);
16520  destroyPQExpBuffer(delq);
16521 }
#define InvalidAttrNumber
Definition: attnum.h:23
@ SECTION_POST_DATA
Definition: pg_backup.h:58
static void append_depends_on_extension(Archive *fout, PQExpBuffer create, const DumpableObject *dobj, const char *catalog, const char *keyword, const char *objname)
Definition: pg_dump.c:4630
static const char * getAttrName(int attrnum, const TableInfo *tblInfo)
Definition: pg_dump.c:15962
static void appendReloptionsArrayAH(PQExpBuffer buffer, const char *reloptions, const char *prefix, Archive *fout)
Definition: pg_dump.c:18126
static void dumpTableConstraintComment(Archive *fout, const ConstraintInfo *coninfo)
Definition: pg_dump.c:16531
static bool nonemptyReloptions(const char *reloptions)
Definition: pg_dump.c:18114
TypeInfo * condomain
Definition: pg_dump.h:476
TableInfo * contable
Definition: pg_dump.h:475
bool condeferred
Definition: pg_dump.h:482
bool conislocal
Definition: pg_dump.h:483
DumpableObject dobj
Definition: pg_dump.h:474
DumpId conindex
Definition: pg_dump.h:480
bool condeferrable
Definition: pg_dump.h:481
char * condef
Definition: pg_dump.h:478
bool indisreplident
Definition: pg_dump.h:400
int indnkeyattrs
Definition: pg_dump.h:395
int indnattrs
Definition: pg_dump.h:396
Oid * indkeys
Definition: pg_dump.h:397
char * indreloptions
Definition: pg_dump.h:392
bool indisclustered
Definition: pg_dump.h:399
char * tablespace
Definition: pg_dump.h:391
bool indnullsnotdistinct
Definition: pg_dump.h:401
DumpableObject dobj
Definition: pg_dump.h:388

References append_depends_on_extension(), 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(), findObjectByDumpId(), fmtId(), fmtQualifiedDumpable, free, getAttrName(), if(), _indxInfo::indisclustered, _indxInfo::indisreplident, _indxInfo::indkeys, _indxInfo::indnattrs, _indxInfo::indnkeyattrs, _indxInfo::indnullsnotdistinct, _indxInfo::indreloptions, InvalidAttrNumber, _dumpableObject::name, nonemptyReloptions(), CatalogId::oid, pg_fatal, psprintf(), _tableInfo::relkind, _typeInfo::rolname, _tableInfo::rolname, SECTION_POST_DATA, _constraintInfo::separate, and _indxInfo::tablespace.

Referenced by dumpDumpableObject().

◆ dumpConversion()

static void dumpConversion ( Archive fout,
const ConvInfo convinfo 
)
static

Definition at line 13189 of file pg_dump.c.

13190 {
13191  DumpOptions *dopt = fout->dopt;
13192  PQExpBuffer query;
13193  PQExpBuffer q;
13194  PQExpBuffer delq;
13195  char *qconvname;
13196  PGresult *res;
13197  int i_conforencoding;
13198  int i_contoencoding;
13199  int i_conproc;
13200  int i_condefault;
13201  const char *conforencoding;
13202  const char *contoencoding;
13203  const char *conproc;
13204  bool condefault;
13205 
13206  /* Do nothing in data-only dump */
13207  if (dopt->dataOnly)
13208  return;
13209 
13210  query = createPQExpBuffer();
13211  q = createPQExpBuffer();
13212  delq = createPQExpBuffer();
13213 
13214  qconvname = pg_strdup(fmtId(convinfo->dobj.name));
13215 
13216  /* Get conversion-specific details */
13217  appendPQExpBuffer(query, "SELECT "
13218  "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
13219  "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
13220  "conproc, condefault "
13221  "FROM pg_catalog.pg_conversion c "
13222  "WHERE c.oid = '%u'::pg_catalog.oid",
13223  convinfo->dobj.catId.oid);
13224 
13225  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13226 
13227  i_conforencoding = PQfnumber(res, "conforencoding");
13228  i_contoencoding = PQfnumber(res, "contoencoding");
13229  i_conproc = PQfnumber(res, "conproc");
13230  i_condefault = PQfnumber(res, "condefault");
13231 
13232  conforencoding = PQgetvalue(res, 0, i_conforencoding);
13233  contoencoding = PQgetvalue(res, 0, i_contoencoding);
13234  conproc = PQgetvalue(res, 0, i_conproc);
13235  condefault = (PQgetvalue(res, 0, i_condefault)[0] == 't');
13236 
13237  appendPQExpBuffer(delq, "DROP CONVERSION %s;\n",
13238  fmtQualifiedDumpable(convinfo));
13239 
13240  appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ",
13241  (condefault) ? "DEFAULT " : "",
13242  fmtQualifiedDumpable(convinfo));
13243  appendStringLiteralAH(q, conforencoding, fout);
13244  appendPQExpBufferStr(q, " TO ");
13245  appendStringLiteralAH(q, contoencoding, fout);
13246  /* regproc output is already sufficiently quoted */
13247  appendPQExpBuffer(q, " FROM %s;\n", conproc);
13248 
13249  if (dopt->binary_upgrade)
13250  binary_upgrade_extension_member(q, &convinfo->dobj,
13251  "CONVERSION", qconvname,
13252  convinfo->dobj.namespace->dobj.name);
13253 
13254  if (convinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13255  ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
13256  ARCHIVE_OPTS(.tag = convinfo->dobj.name,
13257  .namespace = convinfo->dobj.namespace->dobj.name,
13258  .owner = convinfo->rolname,
13259  .description = "CONVERSION",
13260  .section = SECTION_PRE_DATA,
13261  .createStmt = q->data,
13262  .dropStmt = delq->data));
13263 
13264  /* Dump Conversion Comments */
13265  if (convinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13266  dumpComment(fout, "CONVERSION", qconvname,
13267  convinfo->dobj.namespace->dobj.name, convinfo->rolname,
13268  convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
13269 
13270  PQclear(res);
13271 
13272  destroyPQExpBuffer(query);
13273  destroyPQExpBuffer(q);
13274  destroyPQExpBuffer(delq);
13275  free(qconvname);
13276 }
DumpableObject dobj
Definition: pg_dump.h:274
const char * rolname
Definition: pg_dump.h:275

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(), res, _convInfo::rolname, and SECTION_PRE_DATA.

Referenced by dumpDumpableObject().

◆ dumpDatabase()

static void dumpDatabase ( Archive AH)
static

Definition at line 2793 of file pg_dump.c.

2794 {
2795  DumpOptions *dopt = fout->dopt;
2796  PQExpBuffer dbQry = createPQExpBuffer();
2797  PQExpBuffer delQry = createPQExpBuffer();
2798  PQExpBuffer creaQry = createPQExpBuffer();
2799  PQExpBuffer labelq = createPQExpBuffer();
2800  PGconn *conn = GetConnection(fout);
2801  PGresult *res;
2802  int i_tableoid,
2803  i_oid,
2804  i_datname,
2805  i_datdba,
2806  i_encoding,
2807  i_datlocprovider,
2808  i_collate,
2809  i_ctype,
2810  i_daticulocale,
2811  i_frozenxid,
2812  i_minmxid,
2813  i_datacl,
2814  i_acldefault,
2815  i_datistemplate,
2816  i_datconnlimit,
2817  i_datcollversion,
2818  i_tablespace;
2819  CatalogId dbCatId;
2820  DumpId dbDumpId;
2821  DumpableAcl dbdacl;
2822  const char *datname,
2823  *dba,
2824  *encoding,
2825  *datlocprovider,
2826  *collate,
2827  *ctype,
2828  *iculocale,
2829  *datistemplate,
2830  *datconnlimit,
2831  *tablespace;
2832  uint32 frozenxid,
2833  minmxid;
2834  char *qdatname;
2835 
2836  pg_log_info("saving database definition");
2837 
2838  /*
2839  * Fetch the database-level properties for this database.
2840  */
2841  appendPQExpBuffer(dbQry, "SELECT tableoid, oid, datname, "
2842  "datdba, "
2843  "pg_encoding_to_char(encoding) AS encoding, "
2844  "datcollate, datctype, datfrozenxid, "
2845  "datacl, acldefault('d', datdba) AS acldefault, "
2846  "datistemplate, datconnlimit, ");
2847  if (fout->remoteVersion >= 90300)
2848  appendPQExpBuffer(dbQry, "datminmxid, ");
2849  else
2850  appendPQExpBuffer(dbQry, "0 AS datminmxid, ");
2851  if (fout->remoteVersion >= 150000)
2852  appendPQExpBuffer(dbQry, "datlocprovider, daticulocale, datcollversion, ");
2853  else
2854  appendPQExpBuffer(dbQry, "'c' AS datlocprovider, NULL AS daticulocale, NULL AS datcollversion, ");
2855  appendPQExpBuffer(dbQry,
2856  "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2857  "shobj_description(oid, 'pg_database') AS description "
2858  "FROM pg_database "
2859  "WHERE datname = current_database()");
2860 
2861  res = ExecuteSqlQueryForSingleRow(fout, dbQry->data);
2862 
2863  i_tableoid = PQfnumber(res, "tableoid");
2864  i_oid = PQfnumber(res, "oid");
2865  i_datname = PQfnumber(res, "datname");
2866  i_datdba = PQfnumber(res, "datdba");
2867  i_encoding = PQfnumber(res, "encoding");
2868  i_datlocprovider = PQfnumber(res, "datlocprovider");
2869  i_collate = PQfnumber(res, "datcollate");
2870  i_ctype = PQfnumber(res, "datctype");
2871  i_daticulocale = PQfnumber(res, "daticulocale");
2872  i_frozenxid = PQfnumber(res, "datfrozenxid");
2873  i_minmxid = PQfnumber(res, "datminmxid");
2874  i_datacl = PQfnumber(res, "datacl");
2875  i_acldefault = PQfnumber(res, "acldefault");
2876  i_datistemplate = PQfnumber(res, "datistemplate");
2877  i_datconnlimit = PQfnumber(res, "datconnlimit");
2878  i_datcollversion = PQfnumber(res, "datcollversion");
2879  i_tablespace = PQfnumber(res, "tablespace");
2880 
2881  dbCatId.tableoid = atooid(PQgetvalue(res, 0, i_tableoid));
2882  dbCatId.oid = atooid(PQgetvalue(res, 0, i_oid));
2883  datname = PQgetvalue(res, 0, i_datname);
2884  dba = getRoleName(PQgetvalue(res, 0, i_datdba));
2885  encoding = PQgetvalue(res, 0, i_encoding);
2886  datlocprovider = PQgetvalue(res, 0, i_datlocprovider);
2887  collate = PQgetvalue(res, 0, i_collate);
2888  ctype = PQgetvalue(res, 0, i_ctype);
2889  if (!PQgetisnull(res, 0, i_daticulocale))
2890  iculocale = PQgetvalue(res, 0, i_daticulocale);
2891  else
2892  iculocale = NULL;
2893  frozenxid = atooid(PQgetvalue(res, 0, i_frozenxid));
2894  minmxid = atooid(PQgetvalue(res, 0, i_minmxid));
2895  dbdacl.acl = PQgetvalue(res, 0, i_datacl);
2896  dbdacl.acldefault = PQgetvalue(res, 0, i_acldefault);
2897  datistemplate = PQgetvalue(res, 0, i_datistemplate);
2898  datconnlimit = PQgetvalue(res, 0, i_datconnlimit);
2899  tablespace = PQgetvalue(res, 0, i_tablespace);
2900 
2901  qdatname = pg_strdup(fmtId(datname));
2902 
2903  /*
2904  * Prepare the CREATE DATABASE command. We must specify OID (if we want
2905  * to preserve that), as well as the encoding, locale, and tablespace
2906  * since those can't be altered later. Other DB properties are left to
2907  * the DATABASE PROPERTIES entry, so that they can be applied after
2908  * reconnecting to the target DB.
2909  */
2910  if (dopt->binary_upgrade)
2911  {
2912  appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0 OID = %u",
2913  qdatname, dbCatId.oid);
2914  }
2915  else
2916  {
2917  appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0",
2918  qdatname);
2919  }
2920  if (strlen(encoding) > 0)
2921  {
2922  appendPQExpBufferStr(creaQry, " ENCODING = ");
2923  appendStringLiteralAH(creaQry, encoding, fout);
2924  }
2925 
2926  appendPQExpBufferStr(creaQry, " LOCALE_PROVIDER = ");
2927  if (datlocprovider[0] == 'c')
2928  appendPQExpBufferStr(creaQry, "libc");
2929  else if (datlocprovider[0] == 'i')
2930  appendPQExpBufferStr(creaQry, "icu");
2931  else
2932  pg_fatal("unrecognized locale provider: %s",
2933  datlocprovider);
2934 
2935  if (strlen(collate) > 0 && strcmp(collate, ctype) == 0)
2936  {
2937  appendPQExpBufferStr(creaQry, " LOCALE = ");
2938  appendStringLiteralAH(creaQry, collate, fout);
2939  }
2940  else
2941  {
2942  if (strlen(collate) > 0)
2943  {
2944  appendPQExpBufferStr(creaQry, " LC_COLLATE = ");
2945  appendStringLiteralAH(creaQry, collate, fout);
2946  }
2947  if (strlen(ctype) > 0)
2948  {
2949  appendPQExpBufferStr(creaQry, " LC_CTYPE = ");
2950  appendStringLiteralAH(creaQry, ctype, fout);
2951  }
2952  }
2953  if (iculocale)
2954  {
2955  appendPQExpBufferStr(creaQry, " ICU_LOCALE = ");
2956  appendStringLiteralAH(creaQry, iculocale, fout);
2957  }
2958 
2959  /*
2960  * For binary upgrade, carry over the collation version. For normal
2961  * dump/restore, omit the version, so that it is computed upon restore.
2962  */
2963  if (dopt->binary_upgrade)
2964  {
2965  if (!PQgetisnull(res, 0, i_datcollversion))
2966  {
2967  appendPQExpBufferStr(creaQry, " COLLATION_VERSION = ");
2968  appendStringLiteralAH(creaQry,
2969  PQgetvalue(res, 0, i_datcollversion),
2970  fout);
2971  }
2972  }
2973 
2974  /*
2975  * Note: looking at dopt->outputNoTablespaces here is completely the wrong
2976  * thing; the decision whether to specify a tablespace should be left till
2977  * pg_restore, so that pg_restore --no-tablespaces applies. Ideally we'd
2978  * label the DATABASE entry with the tablespace and let the normal
2979  * tablespace selection logic work ... but CREATE DATABASE doesn't pay
2980  * attention to default_tablespace, so that won't work.
2981  */
2982  if (strlen(tablespace) > 0 && strcmp(tablespace, "pg_default") != 0 &&
2983  !dopt->outputNoTablespaces)
2984  appendPQExpBuffer(creaQry, " TABLESPACE = %s",
2985  fmtId(tablespace));
2986  appendPQExpBufferStr(creaQry, ";\n");
2987 
2988  appendPQExpBuffer(delQry, "DROP DATABASE %s;\n",
2989  qdatname);
2990 
2991  dbDumpId = createDumpId();
2992 
2993  ArchiveEntry(fout,
2994  dbCatId, /* catalog ID */
2995  dbDumpId, /* dump ID */
2996  ARCHIVE_OPTS(.tag = datname,
2997  .owner = dba,
2998  .description = "DATABASE",
2999  .section = SECTION_PRE_DATA,
3000  .createStmt = creaQry->data,
3001  .dropStmt = delQry->data));
3002 
3003  /* Compute correct tag for archive entry */
3004  appendPQExpBuffer(labelq, "DATABASE %s", qdatname);
3005 
3006  /* Dump DB comment if any */
3007  {
3008  /*
3009  * 8.2 and up keep comments on shared objects in a shared table, so we
3010  * cannot use the dumpComment() code used for other database objects.
3011  * Be careful that the ArchiveEntry parameters match that function.
3012  */
3013  char *comment = PQgetvalue(res, 0, PQfnumber(res, "description"));
3014 
3015  if (comment && *comment && !dopt->no_comments)
3016  {
3017  resetPQExpBuffer(dbQry);
3018 
3019  /*
3020  * Generates warning when loaded into a differently-named
3021  * database.
3022  */
3023  appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", qdatname);
3024  appendStringLiteralAH(dbQry, comment, fout);
3025  appendPQExpBufferStr(dbQry, ";\n");
3026 
3028  ARCHIVE_OPTS(.tag = labelq->data,
3029  .owner = dba,
3030  .description = "COMMENT",
3031  .section = SECTION_NONE,
3032  .createStmt = dbQry->data,
3033  .deps = &dbDumpId,
3034  .nDeps = 1));
3035  }
3036  }
3037 
3038  /* Dump DB security label, if enabled */
3039  if (!dopt->no_security_labels)
3040  {
3041  PGresult *shres;
3042  PQExpBuffer seclabelQry;
3043 
3044  seclabelQry = createPQExpBuffer();
3045 
3046  buildShSecLabelQuery("pg_database", dbCatId.oid, seclabelQry);
3047  shres = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
3048  resetPQExpBuffer(seclabelQry);
3049  emitShSecLabels(conn, shres, seclabelQry, "DATABASE", datname);
3050  if (seclabelQry->len > 0)
3052  ARCHIVE_OPTS(.tag = labelq->data,
3053  .owner = dba,
3054  .description = "SECURITY LABEL",
3055  .section = SECTION_NONE,
3056  .createStmt = seclabelQry->data,
3057  .deps = &dbDumpId,
3058  .nDeps = 1));
3059  destroyPQExpBuffer(seclabelQry);
3060  PQclear(shres);
3061  }
3062 
3063  /*
3064  * Dump ACL if any. Note that we do not support initial privileges
3065  * (pg_init_privs) on databases.
3066  */
3067  dbdacl.privtype = 0;
3068  dbdacl.initprivs = NULL;
3069 
3070  dumpACL(fout, dbDumpId, InvalidDumpId, "DATABASE",
3071  qdatname, NULL, NULL,
3072  dba, &dbdacl);
3073 
3074  /*
3075  * Now construct a DATABASE PROPERTIES archive entry to restore any
3076  * non-default database-level properties. (The reason this must be
3077  * separate is that we cannot put any additional commands into the TOC
3078  * entry that has CREATE DATABASE. pg_restore would execute such a group
3079  * in an implicit transaction block, and the backend won't allow CREATE
3080  * DATABASE in that context.)
3081  */
3082  resetPQExpBuffer(creaQry);
3083  resetPQExpBuffer(delQry);
3084 
3085  if (strlen(datconnlimit) > 0 && strcmp(datconnlimit, "-1") != 0)
3086  appendPQExpBuffer(creaQry, "ALTER DATABASE %s CONNECTION LIMIT = %s;\n",
3087  qdatname, datconnlimit);
3088 
3089  if (strcmp(datistemplate, "t") == 0)
3090  {
3091  appendPQExpBuffer(creaQry, "ALTER DATABASE %s IS_TEMPLATE = true;\n",
3092  qdatname);
3093 
3094  /*
3095  * The backend won't accept DROP DATABASE on a template database. We
3096  * can deal with that by removing the template marking before the DROP
3097  * gets issued. We'd prefer to use ALTER DATABASE IF EXISTS here, but
3098  * since no such command is currently supported, fake it with a direct
3099  * UPDATE on pg_database.
3100  */
3101  appendPQExpBufferStr(delQry, "UPDATE pg_catalog.pg_database "
3102  "SET datistemplate = false WHERE datname = ");
3103  appendStringLiteralAH(delQry, datname, fout);
3104  appendPQExpBufferStr(delQry, ";\n");
3105  }
3106 
3107  /* Add database-specific SET options */
3108  dumpDatabaseConfig(fout, creaQry, datname, dbCatId.oid);
3109 
3110  /*
3111  * We stick this binary-upgrade query into the DATABASE PROPERTIES archive
3112  * entry, too, for lack of a better place.
3113  */
3114  if (dopt->binary_upgrade)
3115  {
3116  appendPQExpBufferStr(creaQry, "\n-- For binary upgrade, set datfrozenxid and datminmxid.\n");
3117  appendPQExpBuffer(creaQry, "UPDATE pg_catalog.pg_database\n"
3118  "SET datfrozenxid = '%u', datminmxid = '%u'\n"
3119  "WHERE datname = ",
3120  frozenxid, minmxid);
3121  appendStringLiteralAH(creaQry, datname, fout);
3122  appendPQExpBufferStr(creaQry, ";\n");
3123  }
3124 
3125  if (creaQry->len > 0)
3127  ARCHIVE_OPTS(.tag = datname,
3128  .owner = dba,
3129  .description = "DATABASE PROPERTIES",
3130  .section = SECTION_PRE_DATA,
3131  .createStmt = creaQry->data,
3132  .dropStmt = delQry->data,
3133  .deps = &dbDumpId));
3134 
3135  /*
3136  * pg_largeobject comes from the old system intact, so set its
3137  * relfrozenxids and relminmxids.
3138  */
3139  if (dopt->binary_upgrade)
3140  {
3141  PGresult *lo_res;
3142  PQExpBuffer loFrozenQry = createPQExpBuffer();
3143  PQExpBuffer loOutQry = createPQExpBuffer();
3144  int i_relfrozenxid,
3145  i_relminmxid;
3146 
3147  /*
3148  * pg_largeobject
3149  */
3150  if (fout->remoteVersion >= 90300)
3151  appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, relminmxid\n"
3152  "FROM pg_catalog.pg_class\n"
3153  "WHERE oid = %u;\n",
3154  LargeObjectRelationId);
3155  else
3156  appendPQExpBuffer(loFrozenQry, "SELECT relfrozenxid, 0 AS relminmxid\n"
3157  "FROM pg_catalog.pg_class\n"
3158  "WHERE oid = %u;\n",
3159  LargeObjectRelationId);
3160 
3161  lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data);
3162 
3163  i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
3164  i_relminmxid = PQfnumber(lo_res, "relminmxid");
3165 
3166  appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
3167  appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
3168  "SET relfrozenxid = '%u', relminmxid = '%u'\n"
3169  "WHERE oid = %u;\n",
3170  atooid(PQgetvalue(lo_res, 0, i_relfrozenxid)),
3171  atooid(PQgetvalue(lo_res, 0, i_relminmxid)),
3172  LargeObjectRelationId);
3174  ARCHIVE_OPTS(.tag = "pg_largeobject",
3175  .description = "pg_largeobject",
3176  .section = SECTION_PRE_DATA,
3177  .createStmt = loOutQry->data));
3178 
3179  PQclear(lo_res);
3180 
3181  destroyPQExpBuffer(loFrozenQry);
3182  destroyPQExpBuffer(loOutQry);
3183  }
3184 
3185  PQclear(res);
3186 
3187  free(qdatname);
3188  destroyPQExpBuffer(dbQry);
3189  destroyPQExpBuffer(delQry);
3190  destroyPQExpBuffer(creaQry);
3191  destroyPQExpBuffer(labelq);
3192 }
unsigned int uint32
Definition: c.h:441
void buildShSecLabelQuery(const char *catalog_name, Oid objectId, PQExpBuffer sql)
Definition: dumputils.c:637
void emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, const char *objtype, const char *objname)
Definition: dumputils.c:655
char datlocprovider
Definition: pg_database.h:44
NameData datname
Definition: pg_database.h:35
int32 encoding
Definition: pg_database.h:41
bool datistemplate
Definition: pg_database.h:47
int32 datconnlimit
Definition: pg_database.h:53
static const char * getRoleName(const char *roleoid_str)
Definition: pg_dump.c:9201
static void dumpDatabaseConfig(Archive *AH, PQExpBuffer outbuf, const char *dbname, Oid dboid)
Definition: pg_dump.c:3199
char * tablespace
Definition: pgbench.c:229
int no_security_labels
Definition: pg_backup.h:176
int outputNoTablespaces
Definition: pg_backup.h:184

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ARCHIVE_OPTS, ArchiveEntry(), atooid, _dumpOptions::binary_upgrade, buildShSecLabelQuery(), conn, createDumpId(), createPQExpBuffer(), PQExpBufferData::data, datconnlimit, datistemplate, datlocprovider, datname, destroyPQExpBuffer(), Archive::dopt, dumpACL(), dumpDatabaseConfig(), emitShSecLabels(), encoding, ExecuteSqlQuery(), ExecuteSqlQueryForSingleRow(), fmtId(), free, GetConnection(), getRoleName(), _dumpableAcl::initprivs, InvalidDumpId, PQExpBufferData::len, nilCatalogId, _dumpOptions::no_comments, _dumpOptions::no_security_labels, CatalogId::oid, _dumpOptions::outputNoTablespaces, pg_fatal, pg_log_info, pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), _dumpableAcl::privtype, Archive::remoteVersion, res, resetPQExpBuffer(), SECTION_NONE, SECTION_PRE_DATA, CatalogId::tableoid, and tablespace.

Referenced by main().

◆ dumpDatabaseConfig()

static void dumpDatabaseConfig ( Archive AH,
PQExpBuffer  outbuf,
const char *  dbname,
Oid  dboid 
)
static

Definition at line 3199 of file pg_dump.c.

3201 {
3202  PGconn *conn = GetConnection(AH);
3204  PGresult *res;
3205 
3206  /* First collect database-specific options */
3207  printfPQExpBuffer(buf, "SELECT unnest(setconfig) FROM pg_db_role_setting "
3208  "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3209  dboid);
3210 
3211  res = ExecuteSqlQuery(AH, buf->data, PGRES_TUPLES_OK);
3212 
3213  for (int i = 0; i < PQntuples(res); i++)
3215  "DATABASE", dbname, NULL, NULL,
3216  outbuf);
3217 
3218  PQclear(res);
3219 
3220  /* Now look for role-and-database-specific options */
3221  printfPQExpBuffer(buf, "SELECT rolname, unnest(setconfig) "
3222  "FROM pg_db_role_setting s, pg_roles r "
3223  "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3224  dboid);
3225 
3226  res = ExecuteSqlQuery(AH, buf->data, PGRES_TUPLES_OK);
3227 
3228  for (int i = 0; i < PQntuples(res); i++)
3230  "ROLE", PQgetvalue(res, i, 0),
3231  "DATABASE", dbname,
3232  outbuf);
3233 
3234  PQclear(res);
3235 
3237 }
void makeAlterConfigCommand(PGconn *conn, const char *configitem, const char *type, const char *name, const char *type2, const char *name2, PQExpBuffer buf)
Definition: dumputils.c:823
char * dbname
Definition: streamutil.c:51

References buf, conn, createPQExpBuffer(), dbname, destroyPQExpBuffer(), ExecuteSqlQuery(), GetConnection(), i, makeAlterConfigCommand(), PGRES_TUPLES_OK, PQclear(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), and res.

Referenced by dumpDatabase().

◆ dumpDefaultACL()

static void dumpDefaultACL ( Archive fout,
const DefaultACLInfo daclinfo 
)
static

Definition at line 14264 of file pg_dump.c.

14265 {
14266  DumpOptions *dopt = fout->dopt;
14267  PQExpBuffer q;
14268  PQExpBuffer tag;
14269  const char *type;
14270 
14271  /* Do nothing in data-only dump, or if we're skipping ACLs */
14272  if (dopt->dataOnly || dopt->aclsSkip)
14273  return;
14274 
14275  q = createPQExpBuffer();
14276  tag = createPQExpBuffer();
14277 
14278  switch (daclinfo->defaclobjtype)
14279  {
14280  case DEFACLOBJ_RELATION:
14281  type = "TABLES";
14282  break;
14283  case DEFACLOBJ_SEQUENCE:
14284  type = "SEQUENCES";
14285  break;
14286  case DEFACLOBJ_FUNCTION:
14287  type = "FUNCTIONS";
14288  break;
14289  case DEFACLOBJ_TYPE:
14290  type = "TYPES";
14291  break;
14292  case DEFACLOBJ_NAMESPACE:
14293  type = "SCHEMAS";
14294  break;
14295  default:
14296  /* shouldn't get here */
14297  pg_fatal("unrecognized object type in default privileges: %d",
14298  (int) daclinfo->defaclobjtype);
14299  type = ""; /* keep compiler quiet */
14300  }
14301 
14302  appendPQExpBuffer(tag, "DEFAULT PRIVILEGES FOR %s", type);
14303 
14304  /* build the actual command(s) for this tuple */
14306  daclinfo->dobj.namespace != NULL ?
14307  daclinfo->dobj.namespace->dobj.name : NULL,
14308  daclinfo->dacl.acl,
14309  daclinfo->dacl.acldefault,
14310  daclinfo->defaclrole,
14311  fout->remoteVersion,
14312  q))
14313  pg_fatal("could not parse default ACL list (%s)",
14314  daclinfo->dacl.acl);
14315 
14316  if (daclinfo->dobj.dump & DUMP_COMPONENT_ACL)
14317  ArchiveEntry(fout, daclinfo->dobj.catId, daclinfo->dobj.dumpId,
14318  ARCHIVE_OPTS(.tag = tag->data,
14319  .namespace = daclinfo->dobj.namespace ?
14320  daclinfo->dobj.namespace->dobj.name : NULL,
14321  .owner = daclinfo->defaclrole,
14322  .description = "DEFAULT ACL",
14323  .section = SECTION_POST_DATA,
14324  .createStmt = q->data));
14325 
14326  destroyPQExpBuffer(tag);
14327  destroyPQExpBuffer(q);
14328 }
bool buildDefaultACLCommands(const char *type, const char *nspname, const char *acls, const char *acldefault, const char *owner, int remoteVersion, PQExpBuffer sql)
Definition: dumputils.c:327
DumpableObject dobj
Definition: pg_dump.h:579
DumpableAcl dacl
Definition: pg_dump.h:580
const char * defaclrole
Definition: pg_dump.h:581
char defaclobjtype
Definition: pg_dump.h:582

References _dumpableAcl::acl, _dumpableAcl::acldefault, _dumpOptions::aclsSkip, appendPQExpBuffer(), ARCHIVE_OPTS, ArchiveEntry(), buildDefaultACLCommands(), _dumpableObject::catId, createPQExpBuffer(), _defaultACLInfo::dacl, PQExpBufferData::data, _dumpOptions::dataOnly, _defaultACLInfo::defaclobjtype, _defaultACLInfo::defaclrole, destroyPQExpBuffer(), _defaultACLInfo::dobj, Archive::dopt, _dumpableObject::dump, DUMP_COMPONENT_ACL, _dumpableObject::dumpId, _dumpableObject::name, pg_fatal, Archive::remoteVersion, SECTION_POST_DATA, and generate_unaccent_rules::type.

Referenced by dumpDumpableObject().

◆ dumpDomain()

static void dumpDomain ( Archive fout,
const TypeInfo tyinfo 
)
static

Definition at line 10808 of file pg_dump.c.

10809 {
10810  DumpOptions *dopt = fout->dopt;
10812  PQExpBuffer delq = createPQExpBuffer();
10813  PQExpBuffer query = createPQExpBuffer();
10814  PGresult *res;
10815  int i;
10816