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)
 
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)
 
PartInfogetPartitions (Archive *fout, int *numPartitions)
 
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 getTablePartitionKeyInfo (Archive *fout, TableInfo *tblinfo, int numTables)
 
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 17498 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().

17500 {
17501  DumpableObject *preDataBound = boundaryObjs + 0;
17502  DumpableObject *postDataBound = boundaryObjs + 1;
17503  int i;
17504 
17505  for (i = 0; i < numObjs; i++)
17506  {
17507  DumpableObject *dobj = dobjs[i];
17508 
17509  /*
17510  * The classification of object types here must match the SECTION_xxx
17511  * values assigned during subsequent ArchiveEntry calls!
17512  */
17513  switch (dobj->objType)
17514  {
17515  case DO_NAMESPACE:
17516  case DO_EXTENSION:
17517  case DO_TYPE:
17518  case DO_SHELL_TYPE:
17519  case DO_FUNC:
17520  case DO_AGG:
17521  case DO_OPERATOR:
17522  case DO_ACCESS_METHOD:
17523  case DO_OPCLASS:
17524  case DO_OPFAMILY:
17525  case DO_COLLATION:
17526  case DO_CONVERSION:
17527  case DO_TABLE:
17528  case DO_ATTRDEF:
17529  case DO_PROCLANG:
17530  case DO_CAST:
17531  case DO_DUMMY_TYPE:
17532  case DO_TSPARSER:
17533  case DO_TSDICT:
17534  case DO_TSTEMPLATE:
17535  case DO_TSCONFIG:
17536  case DO_FDW:
17537  case DO_FOREIGN_SERVER:
17538  case DO_TRANSFORM:
17539  case DO_BLOB:
17540  /* Pre-data objects: must come before the pre-data boundary */
17541  addObjectDependency(preDataBound, dobj->dumpId);
17542  break;
17543  case DO_TABLE_DATA:
17544  case DO_SEQUENCE_SET:
17545  case DO_BLOB_DATA:
17546  /* Data objects: must come between the boundaries */
17547  addObjectDependency(dobj, preDataBound->dumpId);
17548  addObjectDependency(postDataBound, dobj->dumpId);
17549  break;
17550  case DO_INDEX:
17551  case DO_STATSEXT:
17552  case DO_REFRESH_MATVIEW:
17553  case DO_TRIGGER:
17554  case DO_EVENT_TRIGGER:
17555  case DO_DEFAULT_ACL:
17556  case DO_POLICY:
17557  case DO_PUBLICATION:
17558  case DO_PUBLICATION_REL:
17559  case DO_SUBSCRIPTION:
17560  /* Post-data objects: must come after the post-data boundary */
17561  addObjectDependency(dobj, postDataBound->dumpId);
17562  break;
17563  case DO_RULE:
17564  /* Rules are post-data, but only if dumped separately */
17565  if (((RuleInfo *) dobj)->separate)
17566  addObjectDependency(dobj, postDataBound->dumpId);
17567  break;
17568  case DO_CONSTRAINT:
17569  case DO_FK_CONSTRAINT:
17570  /* Constraints are post-data, but only if dumped separately */
17571  if (((ConstraintInfo *) dobj)->separate)
17572  addObjectDependency(dobj, postDataBound->dumpId);
17573  break;
17574  case DO_PRE_DATA_BOUNDARY:
17575  /* nothing to do */
17576  break;
17577  case DO_POST_DATA_BOUNDARY:
17578  /* must come after the pre-data boundary */
17579  addObjectDependency(dobj, preDataBound->dumpId);
17580  break;
17581  }
17582  }
17583 }
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:749
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 17829 of file pg_dump.c.

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

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

17831 {
17832  bool res;
17833 
17834  res = appendReloptionsArray(buffer, reloptions, prefix, fout->encoding,
17835  fout->std_strings);
17836  if (!res)
17837  write_msg(NULL, "WARNING: could not parse reloptions array\n");
17838 }
int encoding
Definition: pg_backup.h:192
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
Definition: string_utils.c:746
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
bool std_strings
Definition: pg_backup.h:193
static void binary_upgrade_extension_member ( PQExpBuffer  upgrade_buffer,
DumpableObject dobj,
const char *  objlabel 
)
static

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

4009 {
4010  DumpableObject *extobj = NULL;
4011  int i;
4012 
4013  if (!dobj->ext_member)
4014  return;
4015 
4016  /*
4017  * Find the parent extension. We could avoid this search if we wanted to
4018  * add a link field to DumpableObject, but the space costs of that would
4019  * be considerable. We assume that member objects could only have a
4020  * direct dependency on their own extension, not any others.
4021  */
4022  for (i = 0; i < dobj->nDeps; i++)
4023  {
4024  extobj = findObjectByDumpId(dobj->dependencies[i]);
4025  if (extobj && extobj->objType == DO_EXTENSION)
4026  break;
4027  extobj = NULL;
4028  }
4029  if (extobj == NULL)
4030  exit_horribly(NULL, "could not find parent extension for %s\n", objlabel);
4031 
4032  appendPQExpBufferStr(upgrade_buffer,
4033  "\n-- For binary upgrade, handle extension membership the hard way\n");
4034  appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s;\n",
4035  fmtId(extobj->name),
4036  objlabel);
4037 }
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:577
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 3939 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().

3942 {
3943  PQExpBuffer upgrade_query = createPQExpBuffer();
3944  PGresult *upgrade_res;
3945  Oid pg_class_reltoastrelid;
3946  Oid pg_index_indexrelid;
3947 
3948  appendPQExpBuffer(upgrade_query,
3949  "SELECT c.reltoastrelid, i.indexrelid "
3950  "FROM pg_catalog.pg_class c LEFT JOIN "
3951  "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
3952  "WHERE c.oid = '%u'::pg_catalog.oid;",
3953  pg_class_oid);
3954 
3955  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
3956 
3957  pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
3958  pg_index_indexrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "indexrelid")));
3959 
3960  appendPQExpBufferStr(upgrade_buffer,
3961  "\n-- For binary upgrade, must preserve pg_class oids\n");
3962 
3963  if (!is_index)
3964  {
3965  appendPQExpBuffer(upgrade_buffer,
3966  "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
3967  pg_class_oid);
3968  /* only tables have toast tables, not indexes */
3969  if (OidIsValid(pg_class_reltoastrelid))
3970  {
3971  /*
3972  * One complexity is that the table definition might not require
3973  * the creation of a TOAST table, and the TOAST table might have
3974  * been created long after table creation, when the table was
3975  * loaded with wide data. By setting the TOAST oid we force
3976  * creation of the TOAST heap and TOAST index by the backend so we
3977  * can cleanly copy the files during binary upgrade.
3978  */
3979 
3980  appendPQExpBuffer(upgrade_buffer,
3981  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
3982  pg_class_reltoastrelid);
3983 
3984  /* every toast table has an index */
3985  appendPQExpBuffer(upgrade_buffer,
3986  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
3987  pg_index_indexrelid);
3988  }
3989  }
3990  else
3991  appendPQExpBuffer(upgrade_buffer,
3992  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
3993  pg_class_oid);
3994 
3995  appendPQExpBufferChar(upgrade_buffer, '\n');
3996 
3997  PQclear(upgrade_res);
3998  destroyPQExpBuffer(upgrade_query);
3999 }
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 3893 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().

3896 {
3897  PQExpBuffer upgrade_query = createPQExpBuffer();
3898  PGresult *upgrade_res;
3899  Oid pg_type_oid;
3900  bool toast_set = false;
3901 
3902  /* we only support old >= 8.3 for binary upgrades */
3903  appendPQExpBuffer(upgrade_query,
3904  "SELECT c.reltype AS crel, t.reltype AS trel "
3905  "FROM pg_catalog.pg_class c "
3906  "LEFT JOIN pg_catalog.pg_class t ON "
3907  " (c.reltoastrelid = t.oid) "
3908  "WHERE c.oid = '%u'::pg_catalog.oid;",
3909  pg_rel_oid);
3910 
3911  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
3912 
3913  pg_type_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "crel")));
3914 
3915  binary_upgrade_set_type_oids_by_type_oid(fout, upgrade_buffer,
3916  pg_type_oid);
3917 
3918  if (!PQgetisnull(upgrade_res, 0, PQfnumber(upgrade_res, "trel")))
3919  {
3920  /* Toast tables do not have pg_type array rows */
3921  Oid pg_type_toast_oid = atooid(PQgetvalue(upgrade_res, 0,
3922  PQfnumber(upgrade_res, "trel")));
3923 
3924  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
3925  appendPQExpBuffer(upgrade_buffer,
3926  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3927  pg_type_toast_oid);
3928 
3929  toast_set = true;
3930  }
3931 
3932  PQclear(upgrade_res);
3933  destroyPQExpBuffer(upgrade_query);
3934 
3935  return toast_set;
3936 }
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid)
Definition: pg_dump.c:3855
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 3855 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().

3858 {
3859  PQExpBuffer upgrade_query = createPQExpBuffer();
3860  PGresult *upgrade_res;
3861  Oid pg_type_array_oid;
3862 
3863  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
3864  appendPQExpBuffer(upgrade_buffer,
3865  "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3866  pg_type_oid);
3867 
3868  /* we only support old >= 8.3 for binary upgrades */
3869  appendPQExpBuffer(upgrade_query,
3870  "SELECT typarray "
3871  "FROM pg_catalog.pg_type "
3872  "WHERE pg_type.oid = '%u'::pg_catalog.oid;",
3873  pg_type_oid);
3874 
3875  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
3876 
3877  pg_type_array_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "typarray")));
3878 
3879  if (OidIsValid(pg_type_array_oid))
3880  {
3881  appendPQExpBufferStr(upgrade_buffer,
3882  "\n-- For binary upgrade, must preserve pg_type array oid\n");
3883  appendPQExpBuffer(upgrade_buffer,
3884  "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3885  pg_type_array_oid);
3886  }
3887 
3888  PQclear(upgrade_res);
3889  destroyPQExpBuffer(upgrade_query);
3890 }
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 17610 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().

17611 {
17612  ArchiveHandle *AH = (ArchiveHandle *) fout;
17613  TocEntry *te;
17614 
17615  /* Scan all TOC entries in the archive */
17616  for (te = AH->toc->next; te != AH->toc; te = te->next)
17617  {
17618  DumpableObject *dobj;
17619  DumpId *dependencies;
17620  int nDeps;
17621  int allocDeps;
17622 
17623  /* No need to process entries that will not be dumped */
17624  if (te->reqs == 0)
17625  continue;
17626  /* Ignore entries that already have "special" dependencies */
17627  if (te->nDeps > 0)
17628  continue;
17629  /* Otherwise, look up the item's original DumpableObject, if any */
17630  dobj = findObjectByDumpId(te->dumpId);
17631  if (dobj == NULL)
17632  continue;
17633  /* No work if it has no dependencies */
17634  if (dobj->nDeps <= 0)
17635  continue;
17636  /* Set up work array */
17637  allocDeps = 64;
17638  dependencies = (DumpId *) pg_malloc(allocDeps * sizeof(DumpId));
17639  nDeps = 0;
17640  /* Recursively find all dumpable dependencies */
17641  findDumpableDependencies(AH, dobj,
17642  &dependencies, &nDeps, &allocDeps);
17643  /* And save 'em ... */
17644  if (nDeps > 0)
17645  {
17646  dependencies = (DumpId *) pg_realloc(dependencies,
17647  nDeps * sizeof(DumpId));
17648  te->dependencies = dependencies;
17649  te->nDeps = nDeps;
17650  }
17651  else
17652  free(dependencies);
17653  }
17654 }
struct _tocEntry * next
int DumpId
Definition: pg_backup.h:226
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:577
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:17658
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static void buildMatViewRefreshDependencies ( Archive fout)
static

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

