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)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getConstraints (Archive *fout, TableInfo tblinfo[], int numTables)
 
RuleInfogetRules (Archive *fout, int *numRules)
 
void getTriggers (Archive *fout, TableInfo tblinfo[], int numTables)
 
EventTriggerInfogetEventTriggers (Archive *fout, int *numEventTriggers)
 
ProcLangInfogetProcLangs (Archive *fout, int *numProcLangs)
 
CastInfogetCasts (Archive *fout, int *numCasts)
 
static char * get_language_name (Archive *fout, Oid langid)
 
TransformInfogetTransforms (Archive *fout, int *numTransforms)
 
void getTableAttrs (Archive *fout, TableInfo *tblinfo, int numTables)
 
bool shouldPrintColumn (DumpOptions *dopt, TableInfo *tbinfo, int colno)
 
TSParserInfogetTSParsers (Archive *fout, int *numTSParsers)
 
TSDictInfogetTSDictionaries (Archive *fout, int *numTSDicts)
 
TSTemplateInfogetTSTemplates (Archive *fout, int *numTSTemplates)
 
TSConfigInfogetTSConfigurations (Archive *fout, int *numTSConfigs)
 
FdwInfogetForeignDataWrappers (Archive *fout, int *numForeignDataWrappers)
 
ForeignServerInfogetForeignServers (Archive *fout, int *numForeignServers)
 
DefaultACLInfogetDefaultACLs (Archive *fout, int *numDefaultACLs)
 
static void dumpTableComment (Archive *fout, TableInfo *tbinfo, const char *reltypename)
 
static char * format_aggregate_signature (AggInfo *agginfo, Archive *fout, bool honor_quotes)
 
static void dumpTableSecLabel (Archive *fout, TableInfo *tbinfo, const char *reltypename)
 
static PQExpBuffer createViewAsClause (Archive *fout, TableInfo *tbinfo)
 
static PQExpBuffer createDummyViewAsClause (Archive *fout, TableInfo *tbinfo)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 

Variables

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

Typedef Documentation

Enumeration Type Documentation

enum OidOptions
Enumerator
zeroAsOpaque 
zeroAsAny 
zeroAsStar 
zeroAsNone 

Definition at line 82 of file pg_dump.c.

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

Function Documentation

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

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

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

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

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

17839 {
17840  bool res;
17841 
17842  res = appendReloptionsArray(buffer, reloptions, prefix, fout->encoding,
17843  fout->std_strings);
17844  if (!res)
17845  write_msg(NULL, "WARNING: could not parse reloptions array\n");
17846 }
int encoding
Definition: pg_backup.h:195
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
Definition: string_utils.c:747
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
bool std_strings
Definition: pg_backup.h:196
static void binary_upgrade_extension_member ( PQExpBuffer  upgrade_buffer,
DumpableObject dobj,
const char *  objlabel 
)
static

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

4032 {
4033  DumpableObject *extobj = NULL;
4034  int i;
4035 
4036  if (!dobj->ext_member)
4037  return;
4038 
4039  /*
4040  * Find the parent extension. We could avoid this search if we wanted to
4041  * add a link field to DumpableObject, but the space costs of that would
4042  * be considerable. We assume that member objects could only have a
4043  * direct dependency on their own extension, not any others.
4044  */
4045  for (i = 0; i < dobj->nDeps; i++)
4046  {
4047  extobj = findObjectByDumpId(dobj->dependencies[i]);
4048  if (extobj && extobj->objType == DO_EXTENSION)
4049  break;
4050  extobj = NULL;
4051  }
4052  if (extobj == NULL)
4053  exit_horribly(NULL, "could not find parent extension for %s\n", objlabel);
4054 
4055  appendPQExpBufferStr(upgrade_buffer,
4056  "\n-- For binary upgrade, handle extension membership the hard way\n");
4057  appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s;\n",
4058  fmtId(extobj->name),
4059  objlabel);
4060 }
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:521
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 3962 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().

3965 {
3966  PQExpBuffer upgrade_query = createPQExpBuffer();
3967  PGresult *upgrade_res;
3968  Oid pg_class_reltoastrelid;
3969  Oid pg_index_indexrelid;
3970 
3971  appendPQExpBuffer(upgrade_query,
3972  "SELECT c.reltoastrelid, i.indexrelid "
3973  "FROM pg_catalog.pg_class c LEFT JOIN "
3974  "pg_catalog.pg_index i ON (c.reltoastrelid = i.indrelid AND i.indisvalid) "
3975  "WHERE c.oid = '%u'::pg_catalog.oid;",
3976  pg_class_oid);
3977 
3978  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
3979 
3980  pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
3981  pg_index_indexrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "indexrelid")));
3982 
3983  appendPQExpBufferStr(upgrade_buffer,
3984  "\n-- For binary upgrade, must preserve pg_class oids\n");
3985 
3986  if (!is_index)
3987  {
3988  appendPQExpBuffer(upgrade_buffer,
3989  "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
3990  pg_class_oid);
3991  /* only tables have toast tables, not indexes */
3992  if (OidIsValid(pg_class_reltoastrelid))
3993  {
3994  /*
3995  * One complexity is that the table definition might not require
3996  * the creation of a TOAST table, and the TOAST table might have
3997  * been created long after table creation, when the table was
3998  * loaded with wide data. By setting the TOAST oid we force
3999  * creation of the TOAST heap and TOAST index by the backend so we
4000  * can cleanly copy the files during binary upgrade.
4001  */
4002 
4003  appendPQExpBuffer(upgrade_buffer,
4004  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
4005  pg_class_reltoastrelid);
4006 
4007  /* every toast table has an index */
4008  appendPQExpBuffer(upgrade_buffer,
4009  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4010  pg_index_indexrelid);
4011  }
4012  }
4013  else
4014  appendPQExpBuffer(upgrade_buffer,
4015  "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
4016  pg_class_oid);
4017 
4018  appendPQExpBufferChar(upgrade_buffer, '\n');
4019 
4020  PQclear(upgrade_res);
4021  destroyPQExpBuffer(upgrade_query);
4022 }
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 3916 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().

