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

Go to the source code of this file.

Data Structures

struct  CommentItem
 
struct  SecLabelItem
 

Typedefs

typedef enum OidOptions OidOptions
 

Enumerations

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

Functions

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

Variables

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

Typedef Documentation

Enumeration Type Documentation

enum OidOptions
Enumerator
zeroAsOpaque 
zeroAsAny 
zeroAsStar 
zeroAsNone 

Definition at line 82 of file pg_dump.c.

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

Function Documentation

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

Definition at line 17602 of file pg_dump.c.

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

Referenced by main().

17604 {
17605  DumpableObject *preDataBound = boundaryObjs + 0;
17606  DumpableObject *postDataBound = boundaryObjs + 1;
17607  int i;
17608 
17609  for (i = 0; i < numObjs; i++)
17610  {
17611  DumpableObject *dobj = dobjs[i];
17612 
17613  /*
17614  * The classification of object types here must match the SECTION_xxx
17615  * values assigned during subsequent ArchiveEntry calls!
17616  */
17617  switch (dobj->objType)
17618  {
17619  case DO_NAMESPACE:
17620  case DO_EXTENSION:
17621  case DO_TYPE:
17622  case DO_SHELL_TYPE:
17623  case DO_FUNC:
17624  case DO_AGG:
17625  case DO_OPERATOR:
17626  case DO_ACCESS_METHOD:
17627  case DO_OPCLASS:
17628  case DO_OPFAMILY:
17629  case DO_COLLATION:
17630  case DO_CONVERSION:
17631  case DO_TABLE:
17632  case DO_ATTRDEF:
17633  case DO_PROCLANG:
17634  case DO_CAST:
17635  case DO_DUMMY_TYPE:
17636  case DO_TSPARSER:
17637  case DO_TSDICT:
17638  case DO_TSTEMPLATE:
17639  case DO_TSCONFIG:
17640  case DO_FDW:
17641  case DO_FOREIGN_SERVER:
17642  case DO_TRANSFORM:
17643  case DO_BLOB:
17644  /* Pre-data objects: must come before the pre-data boundary */
17645  addObjectDependency(preDataBound, dobj->dumpId);
17646  break;
17647  case DO_TABLE_DATA:
17648  case DO_SEQUENCE_SET:
17649  case DO_BLOB_DATA:
17650  /* Data objects: must come between the boundaries */
17651  addObjectDependency(dobj, preDataBound->dumpId);
17652  addObjectDependency(postDataBound, dobj->dumpId);
17653  break;
17654  case DO_INDEX:
17655  case DO_STATSEXT:
17656  case DO_REFRESH_MATVIEW:
17657  case DO_TRIGGER:
17658  case DO_EVENT_TRIGGER:
17659  case DO_DEFAULT_ACL:
17660  case DO_POLICY:
17661  case DO_PUBLICATION:
17662  case DO_PUBLICATION_REL:
17663  case DO_SUBSCRIPTION:
17664  /* Post-data objects: must come after the post-data boundary */
17665  addObjectDependency(dobj, postDataBound->dumpId);
17666  break;
17667  case DO_RULE:
17668  /* Rules are post-data, but only if dumped separately */
17669  if (((RuleInfo *) dobj)->separate)
17670  addObjectDependency(dobj, postDataBound->dumpId);
17671  break;
17672  case DO_CONSTRAINT:
17673  case DO_FK_CONSTRAINT:
17674  /* Constraints are post-data, but only if dumped separately */
17675  if (((ConstraintInfo *) dobj)->separate)
17676  addObjectDependency(dobj, postDataBound->dumpId);
17677  break;
17678  case DO_PRE_DATA_BOUNDARY:
17679  /* nothing to do */
17680  break;
17681  case DO_POST_DATA_BOUNDARY:
17682  /* must come after the pre-data boundary */
17683  addObjectDependency(dobj, preDataBound->dumpId);
17684  break;
17685  }
17686  }
17687 }
DumpId dumpId
Definition: pg_dump.h:132
Definition: pg_dump.h:49
Definition: pg_dump.h:73
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:712
int i
DumpableObjectType objType
Definition: pg_dump.h:130
static void appendReloptionsArrayAH ( PQExpBuffer  buffer,
const char *  reloptions,
const char *  prefix,
Archive fout 
)
static

Definition at line 17933 of file pg_dump.c.

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

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

17935 {
17936  bool res;
17937 
17938  res = appendReloptionsArray(buffer, reloptions, prefix, fout->encoding,
17939  fout->std_strings);
17940  if (!res)
17941  write_msg(NULL, "WARNING: could not parse reloptions array\n");
17942 }
int encoding
Definition: pg_backup.h:196
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
Definition: string_utils.c:747
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
bool std_strings
Definition: pg_backup.h:197
static void binary_upgrade_extension_member ( PQExpBuffer  upgrade_buffer,
DumpableObject dobj,
const char *  objlabel 
)
static

Definition at line 4101 of file pg_dump.c.

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

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

4104 {
4105  DumpableObject *extobj = NULL;
4106  int i;
4107 
4108  if (!dobj->ext_member)
4109  return;
4110 
4111  /*
4112  * Find the parent extension. We could avoid this search if we wanted to
4113  * add a link field to DumpableObject, but the space costs of that would
4114  * be considerable. We assume that member objects could only have a
4115  * direct dependency on their own extension, not any others.
4116  */
4117  for (i = 0; i < dobj->nDeps; i++)
4118  {
4119  extobj = findObjectByDumpId(dobj->dependencies[i]);
4120  if (extobj && extobj->objType == DO_EXTENSION)
4121  break;
4122  extobj = NULL;
4123  }
4124  if (extobj == NULL)
4125  exit_horribly(NULL, "could not find parent extension for %s\n", objlabel);
4126 
4127  appendPQExpBufferStr(upgrade_buffer,
4128  "\n-- For binary upgrade, handle extension membership the hard way\n");
4129  appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s;\n",
4130  fmtId(extobj->name),
4131  objlabel);
4132 }
char * name
Definition: pg_dump.h:133
DumpId * dependencies
Definition: pg_dump.h:138
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
bool ext_member
Definition: pg_dump.h:137
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:540
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define NULL
Definition: c.h:229
void exit_horribly(const char *modulename, const char *fmt,...)
int i
DumpableObjectType objType
Definition: pg_dump.h:130
static void binary_upgrade_set_pg_class_oids ( Archive fout,
PQExpBuffer  upgrade_buffer,
Oid  pg_class_oid,
bool  is_index 
)
static

Definition at line 4034 of file pg_dump.c.

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

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

4037 {
4038  PQExpBuffer upgrade_query = createPQExpBuffer();
4039  PGresult *upgrade_res;
4040  Oid pg_class_reltoastrelid;
4041  Oid pg_index_indexrelid;
4042 
4043  appendPQExpBuffer(upgrade_query,
4044  "SELECT c.reltoastrelid, i.indexrelid "
4045  "FROM pg_catalog.pg_class c LEFT JOIN "
4046  "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
4047  "WHERE c.oid = '%u'::pg_catalog.oid;",
4048  pg_class_oid);
4049 
4050  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4051 
4052  pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
4053  pg_index_indexrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "indexrelid")));
4054 
4055  appendPQExpBufferStr(upgrade_buffer,
4056  "\n-- For binary upgrade, must preserve pg_class oids\n");
4057 
4058  if (!is_index)
4059  {
4060  appendPQExpBuffer(upgrade_buffer,
4061  "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
4062  pg_class_oid);
4063  /* only tables have toast tables, not indexes */
4064  if (OidIsValid(pg_class_reltoastrelid))
4065  {
4066  /*
4067  * One complexity is that the table definition might not require
4068  * the creation of a TOAST table, and the TOAST table might have
4069  * been created long after table creation, when the table was
4070  * loaded with wide data. By setting the TOAST oid we force
4071  * creation of the TOAST heap and TOAST index by the backend so we
4072  * can cleanly copy the files during binary upgrade.
4073  */
4074 
4075  appendPQExpBuffer(upgrade_buffer,
4076  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
4077  pg_class_reltoastrelid);
4078 
4079  /* every toast table has an index */
4080  appendPQExpBuffer(upgrade_buffer,
4081  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4082  pg_index_indexrelid);
4083  }
4084  }
4085  else
4086  appendPQExpBuffer(upgrade_buffer,
4087  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4088  pg_class_oid);
4089 
4090  appendPQExpBufferChar(upgrade_buffer, '\n');
4091 
4092  PQclear(upgrade_res);
4093  destroyPQExpBuffer(upgrade_query);
4094 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
void PQclear(PGresult *res)
Definition: fe-exec.c:650
static bool binary_upgrade_set_type_oids_by_rel_oid ( Archive fout,
PQExpBuffer  upgrade_buffer,
Oid  pg_rel_oid 
)
static

Definition at line 3988 of file pg_dump.c.

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

Referenced by dumpSequence(), and dumpTableSchema().

3991 {
3992  PQExpBuffer upgrade_query = createPQExpBuffer();
3993  PGresult *upgrade_res;
3994  Oid pg_type_oid;
3995  bool toast_set = false;
3996 
3997  /* we only support old >= 8.3 for binary upgrades */
3998  appendPQExpBuffer(upgrade_query,
3999  "SELECT c.reltype AS crel, t.reltype AS trel "
4000  "FROM pg_catalog.pg_class c "
4001  "LEFT JOIN pg_catalog.pg_class t ON "
4002  " (c.reltoastrelid = t.oid) "
4003  "WHERE c.oid = '%u'::pg_catalog.oid;",
4004  pg_rel_oid);
4005 
4006  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
4007 
4008  pg_type_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "crel")));
4009 
4010  binary_upgrade_set_type_oids_by_type_oid(fout, upgrade_buffer,
4011  pg_type_oid);
4012 
4013  if (!PQgetisnull(upgrade_res, 0, PQfnumber(upgrade_res, "trel")))
4014  {
4015  /* Toast tables do not have pg_type array rows */
4016  Oid pg_type_toast_oid = atooid(PQgetvalue(upgrade_res, 0,
4017  PQfnumber(upgrade_res, "trel")));
4018 
4019  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
4020  appendPQExpBuffer(upgrade_buffer,
4021  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
4022  pg_type_toast_oid);
4023 
4024  toast_set = true;
4025  }
4026 
4027  PQclear(upgrade_res);
4028  destroyPQExpBuffer(upgrade_query);
4029 
4030  return toast_set;
4031 }
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid)
Definition: pg_dump.c:3950
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
static void binary_upgrade_set_type_oids_by_type_oid ( Archive fout,
PQExpBuffer  upgrade_buffer,
Oid  pg_type_oid 
)
static