2212 {
2213  PQExpBuffer query;
2214  PGresult *res;
2215  int ntups,
2216  i;
2217  int i_classid,
2218  i_objid,
2219  i_refobjid;
2220 
2221  /* No Mat Views before 9.3. */
2222  if (fout->remoteVersion < 90300)
2223  return;
2224 
2225  /* Make sure we are in proper schema */
2226  selectSourceSchema(fout, "pg_catalog");
2227 
2228  query = createPQExpBuffer();
2229 
2230  appendPQExpBufferStr(query, "WITH RECURSIVE w AS "
2231  "( "
2232  "SELECT d1.objid, d2.refobjid, c2.relkind AS refrelkind "
2233  "FROM pg_depend d1 "
2234  "JOIN pg_class c1 ON c1.oid = d1.objid "
2235  "AND c1.relkind = " CppAsString2(RELKIND_MATVIEW)
2236  " JOIN pg_rewrite r1 ON r1.ev_class = d1.objid "
2237  "JOIN pg_depend d2 ON d2.classid = 'pg_rewrite'::regclass "
2238  "AND d2.objid = r1.oid "
2239  "AND d2.refobjid <> d1.objid "
2240  "JOIN pg_class c2 ON c2.oid = d2.refobjid "
2241  "AND c2.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2243  "WHERE d1.classid = 'pg_class'::regclass "
2244  "UNION "
2245  "SELECT w.objid, d3.refobjid, c3.relkind "
2246  "FROM w "
2247  "JOIN pg_rewrite r3 ON r3.ev_class = w.refobjid "
2248  "JOIN pg_depend d3 ON d3.classid = 'pg_rewrite'::regclass "
2249  "AND d3.objid = r3.oid "
2250  "AND d3.refobjid <> w.refobjid "
2251  "JOIN pg_class c3 ON c3.oid = d3.refobjid "
2252  "AND c3.relkind IN (" CppAsString2(RELKIND_MATVIEW) ","
2254  ") "
2255  "SELECT 'pg_class'::regclass::oid AS classid, objid, refobjid "
2256  "FROM w "
2257  "WHERE refrelkind = " CppAsString2(RELKIND_MATVIEW));
2258 
2259  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
2260 
2261  ntups = PQntuples(res);
2262 
2263  i_classid = PQfnumber(res, "classid");
2264  i_objid = PQfnumber(res, "objid");
2265  i_refobjid = PQfnumber(res, "refobjid");
2266 
2267  for (i = 0; i < ntups; i++)
2268  {
2269  CatalogId objId;
2270  CatalogId refobjId;
2271  DumpableObject *dobj;
2272  DumpableObject *refdobj;
2273  TableInfo *tbinfo;
2274  TableInfo *reftbinfo;
2275 
2276  objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
2277  objId.oid = atooid(PQgetvalue(res, i, i_objid));
2278  refobjId.tableoid = objId.tableoid;
2279  refobjId.oid = atooid(PQgetvalue(res, i, i_refobjid));
2280 
2281  dobj = findObjectByCatalogId(objId);
2282  if (dobj == NULL)
2283  continue;
2284 
2285  Assert(dobj->objType == DO_TABLE);
2286  tbinfo = (TableInfo *) dobj;
2287  Assert(tbinfo->relkind == RELKIND_MATVIEW);
2288  dobj = (DumpableObject *) tbinfo->dataObj;
2289  if (dobj == NULL)
2290  continue;
2291  Assert(dobj->objType == DO_REFRESH_MATVIEW);
2292 
2293  refdobj = findObjectByCatalogId(refobjId);
2294  if (refdobj == NULL)
2295  continue;
2296 
2297  Assert(refdobj->objType == DO_TABLE);
2298  reftbinfo = (TableInfo *) refdobj;
2299  Assert(reftbinfo->relkind == RELKIND_MATVIEW);
2300  refdobj = (DumpableObject *) reftbinfo->dataObj;
2301  if (refdobj == NULL)
2302  continue;
2303  Assert(refdobj->objType == DO_REFRESH_MATVIEW);
2304 
2305  addObjectDependency(dobj, refdobj->dumpId);
2306 
2307  if (!reftbinfo->relispopulated)
2308  tbinfo->relispopulated = false;
2309  }
2310 
2311  PQclear(res);
2312 
2313  destroyPQExpBuffer(query);
2314 }
char relkind
Definition: pg_dump.h:267
Oid tableoid
Definition: pg_backup.h:222
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:595
#define atooid(x)
Definition: postgres_ext.h:42
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17720
#define CppAsString2(x)
Definition: c.h:162
struct _tableDataInfo * dataObj
Definition: pg_dump.h:329
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:675
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:749
#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:181
static bool checkExtensionMembership ( DumpableObject dobj,
Archive fout 
)
static

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

1319 {
1320  ExtensionInfo *ext = findOwningExtension(dobj->catId);
1321 
1322  if (ext == NULL)
1323  return false;
1324 
1325  dobj->ext_member = true;
1326 
1327  /* Record dependency so that getDependencies needn't deal with that */
1328  addObjectDependency(dobj, ext->dobj.dumpId);
1329 
1330  /*
1331  * In 9.6 and above, mark the member object to have any non-initial ACL,
1332  * policies, and security labels dumped.
1333  *
1334  * Note that any initial ACLs (see pg_init_privs) will be removed when we
1335  * extract the information about the object. We don't provide support for
1336  * initial policies and security labels and it seems unlikely for those to
1337  * ever exist, but we may have to revisit this later.
1338  *
1339  * Prior to 9.6, we do not include any extension member components.
1340  *
1341  * In binary upgrades, we still dump all components of the members
1342  * individually, since the idea is to exactly reproduce the database
1343  * contents rather than replace the extension contents with something
1344  * different.
1345  */
1346  if (fout->dopt->binary_upgrade)
1347  dobj->dump = ext->dobj.dump;
1348  else
1349  {
1350  if (fout->remoteVersion < 90600)
1351  dobj->dump = DUMP_COMPONENT_NONE;
1352  else
1353  dobj->dump = ext->dobj.dump_contains & (DUMP_COMPONENT_ACL |
1356  }
1357 
1358  return true;
1359 }
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:133
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition: common.c:889
DumpOptions * dopt
Definition: pg_backup.h:176
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:749
CatalogId catId
Definition: pg_dump.h:131
#define DUMP_COMPONENT_POLICY
Definition: pg_dump.h:97
int remoteVersion
Definition: pg_backup.h:181
static int collectComments ( Archive fout,
CommentItem **  items 
)
static

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

9323 {
9324  PGresult *res;
9325  PQExpBuffer query;
9326  int i_description;
9327  int i_classoid;
9328  int i_objoid;
9329  int i_objsubid;
9330  int ntups;
9331  int i;
9332  CommentItem *comments;
9333 
9334  /*
9335  * Note we do NOT change source schema here; preserve the caller's
9336  * setting, instead.
9337  */
9338 
9339  query = createPQExpBuffer();
9340 
9341  appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
9342  "FROM pg_catalog.pg_description "
9343  "ORDER BY classoid, objoid, objsubid");
9344 
9345  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9346 
9347  /* Construct lookup table containing OIDs in numeric form */
9348 
9349  i_description = PQfnumber(res, "description");
9350  i_classoid = PQfnumber(res, "classoid");
9351  i_objoid = PQfnumber(res, "objoid");
9352  i_objsubid = PQfnumber(res, "objsubid");
9353 
9354  ntups = PQntuples(res);
9355 
9356  comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
9357 
9358  for (i = 0; i < ntups; i++)
9359  {
9360  comments[i].descr = PQgetvalue(res, i, i_description);
9361  comments[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
9362  comments[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
9363  comments[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
9364  }
9365 
9366  /* Do NOT free the PGresult since we are keeping pointers into it */
9367  destroyPQExpBuffer(query);
9368 
9369  *items = comments;
9370  return ntups;
9371 }
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 14768 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().

14769 {
14770  PGresult *res;
14771  PQExpBuffer query;
14772  int i_label;
14773  int i_provider;
14774  int i_classoid;
14775  int i_objoid;
14776  int i_objsubid;
14777  int ntups;
14778  int i;
14779  SecLabelItem *labels;
14780 
14781  query = createPQExpBuffer();
14782 
14783  appendPQExpBufferStr(query,
14784  "SELECT label, provider, classoid, objoid, objsubid "
14785  "FROM pg_catalog.pg_seclabel "
14786  "ORDER BY classoid, objoid, objsubid");
14787 
14788  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
14789 
14790  /* Construct lookup table containing OIDs in numeric form */
14791  i_label = PQfnumber(res, "label");
14792  i_provider = PQfnumber(res, "provider");
14793  i_classoid = PQfnumber(res, "classoid");
14794  i_objoid = PQfnumber(res, "objoid");
14795  i_objsubid = PQfnumber(res, "objsubid");
14796 
14797  ntups = PQntuples(res);
14798 
14799  labels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
14800 
14801  for (i = 0; i < ntups; i++)
14802  {
14803  labels[i].label = PQgetvalue(res, i, i_label);
14804  labels[i].provider = PQgetvalue(res, i, i_provider);
14805  labels[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
14806  labels[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
14807  labels[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
14808  }
14809 
14810  /* Do NOT free the PGresult since we are keeping pointers into it */
14811  destroyPQExpBuffer(query);
14812 
14813  *items = labels;
14814  return ntups;
14815 }
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 12240 of file pg_dump.c.

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

Referenced by dumpAgg(), and dumpOpr().

12241 {
12242  char *name;
12243  char *oname;
12244  char *ptr;
12245  bool inquote;
12246  bool sawdot;
12247 
12248  /* In all cases "0" means a null reference */
12249  if (strcmp(opr, "0") == 0)
12250  return NULL;
12251 
12252  name = pg_strdup(opr);
12253  /* find non-double-quoted left paren, and check for non-quoted dot */
12254  inquote = false;
12255  sawdot = false;
12256  for (ptr = name; *ptr; ptr++)
12257  {
12258  if (*ptr == '"')
12259  inquote = !inquote;
12260  else if (*ptr == '.' && !inquote)
12261  sawdot = true;
12262  else if (*ptr == '(' && !inquote)
12263  {
12264  *ptr = '\0';
12265  break;
12266  }
12267  }
12268  /* If not schema-qualified, don't need to add OPERATOR() */
12269  if (!sawdot)
12270  return name;
12271  oname = psprintf("OPERATOR(%s)", name);
12272  free(name);
12273  return oname;
12274 }
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 12204 of file pg_dump.c.

References name, NULL, and pg_strdup().

Referenced by dumpOpr().

12205 {
12206  char *name;
12207  char *paren;
12208  bool inquote;
12209 
12210  /* In all cases "-" means a null reference */
12211  if (strcmp(proc, "-") == 0)
12212  return NULL;
12213 
12214  name = pg_strdup(proc);
12215  /* find non-double-quoted left paren */
12216  inquote = false;
12217  for (paren = name; *paren; paren++)
12218  {
12219  if (*paren == '(' && !inquote)
12220  {
12221  *paren = '\0';
12222  break;
12223  }
12224  if (*paren == '"')
12225  inquote = !inquote;
12226  }
12227  return name;
12228 }
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 12285 of file pg_dump.c.

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

Referenced by dumpTSParser(), and dumpTSTemplate().

12286 {
12287  char *result;
12288  char query[128];
12289  PGresult *res;
12290 
12291  snprintf(query, sizeof(query),
12292  "SELECT '%u'::pg_catalog.regproc", funcOid);
12293  res = ExecuteSqlQueryForSingleRow(fout, query);
12294 
12295  result = pg_strdup(PQgetvalue(res, 0, 0));
12296 
12297  PQclear(res);
12298 
12299  return result;
12300 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
return result
Definition: formatting.c:1618
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 17474 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().

17475 {
17476  DumpableObject *dobjs;
17477 
17478  dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject));
17479 
17480  dobjs[0].objType = DO_PRE_DATA_BOUNDARY;
17481  dobjs[0].catId = nilCatalogId;
17482  AssignDumpId(dobjs + 0);
17483  dobjs[0].name = pg_strdup("PRE-DATA BOUNDARY");
17484 
17485  dobjs[1].objType = DO_POST_DATA_BOUNDARY;
17486  dobjs[1].catId = nilCatalogId;
17487  AssignDumpId(dobjs + 1);
17488  dobjs[1].name = pg_strdup("POST-DATA BOUNDARY");
17489 
17490  return dobjs;
17491 }
char * name
Definition: pg_dump.h:133
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
CatalogId catId
Definition: pg_dump.h:131
static const CatalogId nilCatalogId
Definition: pg_dump.c:133
DumpableObjectType objType
Definition: pg_dump.h:130
static PQExpBuffer createDummyViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

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

15007 {
15009  int j;
15010 
15011  appendPQExpBufferStr(result, "SELECT");
15012 
15013  for (j = 0; j < tbinfo->numatts; j++)
15014  {
15015  if (j > 0)
15016  appendPQExpBufferChar(result, ',');
15017  appendPQExpBufferStr(result, "\n ");
15018 
15019  appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]);
15020 
15021  /*
15022  * Must add collation if not default for the type, because CREATE OR
15023  * REPLACE VIEW won't change it
15024  */
15025  if (OidIsValid(tbinfo->attcollation[j]))
15026  {
15027  CollInfo *coll;
15028 
15029  coll = findCollationByOid(tbinfo->attcollation[j]);
15030  if (coll)
15031  {
15032  /* always schema-qualify, don't try to be smart */
15033  appendPQExpBuffer(result, " COLLATE %s.",
15034  fmtId(coll->dobj.namespace->dobj.name));
15035  appendPQExpBufferStr(result, fmtId(coll->dobj.name));
15036  }
15037  }
15038 
15039  appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j]));
15040  }
15041 
15042  return result;
15043 }
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:1618
char ** atttypnames
Definition: pg_dump.h:304
char ** attnames
Definition: pg_dump.h:303
#define OidIsValid(objectId)
Definition: c.h:538
DumpableObject dobj
Definition: pg_dump.h:246
Oid * attcollation
Definition: pg_dump.h:315
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
int numatts
Definition: pg_dump.h:302
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:840
static PQExpBuffer createViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

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

14958 {
14959  PQExpBuffer query = createPQExpBuffer();
14961  PGresult *res;
14962  int len;
14963 
14964  /* Fetch the view definition */
14965  appendPQExpBuffer(query,
14966  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
14967  tbinfo->dobj.catId.oid);
14968 
14969  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
14970 
14971  if (PQntuples(res) != 1)
14972  {
14973  if (PQntuples(res) < 1)
14974  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned no data\n",
14975  tbinfo->dobj.name);
14976  else
14977  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned more than one definition\n",
14978  tbinfo->dobj.name);
14979  }
14980 
14981  len = PQgetlength(res, 0, 0);
14982 
14983  if (len == 0)
14984  exit_horribly(NULL, "definition of view \"%s\" appears to be empty (length zero)\n",
14985  tbinfo->dobj.name);
14986 
14987  /* Strip off the trailing semicolon so that other things may follow. */
14988  Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
14989  appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
14990 
14991  PQclear(res);
14992  destroyPQExpBuffer(query);
14993 
14994  return result;
14995 }
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:1618
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:675
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 12307 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().