3919 {
3920  PQExpBuffer upgrade_query = createPQExpBuffer();
3921  PGresult *upgrade_res;
3922  Oid pg_type_oid;
3923  bool toast_set = false;
3924 
3925  /* we only support old >= 8.3 for binary upgrades */
3926  appendPQExpBuffer(upgrade_query,
3927  "SELECT c.reltype AS crel, t.reltype AS trel "
3928  "FROM pg_catalog.pg_class c "
3929  "LEFT JOIN pg_catalog.pg_class t ON "
3930  " (c.reltoastrelid = t.oid) "
3931  "WHERE c.oid = '%u'::pg_catalog.oid;",
3932  pg_rel_oid);
3933 
3934  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
3935 
3936  pg_type_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "crel")));
3937 
3938  binary_upgrade_set_type_oids_by_type_oid(fout, upgrade_buffer,
3939  pg_type_oid);
3940 
3941  if (!PQgetisnull(upgrade_res, 0, PQfnumber(upgrade_res, "trel")))
3942  {
3943  /* Toast tables do not have pg_type array rows */
3944  Oid pg_type_toast_oid = atooid(PQgetvalue(upgrade_res, 0,
3945  PQfnumber(upgrade_res, "trel")));
3946 
3947  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
3948  appendPQExpBuffer(upgrade_buffer,
3949  "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3950  pg_type_toast_oid);
3951 
3952  toast_set = true;
3953  }
3954 
3955  PQclear(upgrade_res);
3956  destroyPQExpBuffer(upgrade_query);
3957 
3958  return toast_set;
3959 }
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, PQExpBuffer upgrade_buffer, Oid pg_type_oid)
Definition: pg_dump.c:3878
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 3878 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().

3881 {
3882  PQExpBuffer upgrade_query = createPQExpBuffer();
3883  PGresult *upgrade_res;
3884  Oid pg_type_array_oid;
3885 
3886  appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
3887  appendPQExpBuffer(upgrade_buffer,
3888  "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3889  pg_type_oid);
3890 
3891  /* we only support old >= 8.3 for binary upgrades */
3892  appendPQExpBuffer(upgrade_query,
3893  "SELECT typarray "
3894  "FROM pg_catalog.pg_type "
3895  "WHERE pg_type.oid = '%u'::pg_catalog.oid;",
3896  pg_type_oid);
3897 
3898  upgrade_res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
3899 
3900  pg_type_array_oid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "typarray")));
3901 
3902  if (OidIsValid(pg_type_array_oid))
3903  {
3904  appendPQExpBufferStr(upgrade_buffer,
3905  "\n-- For binary upgrade, must preserve pg_type array oid\n");
3906  appendPQExpBuffer(upgrade_buffer,
3907  "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
3908  pg_type_array_oid);
3909  }
3910 
3911  PQclear(upgrade_res);
3912  destroyPQExpBuffer(upgrade_query);
3913 }
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 17618 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().

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

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

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

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

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

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