Definition at line 3950 of file pg_dump.c.

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

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

3953 {
3954  PQExpBuffer upgrade_query = createPQExpBuffer();
3955  PGresult *upgrade_res;
3956  Oid pg_type_array_oid;
3957 
3958  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
3959  appendPQExpBuffer(upgrade_buffer,
3960  "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3961  pg_type_oid);
3962 
3963  /* we only support old >= 8.3 for binary upgrades */
3964  appendPQExpBuffer(upgrade_query,
3965  "SELECT typarray "
3966  "FROM pg_catalog.pg_type "
3967  "WHERE pg_type.oid = '%u'::pg_catalog.oid;",
3968  pg_type_oid);
3969 
3970  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
3971 
3972  pg_type_array_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "typarray")));
3973 
3974  if (OidIsValid(pg_type_array_oid))
3975  {
3976  appendPQExpBufferStr(upgrade_buffer,
3977  "\n-- For binary upgrade, must preserve pg_type array oid\n");
3978  appendPQExpBuffer(upgrade_buffer,
3979  "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3980  pg_type_array_oid);
3981  }
3982 
3983  PQclear(upgrade_res);
3984  destroyPQExpBuffer(upgrade_query);
3985 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
void PQclear(PGresult *res)
Definition: fe-exec.c:650
static void BuildArchiveDependencies ( Archive fout)
static

Definition at line 17714 of file pg_dump.c.

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

Referenced by main().

17715 {
17716  ArchiveHandle *AH = (ArchiveHandle *) fout;
17717  TocEntry *te;
17718 
17719  /* Scan all TOC entries in the archive */
17720  for (te = AH->toc->next; te != AH->toc; te = te->next)
17721  {
17722  DumpableObject *dobj;
17723  DumpId *dependencies;
17724  int nDeps;
17725  int allocDeps;
17726 
17727  /* No need to process entries that will not be dumped */
17728  if (te->reqs == 0)
17729  continue;
17730  /* Ignore entries that already have "special" dependencies */
17731  if (te->nDeps > 0)
17732  continue;
17733  /* Otherwise, look up the item's original DumpableObject, if any */
17734  dobj = findObjectByDumpId(te->dumpId);
17735  if (dobj == NULL)
17736  continue;
17737  /* No work if it has no dependencies */
17738  if (dobj->nDeps <= 0)
17739  continue;
17740  /* Set up work array */
17741  allocDeps = 64;
17742  dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(DumpId));
17743  nDeps = 0;
17744  /* Recursively find all dumpable dependencies */
17745  findDumpableDependencies(AH, dobj,
17746  &dependencies, &nDeps, &allocDeps);
17747  /* And save 'em ... */
17748  if (nDeps > 0)
17749  {
17750  dependencies = (DumpId *) pg_realloc(dependencies,
17751  nDeps * sizeof(DumpId));
17752  te->dependencies = dependencies;
17753  te->nDeps = nDeps;
17754  }
17755  else
17756  free(dependencies);
17757  }
17758 }
struct _tocEntry * next
int DumpId
Definition: pg_backup.h:230
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:540
struct _tocEntry * toc
DumpId * dependencies
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
static void findDumpableDependencies(ArchiveHandle *AH, DumpableObject *dobj, DumpId **dependencies, int *nDeps, int *allocDeps)
Definition: pg_dump.c:17762
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static void buildMatViewRefreshDependencies ( Archive fout)
static

Definition at line 2288 of file pg_dump.c.

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

Referenced by main().

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

Definition at line 1326 of file pg_dump.c.

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

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

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

Definition at line 9366 of file pg_dump.c.

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

Referenced by findComments().