12308 {
12309  DumpOptions *dopt = fout->dopt;
12310  PQExpBuffer q;
12311  PQExpBuffer delq;
12312  PQExpBuffer labelq;
12313  char *qamname;
12314 
12315  /* Skip if not to be dumped */
12316  if (!aminfo->dobj.dump || dopt->dataOnly)
12317  return;
12318 
12319  q = createPQExpBuffer();
12320  delq = createPQExpBuffer();
12321  labelq = createPQExpBuffer();
12322 
12323  qamname = pg_strdup(fmtId(aminfo->dobj.name));
12324 
12325  appendPQExpBuffer(q, "CREATE ACCESS METHOD %s ", qamname);
12326 
12327  switch (aminfo->amtype)
12328  {
12329  case AMTYPE_INDEX:
12330  appendPQExpBuffer(q, "TYPE INDEX ");
12331  break;
12332  default:
12333  write_msg(NULL, "WARNING: invalid type \"%c\" of access method \"%s\"\n",
12334  aminfo->amtype, qamname);
12335  pg_free(qamname);
12336  destroyPQExpBuffer(q);
12337  destroyPQExpBuffer(delq);
12338  destroyPQExpBuffer(labelq);
12339  return;
12340  }
12341 
12342  appendPQExpBuffer(q, "HANDLER %s;\n", aminfo->amhandler);
12343 
12344  appendPQExpBuffer(delq, "DROP ACCESS METHOD %s;\n",
12345  qamname);
12346 
12347  appendPQExpBuffer(labelq, "ACCESS METHOD %s",
12348  qamname);
12349 
12350  if (dopt->binary_upgrade)
12351  binary_upgrade_extension_member(q, &aminfo->dobj, labelq->data);
12352 
12353  if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
12354  ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
12355  aminfo->dobj.name,
12356  NULL,
12357  NULL,
12358  "",
12359  false, "ACCESS METHOD", SECTION_PRE_DATA,
12360  q->data, delq->data, NULL,
12361  NULL, 0,
12362  NULL, NULL);
12363 
12364  /* Dump Access Method Comments */
12365  if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT)
12366  dumpComment(fout, labelq->data,
12367  NULL, "",
12368  aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
12369 
12370  pg_free(qamname);
12371 
12372  destroyPQExpBuffer(q);
12373  destroyPQExpBuffer(delq);
12374  destroyPQExpBuffer(labelq);
12375 }
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:133
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9083
DumpOptions * dopt
Definition: pg_backup.h:176
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
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:4006
#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 14458 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().

14463 {
14464  DumpOptions *dopt = fout->dopt;
14465  PQExpBuffer sql;
14466 
14467  /* Do nothing if ACL dump is not enabled */
14468  if (dopt->aclsSkip)
14469  return;
14470 
14471  /* --data-only skips ACLs *except* BLOB ACLs */
14472  if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
14473  return;
14474 
14475  sql = createPQExpBuffer();
14476 
14477  /*
14478  * Check to see if this object has had any initial ACLs included for it.
14479  * If so, we are in binary upgrade mode and these are the ACLs to turn
14480  * into GRANT and REVOKE statements to set and record the initial
14481  * privileges for an extension object. Let the backend know that these
14482  * are to be recorded by calling binary_upgrade_set_record_init_privs()
14483  * before and after.
14484  */
14485  if (strlen(initacls) != 0 || strlen(initracls) != 0)
14486  {
14487  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
14488  if (!buildACLCommands(name, subname, type, initacls, initracls, owner,
14489  "", fout->remoteVersion, sql))
14491  "could not parse initial GRANT ACL list (%s) or initial REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14492  initacls, initracls, name, type);
14493  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
14494  }
14495 
14496  if (!buildACLCommands(name, subname, type, acls, racls, owner,
14497  "", fout->remoteVersion, sql))
14499  "could not parse GRANT ACL list (%s) or REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14500  acls, racls, name, type);
14501 
14502  if (sql->len > 0)
14504  tag, nspname,
14505  NULL,
14506  owner ? owner : "",
14507  false, "ACL", SECTION_NONE,
14508  sql->data, "", NULL,
14509  &(objDumpId), 1,
14510  NULL, NULL);
14511 
14512  destroyPQExpBuffer(sql);
14513 }
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpOptions * dopt
Definition: pg_backup.h:176
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
bool aclsSkip
Definition: pg_backup.h:139
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:133
DumpId createDumpId(void)
Definition: common.c:557
int remoteVersion
Definition: pg_backup.h:181
static void dumpAgg ( Archive fout,
AggInfo agginfo 
)
static

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