9290 {
9291  PGresult *res;
9292  PQExpBuffer query;
9293  int i_description;
9294  int i_classoid;
9295  int i_objoid;
9296  int i_objsubid;
9297  int ntups;
9298  int i;
9299  CommentItem *comments;
9300 
9301  /*
9302  * Note we do NOT change source schema here; preserve the caller's
9303  * setting, instead.
9304  */
9305 
9306  query = createPQExpBuffer();
9307 
9308  appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
9309  "FROM pg_catalog.pg_description "
9310  "ORDER BY classoid, objoid, objsubid");
9311 
9312  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9313 
9314  /* Construct lookup table containing OIDs in numeric form */
9315 
9316  i_description = PQfnumber(res, "description");
9317  i_classoid = PQfnumber(res, "classoid");
9318  i_objoid = PQfnumber(res, "objoid");
9319  i_objsubid = PQfnumber(res, "objsubid");
9320 
9321  ntups = PQntuples(res);
9322 
9323  comments = (CommentItem *) pg_malloc(ntups * sizeof(CommentItem));
9324 
9325  for (i = 0; i < ntups; i++)
9326  {
9327  comments[i].descr = PQgetvalue(res, i, i_description);
9328  comments[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
9329  comments[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
9330  comments[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
9331  }
9332 
9333  /* Do NOT free the PGresult since we are keeping pointers into it */
9334  destroyPQExpBuffer(query);
9335 
9336  *items = comments;
9337  return ntups;
9338 }
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 14750 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().

14751 {
14752  PGresult *res;
14753  PQExpBuffer query;
14754  int i_label;
14755  int i_provider;
14756  int i_classoid;
14757  int i_objoid;
14758  int i_objsubid;
14759  int ntups;
14760  int i;
14761  SecLabelItem *labels;
14762 
14763  query = createPQExpBuffer();
14764 
14765  appendPQExpBufferStr(query,
14766  "SELECT label, provider, classoid, objoid, objsubid "
14767  "FROM pg_catalog.pg_seclabel "
14768  "ORDER BY classoid, objoid, objsubid");
14769 
14770  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
14771 
14772  /* Construct lookup table containing OIDs in numeric form */
14773  i_label = PQfnumber(res, "label");
14774  i_provider = PQfnumber(res, "provider");
14775  i_classoid = PQfnumber(res, "classoid");
14776  i_objoid = PQfnumber(res, "objoid");
14777  i_objsubid = PQfnumber(res, "objsubid");
14778 
14779  ntups = PQntuples(res);
14780 
14781  labels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
14782 
14783  for (i = 0; i < ntups; i++)
14784  {
14785  labels[i].label = PQgetvalue(res, i, i_label);
14786  labels[i].provider = PQgetvalue(res, i, i_provider);
14787  labels[i].classoid = atooid(PQgetvalue(res, i, i_classoid));
14788  labels[i].objoid = atooid(PQgetvalue(res, i, i_objoid));
14789  labels[i].objsubid = atoi(PQgetvalue(res, i, i_objsubid));
14790  }
14791 
14792  /* Do NOT free the PGresult since we are keeping pointers into it */
14793  destroyPQExpBuffer(query);
14794 
14795  *items = labels;
14796  return ntups;
14797 }
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 12207 of file pg_dump.c.

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

Referenced by dumpAgg(), and dumpOpr().

12208 {
12209  char *name;
12210  char *oname;
12211  char *ptr;
12212  bool inquote;
12213  bool sawdot;
12214 
12215  /* In all cases "0" means a null reference */
12216  if (strcmp(opr, "0") == 0)
12217  return NULL;
12218 
12219  name = pg_strdup(opr);
12220  /* find non-double-quoted left paren, and check for non-quoted dot */
12221  inquote = false;
12222  sawdot = false;
12223  for (ptr = name; *ptr; ptr++)
12224  {
12225  if (*ptr == '"')
12226  inquote = !inquote;
12227  else if (*ptr == '.' && !inquote)
12228  sawdot = true;
12229  else if (*ptr == '(' && !inquote)
12230  {
12231  *ptr = '\0';
12232  break;
12233  }
12234  }
12235  /* If not schema-qualified, don't need to add OPERATOR() */
12236  if (!sawdot)
12237  return name;
12238  oname = psprintf("OPERATOR(%s)", name);
12239  free(name);
12240  return oname;
12241 }
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 12171 of file pg_dump.c.

References name, NULL, and pg_strdup().

Referenced by dumpOpr().

12172 {
12173  char *name;
12174  char *paren;
12175  bool inquote;
12176 
12177  /* In all cases "-" means a null reference */
12178  if (strcmp(proc, "-") == 0)
12179  return NULL;
12180 
12181  name = pg_strdup(proc);
12182  /* find non-double-quoted left paren */
12183  inquote = false;
12184  for (paren = name; *paren; paren++)
12185  {
12186  if (*paren == '(' && !inquote)
12187  {
12188  *paren = '\0';
12189  break;
12190  }
12191  if (*paren == '"')
12192  inquote = !inquote;
12193  }
12194  return name;
12195 }
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 12252 of file pg_dump.c.

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

Referenced by dumpTSParser(), and dumpTSTemplate().

12253 {
12254  char *result;
12255  char query[128];
12256  PGresult *res;
12257 
12258  snprintf(query, sizeof(query),
12259  "SELECT '%u'::pg_catalog.regproc", funcOid);
12260  res = ExecuteSqlQueryForSingleRow(fout, query);
12261 
12262  result = pg_strdup(PQgetvalue(res, 0, 0));
12263 
12264  PQclear(res);
12265 
12266  return result;
12267 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
return result
Definition: formatting.c:1633
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:422
void PQclear(PGresult *res)
Definition: fe-exec.c:650
static DumpableObject * createBoundaryObjects ( void  )
static

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

17483 {
17484  DumpableObject *dobjs;
17485 
17486  dobjs = (DumpableObject *) pg_malloc(2 * sizeof(DumpableObject));
17487 
17488  dobjs[0].objType = DO_PRE_DATA_BOUNDARY;
17489  dobjs[0].catId = nilCatalogId;
17490  AssignDumpId(dobjs + 0);
17491  dobjs[0].name = pg_strdup("PRE-DATA BOUNDARY");
17492 
17493  dobjs[1].objType = DO_POST_DATA_BOUNDARY;
17494  dobjs[1].catId = nilCatalogId;
17495  AssignDumpId(dobjs + 1);
17496  dobjs[1].name = pg_strdup("POST-DATA BOUNDARY");
17497 
17498  return dobjs;
17499 }
char * name
Definition: pg_dump.h:133
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:457
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
CatalogId catId
Definition: pg_dump.h:131
static const CatalogId nilCatalogId
Definition: pg_dump.c:132
DumpableObjectType objType
Definition: pg_dump.h:130
static PQExpBuffer createDummyViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

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

14989 {
14991  int j;
14992 
14993  appendPQExpBufferStr(result, "SELECT");
14994 
14995  for (j = 0; j < tbinfo->numatts; j++)
14996  {
14997  if (j > 0)
14998  appendPQExpBufferChar(result, ',');
14999  appendPQExpBufferStr(result, "\n ");
15000 
15001  appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]);
15002 
15003  /*
15004  * Must add collation if not default for the type, because CREATE OR
15005  * REPLACE VIEW won't change it
15006  */
15007  if (OidIsValid(tbinfo->attcollation[j]))
15008  {
15009  CollInfo *coll;
15010 
15011  coll = findCollationByOid(tbinfo->attcollation[j]);
15012  if (coll)
15013  {
15014  /* always schema-qualify, don't try to be smart */
15015  appendPQExpBuffer(result, " COLLATE %s.",
15016  fmtId(coll->dobj.namespace->dobj.name));
15017  appendPQExpBufferStr(result, fmtId(coll->dobj.name));
15018  }
15019  }
15020 
15021  appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j]));
15022  }
15023 
15024  return result;
15025 }
char * name
Definition: pg_dump.h:133
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
return result
Definition: formatting.c:1633
char ** atttypnames
Definition: pg_dump.h:305
char ** attnames
Definition: pg_dump.h:304
#define OidIsValid(objectId)
Definition: c.h:538
DumpableObject dobj
Definition: pg_dump.h:246
Oid * attcollation
Definition: pg_dump.h:316
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
int numatts
Definition: pg_dump.h:303
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
CollInfo * findCollationByOid(Oid oid)
Definition: common.c:784
static PQExpBuffer createViewAsClause ( Archive fout,
TableInfo tbinfo 
)
static

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

14940 {
14941  PQExpBuffer query = createPQExpBuffer();
14943  PGresult *res;
14944  int len;
14945 
14946  /* Fetch the view definition */
14947  appendPQExpBuffer(query,
14948  "SELECT pg_catalog.pg_get_viewdef('%u'::pg_catalog.oid) AS viewdef",
14949  tbinfo->dobj.catId.oid);
14950 
14951  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
14952 
14953  if (PQntuples(res) != 1)
14954  {
14955  if (PQntuples(res) < 1)
14956  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned no data\n",
14957  tbinfo->dobj.name);
14958  else
14959  exit_horribly(NULL, "query to obtain definition of view \"%s\" returned more than one definition\n",
14960  tbinfo->dobj.name);
14961  }
14962 
14963  len = PQgetlength(res, 0, 0);
14964 
14965  if (len == 0)
14966  exit_horribly(NULL, "definition of view \"%s\" appears to be empty (length zero)\n",
14967  tbinfo->dobj.name);
14968 
14969  /* Strip off the trailing semicolon so that other things may follow. */
14970  Assert(PQgetvalue(res, 0, 0)[len - 1] == ';');
14971  appendBinaryPQExpBuffer(result, PQgetvalue(res, 0, 0), len - 1);
14972 
14973  PQclear(res);
14974  destroyPQExpBuffer(query);
14975 
14976  return result;
14977 }
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3078
char * name
Definition: pg_dump.h:133
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
return result
Definition: formatting.c:1633
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
DumpableObject dobj
Definition: pg_dump.h:261
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h: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 12274 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().