9367 {
9368  PGresult *res;
9369  PQExpBuffer query;
9370  int i_description;
9371  int i_classoid;
9372  int i_objoid;
9373  int i_objsubid;
9374  int ntups;
9375  int i;
9376  CommentItem *comments;
9377 
9378  /*
9379  * Note we do NOT change source schema here; preserve the caller's
9380  * setting, instead.
9381  */
9382 
9383  query = createPQExpBuffer();
9384 
9385  appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
9386  "FROM pg_catalog.pg_description "
9387  "ORDER BY classoid, objoid, objsubid");
9388 
9389  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9390 
9391  /* Construct lookup table containing OIDs in numeric form */
9392 
9393  i_description = PQfnumber(res, "description");
9394  i_classoid = PQfnumber(res, "classoid");
9395  i_objoid = PQfnumber(res, "objoid");
9396  i_objsubid = PQfnumber(res, "objsubid");
9397 
9398  ntups = PQntuples(res);
9399 
9400  comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
9401 
9402  for (i = 0; i < ntups; i++)
9403  {
9404  comments[i].descr = PQgetvalue(res, i, i_description);
9405  comments[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
9406  comments[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
9407  comments[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
9408  }
9409 
9410  /* Do NOT free the PGresult since we are keeping pointers into it */
9411  destroyPQExpBuffer(query);
9412 
9413  *items = comments;
9414  return ntups;
9415 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:70
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
#define atooid(x)
Definition: postgres_ext.h:42
const char * descr
Definition: pg_dump.c:67
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
Oid objoid
Definition: pg_dump.c:69
Oid classoid
Definition: pg_dump.c:68
int i
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
static int collectSecLabels ( Archive fout,
SecLabelItem **  items 
)
static

Definition at line 14837 of file pg_dump.c.

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

Referenced by findSecLabels().

14838 {
14839  PGresult *res;
14840  PQExpBuffer query;
14841  int i_label;
14842  int i_provider;
14843  int i_classoid;
14844  int i_objoid;
14845  int i_objsubid;
14846  int ntups;
14847  int i;
14848  SecLabelItem *labels;
14849 
14850  query = createPQExpBuffer();
14851 
14852  appendPQExpBufferStr(query,
14853  "SELECT label, provider, classoid, objoid, objsubid "
14854  "FROM pg_catalog.pg_seclabel "
14855  "ORDER BY classoid, objoid, objsubid");
14856 
14857  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
14858 
14859  /* Construct lookup table containing OIDs in numeric form */
14860  i_label = PQfnumber(res, "label");
14861  i_provider = PQfnumber(res, "provider");
14862  i_classoid = PQfnumber(res, "classoid");
14863  i_objoid = PQfnumber(res, "objoid");
14864  i_objsubid = PQfnumber(res, "objsubid");
14865 
14866  ntups = PQntuples(res);
14867 
14868  labels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
14869 
14870  for (i = 0; i < ntups; i++)
14871  {
14872  labels[i].label = PQgetvalue(res, i, i_label);
14873  labels[i].provider = PQgetvalue(res, i, i_provider);
14874  labels[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
14875  labels[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
14876  labels[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
14877  }
14878 
14879  /* Do NOT free the PGresult since we are keeping pointers into it */
14880  destroyPQExpBuffer(query);
14881 
14882  *items = labels;
14883  return ntups;
14884 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
Oid objoid
Definition: pg_dump.c:78
const char * provider
Definition: pg_dump.c:75
#define atooid(x)
Definition: postgres_ext.h:42
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
int objsubid
Definition: pg_dump.c:79
int i
Oid classoid
Definition: pg_dump.c:77
const char * label
Definition: pg_dump.c:76
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
static char * convertOperatorReference ( Archive fout,
const char *  opr 
)
static

Definition at line 12284 of file pg_dump.c.

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

Referenced by dumpAgg(), and dumpOpr().

12285 {
12286  char *name;
12287  char *oname;
12288  char *ptr;
12289  bool inquote;
12290  bool sawdot;
12291 
12292  /* In all cases "0" means a null reference */
12293  if (strcmp(opr, "0") == 0)
12294  return NULL;
12295 
12296  name = pg_strdup(opr);
12297  /* find non-double-quoted left paren, and check for non-quoted dot */
12298  inquote = false;
12299  sawdot = false;
12300  for (ptr = name; *ptr; ptr++)
12301  {
12302  if (*ptr == '"')
12303  inquote = !inquote;
12304  else if (*ptr == '.' && !inquote)
12305  sawdot = true;
12306  else if (*ptr == '(' && !inquote)
12307  {
12308  *ptr = '\0';
12309  break;
12310  }
12311  }
12312  /* If not schema-qualified, don't need to add OPERATOR() */
12313  if (!sawdot)
12314  return name;
12315  oname = psprintf("OPERATOR(%s)", name);
12316  free(name);
12317  return oname;
12318 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
static char * convertRegProcReference ( Archive fout,
const char *  proc 
)
static

Definition at line 12248 of file pg_dump.c.

References name, NULL, and pg_strdup().

Referenced by dumpOpr().

12249 {
12250  char *name;
12251  char *paren;
12252  bool inquote;
12253 
12254  /* In all cases "-" means a null reference */
12255  if (strcmp(proc, "-") == 0)
12256  return NULL;
12257 
12258  name = pg_strdup(proc);
12259  /* find non-double-quoted left paren */
12260  inquote = false;
12261  for (paren = name; *paren; paren++)
12262  {
12263  if (*paren == '(' && !inquote)
12264  {
12265  *paren = '\0';
12266  break;
12267  }
12268  if (*paren == '"')
12269  inquote = !inquote;
12270  }
12271  return name;
12272 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
static char * convertTSFunction ( Archive fout,
Oid  funcOid 
)
static

Definition at line 12329 of file pg_dump.c.

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

Referenced by dumpTSParser(), and dumpTSTemplate().

12330 {
12331  char *result;
12332  char query[128];
12333  PGresult *res;
12334 
12335  snprintf(query, sizeof(query),
12336  "SELECT '%u'::pg_catalog.regproc", funcOid);
12337  res = ExecuteSqlQueryForSingleRow(fout, query);
12338 
12339  result = pg_strdup(PQgetvalue(res, 0, 0));
12340 
12341  PQclear(res);
12342 
12343  return result;
12344 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
return result
Definition: formatting.c:1633
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
void PQclear(PGresult *res)
Definition: fe-exec.c:650
static DumpableObject * createBoundaryObjects ( void  )
static

Definition at line 17578 of file pg_dump.c.

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

Referenced by main().

17579 {
17580  DumpableObject *dobjs;
17581 
17582  dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject));
17583 
17584  dobjs[0].objType = DO_PRE_DATA_BOUNDARY;
17585  dobjs[0].catId = nilCatalogId;
17586  AssignDumpId(dobjs + 0);
17587  dobjs[0].name = pg_strdup("PRE-DATA BOUNDARY");
17588 
17589  dobjs[1].objType = DO_POST_DATA_BOUNDARY;
17590  dobjs[1].catId = nilCatalogId;
17591  AssignDumpId(dobjs + 1);
17592  dobjs[1].name = pg_strdup("POST-DATA BOUNDARY");
17593 
17594  return dobjs;
17595 }
char * name
Definition: pg_dump.h:133
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:476
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
CatalogId catId
Definition: pg_dump.h:131
static const CatalogId nilCatalogId
Definition: pg_dump.c:132
DumpableObjectType objType
Definition: pg_dump.h:130
static PQExpBuffer createDummyViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

Definition at line 15075 of file pg_dump.c.

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

Referenced by dumpRule(), and dumpTableSchema().

15076 {
15078  int j;
15079 
15080  appendPQExpBufferStr(result, "SELECT");
15081 
15082  for (j = 0; j < tbinfo->numatts; j++)
15083  {
15084  if (j > 0)
15085  appendPQExpBufferChar(result, ',');
15086  appendPQExpBufferStr(result, "\n ");
15087 
15088  appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]);
15089 
15090  /*
15091  * Must add collation if not default for the type, because CREATE OR
15092  * REPLACE VIEW won't change it
15093  */
15094  if (OidIsValid(tbinfo->attcollation[j]))
15095  {
15096  CollInfo *coll;
15097 
15098  coll = findCollationByOid(tbinfo->attcollation[j]);
15099  if (coll)
15100  {
15101  /* always schema-qualify, don't try to be smart */
15102  appendPQExpBuffer(result, " COLLATE %s.",
15103  fmtId(coll->dobj.namespace->dobj.name));
15104  appendPQExpBufferStr(result, fmtId(coll->dobj.name));
15105  }
15106  }
15107 
15108  appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j]));
15109  }
15110 
15111  return result;
15112 }
char * name
Definition: pg_dump.h:133
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
return result
Definition: formatting.c:1633
char ** atttypnames
Definition: pg_dump.h:305
char ** attnames
Definition: pg_dump.h:304
#define OidIsValid(objectId)
Definition: c.h:538
DumpableObject dobj
Definition: pg_dump.h:246
Oid * attcollation
Definition: pg_dump.h:316
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
int numatts
Definition: pg_dump.h:303
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:803
static PQExpBuffer createViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

Definition at line 15026 of file pg_dump.c.

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

Referenced by dumpRule(), and dumpTableSchema().

15027 {
15028  PQExpBuffer query = createPQExpBuffer();
15030  PGresult *res;
15031  int len;
15032 
15033  /* Fetch the view definition */
15034  appendPQExpBuffer(query,
15035  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
15036  tbinfo->dobj.catId.oid);
15037 
15038  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
15039 
15040  if (PQntuples(res) != 1)
15041  {
15042  if (PQntuples(res) < 1)
15043  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned no data\n",
15044  tbinfo->dobj.name);
15045  else
15046  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned more than one definition\n",
15047  tbinfo->dobj.name);
15048  }
15049 
15050  len = PQgetlength(res, 0, 0);
15051 
15052  if (len == 0)
15053  exit_horribly(NULL, "definition of view \"%s\" appears to be empty (length zero)\n",
15054  tbinfo->dobj.name);
15055 
15056  /* Strip off the trailing semicolon so that other things may follow. */
15057  Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
15058  appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
15059 
15060  PQclear(res);
15061  destroyPQExpBuffer(query);
15062 
15063  return result;
15064 }
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3078
char * name
Definition: pg_dump.h:133
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
return result
Definition: formatting.c:1633
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:261
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:415
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
static void dumpAccessMethod ( Archive fout,
AccessMethodInfo oprinfo 
)
static

Definition at line 12351 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

12352 {
12353  DumpOptions *dopt = fout->dopt;
12354  PQExpBuffer q;
12355  PQExpBuffer delq;
12356  PQExpBuffer labelq;
12357  char *qamname;
12358 
12359  /* Skip if not to be dumped */
12360  if (!aminfo->dobj.dump || dopt->dataOnly)
12361  return;
12362 
12363  q = createPQExpBuffer();
12364  delq = createPQExpBuffer();
12365  labelq = createPQExpBuffer();
12366 
12367  qamname = pg_strdup(fmtId(aminfo->dobj.name));
12368 
12369  appendPQExpBuffer(q, "CREATE ACCESS METHOD %s ", qamname);
12370 
12371  switch (aminfo->amtype)
12372  {
12373  case AMTYPE_INDEX:
12374  appendPQExpBuffer(q, "TYPE INDEX ");
12375  break;
12376  default:
12377  write_msg(NULL, "WARNING: invalid type \"%c\" of access method \"%s\"\n",
12378  aminfo->amtype, qamname);
12379  pg_free(qamname);
12380  destroyPQExpBuffer(q);
12381  destroyPQExpBuffer(delq);
12382  destroyPQExpBuffer(labelq);
12383  return;
12384  }
12385 
12386  appendPQExpBuffer(q, "HANDLER %s;\n", aminfo->amhandler);
12387 
12388  appendPQExpBuffer(delq, "DROP ACCESS METHOD %s;\n",
12389  qamname);
12390 
12391  appendPQExpBuffer(labelq, "ACCESS METHOD %s",
12392  qamname);
12393 
12394  if (dopt->binary_upgrade)
12395  binary_upgrade_extension_member(q, &aminfo->dobj, labelq->data);
12396 
12397  if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
12398  ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
12399  aminfo->dobj.name,
12400  NULL,
12401  NULL,
12402  "",
12403  false, "ACCESS METHOD", SECTION_PRE_DATA,
12404  q->data, delq->data, NULL,
12405  NULL, 0,
12406  NULL, NULL);
12407 
12408  /* Dump Access Method Comments */
12409  if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT)
12410  dumpComment(fout, labelq->data,
12411  NULL, "",
12412  aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
12413 
12414  pg_free(qamname);
12415 
12416  destroyPQExpBuffer(q);
12417  destroyPQExpBuffer(delq);
12418  destroyPQExpBuffer(labelq);
12419 }
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9127
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define AMTYPE_INDEX
Definition: pg_am.h:61
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4101
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static void dumpACL ( Archive fout,
CatalogId  objCatId,
DumpId  objDumpId,
const char *  type,
const char *  name,
const char *  subname,
const char *  tag,
const char *  nspname,
const char *  owner,
const char *  acls,
const char *  racls,
const char *  initacls,
const char *  initracls 
)
static

Definition at line 14527 of file pg_dump.c.

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

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

14532 {
14533  DumpOptions *dopt = fout->dopt;
14534  PQExpBuffer sql;
14535 
14536  /* Do nothing if ACL dump is not enabled */
14537  if (dopt->aclsSkip)
14538  return;
14539 
14540  /* --data-only skips ACLs *except* BLOB ACLs */
14541  if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
14542  return;
14543 
14544  sql = createPQExpBuffer();
14545 
14546  /*
14547  * Check to see if this object has had any initial ACLs included for it.
14548  * If so, we are in binary upgrade mode and these are the ACLs to turn
14549  * into GRANT and REVOKE statements to set and record the initial
14550  * privileges for an extension object. Let the backend know that these
14551  * are to be recorded by calling binary_upgrade_set_record_init_privs()
14552  * before and after.
14553  */
14554  if (strlen(initacls) != 0 || strlen(initracls) != 0)
14555  {
14556  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
14557  if (!buildACLCommands(name, subname, type, initacls, initracls, owner,
14558  "", fout->remoteVersion, sql))
14560  "could not parse initial GRANT ACL list (%s) or initial REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14561  initacls, initracls, name, type);
14562  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
14563  }
14564 
14565  if (!buildACLCommands(name, subname, type, acls, racls, owner,
14566  "", fout->remoteVersion, sql))
14568  "could not parse GRANT ACL list (%s) or REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14569  acls, racls, name, type);
14570 
14571  if (sql->len > 0)
14573  tag, nspname,
14574  NULL,
14575  owner ? owner : "",
14576  false, "ACL", SECTION_NONE,
14577  sql->data, "", NULL,
14578  &(objDumpId), 1,
14579  NULL, NULL);
14580 
14581  destroyPQExpBuffer(sql);
14582 }
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
bool aclsSkip
Definition: pg_backup.h:141
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define NULL
Definition: c.h:229
bool buildACLCommands(const char *name, const char *subname, const char *type, const char *acls, const char *racls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql)
Definition: dumputils.c:55
const char * name
Definition: encode.c:521
void exit_horribly(const char *modulename, const char *fmt,...)
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:132
DumpId createDumpId(void)
Definition: common.c:520
int remoteVersion
Definition: pg_backup.h:186
static void dumpAgg ( Archive fout,
AggInfo agginfo 
)
static

Definition at line 13371 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