13313 {
13314  DumpOptions *dopt = fout->dopt;
13315  PQExpBuffer query;
13316  PQExpBuffer q;
13317  PQExpBuffer delq;
13318  PQExpBuffer labelq;
13319  PQExpBuffer details;
13320  char *aggsig; /* identity signature */
13321  char *aggfullsig = NULL; /* full signature */
13322  char *aggsig_tag;
13323  PGresult *res;
13324  int i_aggtransfn;
13325  int i_aggfinalfn;
13326  int i_aggcombinefn;
13327  int i_aggserialfn;
13328  int i_aggdeserialfn;
13329  int i_aggmtransfn;
13330  int i_aggminvtransfn;
13331  int i_aggmfinalfn;
13332  int i_aggfinalextra;
13333  int i_aggmfinalextra;
13334  int i_aggsortop;
13335  int i_hypothetical;
13336  int i_aggtranstype;
13337  int i_aggtransspace;
13338  int i_aggmtranstype;
13339  int i_aggmtransspace;
13340  int i_agginitval;
13341  int i_aggminitval;
13342  int i_convertok;
13343  int i_proparallel;
13344  const char *aggtransfn;
13345  const char *aggfinalfn;
13346  const char *aggcombinefn;
13347  const char *aggserialfn;
13348  const char *aggdeserialfn;
13349  const char *aggmtransfn;
13350  const char *aggminvtransfn;
13351  const char *aggmfinalfn;
13352  bool aggfinalextra;
13353  bool aggmfinalextra;
13354  const char *aggsortop;
13355  char *aggsortconvop;
13356  bool hypothetical;
13357  const char *aggtranstype;
13358  const char *aggtransspace;
13359  const char *aggmtranstype;
13360  const char *aggmtransspace;
13361  const char *agginitval;
13362  const char *aggminitval;
13363  bool convertok;
13364  const char *proparallel;
13365 
13366  /* Skip if not to be dumped */
13367  if (!agginfo->aggfn.dobj.dump || dopt->dataOnly)
13368  return;
13369 
13370  query = createPQExpBuffer();
13371  q = createPQExpBuffer();
13372  delq = createPQExpBuffer();
13373  labelq = createPQExpBuffer();
13374  details = createPQExpBuffer();
13375 
13376  /* Make sure we are in proper schema */
13377  selectSourceSchema(fout, agginfo->aggfn.dobj.namespace->dobj.name);
13378 
13379  /* Get aggregate-specific details */
13380  if (fout->remoteVersion >= 90600)
13381  {
13382  appendPQExpBuffer(query, "SELECT aggtransfn, "
13383  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13384  "aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, "
13385  "aggminvtransfn, aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13386  "aggfinalextra, aggmfinalextra, "
13387  "aggsortop::pg_catalog.regoperator, "
13388  "(aggkind = 'h') AS hypothetical, "
13389  "aggtransspace, agginitval, "
13390  "aggmtransspace, aggminitval, "
13391  "true AS convertok, "
13392  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13393  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, "
13394  "p.proparallel "
13395  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13396  "WHERE a.aggfnoid = p.oid "
13397  "AND p.oid = '%u'::pg_catalog.oid",
13398  agginfo->aggfn.dobj.catId.oid);
13399  }
13400  else if (fout->remoteVersion >= 90400)
13401  {
13402  appendPQExpBuffer(query, "SELECT aggtransfn, "
13403  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13404  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13405  "'-' AS aggdeserialfn, aggmtransfn, aggminvtransfn, "
13406  "aggmfinalfn, aggmtranstype::pg_catalog.regtype, "
13407  "aggfinalextra, aggmfinalextra, "
13408  "aggsortop::pg_catalog.regoperator, "
13409  "(aggkind = 'h') AS hypothetical, "
13410  "aggtransspace, agginitval, "
13411  "aggmtransspace, aggminitval, "
13412  "true AS convertok, "
13413  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13414  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13415  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13416  "WHERE a.aggfnoid = p.oid "
13417  "AND p.oid = '%u'::pg_catalog.oid",
13418  agginfo->aggfn.dobj.catId.oid);
13419  }
13420  else if (fout->remoteVersion >= 80400)
13421  {
13422  appendPQExpBuffer(query, "SELECT aggtransfn, "
13423  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13424  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13425  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13426  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13427  "0 AS aggmtranstype, false AS aggfinalextra, "
13428  "false AS aggmfinalextra, "
13429  "aggsortop::pg_catalog.regoperator, "
13430  "false AS hypothetical, "
13431  "0 AS aggtransspace, agginitval, "
13432  "0 AS aggmtransspace, NULL AS aggminitval, "
13433  "true AS convertok, "
13434  "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, "
13435  "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs "
13436  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13437  "WHERE a.aggfnoid = p.oid "
13438  "AND p.oid = '%u'::pg_catalog.oid",
13439  agginfo->aggfn.dobj.catId.oid);
13440  }
13441  else if (fout->remoteVersion >= 80100)
13442  {
13443  appendPQExpBuffer(query, "SELECT aggtransfn, "
13444  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13445  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13446  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13447  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13448  "0 AS aggmtranstype, false AS aggfinalextra, "
13449  "false AS aggmfinalextra, "
13450  "aggsortop::pg_catalog.regoperator, "
13451  "false AS hypothetical, "
13452  "0 AS aggtransspace, agginitval, "
13453  "0 AS aggmtransspace, NULL AS aggminitval, "
13454  "true AS convertok "
13455  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13456  "WHERE a.aggfnoid = p.oid "
13457  "AND p.oid = '%u'::pg_catalog.oid",
13458  agginfo->aggfn.dobj.catId.oid);
13459  }
13460  else
13461  {
13462  appendPQExpBuffer(query, "SELECT aggtransfn, "
13463  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
13464  "'-' AS aggcombinefn, '-' AS aggserialfn, "
13465  "'-' AS aggdeserialfn, '-' AS aggmtransfn, "
13466  "'-' AS aggminvtransfn, '-' AS aggmfinalfn, "
13467  "0 AS aggmtranstype, false AS aggfinalextra, "
13468  "false AS aggmfinalextra, 0 AS aggsortop, "
13469  "false AS hypothetical, "
13470  "0 AS aggtransspace, agginitval, "
13471  "0 AS aggmtransspace, NULL AS aggminitval, "
13472  "true AS convertok "
13473  "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
13474  "WHERE a.aggfnoid = p.oid "
13475  "AND p.oid = '%u'::pg_catalog.oid",
13476  agginfo->aggfn.dobj.catId.oid);
13477  }
13478 
13479  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13480 
13481  i_aggtransfn = PQfnumber(res, "aggtransfn");
13482  i_aggfinalfn = PQfnumber(res, "aggfinalfn");
13483  i_aggcombinefn = PQfnumber(res, "aggcombinefn");
13484  i_aggserialfn = PQfnumber(res, "aggserialfn");
13485  i_aggdeserialfn = PQfnumber(res, "aggdeserialfn");
13486  i_aggmtransfn = PQfnumber(res, "aggmtransfn");
13487  i_aggminvtransfn = PQfnumber(res, "aggminvtransfn");
13488  i_aggmfinalfn = PQfnumber(res, "aggmfinalfn");
13489  i_aggfinalextra = PQfnumber(res, "aggfinalextra");
13490  i_aggmfinalextra = PQfnumber(res, "aggmfinalextra");
13491  i_aggsortop = PQfnumber(res, "aggsortop");
13492  i_hypothetical = PQfnumber(res, "hypothetical");
13493  i_aggtranstype = PQfnumber(res, "aggtranstype");
13494  i_aggtransspace = PQfnumber(res, "aggtransspace");
13495  i_aggmtranstype = PQfnumber(res, "aggmtranstype");
13496  i_aggmtransspace = PQfnumber(res, "aggmtransspace");
13497  i_agginitval = PQfnumber(res, "agginitval");
13498  i_aggminitval = PQfnumber(res, "aggminitval");
13499  i_convertok = PQfnumber(res, "convertok");
13500  i_proparallel = PQfnumber(res, "proparallel");
13501 
13502  aggtransfn = PQgetvalue(res, 0, i_aggtransfn);
13503  aggfinalfn = PQgetvalue(res, 0, i_aggfinalfn);
13504  aggcombinefn = PQgetvalue(res, 0, i_aggcombinefn);
13505  aggserialfn = PQgetvalue(res, 0, i_aggserialfn);
13506  aggdeserialfn = PQgetvalue(res, 0, i_aggdeserialfn);
13507  aggmtransfn = PQgetvalue(res, 0, i_aggmtransfn);
13508  aggminvtransfn = PQgetvalue(res, 0, i_aggminvtransfn);
13509  aggmfinalfn = PQgetvalue(res, 0, i_aggmfinalfn);
13510  aggfinalextra = (PQgetvalue(res, 0, i_aggfinalextra)[0] == 't');
13511  aggmfinalextra = (PQgetvalue(res, 0, i_aggmfinalextra)[0] == 't');
13512  aggsortop = PQgetvalue(res, 0, i_aggsortop);
13513  hypothetical = (PQgetvalue(res, 0, i_hypothetical)[0] == 't');
13514  aggtranstype = PQgetvalue(res, 0, i_aggtranstype);
13515  aggtransspace = PQgetvalue(res, 0, i_aggtransspace);
13516  aggmtranstype = PQgetvalue(res, 0, i_aggmtranstype);
13517  aggmtransspace = PQgetvalue(res, 0, i_aggmtransspace);
13518  agginitval = PQgetvalue(res, 0, i_agginitval);
13519  aggminitval = PQgetvalue(res, 0, i_aggminitval);
13520  convertok = (PQgetvalue(res, 0, i_convertok)[0] == 't');
13521 
13522  if (fout->remoteVersion >= 80400)
13523  {
13524  /* 8.4 or later; we rely on server-side code for most of the work */
13525  char *funcargs;
13526  char *funciargs;
13527 
13528  funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs"));
13529  funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs"));
13530  aggfullsig = format_function_arguments(&agginfo->aggfn, funcargs, true);
13531  aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true);
13532  }
13533  else
13534  /* pre-8.4, do it ourselves */
13535  aggsig = format_aggregate_signature(agginfo, fout, true);
13536 
13537  aggsig_tag = format_aggregate_signature(agginfo, fout, false);
13538 
13539  if (i_proparallel != -1)
13540  proparallel = PQgetvalue(res, 0, PQfnumber(res, "proparallel"));
13541  else
13542  proparallel = NULL;
13543 
13544  if (!convertok)
13545  {
13546  write_msg(NULL, "WARNING: aggregate function %s could not be dumped correctly for this database version; ignored\n",
13547  aggsig);
13548 
13549  if (aggfullsig)
13550  free(aggfullsig);
13551 
13552  free(aggsig);
13553 
13554  return;
13555  }
13556 
13557  /* regproc and regtype output is already sufficiently quoted */
13558  appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
13559  aggtransfn, aggtranstype);
13560 
13561  if (strcmp(aggtransspace, "0") != 0)
13562  {
13563  appendPQExpBuffer(details, ",\n SSPACE = %s",
13564  aggtransspace);
13565  }
13566 
13567  if (!PQgetisnull(res, 0, i_agginitval))
13568  {
13569  appendPQExpBufferStr(details, ",\n INITCOND = ");
13570  appendStringLiteralAH(details, agginitval, fout);
13571  }
13572 
13573  if (strcmp(aggfinalfn, "-") != 0)
13574  {
13575  appendPQExpBuffer(details, ",\n FINALFUNC = %s",
13576  aggfinalfn);
13577  if (aggfinalextra)
13578  appendPQExpBufferStr(details, ",\n FINALFUNC_EXTRA");
13579  }
13580 
13581  if (strcmp(aggcombinefn, "-") != 0)
13582  appendPQExpBuffer(details, ",\n COMBINEFUNC = %s", aggcombinefn);
13583 
13584  if (strcmp(aggserialfn, "-") != 0)
13585  appendPQExpBuffer(details, ",\n SERIALFUNC = %s", aggserialfn);
13586 
13587  if (strcmp(aggdeserialfn, "-") != 0)
13588  appendPQExpBuffer(details, ",\n DESERIALFUNC = %s", aggdeserialfn);
13589 
13590  if (strcmp(aggmtransfn, "-") != 0)
13591  {
13592  appendPQExpBuffer(details, ",\n MSFUNC = %s,\n MINVFUNC = %s,\n MSTYPE = %s",
13593  aggmtransfn,
13594  aggminvtransfn,
13595  aggmtranstype);
13596  }
13597 
13598  if (strcmp(aggmtransspace, "0") != 0)
13599  {
13600  appendPQExpBuffer(details, ",\n MSSPACE = %s",
13601  aggmtransspace);
13602  }
13603 
13604  if (!PQgetisnull(res, 0, i_aggminitval))
13605  {
13606  appendPQExpBufferStr(details, ",\n MINITCOND = ");
13607  appendStringLiteralAH(details, aggminitval, fout);
13608  }
13609 
13610  if (strcmp(aggmfinalfn, "-") != 0)
13611  {
13612  appendPQExpBuffer(details, ",\n MFINALFUNC = %s",
13613  aggmfinalfn);
13614  if (aggmfinalextra)
13615  appendPQExpBufferStr(details, ",\n MFINALFUNC_EXTRA");
13616  }
13617 
13618  aggsortconvop = convertOperatorReference(fout, aggsortop);
13619  if (aggsortconvop)
13620  {
13621  appendPQExpBuffer(details, ",\n SORTOP = %s",
13622  aggsortconvop);
13623  free(aggsortconvop);
13624  }
13625 
13626  if (hypothetical)
13627  appendPQExpBufferStr(details, ",\n HYPOTHETICAL");
13628 
13629  if (proparallel != NULL && proparallel[0] != PROPARALLEL_UNSAFE)
13630  {
13631  if (proparallel[0] == PROPARALLEL_SAFE)
13632  appendPQExpBufferStr(details, ",\n PARALLEL = safe");
13633  else if (proparallel[0] == PROPARALLEL_RESTRICTED)
13634  appendPQExpBufferStr(details, ",\n PARALLEL = restricted");
13635  else if (proparallel[0] != PROPARALLEL_UNSAFE)
13636  exit_horribly(NULL, "unrecognized proparallel value for function \"%s\"\n",
13637  agginfo->aggfn.dobj.name);
13638  }
13639 
13640  /*
13641  * DROP must be fully qualified in case same name appears in pg_catalog
13642  */
13643  appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n",
13644  fmtId(agginfo->aggfn.dobj.namespace->dobj.name),
13645  aggsig);
13646 
13647  appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n",
13648  aggfullsig ? aggfullsig : aggsig, details->data);
13649 
13650  appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig);
13651 
13652  if (dopt->binary_upgrade)
13653  binary_upgrade_extension_member(q, &agginfo->aggfn.dobj, labelq->data);
13654 
13655  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_DEFINITION)
13656  ArchiveEntry(fout, agginfo->aggfn.dobj.catId,
13657  agginfo->aggfn.dobj.dumpId,
13658  aggsig_tag,
13659  agginfo->aggfn.dobj.namespace->dobj.name,
13660  NULL,
13661  agginfo->aggfn.rolname,
13662  false, "AGGREGATE", SECTION_PRE_DATA,
13663  q->data, delq->data, NULL,
13664  NULL, 0,
13665  NULL, NULL);
13666 
13667  /* Dump Aggregate Comments */
13668  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_COMMENT)
13669  dumpComment(fout, labelq->data,
13670  agginfo->aggfn.dobj.namespace->dobj.name,
13671  agginfo->aggfn.rolname,
13672  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13673 
13674  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_SECLABEL)
13675  dumpSecLabel(fout, labelq->data,
13676  agginfo->aggfn.dobj.namespace->dobj.name,
13677  agginfo->aggfn.rolname,
13678  agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
13679 
13680  /*
13681  * Since there is no GRANT ON AGGREGATE syntax, we have to make the ACL
13682  * command look like a function's GRANT; in particular this affects the
13683  * syntax for zero-argument aggregates and ordered-set aggregates.
13684  */
13685  free(aggsig);
13686  free(aggsig_tag);
13687 
13688  aggsig = format_function_signature(fout, &agginfo->aggfn, true);
13689  aggsig_tag = format_function_signature(fout, &agginfo->aggfn, false);
13690 
13691  if (agginfo->aggfn.dobj.dump & DUMP_COMPONENT_ACL)
13692  dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
13693  "FUNCTION",
13694  aggsig, NULL, aggsig_tag,
13695  agginfo->aggfn.dobj.namespace->dobj.name,
13696  agginfo->aggfn.rolname, agginfo->aggfn.proacl,
13697  agginfo->aggfn.rproacl,
13698  agginfo->aggfn.initproacl, agginfo->aggfn.initrproacl);
13699 
13700  free(aggsig);
13701  if (aggfullsig)
13702  free(aggfullsig);
13703  free(aggsig_tag);
13704 
13705  PQclear(res);
13706 
13707  destroyPQExpBuffer(query);
13708  destroyPQExpBuffer(q);
13709  destroyPQExpBuffer(delq);
13710  destroyPQExpBuffer(labelq);
13711  destroyPQExpBuffer(details);
13712 }
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:12240
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:5489
DumpId dumpId
Definition: pg_dump.h:132
static char * format_function_arguments(FuncInfo *finfo, char *funcargs, bool is_agg)
Definition: pg_dump.c:11111
FuncInfo aggfn
Definition: pg_dump.h:213
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:133
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9083
DumpOptions * dopt
Definition: pg_backup.h:176
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
static void dumpSecLabel(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:14534
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5488
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17720
#define PROPARALLEL_UNSAFE
Definition: pg_proc.h:5490
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:4006
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:295
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:14458
static char * format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
Definition: pg_dump.c:11206
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:13274
int remoteVersion
Definition: pg_backup.h:181
static void dumpAttrDef ( Archive fout,
AttrDefInfo adinfo 
)
static

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

15752 {
15753  DumpOptions *dopt = fout->dopt;
15754  TableInfo *tbinfo = adinfo->adtable;
15755  int adnum = adinfo->adnum;
15756  PQExpBuffer q;
15757  PQExpBuffer delq;
15758  char *tag;
15759 
15760  /* Skip if table definition not to be dumped */
15761  if (!tbinfo->dobj.dump || dopt->dataOnly)
15762  return;
15763 
15764  /* Skip if not "separate"; it was dumped in the table's definition */
15765  if (!adinfo->separate)
15766  return;
15767 
15768  q = createPQExpBuffer();
15769  delq = createPQExpBuffer();
15770 
15771  appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
15772  fmtId(tbinfo->dobj.name));
15773  appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n",
15774  fmtId(tbinfo->attnames[adnum - 1]),
15775  adinfo->adef_expr);
15776 
15777  /*
15778  * DROP must be fully qualified in case same name appears in pg_catalog
15779  */
15780  appendPQExpBuffer(delq, "ALTER TABLE %s.",
15781  fmtId(tbinfo->dobj.namespace->dobj.name));
15782  appendPQExpBuffer(delq, "%s ",
15783  fmtId(tbinfo->dobj.name));
15784  appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n",
15785  fmtId(tbinfo->attnames[adnum - 1]));
15786 
15787  tag = psprintf("%s %s", tbinfo->dobj.name, tbinfo->attnames[adnum - 1]);
15788 
15789  if (adinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
15790  ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
15791  tag,
15792  tbinfo->dobj.namespace->dobj.name,
15793  NULL,
15794  tbinfo->rolname,
15795  false, "DEFAULT", SECTION_PRE_DATA,
15796  q->data, delq->data, NULL,
15797  NULL, 0,
15798  NULL, NULL);
15799 
15800  free(tag);
15801  destroyPQExpBuffer(q);
15802  destroyPQExpBuffer(delq);
15803 }
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:303
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:176
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
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 10100 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().