12275 {
12276  DumpOptions *dopt = fout->dopt;
12277  PQExpBuffer q;
12278  PQExpBuffer delq;
12279  PQExpBuffer labelq;
12280  char *qamname;
12281 
12282  /* Skip if not to be dumped */
12283  if (!aminfo->dobj.dump || dopt->dataOnly)
12284  return;
12285 
12286  q = createPQExpBuffer();
12287  delq = createPQExpBuffer();
12288  labelq = createPQExpBuffer();
12289 
12290  qamname = pg_strdup(fmtId(aminfo->dobj.name));
12291 
12292  appendPQExpBuffer(q, "CREATE ACCESS METHOD %s ", qamname);
12293 
12294  switch (aminfo->amtype)
12295  {
12296  case AMTYPE_INDEX:
12297  appendPQExpBuffer(q, "TYPE INDEX ");
12298  break;
12299  default:
12300  write_msg(NULL, "WARNING: invalid type \"%c\" of access method \"%s\"\n",
12301  aminfo->amtype, qamname);
12302  pg_free(qamname);
12303  destroyPQExpBuffer(q);
12304  destroyPQExpBuffer(delq);
12305  destroyPQExpBuffer(labelq);
12306  return;
12307  }
12308 
12309  appendPQExpBuffer(q, "HANDLER %s;\n", aminfo->amhandler);
12310 
12311  appendPQExpBuffer(delq, "DROP ACCESS METHOD %s;\n",
12312  qamname);
12313 
12314  appendPQExpBuffer(labelq, "ACCESS METHOD %s",
12315  qamname);
12316 
12317  if (dopt->binary_upgrade)
12318  binary_upgrade_extension_member(q, &aminfo->dobj, labelq->data);
12319 
12320  if (aminfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
12321  ArchiveEntry(fout, aminfo->dobj.catId, aminfo->dobj.dumpId,
12322  aminfo->dobj.name,
12323  NULL,
12324  NULL,
12325  "",
12326  false, "ACCESS METHOD", SECTION_PRE_DATA,
12327  q->data, delq->data, NULL,
12328  NULL, 0,
12329  NULL, NULL);
12330 
12331  /* Dump Access Method Comments */
12332  if (aminfo->dobj.dump & DUMP_COMPONENT_COMMENT)
12333  dumpComment(fout, labelq->data,
12334  NULL, "",
12335  aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
12336 
12337  pg_free(qamname);
12338 
12339  destroyPQExpBuffer(q);
12340  destroyPQExpBuffer(delq);
12341  destroyPQExpBuffer(labelq);
12342 }
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9050
DumpOptions * dopt
Definition: pg_backup.h:180
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define AMTYPE_INDEX
Definition: pg_am.h:61
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
static void binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, DumpableObject *dobj, const char *objlabel)
Definition: pg_dump.c:4029
#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 14440 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().

14445 {
14446  DumpOptions *dopt = fout->dopt;
14447  PQExpBuffer sql;
14448 
14449  /* Do nothing if ACL dump is not enabled */
14450  if (dopt->aclsSkip)
14451  return;
14452 
14453  /* --data-only skips ACLs *except* BLOB ACLs */
14454  if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
14455  return;
14456 
14457  sql = createPQExpBuffer();
14458 
14459  /*
14460  * Check to see if this object has had any initial ACLs included for it.
14461  * If so, we are in binary upgrade mode and these are the ACLs to turn
14462  * into GRANT and REVOKE statements to set and record the initial
14463  * privileges for an extension object. Let the backend know that these
14464  * are to be recorded by calling binary_upgrade_set_record_init_privs()
14465  * before and after.
14466  */
14467  if (strlen(initacls) != 0 || strlen(initracls) != 0)
14468  {
14469  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(true);\n");
14470  if (!buildACLCommands(name, subname, type, initacls, initracls, owner,
14471  "", fout->remoteVersion, sql))
14473  "could not parse initial GRANT ACL list (%s) or initial REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14474  initacls, initracls, name, type);
14475  appendPQExpBuffer(sql, "SELECT pg_catalog.binary_upgrade_set_record_init_privs(false);\n");
14476  }
14477 
14478  if (!buildACLCommands(name, subname, type, acls, racls, owner,
14479  "", fout->remoteVersion, sql))
14481  "could not parse GRANT ACL list (%s) or REVOKE ACL list (%s) for object \"%s\" (%s)\n",
14482  acls, racls, name, type);
14483 
14484  if (sql->len > 0)
14486  tag, nspname,
14487  NULL,
14488  owner ? owner : "",
14489  false, "ACL", SECTION_NONE,
14490  sql->data, "", NULL,
14491  &(objDumpId), 1,
14492  NULL, NULL);
14493 
14494  destroyPQExpBuffer(sql);
14495 }
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpOptions * dopt
Definition: pg_backup.h:180
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
bool aclsSkip
Definition: pg_backup.h:141
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define NULL
Definition: c.h:229
bool buildACLCommands(const char *name, const char *subname, const char *type, const char *acls, const char *racls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql)
Definition: dumputils.c:55
const char * name
Definition: encode.c:521
void exit_horribly(const char *modulename, const char *fmt,...)
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:132
DumpId createDumpId(void)
Definition: common.c:501
int remoteVersion
Definition: pg_backup.h:185
static void dumpAgg ( Archive fout,
AggInfo agginfo 
)
static

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

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

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

15760 {
15761  DumpOptions *dopt = fout->dopt;
15762  TableInfo *tbinfo = adinfo->adtable;
15763  int adnum = adinfo->adnum;
15764  PQExpBuffer q;
15765  PQExpBuffer delq;
15766  char *tag;
15767 
15768  /* Skip if table definition not to be dumped */
15769  if (!tbinfo->dobj.dump || dopt->dataOnly)
15770  return;
15771 
15772  /* Skip if not "separate"; it was dumped in the table's definition */
15773  if (!adinfo->separate)
15774  return;
15775 
15776  q = createPQExpBuffer();
15777  delq = createPQExpBuffer();
15778 
15779  appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
15780  fmtId(tbinfo->dobj.name));
15781  appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n",
15782  fmtId(tbinfo->attnames[adnum - 1]),
15783  adinfo->adef_expr);
15784 
15785  /*
15786  * DROP must be fully qualified in case same name appears in pg_catalog
15787  */
15788  appendPQExpBuffer(delq, "ALTER TABLE %s.",
15789  fmtId(tbinfo->dobj.namespace->dobj.name));
15790  appendPQExpBuffer(delq, "%s ",
15791  fmtId(tbinfo->dobj.name));
15792  appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n",
15793  fmtId(tbinfo->attnames[adnum - 1]));
15794 
15795  tag = psprintf("%s %s", tbinfo->dobj.name, tbinfo->attnames[adnum - 1]);
15796 
15797  if (adinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
15798  ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
15799  tag,
15800  tbinfo->dobj.namespace->dobj.name,
15801  NULL,
15802  tbinfo->rolname,
15803  false, "DEFAULT", SECTION_PRE_DATA,
15804  q->data, delq->data, NULL,
15805  NULL, 0,
15806  NULL, NULL);
15807 
15808  free(tag);
15809  destroyPQExpBuffer(q);
15810  destroyPQExpBuffer(delq);
15811 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * rolname
Definition: pg_dump.h:262
DumpId dumpId
Definition: pg_dump.h:132
char ** attnames
Definition: pg_dump.h:304
DumpableObject dobj
Definition: pg_dump.h:261
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
bool separate
Definition: pg_dump.h:342
DumpOptions * dopt
Definition: pg_backup.h:180
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
TableInfo * adtable
Definition: pg_dump.h:339
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
DumpableObject dobj
Definition: pg_dump.h:338
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
char * adef_expr
Definition: pg_dump.h:341
static void dumpBaseType ( Archive fout,
TypeInfo tyinfo 
)
static

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

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

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