13372 {
13373  DumpOptions *dopt = fout->dopt;
13374  PQExpBuffer query;
13375  PQExpBuffer q;
13376  PQExpBuffer delq;
13377  PQExpBuffer labelq;
13378  PQExpBuffer details;
13379  char *aggsig; /* identity signature */
13380  char *aggfullsig = NULL; /* full signature */
13381  char *aggsig_tag;
13382  PGresult *res;
13383  int i_aggtransfn;
13384  int i_aggfinalfn;
13385  int i_aggcombinefn;
13386  int i_aggserialfn;
13387  int i_aggdeserialfn;
13388  int i_aggmtransfn;
13389  int i_aggminvtransfn;
13390  int i_aggmfinalfn;
13391  int i_aggfinalextra;
13392  int i_aggmfinalextra;
13393  int i_aggsortop;
13394  int i_hypothetical;
13395  int i_aggtranstype;
13396  int i_aggtransspace;
13397  int i_aggmtranstype;
13398  int i_aggmtransspace;
13399  int i_agginitval;
13400  int i_aggminitval;
13401  int i_convertok;
13402  int i_proparallel;
13403  const char *aggtransfn;
13404  const char *aggfinalfn;
13405  const char *aggcombinefn;
13406  const char *aggserialfn;
13407  const char *aggdeserialfn;
13408  const char *aggmtransfn;
13409  const char *aggminvtransfn;
13410  const char *aggmfinalfn;
13411  bool aggfinalextra;
13412  bool aggmfinalextra;
13413  const char *aggsortop;
13414  char *aggsortconvop;
13415  bool hypothetical;
13416  const char *aggtranstype;
13417  const char *aggtransspace;
13418  const char *aggmtranstype;
13419  const char *aggmtransspace;
13420  const char *agginitval;
13421  const char *aggminitval;
13422  bool convertok;
13423  const char *proparallel;
13424 
13425  /* Skip if not to be dumped */
13426  if (!agginfo->aggfn.dobj.dump || dopt->dataOnly)
13427  return;
13428 
13429  query = createPQExpBuffer();
13430  q = createPQExpBuffer();
13431  delq = createPQExpBuffer();
13432  labelq = createPQExpBuffer();
13433  details = createPQExpBuffer();
13434 
13435  /* Make sure we are in proper schema */
13436  selectSourceSchema(fout, agginfo->aggfn.dobj.namespace->dobj.name);
13437 
13438  /* Get aggregate-specific details */
13439  if (fout->remoteVersion >= 90600)
13440  {
13441  appendPQExpBuffer(query, "SELECT aggtransfn, "
13442  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13443  "aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, "
13444  "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13445  "aggfinalextra, aggmfinalextra, "
13446  "aggsortop::pg_catalog.regoperator, "
13447  "(aggkind = 'h') AS hypothetical, "
13448  "aggtransspace, agginitval, "
13449  "aggmtransspace, aggminitval, "
13450  "true AS convertok, "
13451  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13452  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, "
13453  "p.proparallel "
13454  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13455  "WHERE a.aggfnoid = p.oid "
13456  "AND p.oid = '%u'::pg_catalog.oid",
13457  agginfo->aggfn.dobj.catId.oid);
13458  }
13459  else if (fout->remoteVersion >= 90400)
13460  {
13461  appendPQExpBuffer(query, "SELECT aggtransfn, "
13462  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13463  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13464  "'-' AS aggdeserialfn, aggmtransfn, aggminvtransfn, "
13465  "aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13466  "aggfinalextra, aggmfinalextra, "
13467  "aggsortop::pg_catalog.regoperator, "
13468  "(aggkind = 'h') AS hypothetical, "
13469  "aggtransspace, agginitval, "
13470  "aggmtransspace, aggminitval, "
13471  "true AS convertok, "
13472  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13473  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13474  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13475  "WHERE a.aggfnoid = p.oid "
13476  "AND p.oid = '%u'::pg_catalog.oid",
13477  agginfo->aggfn.dobj.catId.oid);
13478  }
13479  else if (fout->remoteVersion >= 80400)
13480  {
13481  appendPQExpBuffer(query, "SELECT aggtransfn, "
13482  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13483  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13484  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13485  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13486  "0 AS aggmtranstype, false AS aggfinalextra, "
13487  "false AS aggmfinalextra, "
13488  "aggsortop::pg_catalog.regoperator, "
13489  "false AS hypothetical, "
13490  "0 AS aggtransspace, agginitval, "
13491  "0 AS aggmtransspace, NULL AS aggminitval, "
13492  "true AS convertok, "
13493  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13494  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13495  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13496  "WHERE a.aggfnoid = p.oid "
13497  "AND p.oid = '%u'::pg_catalog.oid",
13498  agginfo->aggfn.dobj.catId.oid);
13499  }
13500  else if (fout->remoteVersion >= 80100)
13501  {
13502  appendPQExpBuffer(query, "SELECT aggtransfn, "
13503  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13504  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13505  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13506  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13507  "0 AS aggmtranstype, false AS aggfinalextra, "
13508  "false AS aggmfinalextra, "
13509  "aggsortop::pg_catalog.regoperator, "
13510  "false AS hypothetical, "
13511  "0 AS aggtransspace, agginitval, "
13512  "0 AS aggmtransspace, NULL AS aggminitval, "
13513  "true AS convertok "
13514  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13515  "WHERE a.aggfnoid = p.oid "
13516  "AND p.oid = '%u'::pg_catalog.oid",
13517  agginfo->aggfn.dobj.catId.oid);
13518  }
13519  else
13520  {
13521  appendPQExpBuffer(query, "SELECT aggtransfn, "
13522  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13523  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13524  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13525  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13526  "0 AS aggmtranstype, false AS aggfinalextra, "
13527  "false AS aggmfinalextra, 0 AS aggsortop, "
13528  "false AS hypothetical, "
13529  "0 AS aggtransspace, agginitval, "
13530  "0 AS aggmtransspace, NULL AS aggminitval, "
13531  "true AS convertok "
13532  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13533  "WHERE a.aggfnoid = p.oid "
13534  "AND p.oid = '%u'::pg_catalog.oid",
13535  agginfo->aggfn.dobj.catId.oid);
13536  }
13537 
13538  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13539 
13540  i_aggtransfn = PQfnumber(res, "aggtransfn");
13541  i_aggfinalfn = PQfnumber(res, "aggfinalfn");
13542  i_aggcombinefn = PQfnumber(res, "aggcombinefn");
13543  i_aggserialfn = PQfnumber(res, "aggserialfn");
13544  i_aggdeserialfn = PQfnumber(res, "aggdeserialfn");
13545  i_aggmtransfn = PQfnumber(res, "aggmtransfn");
13546  i_aggminvtransfn = PQfnumber(res, "aggminvtransfn");
13547  i_aggmfinalfn = PQfnumber(res, "aggmfinalfn");
13548  i_aggfinalextra = PQfnumber(res, "aggfinalextra");
13549  i_aggmfinalextra = PQfnumber(res, "aggmfinalextra");
13550  i_aggsortop = PQfnumber(res, "aggsortop");
13551  i_hypothetical = PQfnumber(res, "hypothetical");
13552  i_aggtranstype = PQfnumber(res, "aggtranstype");
13553  i_aggtransspace = PQfnumber(res, "aggtransspace");
13554  i_aggmtranstype = PQfnumber(res, "aggmtranstype");
13555  i_aggmtransspace = PQfnumber(res, "aggmtransspace");
13556  i_agginitval = PQfnumber(res, "agginitval");
13557  i_aggminitval = PQfnumber(res, "aggminitval");
13558  i_convertok = PQfnumber(res, "convertok");
13559  i_proparallel = PQfnumber(res, "proparallel");
13560 
13561  aggtransfn = PQgetvalue(res, 0, i_aggtransfn);
13562  aggfinalfn = PQgetvalue(res, 0, i_aggfinalfn);
13563  aggcombinefn = PQgetvalue(res, 0, i_aggcombinefn);
13564  aggserialfn = PQgetvalue(res, 0, i_aggserialfn);
13565  aggdeserialfn = PQgetvalue(res, 0, i_aggdeserialfn);
13566  aggmtransfn = PQgetvalue(res, 0, i_aggmtransfn);
13567  aggminvtransfn = PQgetvalue(res, 0, i_aggminvtransfn);
13568  aggmfinalfn = PQgetvalue(res, 0, i_aggmfinalfn);
13569  aggfinalextra = (PQgetvalue(res, 0, i_aggfinalextra)[0] == 't');
13570  aggmfinalextra = (PQgetvalue(res, 0, i_aggmfinalextra)[0] == 't');
13571  aggsortop = PQgetvalue(res, 0, i_aggsortop);
13572  hypothetical = (PQgetvalue(res, 0, i_hypothetical)[0] == 't');
13573  aggtranstype = PQgetvalue(res, 0, i_aggtranstype);
13574  aggtransspace = PQgetvalue(res, 0, i_aggtransspace);
13575  aggmtranstype = PQgetvalue(res, 0, i_aggmtranstype);
13576  aggmtransspace = PQgetvalue(res, 0, i_aggmtransspace);
13577  agginitval = PQgetvalue(res, 0, i_agginitval);
13578  aggminitval = PQgetvalue(res, 0, i_aggminitval);
13579  convertok = (PQgetvalue(res, 0, i_convertok)[0] == 't');
13580 
13581  if (fout->remoteVersion >= 80400)
13582  {
13583  /* 8.4 or later; we rely on server-side code for most of the work */
13584  char *funcargs;
13585  char *funciargs;
13586 
13587  funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs"));
13588  funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs"));
13589  aggfullsig = format_function_arguments(&agginfo->aggfn, funcargs, true);
13590  aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true);
13591  }
13592  else
13593  /* pre-8.4, do it ourselves */
13594  aggsig = format_aggregate_signature(agginfo, fout, true);
13595 
13596  aggsig_tag = format_aggregate_signature(agginfo, fout, false);
13597 
13598  if (i_proparallel != -1)
13599  proparallel = PQgetvalue(res, 0, PQfnumber(res, "proparallel"));
13600  else
13601  proparallel = NULL;
13602 
13603  if (!convertok)
13604  {
13605  write_msg(NULL, "WARNING: aggregate function %s could not be dumped correctly for this database version; ignored\n",
13606  aggsig);
13607 
13608  if (aggfullsig)
13609  free(aggfullsig);
13610 
13611  free(aggsig);
13612 
13613  return;
13614  }
13615 
13616  /* regproc and regtype output is already sufficiently quoted */
13617  appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
13618  aggtransfn, aggtranstype);
13619 
13620  if (strcmp(aggtransspace, "0") != 0)
13621  {
13622  appendPQExpBuffer(details, ",\n SSPACE = %s",
13623  aggtransspace);
13624  }
13625 
13626  if (!PQgetisnull(res, 0, i_agginitval))
13627  {
13628  appendPQExpBufferStr(details, ",\n INITCOND = ");
13629  appendStringLiteralAH(details, agginitval, fout);
13630  }
13631 
13632  if (strcmp(aggfinalfn, "-") != 0)
13633  {
13634  appendPQExpBuffer(details, ",\n FINALFUNC = %s",
13635  aggfinalfn);
13636  if (aggfinalextra)
13637  appendPQExpBufferStr(details, ",\n FINALFUNC_EXTRA");
13638  }
13639 
13640  if (strcmp(aggcombinefn, "-") != 0)
13641  appendPQExpBuffer(details, ",\n COMBINEFUNC = %s", aggcombinefn);
13642 
13643  if (strcmp(aggserialfn, "-") != 0)
13644  appendPQExpBuffer(details, ",\n SERIALFUNC = %s", aggserialfn);
13645 
13646  if (strcmp(aggdeserialfn, "-") != 0)
13647  appendPQExpBuffer(details, ",\n DESERIALFUNC = %s", aggdeserialfn);
13648 
13649  if (strcmp(aggmtransfn, "-") != 0)
13650  {
13651  appendPQExpBuffer(details, ",\n MSFUNC = %s,\n MINVFUNC = %s,\n MSTYPE = %s",
13652  aggmtransfn,
13653  aggminvtransfn,
13654  aggmtranstype);
13655  }
13656 
13657  if (strcmp(aggmtransspace, "0") != 0)
13658  {
13659  appendPQExpBuffer(details, ",\n MSSPACE = %s",
13660  aggmtransspace);
13661  }
13662 
13663  if (!PQgetisnull(res, 0, i_aggminitval))
13664  {
13665  appendPQExpBufferStr(details, ",\n MINITCOND = ");
13666  appendStringLiteralAH(details, aggminitval, fout);
13667  }
13668 
13669  if (strcmp(aggmfinalfn, "-") != 0)
13670  {
13671  appendPQExpBuffer(details, ",\n MFINALFUNC = %s",
13672  aggmfinalfn);
13673  if (aggmfinalextra)
13674  appendPQExpBufferStr(details, ",\n MFINALFUNC_EXTRA");
13675  }
13676 
13677  aggsortconvop = convertOperatorReference(fout, aggsortop);
13678  if (aggsortconvop)
13679  {
13680  appendPQExpBuffer(details, ",\n SORTOP = %s",
13681  aggsortconvop);
13682  free(aggsortconvop);
13683  }
13684 
13685  if (hypothetical)
13686  appendPQExpBufferStr(details, ",\n HYPOTHETICAL");
13687 
13688  if (proparallel != NULL && proparallel[0] != PROPARALLEL_UNSAFE)
13689  {
13690  if (proparallel[0] == PROPARALLEL_SAFE)
13691  appendPQExpBufferStr(details, ",\n PARALLEL = safe");
13692  else if (proparallel[0] == PROPARALLEL_RESTRICTED)
13693  appendPQExpBufferStr(details, ",\n PARALLEL = restricted");
13694  else if (proparallel[0] != PROPARALLEL_UNSAFE)
13695  exit_horribly(NULL, "unrecognized proparallel value for function \"%s\"\n",
13696  agginfo->aggfn.dobj.name);
13697  }
13698 
13699  /*
13700  * DROP must be fully qualified in case same name appears in pg_catalog
13701  */
13702  appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n",
13703  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
13704  aggsig);
13705 
13706  appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n",
13707  aggfullsig ? aggfullsig : aggsig, details->data);
13708 
13709  appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig);
13710 
13711  if (dopt->binary_upgrade)
13712  binary_upgrade_extension_member(q, &agginfo->aggfn.dobj, labelq->data);
13713 
13714  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_DEFINITION)
13715  ArchiveEntry(fout, agginfo->aggfn.dobj.catId,
13716  agginfo->aggfn.dobj.dumpId,
13717  aggsig_tag,
13718  agginfo->aggfn.dobj.namespace->dobj.name,
13719  NULL,
13720  agginfo->aggfn.rolname,
13721  false, "AGGREGATE", SECTION_PRE_DATA,
13722  q->data, delq->data, NULL,
13723  NULL, 0,
13724  NULL, NULL);
13725 
13726  /* Dump Aggregate Comments */
13727  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_COMMENT)
13728  dumpComment(fout, labelq->data,
13729  agginfo->aggfn.dobj.namespace->dobj.name,
13730  agginfo->aggfn.rolname,
13731  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13732 
13733  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_SECLABEL)
13734  dumpSecLabel(fout, labelq->data,
13735  agginfo->aggfn.dobj.namespace->dobj.name,
13736  agginfo->aggfn.rolname,
13737  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13738 
13739  /*
13740  * Since there is no GRANT ON AGGREGATE syntax, we have to make the ACL
13741  * command look like a function's GRANT; in particular this affects the
13742  * syntax for zero-argument aggregates and ordered-set aggregates.
13743  */
13744  free(aggsig);
13745  free(aggsig_tag);
13746 
13747  aggsig = format_function_signature(fout, &agginfo->aggfn, true);
13748  aggsig_tag = format_function_signature(fout, &agginfo->aggfn, false);
13749 
13750  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_ACL)
13751  dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
13752  "FUNCTION",
13753  aggsig, NULL, aggsig_tag,
13754  agginfo->aggfn.dobj.namespace->dobj.name,
13755  agginfo->aggfn.rolname, agginfo->aggfn.proacl,
13756  agginfo->aggfn.rproacl,
13757  agginfo->aggfn.initproacl, agginfo->aggfn.initrproacl);
13758 
13759  free(aggsig);
13760  if (aggfullsig)
13761  free(aggfullsig);
13762  free(aggsig_tag);
13763 
13764  PQclear(res);
13765 
13766  destroyPQExpBuffer(query);
13767  destroyPQExpBuffer(q);
13768  destroyPQExpBuffer(delq);
13769  destroyPQExpBuffer(labelq);
13770  destroyPQExpBuffer(details);
13771 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
static char * convertOperatorReference(Archive *fout, const char *opr)
Definition: pg_dump.c:12284
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * initrproacl
Definition: pg_dump.h:207
DumpableObject dobj
Definition: pg_dump.h:198
#define PROPARALLEL_RESTRICTED
Definition: pg_proc.h:5496
DumpId dumpId
Definition: pg_dump.h:132
static char * format_function_arguments(FuncInfo *finfo, char *funcargs, bool is_agg)
Definition: pg_dump.c:11155
FuncInfo aggfn
Definition: pg_dump.h:213
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9127
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void dumpSecLabel(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14603
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5495
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
#define PROPARALLEL_UNSAFE
Definition: pg_proc.h:5497
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4101
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
char * initproacl
Definition: pg_dump.h:206
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *tag, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14527
static char * format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11250
char * rolname
Definition: pg_dump.h:199
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:95
char * proacl
Definition: pg_dump.h:204
char * rproacl
Definition: pg_dump.h:205
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
static char * format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
Definition: pg_dump.c:13333
int remoteVersion
Definition: pg_backup.h:186
static void dumpAttrDef ( Archive fout,
AttrDefInfo adinfo 
)
static

Definition at line 15846 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

15847 {
15848  DumpOptions *dopt = fout->dopt;
15849  TableInfo *tbinfo = adinfo->adtable;
15850  int adnum = adinfo->adnum;
15851  PQExpBuffer q;
15852  PQExpBuffer delq;
15853  char *tag;
15854 
15855  /* Skip if table definition not to be dumped */
15856  if (!tbinfo->dobj.dump || dopt->dataOnly)
15857  return;
15858 
15859  /* Skip if not "separate"; it was dumped in the table's definition */
15860  if (!adinfo->separate)
15861  return;
15862 
15863  q = createPQExpBuffer();
15864  delq = createPQExpBuffer();
15865 
15866  appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
15867  fmtId(tbinfo->dobj.name));
15868  appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n",
15869  fmtId(tbinfo->attnames[adnum - 1]),
15870  adinfo->adef_expr);
15871 
15872  /*
15873  * DROP must be fully qualified in case same name appears in pg_catalog
15874  */
15875  appendPQExpBuffer(delq, "ALTER TABLE %s.",
15876  fmtId(tbinfo->dobj.namespace->dobj.name));
15877  appendPQExpBuffer(delq, "%s ",
15878  fmtId(tbinfo->dobj.name));
15879  appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n",
15880  fmtId(tbinfo->attnames[adnum - 1]));
15881 
15882  tag = psprintf("%s %s", tbinfo->dobj.name, tbinfo->attnames[adnum - 1]);
15883 
15884  if (adinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
15885  ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
15886  tag,
15887  tbinfo->dobj.namespace->dobj.name,
15888  NULL,
15889  tbinfo->rolname,
15890  false, "DEFAULT", SECTION_PRE_DATA,
15891  q->data, delq->data, NULL,
15892  NULL, 0,
15893  NULL, NULL);
15894 
15895  free(tag);
15896  destroyPQExpBuffer(q);
15897  destroyPQExpBuffer(delq);
15898 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * rolname
Definition: pg_dump.h:262
DumpId dumpId
Definition: pg_dump.h:132
char ** attnames
Definition: pg_dump.h:304
DumpableObject dobj
Definition: pg_dump.h:261
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
bool separate
Definition: pg_dump.h:342
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
TableInfo * adtable
Definition: pg_dump.h:339
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:338
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
char * adef_expr
Definition: pg_dump.h:341
static void dumpBaseType ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10144 of file pg_dump.c.

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