10101 {
10102  DumpOptions *dopt = fout->dopt;
10104  PQExpBuffer delq = createPQExpBuffer();
10105  PQExpBuffer labelq = createPQExpBuffer();
10106  PQExpBuffer query = createPQExpBuffer();
10107  PGresult *res;
10108  char *qtypname;
10109  char *typlen;
10110  char *typinput;
10111  char *typoutput;
10112  char *typreceive;
10113  char *typsend;
10114  char *typmodin;
10115  char *typmodout;
10116  char *typanalyze;
10117  Oid typreceiveoid;
10118  Oid typsendoid;
10119  Oid typmodinoid;
10120  Oid typmodoutoid;
10121  Oid typanalyzeoid;
10122  char *typcategory;
10123  char *typispreferred;
10124  char *typdelim;
10125  char *typbyval;
10126  char *typalign;
10127  char *typstorage;
10128  char *typcollatable;
10129  char *typdefault;
10130  bool typdefault_is_literal = false;
10131 
10132  /* Set proper schema search path so regproc references list correctly */
10133  selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
10134 
10135  /* Fetch type-specific details */
10136  if (fout->remoteVersion >= 90100)
10137  {
10138  appendPQExpBuffer(query, "SELECT typlen, "
10139  "typinput, typoutput, typreceive, typsend, "
10140  "typmodin, typmodout, typanalyze, "
10141  "typreceive::pg_catalog.oid AS typreceiveoid, "
10142  "typsend::pg_catalog.oid AS typsendoid, "
10143  "typmodin::pg_catalog.oid AS typmodinoid, "
10144  "typmodout::pg_catalog.oid AS typmodoutoid, "
10145  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10146  "typcategory, typispreferred, "
10147  "typdelim, typbyval, typalign, typstorage, "
10148  "(typcollation <> 0) AS typcollatable, "
10149  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10150  "FROM pg_catalog.pg_type "
10151  "WHERE oid = '%u'::pg_catalog.oid",
10152  tyinfo->dobj.catId.oid);
10153  }
10154  else if (fout->remoteVersion >= 80400)
10155  {
10156  appendPQExpBuffer(query, "SELECT typlen, "
10157  "typinput, typoutput, typreceive, typsend, "
10158  "typmodin, typmodout, typanalyze, "
10159  "typreceive::pg_catalog.oid AS typreceiveoid, "
10160  "typsend::pg_catalog.oid AS typsendoid, "
10161  "typmodin::pg_catalog.oid AS typmodinoid, "
10162  "typmodout::pg_catalog.oid AS typmodoutoid, "
10163  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10164  "typcategory, typispreferred, "
10165  "typdelim, typbyval, typalign, typstorage, "
10166  "false AS typcollatable, "
10167  "pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault "
10168  "FROM pg_catalog.pg_type "
10169  "WHERE oid = '%u'::pg_catalog.oid",
10170  tyinfo->dobj.catId.oid);
10171  }
10172  else if (fout->remoteVersion >= 80300)
10173  {
10174  /* Before 8.4, pg_get_expr does not allow 0 for its second arg */
10175  appendPQExpBuffer(query, "SELECT typlen, "
10176  "typinput, typoutput, typreceive, typsend, "
10177  "typmodin, typmodout, typanalyze, "
10178  "typreceive::pg_catalog.oid AS typreceiveoid, "
10179  "typsend::pg_catalog.oid AS typsendoid, "
10180  "typmodin::pg_catalog.oid AS typmodinoid, "
10181  "typmodout::pg_catalog.oid AS typmodoutoid, "
10182  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10183  "'U' AS typcategory, false AS typispreferred, "
10184  "typdelim, typbyval, typalign, typstorage, "
10185  "false AS typcollatable, "
10186  "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10187  "FROM pg_catalog.pg_type "
10188  "WHERE oid = '%u'::pg_catalog.oid",
10189  tyinfo->dobj.catId.oid);
10190  }
10191  else
10192  {
10193  appendPQExpBuffer(query, "SELECT typlen, "
10194  "typinput, typoutput, typreceive, typsend, "
10195  "'-' AS typmodin, '-' AS typmodout, "
10196  "typanalyze, "
10197  "typreceive::pg_catalog.oid AS typreceiveoid, "
10198  "typsend::pg_catalog.oid AS typsendoid, "
10199  "0 AS typmodinoid, 0 AS typmodoutoid, "
10200  "typanalyze::pg_catalog.oid AS typanalyzeoid, "
10201  "'U' AS typcategory, false AS typispreferred, "
10202  "typdelim, typbyval, typalign, typstorage, "
10203  "false AS typcollatable, "
10204  "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault "
10205  "FROM pg_catalog.pg_type "
10206  "WHERE oid = '%u'::pg_catalog.oid",
10207  tyinfo->dobj.catId.oid);
10208  }
10209 
10210  res = ExecuteSqlQueryForSingleRow(fout, query->data);
10211 
10212  typlen = PQgetvalue(res, 0, PQfnumber(res, "typlen"));
10213  typinput = PQgetvalue(res, 0, PQfnumber(res, "typinput"));
10214  typoutput = PQgetvalue(res, 0, PQfnumber(res, "typoutput"));
10215  typreceive = PQgetvalue(res, 0, PQfnumber(res, "typreceive"));
10216  typsend = PQgetvalue(res, 0, PQfnumber(res, "typsend"));
10217  typmodin = PQgetvalue(res, 0, PQfnumber(res, "typmodin"));
10218  typmodout = PQgetvalue(res, 0, PQfnumber(res, "typmodout"));
10219  typanalyze = PQgetvalue(res, 0, PQfnumber(res, "typanalyze"));
10220  typreceiveoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typreceiveoid")));
10221  typsendoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typsendoid")));
10222  typmodinoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodinoid")));
10223  typmodoutoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typmodoutoid")));
10224  typanalyzeoid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typanalyzeoid")));
10225  typcategory = PQgetvalue(res, 0, PQfnumber(res, "typcategory"));
10226  typispreferred = PQgetvalue(res, 0, PQfnumber(res, "typispreferred"));
10227  typdelim = PQgetvalue(res, 0, PQfnumber(res, "typdelim"));
10228  typbyval = PQgetvalue(res, 0, PQfnumber(res, "typbyval"));
10229  typalign = PQgetvalue(res, 0, PQfnumber(res, "typalign"));
10230  typstorage = PQgetvalue(res, 0, PQfnumber(res, "typstorage"));
10231  typcollatable = PQgetvalue(res, 0, PQfnumber(res, "typcollatable"));
10232  if (!PQgetisnull(res, 0, PQfnumber(res, "typdefaultbin")))
10233  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefaultbin"));
10234  else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault")))
10235  {
10236  typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault"));
10237  typdefault_is_literal = true; /* it needs quotes */
10238  }
10239  else
10240  typdefault = NULL;
10241 
10242  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
10243 
10244  /*
10245  * DROP must be fully qualified in case same name appears in pg_catalog.
10246  * The reason we include CASCADE is that the circular dependency between
10247  * the type and its I/O functions makes it impossible to drop the type any
10248  * other way.
10249  */
10250  appendPQExpBuffer(delq, "DROP TYPE %s.",
10251  fmtId(tyinfo->dobj.namespace->dobj.name));
10252  appendPQExpBuffer(delq, "%s CASCADE;\n",
10253  qtypname);
10254 
10255  /* We might already have a shell type, but setting pg_type_oid is harmless */
10256  if (dopt->binary_upgrade)
10258  tyinfo->dobj.catId.oid);
10259 
10261  "CREATE TYPE %s (\n"
10262  " INTERNALLENGTH = %s",
10263  qtypname,
10264  (strcmp(typlen, "-1") == 0) ? "variable" : typlen);
10265 
10266  /* regproc result is sufficiently quoted already */
10267  appendPQExpBuffer(q, ",\n INPUT = %s", typinput);
10268  appendPQExpBuffer(q, ",\n OUTPUT = %s", typoutput);
10269  if (OidIsValid(typreceiveoid))
10270  appendPQExpBuffer(q, ",\n RECEIVE = %s", typreceive);
10271  if (OidIsValid(typsendoid))
10272  appendPQExpBuffer(q, ",\n SEND = %s", typsend);
10273  if (OidIsValid(typmodinoid))
10274  appendPQExpBuffer(q, ",\n TYPMOD_IN = %s", typmodin);
10275  if (OidIsValid(typmodoutoid))
10276  appendPQExpBuffer(q, ",\n TYPMOD_OUT = %s", typmodout);
10277  if (OidIsValid(typanalyzeoid))
10278  appendPQExpBuffer(q, ",\n ANALYZE = %s", typanalyze);
10279 
10280  if (strcmp(typcollatable, "t") == 0)
10281  appendPQExpBufferStr(q, ",\n COLLATABLE = true");
10282 
10283  if (typdefault != NULL)
10284  {
10285  appendPQExpBufferStr(q, ",\n DEFAULT = ");
10286  if (typdefault_is_literal)
10287  appendStringLiteralAH(q, typdefault, fout);
10288  else
10289  appendPQExpBufferStr(q, typdefault);
10290  }
10291 
10292  if (OidIsValid(tyinfo->typelem))
10293  {
10294  char *elemType;
10295 
10296  /* reselect schema in case changed by function dump */
10297  selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
10298  elemType = getFormattedTypeName(fout, tyinfo->typelem, zeroAsOpaque);
10299  appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType);
10300  free(elemType);
10301  }
10302 
10303  if (strcmp(typcategory, "U") != 0)
10304  {
10305  appendPQExpBufferStr(q, ",\n CATEGORY = ");
10306  appendStringLiteralAH(q, typcategory, fout);
10307  }
10308 
10309  if (strcmp(typispreferred, "t") == 0)
10310  appendPQExpBufferStr(q, ",\n PREFERRED = true");
10311 
10312  if (typdelim && strcmp(typdelim, ",") != 0)
10313  {
10314  appendPQExpBufferStr(q, ",\n DELIMITER = ");
10315  appendStringLiteralAH(q, typdelim, fout);
10316  }
10317 
10318  if (strcmp(typalign, "c") == 0)
10319  appendPQExpBufferStr(q, ",\n ALIGNMENT = char");
10320  else if (strcmp(typalign, "s") == 0)
10321  appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
10322  else if (strcmp(typalign, "i") == 0)
10323  appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
10324  else if (strcmp(typalign, "d") == 0)
10325  appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
10326 
10327  if (strcmp(typstorage, "p") == 0)
10328  appendPQExpBufferStr(q, ",\n STORAGE = plain");
10329  else if (strcmp(typstorage, "e") == 0)
10330  appendPQExpBufferStr(q, ",\n STORAGE = external");
10331  else if (strcmp(typstorage, "x") == 0)
10332  appendPQExpBufferStr(q, ",\n STORAGE = extended");
10333  else if (strcmp(typstorage, "m") == 0)
10334  appendPQExpBufferStr(q, ",\n STORAGE = main");
10335 
10336  if (strcmp(typbyval, "t") == 0)
10337  appendPQExpBufferStr(q, ",\n PASSEDBYVALUE");
10338 
10339  appendPQExpBufferStr(q, "\n);\n");
10340 
10341  appendPQExpBuffer(labelq, "TYPE %s", qtypname);
10342 
10343  if (dopt->binary_upgrade)
10344  binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
10345 
10346  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
10347  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
10348  tyinfo->dobj.name,
10349  tyinfo->dobj.namespace->dobj.name,
10350  NULL,
10351  tyinfo->rolname, false,
10352  "TYPE", SECTION_PRE_DATA,
10353  q->data, delq->data, NULL,
10354  NULL, 0,
10355  NULL, NULL);
10356 
10357  /* Dump Type Comments and Security Labels */
10358  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10359  dumpComment(fout, labelq->data,
10360  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10361  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10362 
10363  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
10364  dumpSecLabel(fout, labelq->data,
10365  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10366  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10367 
10368  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
10369  dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
10370  qtypname, NULL, tyinfo->dobj.name,
10371  tyinfo->dobj.namespace->dobj.name,
10372  tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl,
10373  tyinfo->inittypacl, tyinfo->initrtypacl);
10374 
10375  PQclear(res);
10376  destroyPQExpBuffer(q);
10377  destroyPQExpBuffer(delq);
10378  destroyPQExpBuffer(labelq);
10379  destroyPQExpBuffer(query);
10380 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:17746
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:3855
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:133
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9083
DumpOptions * dopt
Definition: pg_backup.h:176
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:14534
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:17720
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:4006
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:295
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:14458
#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:181
static void dumpBlob ( Archive fout,
BlobInfo binfo 
)
static

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

2978 {
2979  PQExpBuffer cquery = createPQExpBuffer();
2980  PQExpBuffer dquery = createPQExpBuffer();
2981 
2982  appendPQExpBuffer(cquery,
2983  "SELECT pg_catalog.lo_create('%s');\n",
2984  binfo->dobj.name);
2985 
2986  appendPQExpBuffer(dquery,
2987  "SELECT pg_catalog.lo_unlink('%s');\n",
2988  binfo->dobj.name);
2989 
2990  if (binfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
2991  ArchiveEntry(fout, binfo->dobj.catId, binfo->dobj.dumpId,
2992  binfo->dobj.name,
2993  NULL, NULL,
2994  binfo->rolname, false,
2995  "BLOB", SECTION_PRE_DATA,
2996  cquery->data, dquery->data, NULL,
2997  NULL, 0,
2998  NULL, NULL);
2999 
3000  /* set up tag for comment and/or ACL */
3001  resetPQExpBuffer(cquery);
3002  appendPQExpBuffer(cquery, "LARGE OBJECT %s", binfo->dobj.name);
3003 
3004  /* Dump comment if any */
3005  if (binfo->dobj.dump & DUMP_COMPONENT_COMMENT)
3006  dumpComment(fout, cquery->data,
3007  NULL, binfo->rolname,
3008  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3009 
3010  /* Dump security label if any */
3011  if (binfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
3012  dumpSecLabel(fout, cquery->data,
3013  NULL, binfo->rolname,
3014  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3015 
3016  /* Dump ACL if any */
3017  if (binfo->blobacl && (binfo->dobj.dump & DUMP_COMPONENT_ACL))
3018  dumpACL(fout, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT",
3019  binfo->dobj.name, NULL, cquery->data,
3020  NULL, binfo->rolname, binfo->blobacl, binfo->rblobacl,
3021  binfo->initblobacl, binfo->initrblobacl);
3022 
3023  destroyPQExpBuffer(cquery);
3024  destroyPQExpBuffer(dquery);
3025 }
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:564
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:560
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9083
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:14534
char * rolname
Definition: pg_dump.h:561
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:14458
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:95
char * blobacl
Definition: pg_dump.h:562
#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:563
char * initrblobacl
Definition: pg_dump.h:565
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
static int dumpBlobs ( Archive fout,
void *  arg 
)
static

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

3033 {
3034  const char *blobQry;
3035  const char *blobFetchQry;
3036  PGconn *conn = GetConnection(fout);
3037  PGresult *res;
3038  char buf[LOBBUFSIZE];
3039  int ntups;
3040  int i;
3041  int cnt;
3042 
3043  if (g_verbose)
3044  write_msg(NULL, "saving large objects\n");
3045 
3046  /* Make sure we are in proper schema */
3047  selectSourceSchema(fout, "pg_catalog");
3048 
3049  /*
3050  * Currently, we re-fetch all BLOB OIDs using a cursor. Consider scanning
3051  * the already-in-memory dumpable objects instead...
3052  */
3053  if (fout->remoteVersion >= 90000)
3054  blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_largeobject_metadata";
3055  else
3056  blobQry = "DECLARE bloboid CURSOR FOR SELECT DISTINCT loid FROM pg_largeobject";
3057 
3058  ExecuteSqlStatement(fout, blobQry);
3059 
3060  /* Command to fetch from cursor */
3061  blobFetchQry = "FETCH 1000 IN bloboid";
3062 
3063  do
3064  {
3065  /* Do a fetch */
3066  res = ExecuteSqlQuery(fout, blobFetchQry, PGRES_TUPLES_OK);
3067 
3068  /* Process the tuples, if any */
3069  ntups = PQntuples(res);
3070  for (i = 0; i < ntups; i++)
3071  {
3072  Oid blobOid;
3073  int loFd;
3074 
3075  blobOid = atooid(PQgetvalue(res, i, 0));
3076  /* Open the BLOB */
3077  loFd = lo_open(conn, blobOid, INV_READ);
3078  if (loFd == -1)
3079  exit_horribly(NULL, "could not open large object %u: %s",
3080  blobOid, PQerrorMessage(conn));
3081 
3082  StartBlob(fout, blobOid);
3083 
3084  /* Now read it in chunks, sending data to archive */
3085  do
3086  {
3087  cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
3088  if (cnt < 0)
3089  exit_horribly(NULL, "error reading large object %u: %s",
3090  blobOid, PQerrorMessage(conn));
3091 
3092  WriteData(fout, buf, cnt);
3093  } while (cnt > 0);
3094 
3095  lo_close(conn, loFd);
3096 
3097  EndBlob(fout, blobOid);
3098  }
3099 
3100  PQclear(res);
3101  } while (ntups > 0);
3102 
3103  return 1;
3104 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:5934
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:42
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:17720
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:97
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:181
static void dumpCast ( Archive fout,
CastInfo cast 
)
static

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

11743 {
11744  DumpOptions *dopt = fout->dopt;
11745  PQExpBuffer defqry;
11746  PQExpBuffer delqry;
11747  PQExpBuffer labelq;
11748  FuncInfo *funcInfo = NULL;
11749  char *sourceType;
11750  char *targetType;
11751 
11752  /* Skip if not to be dumped */
11753  if (!cast->dobj.dump || dopt->dataOnly)
11754  return;
11755 
11756  /* Cannot dump if we don't have the cast function's info */
11757  if (OidIsValid(cast->castfunc))
11758  {
11759  funcInfo = findFuncByOid(cast->castfunc);
11760  if (funcInfo == NULL)
11761  exit_horribly(NULL, "could not find function definition for function with OID %u\n",
11762  cast->castfunc);
11763  }
11764 
11765  /*
11766  * Make sure we are in proper schema (needed for getFormattedTypeName).
11767  * Casts don't have a schema of their own, so use pg_catalog.
11768  */
11769  selectSourceSchema(fout, "pg_catalog");
11770 
11771  defqry = createPQExpBuffer();
11772  delqry = createPQExpBuffer();
11773  labelq = createPQExpBuffer();
11774 
11775  sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone);
11776  targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone);
11777  appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
11778  sourceType, targetType);
11779 
11780  appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
11781  sourceType, targetType);
11782 
11783  switch (cast->castmethod)
11784  {
11786  appendPQExpBufferStr(defqry, "WITHOUT FUNCTION");
11787  break;
11788  case COERCION_METHOD_INOUT:
11789  appendPQExpBufferStr(defqry, "WITH INOUT");
11790  break;
11792  if (funcInfo)
11793  {
11794  char *fsig = format_function_signature(fout, funcInfo, true);
11795 
11796  /*
11797  * Always qualify the function name, in case it is not in
11798  * pg_catalog schema (format_function_signature won't qualify
11799  * it).
11800  */
11801  appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
11802  fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
11803  free(fsig);
11804  }
11805  else
11806  write_msg(NULL, "WARNING: bogus value in pg_cast.castfunc or pg_cast.castmethod field\n");
11807  break;
11808  default:
11809  write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
11810  }
11811 
11812  if (cast->castcontext == 'a')
11813  appendPQExpBufferStr(defqry, " AS ASSIGNMENT");
11814  else if (cast->castcontext == 'i')
11815  appendPQExpBufferStr(defqry, " AS IMPLICIT");
11816  appendPQExpBufferStr(defqry, ";\n");
11817 
11818  appendPQExpBuffer(labelq, "CAST (%s AS %s)",
11819  sourceType, targetType);
11820 
11821  if (dopt->binary_upgrade)
11822  binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data);
11823 
11824  if (cast->dobj.dump & DUMP_COMPONENT_DEFINITION)
11825  ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
11826  labelq->data,
11827  "pg_catalog", NULL, "",
11828  false, "CAST", SECTION_PRE_DATA,
11829  defqry->data, delqry->data, NULL,
11830  NULL, 0,
11831  NULL, NULL);
11832 
11833  /* Dump Cast Comments */
11834  if (cast->dobj.dump & DUMP_COMPONENT_COMMENT)
11835  dumpComment(fout, labelq->data,
11836  "pg_catalog", "",
11837  cast->dobj.catId, 0, cast->dobj.dumpId);
11838 
11839  free(sourceType);
11840  free(targetType);
11841 
11842  destroyPQExpBuffer(defqry);
11843  destroyPQExpBuffer(delqry);
11844  destroyPQExpBuffer(labelq);
11845 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:17746
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:133
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:9083
Oid casttarget
Definition: pg_dump.h:457
DumpOptions * dopt
Definition: pg_backup.h:176
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17720
FuncInfo * findFuncByOid(Oid oid)
Definition: common.c:818
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:4006
#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:11206
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 13024 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().

13025 {
13026  DumpOptions *dopt = fout->dopt;
13027  PQExpBuffer query;
13028  PQExpBuffer q;
13029  PQExpBuffer delq;
13030  PQExpBuffer labelq;
13031  PGresult *res;
13032  int i_collprovider;
13033  int i_collcollate;
13034  int i_collctype;
13035  const char *collprovider;
13036  const char *collcollate;
13037  const char *collctype;
13038 
13039  /* Skip if not to be dumped */
13040  if (!collinfo->dobj.dump || dopt->dataOnly)
13041  return;
13042 
13043  query = createPQExpBuffer();
13044  q = createPQExpBuffer();
13045  delq = createPQExpBuffer();
13046  labelq = createPQExpBuffer();
13047 
13048  /* Make sure we are in proper schema */
13049  selectSourceSchema(fout, collinfo->dobj.namespace->dobj.name);
13050 
13051  /* Get collation-specific details */
13052  if (fout->remoteVersion >= 100000)
13053  appendPQExpBuffer(query, "SELECT "
13054  "collprovider, "
13055  "collcollate, "
13056  "collctype, "
13057  "collversion "
13058  "FROM pg_catalog.pg_collation c "
13059  "WHERE c.oid = '%u'::pg_catalog.oid",
13060  collinfo->dobj.catId.oid);
13061  else
13062  appendPQExpBuffer(query, "SELECT "
13063  "'p'::char AS collprovider, "
13064  "collcollate, "
13065  "collctype, "
13066  "NULL AS collversion "
13067  "FROM pg_catalog.pg_collation c "
13068  "WHERE c.oid = '%u'::pg_catalog.oid",
13069  collinfo->dobj.catId.oid);
13070 
13071  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13072 
13073  i_collprovider = PQfnumber(res, "collprovider");
13074  i_collcollate = PQfnumber(res, "collcollate");
13075  i_collctype = PQfnumber(res, "collctype");
13076 
13077  collprovider = PQgetvalue(res, 0, i_collprovider);
13078  collcollate = PQgetvalue(res, 0, i_collcollate);
13079  collctype = PQgetvalue(res, 0, i_collctype);
13080 
13081  /*
13082  * DROP must be fully qualified in case same name appears in pg_catalog
13083  */
13084  appendPQExpBuffer(delq, "DROP COLLATION %s",
13085  fmtId(collinfo->dobj.namespace->dobj.name));
13086  appendPQExpBuffer(delq, ".%s;\n",
13087  fmtId(collinfo->dobj.name));
13088 
13089  appendPQExpBuffer(q, "CREATE COLLATION %s (",
13090  fmtId(collinfo->dobj.name));
13091 
13092  appendPQExpBufferStr(q, "provider = ");
13093  if (collprovider[0] == 'c')
13094  appendPQExpBufferStr(q, "libc");
13095  else if (collprovider[0] == 'i')
13096  appendPQExpBufferStr(q, "icu");
13097  else
13099  "unrecognized collation provider: %s\n",
13100  collprovider);
13101 
13102  if (strcmp(collcollate, collctype) == 0)
13103  {
13104  appendPQExpBufferStr(q, ", locale = ");
13105  appendStringLiteralAH(q, collcollate, fout);
13106  }
13107  else
13108  {
13109  appendPQExpBufferStr(q, ", lc_collate = ");
13110  appendStringLiteralAH(q, collcollate, fout);
13111  appendPQExpBufferStr(q, ", lc_ctype = ");
13112  appendStringLiteralAH(q, collctype, fout);
13113  }
13114 
13115  /*
13116  * For binary upgrade, carry over the collation version. For normal
13117  * dump/restore, omit the version, so that it is computed upon restore.
13118  */
13119  if (dopt->binary_upgrade)
13120  {
13121  int i_collversion;
13122 
13123  i_collversion = PQfnumber(res, "collversion");
13124  if (!PQgetisnull(res, 0, i_collversion))
13125  {
13126  appendPQExpBufferStr(q, ", version = ");
13128  PQgetvalue(res, 0, i_collversion),
13129  fout);
13130  }
13131  }
13132 
13133  appendPQExpBufferStr(q, ");\n");
13134 
13135  appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name));
13136 
13137  if (dopt->binary_upgrade)
13138  binary_upgrade_extension_member(q, &collinfo->dobj, labelq->data);
13139 
13140  if (collinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13141  ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId,
13142  collinfo->dobj.name,
13143  collinfo->dobj.namespace->dobj.name,
13144  NULL,
13145  collinfo->rolname,
13146  false, "COLLATION", SECTION_PRE_DATA,
13147  q->data, delq->data, NULL,
13148  NULL, 0,
13149  NULL, NULL);
13150 
13151  /* Dump Collation Comments */
13152  if (collinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13153  dumpComment(fout, labelq->data,
13154  collinfo->dobj.namespace->dobj.name, collinfo->rolname,
13155  collinfo->dobj.catId, 0, collinfo->dobj.dumpId);
13156 
13157  PQclear(res);
13158 
13159  destroyPQExpBuffer(query);
13160  destroyPQExpBuffer(q);
13161  destroyPQExpBuffer(delq);
13162  destroyPQExpBuffer(labelq);
13163 }
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:133
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9083
DumpOptions * dopt
Definition: pg_backup.h:176
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17720
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:4006
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:295
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:181
static void dumpComment ( Archive fout,
const char *  target,
const char *  namespace,
const char *  owner,
CatalogId  catalogId,
int  subid,
DumpId  dumpId 
)
static

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