2983 {
2984  PQExpBuffer cquery = createPQExpBuffer();
2985  PQExpBuffer dquery = createPQExpBuffer();
2986 
2987  appendPQExpBuffer(cquery,
2988  "SELECT pg_catalog.lo_create('%s');\n",
2989  binfo->dobj.name);
2990 
2991  appendPQExpBuffer(dquery,
2992  "SELECT pg_catalog.lo_unlink('%s');\n",
2993  binfo->dobj.name);
2994 
2995  if (binfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
2996  ArchiveEntry(fout, binfo->dobj.catId, binfo->dobj.dumpId,
2997  binfo->dobj.name,
2998  NULL, NULL,
2999  binfo->rolname, false,
3000  "BLOB", SECTION_PRE_DATA,
3001  cquery->data, dquery->data, NULL,
3002  NULL, 0,
3003  NULL, NULL);
3004 
3005  /* set up tag for comment and/or ACL */
3006  resetPQExpBuffer(cquery);
3007  appendPQExpBuffer(cquery, "LARGE OBJECT %s", binfo->dobj.name);
3008 
3009  /* Dump comment if any */
3010  if (binfo->dobj.dump & DUMP_COMPONENT_COMMENT)
3011  dumpComment(fout, cquery->data,
3012  NULL, binfo->rolname,
3013  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3014 
3015  /* Dump security label if any */
3016  if (binfo->dobj.dump & DUMP_COMPONENT_SECLABEL)
3017  dumpSecLabel(fout, cquery->data,
3018  NULL, binfo->rolname,
3019  binfo->dobj.catId, 0, binfo->dobj.dumpId);
3020 
3021  /* Dump ACL if any */
3022  if (binfo->blobacl && (binfo->dobj.dump & DUMP_COMPONENT_ACL))
3023  dumpACL(fout, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT",
3024  binfo->dobj.name, NULL, cquery->data,
3025  NULL, binfo->rolname, binfo->blobacl, binfo->rblobacl,
3026  binfo->initblobacl, binfo->initrblobacl);
3027 
3028  destroyPQExpBuffer(cquery);
3029  destroyPQExpBuffer(dquery);
3030 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
DumpId dumpId
Definition: pg_dump.h:132
char * initblobacl
Definition: pg_dump.h:555
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
DumpableObject dobj
Definition: pg_dump.h:551
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9050
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:14516
char * rolname
Definition: pg_dump.h:552
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define DUMP_COMPONENT_COMMENT
Definition: pg_dump.h:94
#define DUMP_COMPONENT_DEFINITION
Definition: pg_dump.h:92
#define NULL
Definition: c.h:229
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, const char *type, const char *name, const char *subname, const char *tag, const char *nspname, const char *owner, const char *acls, const char *racls, const char *initacls, const char *initracls)
Definition: pg_dump.c:14440
#define DUMP_COMPONENT_SECLABEL
Definition: pg_dump.h:95
char * blobacl
Definition: pg_dump.h:553
#define DUMP_COMPONENT_ACL
Definition: pg_dump.h:96
CatalogId catId
Definition: pg_dump.h:131
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
char * rblobacl
Definition: pg_dump.h:554
char * initrblobacl
Definition: pg_dump.h:556
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
static int dumpBlobs ( Archive fout,
void *  arg 
)
static

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

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

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

11710 {
11711  DumpOptions *dopt = fout->dopt;
11712  PQExpBuffer defqry;
11713  PQExpBuffer delqry;
11714  PQExpBuffer labelq;
11715  FuncInfo *funcInfo = NULL;
11716  char *sourceType;
11717  char *targetType;
11718 
11719  /* Skip if not to be dumped */
11720  if (!cast->dobj.dump || dopt->dataOnly)
11721  return;
11722 
11723  /* Cannot dump if we don't have the cast function's info */
11724  if (OidIsValid(cast->castfunc))
11725  {
11726  funcInfo = findFuncByOid(cast->castfunc);
11727  if (funcInfo == NULL)
11728  exit_horribly(NULL, "could not find function definition for function with OID %u\n",
11729  cast->castfunc);
11730  }
11731 
11732  /*
11733  * Make sure we are in proper schema (needed for getFormattedTypeName).
11734  * Casts don't have a schema of their own, so use pg_catalog.
11735  */
11736  selectSourceSchema(fout, "pg_catalog");
11737 
11738  defqry = createPQExpBuffer();
11739  delqry = createPQExpBuffer();
11740  labelq = createPQExpBuffer();
11741 
11742  sourceType = getFormattedTypeName(fout, cast->castsource, zeroAsNone);
11743  targetType = getFormattedTypeName(fout, cast->casttarget, zeroAsNone);
11744  appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
11745  sourceType, targetType);
11746 
11747  appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
11748  sourceType, targetType);
11749 
11750  switch (cast->castmethod)
11751  {
11753  appendPQExpBufferStr(defqry, "WITHOUT FUNCTION");
11754  break;
11755  case COERCION_METHOD_INOUT:
11756  appendPQExpBufferStr(defqry, "WITH INOUT");
11757  break;
11759  if (funcInfo)
11760  {
11761  char *fsig = format_function_signature(fout, funcInfo, true);
11762 
11763  /*
11764  * Always qualify the function name, in case it is not in
11765  * pg_catalog schema (format_function_signature won't qualify
11766  * it).
11767  */
11768  appendPQExpBuffer(defqry, "WITH FUNCTION %s.%s",
11769  fmtId(funcInfo->dobj.namespace->dobj.name), fsig);
11770  free(fsig);
11771  }
11772  else
11773  write_msg(NULL, "WARNING: bogus value in pg_cast.castfunc or pg_cast.castmethod field\n");
11774  break;
11775  default:
11776  write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
11777  }
11778 
11779  if (cast->castcontext == 'a')
11780  appendPQExpBufferStr(defqry, " AS ASSIGNMENT");
11781  else if (cast->castcontext == 'i')
11782  appendPQExpBufferStr(defqry, " AS IMPLICIT");
11783  appendPQExpBufferStr(defqry, ";\n");
11784 
11785  appendPQExpBuffer(labelq, "CAST (%s AS %s)",
11786  sourceType, targetType);
11787 
11788  if (dopt->binary_upgrade)
11789  binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data);
11790 
11791  if (cast->dobj.dump & DUMP_COMPONENT_DEFINITION)
11792  ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
11793  labelq->data,
11794  "pg_catalog", NULL, "",
11795  false, "CAST", SECTION_PRE_DATA,
11796  defqry->data, delqry->data, NULL,
11797  NULL, 0,
11798  NULL, NULL);
11799 
11800  /* Dump Cast Comments */
11801  if (cast->dobj.dump & DUMP_COMPONENT_COMMENT)
11802  dumpComment(fout, labelq->data,
11803  "pg_catalog", "",
11804  cast->dobj.catId, 0, cast->dobj.dumpId);
11805 
11806  free(sourceType);
11807  free(targetType);
11808 
11809  destroyPQExpBuffer(defqry);
11810  destroyPQExpBuffer(delqry);
11811  destroyPQExpBuffer(labelq);
11812 }
static char * getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
Definition: pg_dump.c:17754
char * name
Definition: pg_dump.h:133
Oid castsource
Definition: pg_dump.h:456
DumpComponents dump
Definition: pg_dump.h:134
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
DumpableObject dobj
Definition: pg_dump.h:198
DumpId dumpId
Definition: pg_dump.h:132
Oid castfunc
Definition: pg_dump.h:458
#define OidIsValid(objectId)
Definition: c.h:538
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpableObject dobj
Definition: pg_dump.h:455
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9050
Oid casttarget
Definition: pg_dump.h:457
DumpOptions * dopt
Definition: pg_backup.h:180
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17728
FuncInfo * findFuncByOid(Oid oid)
Definition: common.c:762
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:4029
#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:11173
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 13003 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().