Referenced by dumpType().

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

Definition at line 3054 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

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

Definition at line 3109 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

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

Definition at line 11786 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

11787 {
11788  DumpOptions *dopt = fout->dopt;
11789  PQExpBuffer defqry;
11790  PQExpBuffer delqry;
11791  PQExpBuffer labelq;
11792  FuncInfo *funcInfo = NULL;
11793  char *sourceType;
11794  char *targetType;
11795 
11796  /* Skip if not to be dumped */
11797  if (!cast->dobj.dump || dopt->dataOnly)
11798  return;
11799 
11800  /* Cannot dump if we don't have the cast function's info */
11801  if (OidIsValid(cast->castfunc))
11802  {
11803  funcInfo = findFuncByOid(cast->castfunc);
11804  if (funcInfo == NULL)
11805  exit_horribly(NULL, "could not find function definition for function with OID %u\n",
11806  cast->castfunc);
11807  }
11808 
11809  /*
11810  * Make sure we are in proper schema (needed for getFormattedTypeName).
11811  * Casts don't have a schema of their own, so use pg_catalog.
11812  */
11813  selectSourceSchema(fout, "pg_catalog");
11814 
11815  defqry = createPQExpBuffer();
11816  delqry = createPQExpBuffer();
11817  labelq = createPQExpBuffer();
11818 
11819  sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone);
11820  targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone);
11821  appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
11822  sourceType, targetType);
11823 
11824  appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
11825  sourceType, targetType);
11826 
11827  switch (cast->castmethod)
11828  {
11830  appendPQExpBufferStr(defqry, "WITHOUT FUNCTION");
11831  break;
11832  case COERCION_METHOD_INOUT:
11833  appendPQExpBufferStr(defqry, "WITH INOUT");
11834  break;
11836  if (funcInfo)
11837  {
11838  char *fsig = format_function_signature(fout, funcInfo, true);
11839 
11840  /*
11841  * Always qualify the function name, in case it is not in
11842  * pg_catalog schema (format_function_signature won't qualify
11843  * it).
11844  */
11845  appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
11846  fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
11847  free(fsig);
11848  }
11849  else
11850  write_msg(NULL, "WARNING: bogus value in pg_cast.castfunc or pg_cast.castmethod field\n");
11851  break;
11852  default:
11853  write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
11854  }
11855 
11856  if (cast->castcontext == 'a')
11857  appendPQExpBufferStr(defqry, " AS ASSIGNMENT");
11858  else if (cast->castcontext == 'i')
11859  appendPQExpBufferStr(defqry, " AS IMPLICIT");
11860  appendPQExpBufferStr(defqry, ";\n");
11861 
11862  appendPQExpBuffer(labelq, "CAST (%s AS %s)",
11863  sourceType, targetType);
11864 
11865  if (dopt->binary_upgrade)
11866  binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data);
11867 
11868  if (cast->dobj.dump & DUMP_COMPONENT_DEFINITION)
11869  ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
11870  labelq->data,
11871  "pg_catalog", NULL, "",
11872  false, "CAST", SECTION_PRE_DATA,
11873  defqry->data, delqry->data, NULL,
11874  NULL, 0,
11875  NULL, NULL);
11876 
11877  /* Dump Cast Comments */
11878  if (cast->dobj.dump & DUMP_COMPONENT_COMMENT)
11879  dumpComment(fout, labelq->data,
11880  "pg_catalog", "",
11881  cast->dobj.catId, 0, cast->dobj.dumpId);
11882 
11883  free(sourceType);
11884  free(targetType);
11885 
11886  destroyPQExpBuffer(defqry);
11887  destroyPQExpBuffer(delqry);
11888  destroyPQExpBuffer(labelq);
11889 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:17850
char * name
Definition: pg_dump.h:133
Oid castsource
Definition: pg_dump.h:456
DumpComponents dump
Definition: pg_dump.h:134
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
DumpableObject dobj
Definition: pg_dump.h:198
DumpId dumpId
Definition: pg_dump.h:132
Oid castfunc
Definition: pg_dump.h:458
#define OidIsValid(objectId)
Definition: c.h:538
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpableObject dobj
Definition: pg_dump.h:455
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9127
Oid casttarget
Definition: pg_dump.h:457
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
FuncInfo * findFuncByOid(Oid oid)
Definition: common.c:781
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4101
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
static char * format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11250
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
char castmethod
Definition: pg_dump.h:460
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
char castcontext
Definition: pg_dump.h:459
static void dumpCollation ( Archive fout,
CollInfo collinfo 
)
static