9086 {
9087  DumpOptions *dopt = fout->dopt;
9088  CommentItem *comments;
9089  int ncomments;
9090 
9091  /* Comments are schema not data ... except blob comments are data */
9092  if (strncmp(target, "LARGE OBJECT ", 13) != 0)
9093  {
9094  if (dopt->dataOnly)
9095  return;
9096  }
9097  else
9098  {
9099  /* We do dump blob comments in binary-upgrade mode */
9100  if (dopt->schemaOnly && !dopt->binary_upgrade)
9101  return;
9102  }
9103 
9104  /* Search for comments associated with catalogId, using table */
9105  ncomments = findComments(fout, catalogId.tableoid, catalogId.oid,
9106  &comments);
9107 
9108  /* Is there one matching the subid? */
9109  while (ncomments > 0)
9110  {
9111  if (comments->objsubid == subid)
9112  break;
9113  comments++;
9114  ncomments--;
9115  }
9116 
9117  /* If a comment exists, build COMMENT ON statement */
9118  if (ncomments > 0)
9119  {
9120  PQExpBuffer query = createPQExpBuffer();
9121 
9122  appendPQExpBuffer(query, "COMMENT ON %s IS ", target);
9123  appendStringLiteralAH(query, comments->descr, fout);
9124  appendPQExpBufferStr(query, ";\n");
9125 
9126  /*
9127  * We mark comments as SECTION_NONE because they really belong in the
9128  * same section as their parent, whether that is pre-data or
9129  * post-data.
9130  */
9132  target, namespace, NULL, owner,
9133  false, "COMMENT", SECTION_NONE,
9134  query->data, "", NULL,
9135  &(dumpId), 1,
9136  NULL, NULL);
9137 
9138  destroyPQExpBuffer(query);
9139  }
9140 }
Oid tableoid
Definition: pg_backup.h:222
bool schemaOnly
Definition: pg_backup.h:136
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:9238
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:133
DumpOptions * dopt
Definition: pg_backup.h:176
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
const char * descr
Definition: pg_dump.c:67
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:295
#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:133
DumpId createDumpId(void)
Definition: common.c:557
static void dumpCompositeType ( Archive fout,
TypeInfo tyinfo 
)
static

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