13004 {
13005  DumpOptions *dopt = fout->dopt;
13006  PQExpBuffer query;
13007  PQExpBuffer q;
13008  PQExpBuffer delq;
13009  PQExpBuffer labelq;
13010  PGresult *res;
13011  int i_collprovider;
13012  int i_collcollate;
13013  int i_collctype;
13014  const char *collprovider;
13015  const char *collcollate;
13016  const char *collctype;
13017 
13018  /* Skip if not to be dumped */
13019  if (!collinfo->dobj.dump || dopt->dataOnly)
13020  return;
13021 
13022  query = createPQExpBuffer();
13023  q = createPQExpBuffer();
13024  delq = createPQExpBuffer();
13025  labelq = createPQExpBuffer();
13026 
13027  /* Make sure we are in proper schema */
13028  selectSourceSchema(fout, collinfo->dobj.namespace->dobj.name);
13029 
13030  /* Get collation-specific details */
13031  if (fout->remoteVersion >= 100000)
13032  appendPQExpBuffer(query, "SELECT "
13033  "collprovider, "
13034  "collcollate, "
13035  "collctype, "
13036  "collversion "
13037  "FROM pg_catalog.pg_collation c "
13038  "WHERE c.oid = '%u'::pg_catalog.oid",
13039  collinfo->dobj.catId.oid);
13040  else
13041  appendPQExpBuffer(query, "SELECT "
13042  "'c'::char AS collprovider, "
13043  "collcollate, "
13044  "collctype, "
13045  "NULL AS collversion "
13046  "FROM pg_catalog.pg_collation c "
13047  "WHERE c.oid = '%u'::pg_catalog.oid",
13048  collinfo->dobj.catId.oid);
13049 
13050  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13051 
13052  i_collprovider = PQfnumber(res, "collprovider");
13053  i_collcollate = PQfnumber(res, "collcollate");
13054  i_collctype = PQfnumber(res, "collctype");
13055 
13056  collprovider = PQgetvalue(res, 0, i_collprovider);
13057  collcollate = PQgetvalue(res, 0, i_collcollate);
13058  collctype = PQgetvalue(res, 0, i_collctype);
13059 
13060  /*
13061  * DROP must be fully qualified in case same name appears in pg_catalog
13062  */
13063  appendPQExpBuffer(delq, "DROP COLLATION %s",
13064  fmtId(collinfo->dobj.namespace->dobj.name));
13065  appendPQExpBuffer(delq, ".%s;\n",
13066  fmtId(collinfo->dobj.name));
13067 
13068  appendPQExpBuffer(q, "CREATE COLLATION %s (",
13069  fmtId(collinfo->dobj.name));
13070 
13071  appendPQExpBufferStr(q, "provider = ");
13072  if (collprovider[0] == 'c')
13073  appendPQExpBufferStr(q, "libc");
13074  else if (collprovider[0] == 'i')
13075  appendPQExpBufferStr(q, "icu");
13076  else if (collprovider[0] == 'd')
13077  /* to allow dumping pg_catalog; not accepted on input */
13078  appendPQExpBufferStr(q, "default");
13079  else
13081  "unrecognized collation provider: %s\n",
13082  collprovider);
13083 
13084  if (strcmp(collcollate, collctype) == 0)
13085  {
13086  appendPQExpBufferStr(q, ", locale = ");
13087  appendStringLiteralAH(q, collcollate, fout);
13088  }
13089  else
13090  {
13091  appendPQExpBufferStr(q, ", lc_collate = ");
13092  appendStringLiteralAH(q, collcollate, fout);
13093  appendPQExpBufferStr(q, ", lc_ctype = ");
13094  appendStringLiteralAH(q, collctype, fout);
13095  }
13096 
13097  /*
13098  * For binary upgrade, carry over the collation version. For normal
13099  * dump/restore, omit the version, so that it is computed upon restore.
13100  */
13101  if (dopt->binary_upgrade)
13102  {
13103  int i_collversion;
13104 
13105  i_collversion = PQfnumber(res, "collversion");
13106  if (!PQgetisnull(res, 0, i_collversion))
13107  {
13108  appendPQExpBufferStr(q, ", version = ");
13110  PQgetvalue(res, 0, i_collversion),
13111  fout);
13112  }
13113  }
13114 
13115  appendPQExpBufferStr(q, ");\n");
13116 
13117  appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name));
13118 
13119  if (dopt->binary_upgrade)
13120  binary_upgrade_extension_member(q, &collinfo->dobj, labelq->data);
13121 
13122  if (collinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13123  ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId,
13124  collinfo->dobj.name,
13125  collinfo->dobj.namespace->dobj.name,
13126  NULL,
13127  collinfo->rolname,
13128  false, "COLLATION", SECTION_PRE_DATA,
13129  q->data, delq->data, NULL,
13130  NULL, 0,
13131  NULL, NULL);
13132 
13133  /* Dump Collation Comments */
13134  if (collinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13135  dumpComment(fout, labelq->data,
13136  collinfo->dobj.namespace->dobj.name, collinfo->rolname,
13137  collinfo->dobj.catId, 0, collinfo->dobj.dumpId);
13138 
13139  PQclear(res);
13140 
13141  destroyPQExpBuffer(query);
13142  destroyPQExpBuffer(q);
13143  destroyPQExpBuffer(delq);
13144  destroyPQExpBuffer(labelq);
13145 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
DumpId dumpId
Definition: pg_dump.h:132
DumpableObject dobj
Definition: pg_dump.h:246
char * rolname
Definition: pg_dump.h:247
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9050
DumpOptions * dopt
Definition: pg_backup.h:180
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17728
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:4029
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:298
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:185
static void dumpComment ( Archive fout,
const char *  target,
const char *  namespace,
const char *  owner,
CatalogId  catalogId,
int  subid,
DumpId  dumpId 
)
static

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

9053 {
9054  DumpOptions *dopt = fout->dopt;
9055  CommentItem *comments;
9056  int ncomments;
9057 
9058  /* Comments are schema not data ... except blob comments are data */
9059  if (strncmp(target, "LARGE OBJECT ", 13) != 0)
9060  {
9061  if (dopt->dataOnly)
9062  return;
9063  }
9064  else
9065  {
9066  /* We do dump blob comments in binary-upgrade mode */
9067  if (dopt->schemaOnly && !dopt->binary_upgrade)
9068  return;
9069  }
9070 
9071  /* Search for comments associated with catalogId, using table */
9072  ncomments = findComments(fout, catalogId.tableoid, catalogId.oid,
9073  &comments);
9074 
9075  /* Is there one matching the subid? */
9076  while (ncomments > 0)
9077  {
9078  if (comments->objsubid == subid)
9079  break;
9080  comments++;
9081  ncomments--;
9082  }
9083 
9084  /* If a comment exists, build COMMENT ON statement */
9085  if (ncomments > 0)
9086  {
9087  PQExpBuffer query = createPQExpBuffer();
9088 
9089  appendPQExpBuffer(query, "COMMENT ON %s IS ", target);
9090  appendStringLiteralAH(query, comments->descr, fout);
9091  appendPQExpBufferStr(query, ";\n");
9092 
9093  /*
9094  * We mark comments as SECTION_NONE because they really belong in the
9095  * same section as their parent, whether that is pre-data or
9096  * post-data.
9097  */
9099  target, namespace, NULL, owner,
9100  false, "COMMENT", SECTION_NONE,
9101  query->data, "", NULL,
9102  &(dumpId), 1,
9103  NULL, NULL);
9104 
9105  destroyPQExpBuffer(query);
9106  }
9107 }
Oid tableoid
Definition: pg_backup.h:225
bool schemaOnly
Definition: pg_backup.h:138
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
int objsubid
Definition: pg_dump.c:70
static int findComments(Archive *fout, Oid classoid, Oid objoid, CommentItem **items)
Definition: pg_dump.c:9205
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
DumpOptions * dopt
Definition: pg_backup.h:180
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
const char * descr
Definition: pg_dump.c:67
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:298
#define NULL
Definition: c.h:229
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:132
DumpId createDumpId(void)
Definition: common.c:501
static void dumpCompositeType ( Archive fout,
TypeInfo tyinfo 
)
static

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

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

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