Definition at line 13080 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

13081 {
13082  DumpOptions *dopt = fout->dopt;
13083  PQExpBuffer query;
13084  PQExpBuffer q;
13085  PQExpBuffer delq;
13086  PQExpBuffer labelq;
13087  PGresult *res;
13088  int i_collprovider;
13089  int i_collcollate;
13090  int i_collctype;
13091  const char *collprovider;
13092  const char *collcollate;
13093  const char *collctype;
13094 
13095  /* Skip if not to be dumped */
13096  if (!collinfo->dobj.dump || dopt->dataOnly)
13097  return;
13098 
13099  query = createPQExpBuffer();
13100  q = createPQExpBuffer();
13101  delq = createPQExpBuffer();
13102  labelq = createPQExpBuffer();
13103 
13104  /* Make sure we are in proper schema */
13105  selectSourceSchema(fout, collinfo->dobj.namespace->dobj.name);
13106 
13107  /* Get collation-specific details */
13108  if (fout->remoteVersion >= 100000)
13109  appendPQExpBuffer(query, "SELECT "
13110  "collprovider, "
13111  "collcollate, "
13112  "collctype, "
13113  "collversion "
13114  "FROM pg_catalog.pg_collation c "
13115  "WHERE c.oid = '%u'::pg_catalog.oid",
13116  collinfo->dobj.catId.oid);
13117  else
13118  appendPQExpBuffer(query, "SELECT "
13119  "'c'::char AS collprovider, "
13120  "collcollate, "
13121  "collctype, "
13122  "NULL AS collversion "
13123  "FROM pg_catalog.pg_collation c "
13124  "WHERE c.oid = '%u'::pg_catalog.oid",
13125  collinfo->dobj.catId.oid);
13126 
13127  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13128 
13129  i_collprovider = PQfnumber(res, "collprovider");
13130  i_collcollate = PQfnumber(res, "collcollate");
13131  i_collctype = PQfnumber(res, "collctype");
13132 
13133  collprovider = PQgetvalue(res, 0, i_collprovider);
13134  collcollate = PQgetvalue(res, 0, i_collcollate);
13135  collctype = PQgetvalue(res, 0, i_collctype);
13136 
13137  /*
13138  * DROP must be fully qualified in case same name appears in pg_catalog
13139  */
13140  appendPQExpBuffer(delq, "DROP COLLATION %s",
13141  fmtId(collinfo->dobj.namespace->dobj.name));
13142  appendPQExpBuffer(delq, ".%s;\n",
13143  fmtId(collinfo->dobj.name));
13144 
13145  appendPQExpBuffer(q, "CREATE COLLATION %s (",
13146  fmtId(collinfo->dobj.name));
13147 
13148  appendPQExpBufferStr(q, "provider = ");
13149  if (collprovider[0] == 'c')
13150  appendPQExpBufferStr(q, "libc");
13151  else if (collprovider[0] == 'i')
13152  appendPQExpBufferStr(q, "icu");
13153  else if (collprovider[0] == 'd')
13154  /* to allow dumping pg_catalog; not accepted on input */
13155  appendPQExpBufferStr(q, "default");
13156  else
13158  "unrecognized collation provider: %s\n",
13159  collprovider);
13160 
13161  if (strcmp(collcollate, collctype) == 0)
13162  {
13163  appendPQExpBufferStr(q, ", locale = ");
13164  appendStringLiteralAH(q, collcollate, fout);
13165  }
13166  else
13167  {
13168  appendPQExpBufferStr(q, ", lc_collate = ");
13169  appendStringLiteralAH(q, collcollate, fout);
13170  appendPQExpBufferStr(q, ", lc_ctype = ");
13171  appendStringLiteralAH(q, collctype, fout);
13172  }
13173 
13174  /*
13175  * For binary upgrade, carry over the collation version. For normal
13176  * dump/restore, omit the version, so that it is computed upon restore.
13177  */
13178  if (dopt->binary_upgrade)
13179  {
13180  int i_collversion;
13181 
13182  i_collversion = PQfnumber(res, "collversion");
13183  if (!PQgetisnull(res, 0, i_collversion))
13184  {
13185  appendPQExpBufferStr(q, ", version = ");
13187  PQgetvalue(res, 0, i_collversion),
13188  fout);
13189  }
13190  }
13191 
13192  appendPQExpBufferStr(q, ");\n");
13193 
13194  appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name));
13195 
13196  if (dopt->binary_upgrade)
13197  binary_upgrade_extension_member(q, &collinfo->dobj, labelq->data);
13198 
13199  if (collinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13200  ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId,
13201  collinfo->dobj.name,
13202  collinfo->dobj.namespace->dobj.name,
13203  NULL,
13204  collinfo->rolname,
13205  false, "COLLATION", SECTION_PRE_DATA,
13206  q->data, delq->data, NULL,
13207  NULL, 0,
13208  NULL, NULL);
13209 
13210  /* Dump Collation Comments */
13211  if (collinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13212  dumpComment(fout, labelq->data,
13213  collinfo->dobj.namespace->dobj.name, collinfo->rolname,
13214  collinfo->dobj.catId, 0, collinfo->dobj.dumpId);
13215 
13216  PQclear(res);
13217 
13218  destroyPQExpBuffer(query);
13219  destroyPQExpBuffer(q);
13220  destroyPQExpBuffer(delq);
13221  destroyPQExpBuffer(labelq);
13222 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
DumpId dumpId
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:246
char * rolname
Definition: pg_dump.h:247
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9127
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4101
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define NULL
Definition: c.h:229
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
int remoteVersion
Definition: pg_backup.h:186
static void dumpComment ( Archive fout,
const char *  target,
const char *  namespace,
const char *  owner,
CatalogId  catalogId,
int  subid,
DumpId  dumpId 
)
static

Definition at line 9127 of file pg_dump.c.

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

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

9130 {
9131  DumpOptions *dopt = fout->dopt;
9132  CommentItem *comments;
9133  int ncomments;
9134 
9135  /* Comments are schema not data ... except blob comments are data */
9136  if (strncmp(target, "LARGE OBJECT ", 13) != 0)
9137  {
9138  if (dopt->dataOnly)
9139  return;
9140  }
9141  else
9142  {
9143  /* We do dump blob comments in binary-upgrade mode */
9144  if (dopt->schemaOnly && !dopt->binary_upgrade)
9145  return;
9146  }
9147 
9148  /* Search for comments associated with catalogId, using table */
9149  ncomments = findComments(fout, catalogId.tableoid, catalogId.oid,
9150  &comments);
9151 
9152  /* Is there one matching the subid? */
9153  while (ncomments > 0)
9154  {
9155  if (comments->objsubid == subid)
9156  break;
9157  comments++;
9158  ncomments--;
9159  }
9160 
9161  /* If a comment exists, build COMMENT ON statement */
9162  if (ncomments > 0)
9163  {
9164  PQExpBuffer query = createPQExpBuffer();
9165 
9166  appendPQExpBuffer(query, "COMMENT ON %s IS ", target);
9167  appendStringLiteralAH(query, comments->descr, fout);
9168  appendPQExpBufferStr(query, ";\n");
9169 
9170  /*
9171  * We mark comments as SECTION_NONE because they really belong in the
9172  * same section as their parent, whether that is pre-data or
9173  * post-data.
9174  */
9176  target, namespace, NULL, owner,
9177  false, "COMMENT", SECTION_NONE,
9178  query->data, "", NULL,
9179  &(dumpId), 1,
9180  NULL, NULL);
9181 
9182  destroyPQExpBuffer(query);
9183  }
9184 }
Oid tableoid
Definition: pg_backup.h:226
bool schemaOnly
Definition: pg_backup.h:138
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:70
static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9282
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
const char * descr
Definition: pg_dump.c:67
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
#define NULL
Definition: c.h:229
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:132
DumpId createDumpId(void)
Definition: common.c:520
static void dumpCompositeType ( Archive fout,
TypeInfo tyinfo 
)
static