10576 {
10577  DumpOptions *dopt = fout->dopt;
10579  PQExpBuffer dropped = createPQExpBuffer();
10580  PQExpBuffer delq = createPQExpBuffer();
10581  PQExpBuffer labelq = createPQExpBuffer();
10582  PQExpBuffer query = createPQExpBuffer();
10583  PGresult *res;
10584  char *qtypname;
10585  int ntups;
10586  int i_attname;
10587  int i_atttypdefn;
10588  int i_attlen;
10589  int i_attalign;
10590  int i_attisdropped;
10591  int i_attcollation;
10592  int i;
10593  int actual_atts;
10594 
10595  /* Set proper schema search path so type references list correctly */
10596  selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
10597 
10598  /* Fetch type specific details */
10599  if (fout->remoteVersion >= 90100)
10600  {
10601  /*
10602  * attcollation is new in 9.1. Since we only want to dump COLLATE
10603  * clauses for attributes whose collation is different from their
10604  * type's default, we use a CASE here to suppress uninteresting
10605  * attcollations cheaply. atttypid will be 0 for dropped columns;
10606  * collation does not matter for those.
10607  */
10608  appendPQExpBuffer(query, "SELECT a.attname, "
10609  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
10610  "a.attlen, a.attalign, a.attisdropped, "
10611  "CASE WHEN a.attcollation <> at.typcollation "
10612  "THEN a.attcollation ELSE 0 END AS attcollation "
10613  "FROM pg_catalog.pg_type ct "
10614  "JOIN pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
10615  "LEFT JOIN pg_catalog.pg_type at ON at.oid = a.atttypid "
10616  "WHERE ct.oid = '%u'::pg_catalog.oid "
10617  "ORDER BY a.attnum ",
10618  tyinfo->dobj.catId.oid);
10619  }
10620  else
10621  {
10622  /*
10623  * Since ALTER TYPE could not drop columns until 9.1, attisdropped
10624  * should always be false.
10625  */
10626  appendPQExpBuffer(query, "SELECT a.attname, "
10627  "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
10628  "a.attlen, a.attalign, a.attisdropped, "
10629  "0 AS attcollation "
10630  "FROM pg_catalog.pg_type ct, pg_catalog.pg_attribute a "
10631  "WHERE ct.oid = '%u'::pg_catalog.oid "
10632  "AND a.attrelid = ct.typrelid "
10633  "ORDER BY a.attnum ",
10634  tyinfo->dobj.catId.oid);
10635  }
10636 
10637  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10638 
10639  ntups = PQntuples(res);
10640 
10641  i_attname = PQfnumber(res, "attname");
10642  i_atttypdefn = PQfnumber(res, "atttypdefn");
10643  i_attlen = PQfnumber(res, "attlen");
10644  i_attalign = PQfnumber(res, "attalign");
10645  i_attisdropped = PQfnumber(res, "attisdropped");
10646  i_attcollation = PQfnumber(res, "attcollation");
10647 
10648  if (dopt->binary_upgrade)
10649  {
10651  tyinfo->dobj.catId.oid);
10652  binary_upgrade_set_pg_class_oids(fout, q, tyinfo->typrelid, false);
10653  }
10654 
10655  qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
10656 
10657  appendPQExpBuffer(q, "CREATE TYPE %s AS (",
10658  qtypname);
10659 
10660  actual_atts = 0;
10661  for (i = 0; i < ntups; i++)
10662  {
10663  char *attname;
10664  char *atttypdefn;
10665  char *attlen;
10666  char *attalign;
10667  bool attisdropped;
10668  Oid attcollation;
10669 
10670  attname = PQgetvalue(res, i, i_attname);
10671  atttypdefn = PQgetvalue(res, i, i_atttypdefn);
10672  attlen = PQgetvalue(res, i, i_attlen);
10673  attalign = PQgetvalue(res, i, i_attalign);
10674  attisdropped = (PQgetvalue(res, i, i_attisdropped)[0] == 't');
10675  attcollation = atooid(PQgetvalue(res, i, i_attcollation));
10676 
10677  if (attisdropped && !dopt->binary_upgrade)
10678  continue;
10679 
10680  /* Format properly if not first attr */
10681  if (actual_atts++ > 0)
10682  appendPQExpBufferChar(q, ',');
10683  appendPQExpBufferStr(q, "\n\t");
10684 
10685  if (!attisdropped)
10686  {
10687  appendPQExpBuffer(q, "%s %s", fmtId(attname), atttypdefn);
10688 
10689  /* Add collation if not default for the column type */
10690  if (OidIsValid(attcollation))
10691  {
10692  CollInfo *coll;
10693 
10694  coll = findCollationByOid(attcollation);
10695  if (coll)
10696  {
10697  /* always schema-qualify, don't try to be smart */
10698  appendPQExpBuffer(q, " COLLATE %s.",
10699  fmtId(coll->dobj.namespace->dobj.name));
10700  appendPQExpBufferStr(q, fmtId(coll->dobj.name));
10701  }
10702  }
10703  }
10704  else
10705  {
10706  /*
10707  * This is a dropped attribute and we're in binary_upgrade mode.
10708  * Insert a placeholder for it in the CREATE TYPE command, and set
10709  * length and alignment with direct UPDATE to the catalogs
10710  * afterwards. See similar code in dumpTableSchema().
10711  */
10712  appendPQExpBuffer(q, "%s INTEGER /* dummy */", fmtId(attname));
10713 
10714  /* stash separately for insertion after the CREATE TYPE */
10715  appendPQExpBufferStr(dropped,
10716  "\n-- For binary upgrade, recreate dropped column.\n");
10717  appendPQExpBuffer(dropped, "UPDATE pg_catalog.pg_attribute\n"
10718  "SET attlen = %s, "
10719  "attalign = '%s', attbyval = false\n"
10720  "WHERE attname = ", attlen, attalign);
10721  appendStringLiteralAH(dropped, attname, fout);
10722  appendPQExpBufferStr(dropped, "\n AND attrelid = ");
10723  appendStringLiteralAH(dropped, qtypname, fout);
10724  appendPQExpBufferStr(dropped, "::pg_catalog.regclass;\n");
10725 
10726  appendPQExpBuffer(dropped, "ALTER TYPE %s ",
10727  qtypname);
10728  appendPQExpBuffer(dropped, "DROP ATTRIBUTE %s;\n",
10729  fmtId(attname));
10730  }
10731  }
10732  appendPQExpBufferStr(q, "\n);\n");
10733  appendPQExpBufferStr(q, dropped->data);
10734 
10735  /*
10736  * DROP must be fully qualified in case same name appears in pg_catalog
10737  */
10738  appendPQExpBuffer(delq, "DROP TYPE %s.",
10739  fmtId(tyinfo->dobj.namespace->dobj.name));
10740  appendPQExpBuffer(delq, "%s;\n",
10741  qtypname);
10742 
10743  appendPQExpBuffer(labelq, "TYPE %s", qtypname);
10744 
10745  if (dopt->binary_upgrade)
10746  binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
10747 
10748  if (tyinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
10749  ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
10750  tyinfo->dobj.name,
10751  tyinfo->dobj.namespace->dobj.name,
10752  NULL,
10753  tyinfo->rolname, false,
10754  "TYPE", SECTION_PRE_DATA,
10755  q->data, delq->data, NULL,
10756  NULL, 0,
10757  NULL, NULL);
10758 
10759 
10760  /* Dump Type Comments and Security Labels */
10761  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10762  dumpComment(fout, labelq->data,
10763  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10764  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10765 
10766  if (tyinfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
10767  dumpSecLabel(fout, labelq->data,
10768  tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
10769  tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
10770 
10771  if (tyinfo->dobj.dump & DUMP_COMPONENT_ACL)
10772  dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
10773  qtypname, NULL, tyinfo->dobj.name,
10774  tyinfo->dobj.namespace->dobj.name,
10775  tyinfo->rolname, tyinfo->typacl, tyinfo->rtypacl,
10776  tyinfo->inittypacl, tyinfo->initrtypacl);
10777 
10778  PQclear(res);
10779  destroyPQExpBuffer(q);
10780  destroyPQExpBuffer(dropped);
10781  destroyPQExpBuffer(delq);
10782  destroyPQExpBuffer(labelq);
10783  destroyPQExpBuffer(query);
10784 
10785  /* Dump any per-column comments */
10786  if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10787  dumpCompositeTypeColComments(fout, tyinfo);
10788 }
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:3855
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:10796
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:133
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9083
DumpOptions * dopt
Definition: pg_backup.h:176
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:14534
static void binary_upgrade_set_pg_class_oids(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_class_oid, bool is_index)
Definition: pg_dump.c:3939
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:17720
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:4006
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:295
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:14458
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:840
#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:181
static void dumpCompositeTypeColComments ( Archive fout,
TypeInfo tyinfo 
)
static

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

10797 {
10798  CommentItem *comments;
10799  int ncomments;
10800  PGresult *res;
10801  PQExpBuffer query;
10802  PQExpBuffer target;
10803  Oid pgClassOid;
10804  int i;
10805  int ntups;
10806  int i_attname;
10807  int i_attnum;
10808 
10809  query = createPQExpBuffer();
10810 
10811  appendPQExpBuffer(query,
10812  "SELECT c.tableoid, a.attname, a.attnum "
10813  "FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
10814  "WHERE c.oid = '%u' AND c.oid = a.attrelid "
10815  " AND NOT a.attisdropped "
10816  "ORDER BY a.attnum ",
10817  tyinfo->typrelid);
10818 
10819  /* Fetch column attnames */
10820  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10821 
10822  ntups = PQntuples(res);
10823  if (ntups < 1)
10824  {
10825  PQclear(res);
10826  destroyPQExpBuffer(query);
10827  return;
10828  }
10829 
10830  pgClassOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "tableoid")));
10831 
10832  /* Search for comments associated with type's pg_class OID */
10833  ncomments = findComments(fout,
10834  pgClassOid,
10835  tyinfo->typrelid,
10836  &comments);
10837 
10838  /* If no comments exist, we're done */
10839  if (ncomments <= 0)
10840  {
10841  PQclear(res);
10842  destroyPQExpBuffer(query);
10843  return;
10844  }
10845 
10846  /* Build COMMENT ON statements */
10847  target = createPQExpBuffer();
10848 
10849  i_attnum = PQfnumber(res, "attnum");
10850  i_attname = PQfnumber(res, "attname");
10851  while (ncomments > 0)
10852  {
10853  const char *attname;
10854 
10855  attname = NULL;
10856  for (i = 0; i < ntups; i++)
10857  {
10858  if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid)
10859  {
10860  attname = PQgetvalue(res, i, i_attname);
10861  break;
10862  }
10863  }
10864  if (attname) /* just in case we don't find it */
10865  {
10866  const char *descr = comments->descr;
10867 
10868  resetPQExpBuffer(target);
10869  appendPQExpBuffer(target, "COLUMN %s.",
10870  fmtId(tyinfo->dobj.name));
10871  appendPQExpBufferStr(target, fmtId(attname));
10872 
10873  resetPQExpBuffer(query);
10874  appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
10875  appendStringLiteralAH(query, descr, fout);
10876  appendPQExpBufferStr(query, ";\n");
10877 
10879  target->data,
10880  tyinfo->dobj.namespace->dobj.name,
10881  NULL, tyinfo->rolname,
10882  false, "COMMENT", SECTION_NONE,
10883  query->data, "", NULL,
10884  &(tyinfo->dobj.dumpId), 1,
10885  NULL, NULL);
10886  }
10887 
10888  comments++;
10889  ncomments--;
10890  }
10891 
10892  PQclear(res);
10893  destroyPQExpBuffer(query);
10894  destroyPQExpBuffer(target);
10895 }
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:9238
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:295
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:133
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DumpId createDumpId(void)
Definition: common.c:557
static void dumpConstraint ( Archive fout,
ConstraintInfo coninfo 
)
static

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