10764 {
10765  CommentItem *comments;
10766  int ncomments;
10767  PGresult *res;
10768  PQExpBuffer query;
10769  PQExpBuffer target;
10770  Oid pgClassOid;
10771  int i;
10772  int ntups;
10773  int i_attname;
10774  int i_attnum;
10775 
10776  query = createPQExpBuffer();
10777 
10778  appendPQExpBuffer(query,
10779  "SELECT c.tableoid, a.attname, a.attnum "
10780  "FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
10781  "WHERE c.oid = '%u' AND c.oid = a.attrelid "
10782  " AND NOT a.attisdropped "
10783  "ORDER BY a.attnum ",
10784  tyinfo->typrelid);
10785 
10786  /* Fetch column attnames */
10787  res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10788 
10789  ntups = PQntuples(res);
10790  if (ntups < 1)
10791  {
10792  PQclear(res);
10793  destroyPQExpBuffer(query);
10794  return;
10795  }
10796 
10797  pgClassOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "tableoid")));
10798 
10799  /* Search for comments associated with type's pg_class OID */
10800  ncomments = findComments(fout,
10801  pgClassOid,
10802  tyinfo->typrelid,
10803  &comments);
10804 
10805  /* If no comments exist, we're done */
10806  if (ncomments <= 0)
10807  {
10808  PQclear(res);
10809  destroyPQExpBuffer(query);
10810  return;
10811  }
10812 
10813  /* Build COMMENT ON statements */
10814  target = createPQExpBuffer();
10815 
10816  i_attnum = PQfnumber(res, "attnum");
10817  i_attname = PQfnumber(res, "attname");
10818  while (ncomments > 0)
10819  {
10820  const char *attname;
10821 
10822  attname = NULL;
10823  for (i = 0; i < ntups; i++)
10824  {
10825  if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid)
10826  {
10827  attname = PQgetvalue(res, i, i_attname);
10828  break;
10829  }
10830  }
10831  if (attname) /* just in case we don't find it */
10832  {
10833  const char *descr = comments->descr;
10834 
10835  resetPQExpBuffer(target);
10836  appendPQExpBuffer(target, "COLUMN %s.",
10837  fmtId(tyinfo->dobj.name));
10838  appendPQExpBufferStr(target, fmtId(attname));
10839 
10840  resetPQExpBuffer(query);
10841  appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
10842  appendStringLiteralAH(query, descr, fout);
10843  appendPQExpBufferStr(query, ";\n");
10844 
10846  target->data,
10847  tyinfo->dobj.namespace->dobj.name,
10848  NULL, tyinfo->rolname,
10849  false, "COMMENT", SECTION_NONE,
10850  query->data, "", NULL,
10851  &(tyinfo->dobj.dumpId), 1,
10852  NULL, NULL);
10853  }
10854 
10855  comments++;
10856  ncomments--;
10857  }
10858 
10859  PQclear(res);
10860  destroyPQExpBuffer(query);
10861  destroyPQExpBuffer(target);
10862 }
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:9205
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:298
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define NULL
Definition: c.h:229
char * rolname
Definition: pg_dump.h:171
int i
void ArchiveEntry(Archive *AHX, CatalogId catalogId, DumpId dumpId, const char *tag, const char *namespace, const char *tablespace, const char *owner, bool withOids, const char *desc, teSection section, const char *defn, const char *dropStmt, const char *copyStmt, const DumpId *deps, int nDeps, DataDumperPtr dumpFn, void *dumpArg)
static const CatalogId nilCatalogId
Definition: pg_dump.c:132
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:407
DumpId createDumpId(void)
Definition: common.c:501
static void dumpConstraint ( Archive fout,
ConstraintInfo coninfo 
)
static

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

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