Definition at line 10619 of file pg_dump.c.

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

Referenced by dumpType().

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

Definition at line 10840 of file pg_dump.c.

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

Referenced by dumpCompositeType().

10841 {
10842  CommentItem *comments;
10843  int ncomments;
10844  PGresult *res;
10845  PQExpBuffer query;
10846  PQExpBuffer target;
10847  Oid pgClassOid;
10848  int i;
10849  int ntups;
10850  int i_attname;
10851  int i_attnum;
10852 
10853  query = createPQExpBuffer();
10854 
10855  appendPQExpBuffer(query,
10856  "SELECT c.tableoid, a.attname, a.attnum "
10857  "FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
10858  "WHERE c.oid = '%u' AND c.oid = a.attrelid "
10859  " AND NOT a.attisdropped "
10860  "ORDER BY a.attnum ",
10861  tyinfo->typrelid);
10862 
10863  /* Fetch column attnames */
10864  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10865 
10866  ntups = PQntuples(res);
10867  if (ntups < 1)
10868  {
10869  PQclear(res);
10870  destroyPQExpBuffer(query);
10871  return;
10872  }
10873 
10874  pgClassOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "tableoid")));
10875 
10876  /* Search for comments associated with type's pg_class OID */
10877  ncomments = findComments(fout,
10878  pgClassOid,
10879  tyinfo->typrelid,
10880  &comments);
10881 
10882  /* If no comments exist, we're done */
10883  if (ncomments <= 0)
10884  {
10885  PQclear(res);
10886  destroyPQExpBuffer(query);
10887  return;
10888  }
10889 
10890  /* Build COMMENT ON statements */
10891  target = createPQExpBuffer();
10892 
10893  i_attnum = PQfnumber(res, "attnum");
10894  i_attname = PQfnumber(res, "attname");
10895  while (ncomments > 0)
10896  {
10897  const char *attname;
10898 
10899  attname = NULL;
10900  for (i = 0; i < ntups; i++)
10901  {
10902  if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid)
10903  {
10904  attname = PQgetvalue(res, i, i_attname);
10905  break;
10906  }
10907  }
10908  if (attname) /* just in case we don't find it */
10909  {
10910  const char *descr = comments->descr;
10911 
10912  resetPQExpBuffer(target);
10913  appendPQExpBuffer(target, "COLUMN %s.",
10914  fmtId(tyinfo->dobj.name));
10915  appendPQExpBufferStr(target, fmtId(attname));
10916 
10917  resetPQExpBuffer(query);
10918  appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
10919  appendStringLiteralAH(query, descr, fout);
10920  appendPQExpBufferStr(query, ";\n");
10921 
10923  target->data,
10924  tyinfo->dobj.namespace->dobj.name,
10925  NULL, tyinfo->rolname,
10926  false, "COMMENT", SECTION_NONE,
10927  query->data, "", NULL,
10928  &(tyinfo->dobj.dumpId), 1,
10929  NULL, NULL);
10930  }
10931 
10932  comments++;
10933  ncomments--;
10934  }
10935 
10936  PQclear(res);
10937  destroyPQExpBuffer(query);
10938  destroyPQExpBuffer(target);
10939 }
char * name
Definition: pg_dump.h:133
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
Oid typrelid
Definition: pg_dump.h:177
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:70
DumpId dumpId
Definition: pg_dump.h:132
unsigned int Oid
Definition: postgres_ext.h:31
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9282
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
#define atooid(x)
Definition: postgres_ext.h:42
const char * descr
Definition: pg_dump.c:67
DumpableObject dobj
Definition: pg_dump.h:165
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
char * rolname
Definition: pg_dump.h:171
int i
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:132
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DumpId createDumpId(void)
Definition: common.c:520
static void dumpConstraint ( Archive fout,
ConstraintInfo coninfo 
)
static

Definition at line 16087 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

16088 {
16089  DumpOptions *dopt = fout->dopt;
16090  TableInfo *tbinfo = coninfo->contable;
16091  PQExpBuffer q;
16092  PQExpBuffer delq;
16093  char *tag = NULL;
16094 
16095  /* Skip if not to be dumped */
16096  if (!coninfo->dobj.dump || dopt->dataOnly)
16097  return;
16098 
16099  q = createPQExpBuffer();
16100  delq = createPQExpBuffer();
16101 
16102  if (coninfo->contype == 'p' ||
16103  coninfo->contype == 'u' ||
16104  coninfo->contype == 'x')
16105  {
16106  /* Index-related constraint */
16107  IndxInfo *indxinfo;
16108  int k;
16109 
16110  indxinfo = (IndxInfo *) findObjectByDumpId(coninfo->conindex);
16111 
16112  if (indxinfo == NULL)
16113  exit_horribly(NULL, "missing index for constraint \"%s\"\n",
16114  coninfo->dobj.name);
16115 
16116  if (dopt->binary_upgrade)
16118  indxinfo->dobj.catId.oid, true);
16119 
16120  appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
16121  fmtId(tbinfo->dobj.name));
16122  appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
16123  fmtId(coninfo->dobj.name));
16124 
16125  if (coninfo->condef)
16126  {
16127  /* pg_get_constraintdef should have provided everything */
16128  appendPQExpBuffer(q, "%s;\n", coninfo->condef);
16129  }
16130  else
16131  {
16132  appendPQExpBuffer(q, "%s (",
16133  coninfo->contype == 'p' ? "PRIMARY KEY" : "UNIQUE");
16134  for (k = 0; k < indxinfo->indnkeys; k++)
16135  {
16136  int indkey = (int) indxinfo->indkeys[k];
16137  const char *attname;
16138 
16139  if (indkey == InvalidAttrNumber)
16140  break;
16141  attname = getAttrName(indkey, tbinfo);
16142 
16143  appendPQExpBuffer(q, "%s%s",
16144  (k == 0) ? "" : ", ",
16145  fmtId(attname));
16146  }
16147 
16148  appendPQExpBufferChar(q, ')');
16149 
16150  if (nonemptyReloptions(indxinfo->indreloptions))
16151  {
16152  appendPQExpBufferStr(q, " WITH (");
16153  appendReloptionsArrayAH(q, indxinfo->indreloptions, "", fout);
16154  appendPQExpBufferChar(q, ')');
16155  }
16156 
16157  if (coninfo->condeferrable)
16158  {
16159  appendPQExpBufferStr(q, " DEFERRABLE");
16160  if (coninfo->condeferred)
16161  appendPQExpBufferStr(q, " INITIALLY DEFERRED");
16162  }
16163 
16164  appendPQExpBufferStr(q, ";\n");
16165  }
16166 
16167  /* If the index is clustered, we need to record that. */
16168  if (indxinfo->indisclustered)
16169  {
16170  appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER",
16171  fmtId(tbinfo->dobj.name));
16172  appendPQExpBuffer(q, " ON %s;\n",
16173  fmtId(indxinfo->dobj.name));
16174  }
16175 
16176  /*
16177  * DROP must be fully qualified in case same name appears in
16178  * pg_catalog
16179  */
16180  appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.",
16181  fmtId(tbinfo->dobj.namespace->dobj.name));
16182  appendPQExpBuffer(delq, "%s ",
16183  fmtId(tbinfo->dobj.name));
16184  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16185  fmtId(coninfo->dobj.name));
16186 
16187  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16188 
16189  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16190  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16191  tag,
16192  tbinfo->dobj.namespace->dobj.name,
16193  indxinfo->tablespace,
16194  tbinfo->rolname, false,
16195  "CONSTRAINT", SECTION_POST_DATA,
16196  q->data, delq->data, NULL,
16197  NULL, 0,
16198  NULL, NULL);
16199  }
16200  else if (coninfo->contype == 'f')
16201  {
16202  /*
16203  * XXX Potentially wrap in a 'SET CONSTRAINTS OFF' block so that the
16204  * current table data is not processed
16205  */
16206  appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
16207  fmtId(tbinfo->dobj.name));
16208  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16209  fmtId(coninfo->dobj.name),
16210  coninfo->condef);
16211 
16212  /*
16213  * DROP must be fully qualified in case same name appears in
16214  * pg_catalog
16215  */
16216  appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.",
16217  fmtId(tbinfo->dobj.namespace->dobj.name));
16218  appendPQExpBuffer(delq, "%s ",
16219  fmtId(tbinfo->dobj.name));
16220  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16221  fmtId(coninfo->dobj.name));
16222 
16223  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16224 
16225  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16226  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16227  tag,
16228  tbinfo->dobj.namespace->dobj.name,
16229  NULL,
16230  tbinfo->rolname, false,
16231  "FK CONSTRAINT", SECTION_POST_DATA,
16232  q->data, delq->data, NULL,
16233  NULL, 0,
16234  NULL, NULL);
16235  }
16236  else if (coninfo->contype == 'c' && tbinfo)
16237  {
16238  /* CHECK constraint on a table */
16239 
16240  /* Ignore if not to be dumped separately, or if it was inherited */
16241  if (coninfo->separate && coninfo->conislocal)
16242  {
16243  /* not ONLY since we want it to propagate to children */
16244  appendPQExpBuffer(q, "ALTER TABLE %s\n",
16245  fmtId(tbinfo->dobj.name));
16246  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16247  fmtId(coninfo->dobj.name),
16248  coninfo->condef);
16249 
16250  /*
16251  * DROP must be fully qualified in case same name appears in
16252  * pg_catalog
16253  */
16254  appendPQExpBuffer(delq, "ALTER TABLE %s.",
16255  fmtId(tbinfo->dobj.namespace->dobj.name));
16256  appendPQExpBuffer(delq, "%s ",
16257  fmtId(tbinfo->dobj.name));
16258  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16259  fmtId(coninfo->dobj.name));
16260 
16261  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16262 
16263  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16264  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16265  tag,
16266  tbinfo->dobj.namespace->dobj.name,
16267  NULL,
16268  tbinfo->rolname, false,
16269  "CHECK CONSTRAINT", SECTION_POST_DATA,
16270  q->data, delq->data, NULL,
16271  NULL, 0,
16272  NULL, NULL);
16273  }
16274  }
16275  else if (coninfo->contype == 'c' && tbinfo == NULL)
16276  {
16277  /* CHECK constraint on a domain */
16278  TypeInfo *tyinfo = coninfo->condomain;
16279 
16280  /* Ignore if not to be dumped separately */
16281  if (coninfo->separate)
16282  {
16283  appendPQExpBuffer(q, "ALTER DOMAIN %s\n",
16284  fmtId(tyinfo->dobj.name));
16285  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16286  fmtId(coninfo->dobj.name),
16287  coninfo->condef);
16288 
16289  /*
16290  * DROP must be fully qualified in case same name appears in
16291  * pg_catalog
16292  */
16293  appendPQExpBuffer(delq, "ALTER DOMAIN %s.",
16294  fmtId(tyinfo->dobj.namespace->dobj.name));
16295  appendPQExpBuffer(delq, "%s ",
16296  fmtId(tyinfo->dobj.name));
16297  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16298  fmtId(coninfo->dobj.name));
16299 
16300  tag = psprintf("%s %s", tyinfo->dobj.name, coninfo->dobj.name);
16301 
16302  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16303  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16304  tag,
16305  tyinfo->dobj.namespace->dobj.name,
16306  NULL,
16307  tyinfo->rolname, false,
16308  "CHECK CONSTRAINT", SECTION_POST_DATA,
16309  q->data, delq->data, NULL,
16310  NULL, 0,
16311  NULL, NULL);
16312  }
16313  }
16314  else
16315  {
16316  exit_horribly(NULL, "unrecognized constraint type: %c\n",
16317  coninfo->contype);
16318  }
16319 
16320  /* Dump Constraint Comments --- only works for table constraints */
16321  if (tbinfo && coninfo->separate &&
16322  coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
16323  dumpTableConstraintComment(fout, coninfo);
16324 
16325  free(tag);
16326  destroyPQExpBuffer(q);
16327  destroyPQExpBuffer(delq);
16328 }
char * tablespace
Definition: pg_dump.h:358
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static void appendReloptionsArrayAH(PQExpBuffer buffer, const char *reloptions, const char *prefix, Archive *fout)
Definition: pg_dump.c:17933
char * rolname
Definition: pg_dump.h:262
DumpId dumpId
Definition: pg_dump.h:132
DumpId conindex
Definition: pg_dump.h:432
DumpableObject dobj
Definition: pg_dump.h:261
char * condef
Definition: pg_dump.h:430
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpableObject dobj
Definition: pg_dump.h:426
DumpOptions * dopt
Definition: pg_backup.h:181
static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
Definition: pg_dump.c:16338
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:540
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
Oid * indkeys
Definition: pg_dump.h:361
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
Definition: pg_dump.c:4034
static const char * getAttrName(int attrnum, TableInfo *tblInfo)
Definition: pg_dump.c:15908
bool condeferrable
Definition: pg_dump.h:433
static bool nonemptyReloptions(const char *reloptions)
Definition: pg_dump.c:17921
int indnkeys
Definition: pg_dump.h:360
char * indreloptions
Definition: pg_dump.h:359
DumpableObject dobj
Definition: pg_dump.h:165
TypeInfo * condomain
Definition: pg_dump.h:428
bool conislocal
Definition: pg_dump.h:435
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
TableInfo * contable
Definition: pg_dump.h:427
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
bool condeferred
Definition: pg_dump.h:434
#define NULL
Definition: c.h:229
char * rolname
Definition: pg_dump.h:171
#define InvalidAttrNumber
Definition: attnum.h:23
void exit_horribly(const char *modulename, const char *fmt,...)
CatalogId catId
Definition: pg_dump.h:131
DumpableObject dobj
Definition: pg_dump.h:355
bool indisclustered
Definition: pg_dump.h:362
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static void dumpConversion ( Archive fout,
ConvInfo convinfo 
)
static