15993 {
15994  DumpOptions *dopt = fout->dopt;
15995  TableInfo *tbinfo = coninfo->contable;
15996  PQExpBuffer q;
15997  PQExpBuffer delq;
15998  char *tag = NULL;
15999 
16000  /* Skip if not to be dumped */
16001  if (!coninfo->dobj.dump || dopt->dataOnly)
16002  return;
16003 
16004  q = createPQExpBuffer();
16005  delq = createPQExpBuffer();
16006 
16007  if (coninfo->contype == 'p' ||
16008  coninfo->contype == 'u' ||
16009  coninfo->contype == 'x')
16010  {
16011  /* Index-related constraint */
16012  IndxInfo *indxinfo;
16013  int k;
16014 
16015  indxinfo = (IndxInfo *) findObjectByDumpId(coninfo->conindex);
16016 
16017  if (indxinfo == NULL)
16018  exit_horribly(NULL, "missing index for constraint \"%s\"\n",
16019  coninfo->dobj.name);
16020 
16021  if (dopt->binary_upgrade)
16023  indxinfo->dobj.catId.oid, true);
16024 
16025  appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
16026  fmtId(tbinfo->dobj.name));
16027  appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
16028  fmtId(coninfo->dobj.name));
16029 
16030  if (coninfo->condef)
16031  {
16032  /* pg_get_constraintdef should have provided everything */
16033  appendPQExpBuffer(q, "%s;\n", coninfo->condef);
16034  }
16035  else
16036  {
16037  appendPQExpBuffer(q, "%s (",
16038  coninfo->contype == 'p' ? "PRIMARY KEY" : "UNIQUE");
16039  for (k = 0; k < indxinfo->indnkeys; k++)
16040  {
16041  int indkey = (int) indxinfo->indkeys[k];
16042  const char *attname;
16043 
16044  if (indkey == InvalidAttrNumber)
16045  break;
16046  attname = getAttrName(indkey, tbinfo);
16047 
16048  appendPQExpBuffer(q, "%s%s",
16049  (k == 0) ? "" : ", ",
16050  fmtId(attname));
16051  }
16052 
16053  appendPQExpBufferChar(q, ')');
16054 
16055  if (nonemptyReloptions(indxinfo->indreloptions))
16056  {
16057  appendPQExpBufferStr(q, " WITH (");
16058  appendReloptionsArrayAH(q, indxinfo->indreloptions, "", fout);
16059  appendPQExpBufferChar(q, ')');
16060  }
16061 
16062  if (coninfo->condeferrable)
16063  {
16064  appendPQExpBufferStr(q, " DEFERRABLE");
16065  if (coninfo->condeferred)
16066  appendPQExpBufferStr(q, " INITIALLY DEFERRED");
16067  }
16068 
16069  appendPQExpBufferStr(q, ";\n");
16070  }
16071 
16072  /* If the index is clustered, we need to record that. */
16073  if (indxinfo->indisclustered)
16074  {
16075  appendPQExpBuffer(q, "\nALTER TABLE %s CLUSTER",
16076  fmtId(tbinfo->dobj.name));
16077  appendPQExpBuffer(q, " ON %s;\n",
16078  fmtId(indxinfo->dobj.name));
16079  }
16080 
16081  /*
16082  * DROP must be fully qualified in case same name appears in
16083  * pg_catalog
16084  */
16085  appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.",
16086  fmtId(tbinfo->dobj.namespace->dobj.name));
16087  appendPQExpBuffer(delq, "%s ",
16088  fmtId(tbinfo->dobj.name));
16089  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16090  fmtId(coninfo->dobj.name));
16091 
16092  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16093 
16094  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16095  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16096  tag,
16097  tbinfo->dobj.namespace->dobj.name,
16098  indxinfo->tablespace,
16099  tbinfo->rolname, false,
16100  "CONSTRAINT", SECTION_POST_DATA,
16101  q->data, delq->data, NULL,
16102  NULL, 0,
16103  NULL, NULL);
16104  }
16105  else if (coninfo->contype == 'f')
16106  {
16107  /*
16108  * XXX Potentially wrap in a 'SET CONSTRAINTS OFF' block so that the
16109  * current table data is not processed
16110  */
16111  appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
16112  fmtId(tbinfo->dobj.name));
16113  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16114  fmtId(coninfo->dobj.name),
16115  coninfo->condef);
16116 
16117  /*
16118  * DROP must be fully qualified in case same name appears in
16119  * pg_catalog
16120  */
16121  appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.",
16122  fmtId(tbinfo->dobj.namespace->dobj.name));
16123  appendPQExpBuffer(delq, "%s ",
16124  fmtId(tbinfo->dobj.name));
16125  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16126  fmtId(coninfo->dobj.name));
16127 
16128  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16129 
16130  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16131  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16132  tag,
16133  tbinfo->dobj.namespace->dobj.name,
16134  NULL,
16135  tbinfo->rolname, false,
16136  "FK CONSTRAINT", SECTION_POST_DATA,
16137  q->data, delq->data, NULL,
16138  NULL, 0,
16139  NULL, NULL);
16140  }
16141  else if (coninfo->contype == 'c' && tbinfo)
16142  {
16143  /* CHECK constraint on a table */
16144 
16145  /* Ignore if not to be dumped separately, or if it was inherited */
16146  if (coninfo->separate && coninfo->conislocal)
16147  {
16148  /* not ONLY since we want it to propagate to children */
16149  appendPQExpBuffer(q, "ALTER TABLE %s\n",
16150  fmtId(tbinfo->dobj.name));
16151  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16152  fmtId(coninfo->dobj.name),
16153  coninfo->condef);
16154 
16155  /*
16156  * DROP must be fully qualified in case same name appears in
16157  * pg_catalog
16158  */
16159  appendPQExpBuffer(delq, "ALTER TABLE %s.",
16160  fmtId(tbinfo->dobj.namespace->dobj.name));
16161  appendPQExpBuffer(delq, "%s ",
16162  fmtId(tbinfo->dobj.name));
16163  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16164  fmtId(coninfo->dobj.name));
16165 
16166  tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
16167 
16168  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16169  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16170  tag,
16171  tbinfo->dobj.namespace->dobj.name,
16172  NULL,
16173  tbinfo->rolname, false,
16174  "CHECK CONSTRAINT", SECTION_POST_DATA,
16175  q->data, delq->data, NULL,
16176  NULL, 0,
16177  NULL, NULL);
16178  }
16179  }
16180  else if (coninfo->contype == 'c' && tbinfo == NULL)
16181  {
16182  /* CHECK constraint on a domain */
16183  TypeInfo *tyinfo = coninfo->condomain;
16184 
16185  /* Ignore if not to be dumped separately */
16186  if (coninfo->separate)
16187  {
16188  appendPQExpBuffer(q, "ALTER DOMAIN %s\n",
16189  fmtId(tyinfo->dobj.name));
16190  appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
16191  fmtId(coninfo->dobj.name),
16192  coninfo->condef);
16193 
16194  /*
16195  * DROP must be fully qualified in case same name appears in
16196  * pg_catalog
16197  */
16198  appendPQExpBuffer(delq, "ALTER DOMAIN %s.",
16199  fmtId(tyinfo->dobj.namespace->dobj.name));
16200  appendPQExpBuffer(delq, "%s ",
16201  fmtId(tyinfo->dobj.name));
16202  appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
16203  fmtId(coninfo->dobj.name));
16204 
16205  tag = psprintf("%s %s", tyinfo->dobj.name, coninfo->dobj.name);
16206 
16207  if (coninfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
16208  ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
16209  tag,
16210  tyinfo->dobj.namespace->dobj.name,
16211  NULL,
16212  tyinfo->rolname, false,
16213  "CHECK CONSTRAINT", SECTION_POST_DATA,
16214  q->data, delq->data, NULL,
16215  NULL, 0,
16216  NULL, NULL);
16217  }
16218  }
16219  else
16220  {
16221  exit_horribly(NULL, "unrecognized constraint type: %c\n",
16222  coninfo->contype);
16223  }
16224 
16225  /* Dump Constraint Comments --- only works for table constraints */
16226  if (tbinfo && coninfo->separate &&
16227  coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
16228  dumpTableConstraintComment(fout, coninfo);
16229 
16230  free(tag);
16231  destroyPQExpBuffer(q);
16232  destroyPQExpBuffer(delq);
16233 }
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:17829
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:133
DumpableObject dobj
Definition: pg_dump.h:426
DumpOptions * dopt
Definition: pg_backup.h:176
static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
Definition: pg_dump.c:16243
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition: common.c:577
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
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:3939
static const char * getAttrName(int attrnum, TableInfo *tblInfo)
Definition: pg_dump.c:15813
bool condeferrable
Definition: pg_dump.h:433
static bool nonemptyReloptions(const char *reloptions)
Definition: pg_dump.c:17817
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 13170 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().

13171 {
13172  DumpOptions *dopt = fout->dopt;
13173  PQExpBuffer query;
13174  PQExpBuffer q;
13175  PQExpBuffer delq;
13176  PQExpBuffer labelq;
13177  PGresult *res;
13178  int i_conforencoding;
13179  int i_contoencoding;
13180  int i_conproc;
13181  int i_condefault;
13182  const char *conforencoding;
13183  const char *contoencoding;
13184  const char *conproc;
13185  bool condefault;
13186 
13187  /* Skip if not to be dumped */
13188  if (!convinfo->dobj.dump || dopt->dataOnly)
13189  return;
13190 
13191  query = createPQExpBuffer();
13192  q = createPQExpBuffer();
13193  delq = createPQExpBuffer();
13194  labelq = createPQExpBuffer();
13195 
13196  /* Make sure we are in proper schema */
13197  selectSourceSchema(fout, convinfo->dobj.namespace->dobj.name);
13198 
13199  /* Get conversion-specific details */
13200  appendPQExpBuffer(query, "SELECT "
13201  "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
13202  "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
13203  "conproc, condefault "
13204  "FROM pg_catalog.pg_conversion c "
13205  "WHERE c.oid = '%u'::pg_catalog.oid",
13206  convinfo->dobj.catId.oid);
13207 
13208  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13209 
13210  i_conforencoding = PQfnumber(res, "conforencoding");
13211  i_contoencoding = PQfnumber(res, "contoencoding");
13212  i_conproc = PQfnumber(res, "conproc");
13213  i_condefault = PQfnumber(res, "condefault");
13214 
13215  conforencoding = PQgetvalue(res, 0, i_conforencoding);
13216  contoencoding = PQgetvalue(res, 0, i_contoencoding);
13217  conproc = PQgetvalue(res, 0, i_conproc);
13218  condefault = (PQgetvalue(res, 0, i_condefault)[0] == 't');
13219 
13220  /*
13221  * DROP must be fully qualified in case same name appears in pg_catalog
13222  */
13223  appendPQExpBuffer(delq, "DROP CONVERSION %s",
13224  fmtId(convinfo->dobj.namespace->dobj.name));
13225  appendPQExpBuffer(delq, ".%s;\n",
13226  fmtId(convinfo->dobj.name));
13227 
13228  appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ",
13229  (condefault) ? "DEFAULT " : "",
13230  fmtId(convinfo->dobj.name));
13231  appendStringLiteralAH(q, conforencoding, fout);
13232  appendPQExpBufferStr(q, " TO ");
13233  appendStringLiteralAH(q, contoencoding, fout);
13234  /* regproc output is already sufficiently quoted */
13235  appendPQExpBuffer(q, " FROM %s;\n", conproc);
13236 
13237  appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name));
13238 
13239  if (dopt->binary_upgrade)
13240  binary_upgrade_extension_member(q, &convinfo->dobj, labelq->data);
13241 
13242  if (convinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13243  ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
13244  convinfo->dobj.name,
13245  convinfo->dobj.namespace->dobj.name,
13246  NULL,
13247  convinfo->rolname,
13248  false, "CONVERSION", SECTION_PRE_DATA,
13249  q->data, delq->data, NULL,
13250  NULL, 0,
13251  NULL, NULL);
13252 
13253  /* Dump Conversion Comments */
13254  if (convinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13255  dumpComment(fout, labelq->data,
13256  convinfo->dobj.namespace->dobj.name, convinfo->rolname,
13257  convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
13258 
13259  PQclear(res);
13260 
13261  destroyPQExpBuffer(query);
13262  destroyPQExpBuffer(q);
13263  destroyPQExpBuffer(delq);
13264  destroyPQExpBuffer(labelq);
13265 }
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:133
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9083
DumpOptions * dopt
Definition: pg_backup.h:176
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:137
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17720
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:4006
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:295
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 2445 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().

2446 {
2447  DumpOptions *dopt = fout->dopt;
2448  PQExpBuffer dbQry = createPQExpBuffer();
2449  PQExpBuffer delQry = createPQExpBuffer();
2450  PQExpBuffer creaQry = createPQExpBuffer();
2451  PGconn *conn = GetConnection(fout);
2452  PGresult *res;
2453  int i_tableoid,
2454  i_oid,
2455  i_dba,
2456  i_encoding,
2457  i_collate,
2458  i_ctype,
2459  i_frozenxid,
2460  i_minmxid,
2461  i_tablespace;
2462  CatalogId dbCatId;
2463  DumpId dbDumpId;
2464  const char *datname,
2465  *dba,
2466  *encoding,
2467  *collate,
2468  *ctype,
2469  *tablespace;
2470  uint32 frozenxid,
2471  minmxid;
2472 
2473  datname = PQdb(conn);
2474 
2475  if (g_verbose)
2476  write_msg(NULL, "saving database definition\n");
2477 
2478  /* Make sure we are in proper schema */
2479  selectSourceSchema(fout, "pg_catalog");
2480 
2481  /* Get the database owner and parameters from pg_database */
2482  if (fout->remoteVersion >= 90300)
2483  {
2484  appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
2485  "(%s datdba) AS dba, "
2486  "pg_encoding_to_char(encoding) AS encoding, "
2487  "datcollate, datctype, datfrozenxid, datminmxid, "
2488  "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) AS tablespace, "
2489  "shobj_description(oid, 'pg_database') AS description "
2490 
2491  "FROM pg_database "
2492  "WHERE datname = ",
2493