13153 {
13154  DumpOptions *dopt = fout->dopt;
13155  PQExpBuffer query;
13156  PQExpBuffer q;
13157  PQExpBuffer delq;
13158  PQExpBuffer labelq;
13159  PGresult *res;
13160  int i_conforencoding;
13161  int i_contoencoding;
13162  int i_conproc;
13163  int i_condefault;
13164  const char *conforencoding;
13165  const char *contoencoding;
13166  const char *conproc;
13167  bool condefault;
13168 
13169  /* Skip if not to be dumped */
13170  if (!convinfo->dobj.dump || dopt->dataOnly)
13171  return;
13172 
13173  query = createPQExpBuffer();
13174  q = createPQExpBuffer();
13175  delq = createPQExpBuffer();
13176  labelq = createPQExpBuffer();
13177 
13178  /* Make sure we are in proper schema */
13179  selectSourceSchema(fout, convinfo->dobj.namespace->dobj.name);
13180 
13181  /* Get conversion-specific details */
13182  appendPQExpBuffer(query, "SELECT "
13183  "pg_catalog.pg_encoding_to_char(conforencoding) AS conforencoding, "
13184  "pg_catalog.pg_encoding_to_char(contoencoding) AS contoencoding, "
13185  "conproc, condefault "
13186  "FROM pg_catalog.pg_conversion c "
13187  "WHERE c.oid = '%u'::pg_catalog.oid",
13188  convinfo->dobj.catId.oid);
13189 
13190  res = ExecuteSqlQueryForSingleRow(fout, query->data);
13191 
13192  i_conforencoding = PQfnumber(res, "conforencoding");
13193  i_contoencoding = PQfnumber(res, "contoencoding");
13194  i_conproc = PQfnumber(res, "conproc");
13195  i_condefault = PQfnumber(res, "condefault");
13196 
13197  conforencoding = PQgetvalue(res, 0, i_conforencoding);
13198  contoencoding = PQgetvalue(res, 0, i_contoencoding);
13199  conproc = PQgetvalue(res, 0, i_conproc);
13200  condefault = (PQgetvalue(res, 0, i_condefault)[0] == 't');
13201 
13202  /*
13203  * DROP must be fully qualified in case same name appears in pg_catalog
13204  */
13205  appendPQExpBuffer(delq, "DROP CONVERSION %s",
13206  fmtId(convinfo->dobj.namespace->dobj.name));
13207  appendPQExpBuffer(delq, ".%s;\n",
13208  fmtId(convinfo->dobj.name));
13209 
13210  appendPQExpBuffer(q, "CREATE %sCONVERSION %s FOR ",
13211  (condefault) ? "DEFAULT " : "",
13212  fmtId(convinfo->dobj.name));
13213  appendStringLiteralAH(q, conforencoding, fout);
13214  appendPQExpBufferStr(q, " TO ");
13215  appendStringLiteralAH(q, contoencoding, fout);
13216  /* regproc output is already sufficiently quoted */
13217  appendPQExpBuffer(q, " FROM %s;\n", conproc);
13218 
13219  appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name));
13220 
13221  if (dopt->binary_upgrade)
13222  binary_upgrade_extension_member(q, &convinfo->dobj, labelq->data);
13223 
13224  if (convinfo->dobj.dump & DUMP_COMPONENT_DEFINITION)
13225  ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
13226  convinfo->dobj.name,
13227  convinfo->dobj.namespace->dobj.name,
13228  NULL,
13229  convinfo->rolname,
13230  false, "CONVERSION", SECTION_PRE_DATA,
13231  q->data, delq->data, NULL,
13232  NULL, 0,
13233  NULL, NULL);
13234 
13235  /* Dump Conversion Comments */
13236  if (convinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
13237  dumpComment(fout, labelq->data,
13238  convinfo->dobj.namespace->dobj.name, convinfo->rolname,
13239  convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
13240 
13241  PQclear(res);
13242 
13243  destroyPQExpBuffer(query);
13244  destroyPQExpBuffer(q);
13245  destroyPQExpBuffer(delq);
13246  destroyPQExpBuffer(labelq);
13247 }
char * name
Definition: pg_dump.h:133
DumpComponents dump
Definition: pg_dump.h:134
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
const char * fmtId(const char *rawid)
Definition: string_utils.c:66
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:385
char * rolname
Definition: pg_dump.h:253
DumpId dumpId
Definition: pg_dump.h:132
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
int binary_upgrade
Definition: pg_backup.h:135
static void dumpComment(Archive *fout, const char *target, const char *namespace, const char *owner, CatalogId catalogId, int subid, DumpId dumpId)
Definition: pg_dump.c:9050
DumpOptions * dopt
Definition: pg_backup.h:180
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
bool dataOnly
Definition: pg_backup.h:139
static void selectSourceSchema(Archive *fout, const char *schemaName)
Definition: pg_dump.c:17728
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:4029
#define appendStringLiteralAH(buf, str, AH)
Definition: pg_backup.h:298
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 2450 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().

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