Definition at line 13229 of file pg_dump.c.

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

Referenced by dumpDumpableObject().

13230 {
13231  DumpOptions *dopt = fout->dopt;
13232  PQExpBuffer query;
13233  PQExpBuffer q;
13234  PQExpBuffer delq;
13235  PQExpBuffer labelq;
13236  PGresult *res;
13237  int i_conforencoding;
13238  int i_contoencoding;
13239  int i_conproc;
13240  int i_condefault;
13241  const char *conforencoding;
13242  const char *contoencoding;
13243  const char *conproc;
13244  bool condefault;
13245 
13246  /* Skip if not to be dumped */
13247  if (!convinfo->dobj.dump || dopt->dataOnly)
13248  return;
13249 
13250  query = createPQExpBuffer();
13251  q = createPQExpBuffer();
13252  delq = createPQExpBuffer();
13253  labelq = createPQExpBuffer();
13254 
13255  /* Make sure we are in proper schema */
13256  selectSourceSchema(fout, convinfo->dobj.namespace->dobj.name);
13257 
13258  /* Get conversion-specific details */
13259  appendPQExpBuffer(query, "SELECT "
13260  "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
13261  "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
13262  "conproc, condefault "
13263  "FROM pg_catalog.pg_conversion c "
13264  "WHERE c.oid = '%u'::pg_catalog.oid",
13265  convinfo->dobj.catId.oid);
13266 
13267  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13268 
13269  i_conforencoding = PQfnumber(res, "conforencoding");
13270  i_contoencoding = PQfnumber(res, "contoencoding");
13271  i_conproc = PQfnumber(res, "conproc");
13272  i_condefault = PQfnumber(res, "condefault");
13273 
13274  conforencoding = PQgetvalue(res, 0, i_conforencoding);
13275  contoencoding = PQgetvalue(res, 0, i_contoencoding);
13276  conproc = PQgetvalue(res, 0, i_conproc);
13277  condefault = (PQgetvalue(res, 0, i_condefault)[0] == 't');
13278 
13279  /*
13280  * DROP must be fully qualified in case same name appears in pg_catalog
13281  */
13282  appendPQExpBuffer(delq, "DROP CONVERSION %s",
13283  fmtId(convinfo->dobj.namespace->dobj.name));
13284  appendPQExpBuffer(delq, ".%s;\n",
13285  fmtId(convinfo->dobj.name));
13286 
13287  appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ",
13288  (condefault) ? "DEFAULT " : "",
13289  fmtId(convinfo->dobj.name));
13290  appendStringLiteralAH(q, conforencoding, fout);
13291  appendPQExpBufferStr(q, " TO ");
13292  appendStringLiteralAH(q, contoencoding, fout);
13293  /* regproc output is already sufficiently quoted */
13294  appendPQExpBuffer(q, " FROM %s;\n", conproc);
13295 
13296  appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name));
13297 
13298  if (dopt->binary_upgrade)
13299  binary_upgrade_extension_member(q, &convinfo->dobj, labelq->data);
13300 
13301  if (convinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13302  ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
13303  convinfo->dobj.name,
13304  convinfo->dobj.namespace->dobj.name,
13305  NULL,
13306  convinfo->rolname,
13307  false, "CONVERSION", SECTION_PRE_DATA,
13308  q->data, delq->data, NULL,
13309  NULL, 0,
13310  NULL, NULL);
13311 
13312  /* Dump Conversion Comments */
13313  if (convinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13314  dumpComment(fout, labelq->data,
13315  convinfo->dobj.namespace->dobj.name, convinfo->rolname,
13316  convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
13317 
13318  PQclear(res);
13319 
13320  destroyPQExpBuffer(query);
13321  destroyPQExpBuffer(q);
13322  destroyPQExpBuffer(delq);
13323  destroyPQExpBuffer(labelq);
13324 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * rolname
Definition: pg_dump.h:253
DumpId dumpId
Definition: pg_dump.h:132
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9127
DumpOptions * dopt
Definition: pg_backup.h:181
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17824
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2781
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4101
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:299
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define NULL
Definition: c.h:229
DumpableObject dobj
Definition: pg_dump.h:252
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static void dumpDatabase ( Archive AH)
static

Definition at line 2522 of file pg_dump.c.

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralAH, ArchiveEntry(), atooid, _dumpOptions::binary_upgrade, buildShSecLabelQuery(), conn, createDumpId(), createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), Archive::dopt, dumpComment(), emitShSecLabels(), encoding, ExecuteSqlQuery(), ExecuteSqlQueryForSingleRow(), fmtId(), g_verbose, GetConnection(), LargeObjectMetadataRelationId, LargeObjectRelationId, _dumpOptions::no_security_labels, NULL, CatalogId::oid, _dumpOptions::outputNoTablespaces, PGRES_TUPLES_OK, PQclear(), PQdb(), PQfnumber(), PQgetvalue(), Archive::remoteVersion, resetPQExpBuffer(), SECTION_NONE, SECTION_PRE_DATA, selectSourceSchema(), CatalogId::tableoid, tablespace, username_subquery, and write_msg().

Referenced by main().

2523 {
2524  DumpOptions *dopt = fout->dopt;
2525  PQExpBuffer dbQry = createPQExpBuffer();
2526  PQExpBuffer delQry = createPQExpBuffer();
2527  PQExpBuffer creaQry = createPQExpBuffer();
2528  PGconn *conn = GetConnection(fout);
2529  PGresult *res;
2530  int i_tableoid,
2531  i_oid,
2532  i_dba,
2533  i_encoding,
2534  i_collate,
2535  i_ctype,
2536  i_frozenxid,
2537  i_minmxid,
2538  i_tablespace;
2539  CatalogId dbCatId;
2540  DumpId dbDumpId;
2541  const char *datname,
2542  *dba,
2543  *encoding,
2544  *collate,
2545  *ctype,
2546  *tablespace;
2547  uint32 frozenxid,
2548  minmxid;
2549 
2550  datname = PQdb(conn);
2551 
2552  if (g_verbose)
2553  write_msg(NULL, "saving database definition\n");
2554 
2555  /* Make sure we are in proper schema */
2556  selectSourceSchema(fout, "pg_catalog");
2557 
2558  /* Get the database owner and parameters from pg_database */
2559  if (fout->remoteVersion >= 90300)
2560  {
2561  appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
2562  "(%s datdba) AS dba, "
2563  "pg_encoding_to_char(encoding) AS encoding, "
2564  "datcollate, datctype, datfrozenxid, datminmxid, "
2565  "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2566  "shobj_description(oid, 'pg_database') AS description "
2567 
2568