PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_dump.h File Reference
#include "pg_backup.h"
#include "catalog/pg_publication_d.h"
Include dependency graph for pg_dump.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _dumpableObject
 
struct  _dumpableAcl
 
struct  _dumpableObjectWithAcl
 
struct  _namespaceInfo
 
struct  _extensionInfo
 
struct  _typeInfo
 
struct  _shellTypeInfo
 
struct  _funcInfo
 
struct  _aggInfo
 
struct  _oprInfo
 
struct  _accessMethodInfo
 
struct  _opclassInfo
 
struct  _opfamilyInfo
 
struct  _collInfo
 
struct  _convInfo
 
struct  _tableInfo
 
struct  _tableAttachInfo
 
struct  _attrDefInfo
 
struct  _tableDataInfo
 
struct  _indxInfo
 
struct  _indexAttachInfo
 
struct  _relStatsInfo
 
struct  _statsExtInfo
 
struct  _ruleInfo
 
struct  _triggerInfo
 
struct  _evttriggerInfo
 
struct  _constraintInfo
 
struct  _procLangInfo
 
struct  _castInfo
 
struct  _transformInfo
 
struct  _inhInfo
 
struct  _prsInfo
 
struct  _dictInfo
 
struct  _tmplInfo
 
struct  _cfgInfo
 
struct  _fdwInfo
 
struct  _foreignServerInfo
 
struct  _defaultACLInfo
 
struct  _loInfo
 
struct  _policyInfo
 
struct  _PublicationInfo
 
struct  _PublicationRelInfo
 
struct  _PublicationSchemaInfo
 
struct  _SubscriptionInfo
 
struct  _SubRelInfo
 

Macros

#define oidcmp(x, y)   ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
 
#define NUM_DUMPABLE_OBJECT_TYPES   (DO_SUBSCRIPTION_REL + 1)
 
#define DUMP_COMPONENT_NONE   (0)
 
#define DUMP_COMPONENT_DEFINITION   (1 << 0)
 
#define DUMP_COMPONENT_DATA   (1 << 1)
 
#define DUMP_COMPONENT_COMMENT   (1 << 2)
 
#define DUMP_COMPONENT_SECLABEL   (1 << 3)
 
#define DUMP_COMPONENT_ACL   (1 << 4)
 
#define DUMP_COMPONENT_POLICY   (1 << 5)
 
#define DUMP_COMPONENT_USERMAP   (1 << 6)
 
#define DUMP_COMPONENT_STATISTICS   (1 << 7)
 
#define DUMP_COMPONENT_ALL   (0xFFFF)
 
#define DUMP_COMPONENTS_REQUIRING_LOCK
 

Typedefs

typedef uint32 DumpComponents
 
typedef struct _dumpableObject DumpableObject
 
typedef struct _dumpableAcl DumpableAcl
 
typedef struct _dumpableObjectWithAcl DumpableObjectWithAcl
 
typedef struct _namespaceInfo NamespaceInfo
 
typedef struct _extensionInfo ExtensionInfo
 
typedef struct _typeInfo TypeInfo
 
typedef struct _shellTypeInfo ShellTypeInfo
 
typedef struct _funcInfo FuncInfo
 
typedef struct _aggInfo AggInfo
 
typedef struct _oprInfo OprInfo
 
typedef struct _accessMethodInfo AccessMethodInfo
 
typedef struct _opclassInfo OpclassInfo
 
typedef struct _opfamilyInfo OpfamilyInfo
 
typedef struct _collInfo CollInfo
 
typedef struct _convInfo ConvInfo
 
typedef struct _tableInfo TableInfo
 
typedef struct _tableAttachInfo TableAttachInfo
 
typedef struct _attrDefInfo AttrDefInfo
 
typedef struct _tableDataInfo TableDataInfo
 
typedef struct _indxInfo IndxInfo
 
typedef struct _indexAttachInfo IndexAttachInfo
 
typedef struct _relStatsInfo RelStatsInfo
 
typedef struct _statsExtInfo StatsExtInfo
 
typedef struct _ruleInfo RuleInfo
 
typedef struct _triggerInfo TriggerInfo
 
typedef struct _evttriggerInfo EventTriggerInfo
 
typedef struct _constraintInfo ConstraintInfo
 
typedef struct _procLangInfo ProcLangInfo
 
typedef struct _castInfo CastInfo
 
typedef struct _transformInfo TransformInfo
 
typedef struct _inhInfo InhInfo
 
typedef struct _prsInfo TSParserInfo
 
typedef struct _dictInfo TSDictInfo
 
typedef struct _tmplInfo TSTemplateInfo
 
typedef struct _cfgInfo TSConfigInfo
 
typedef struct _fdwInfo FdwInfo
 
typedef struct _foreignServerInfo ForeignServerInfo
 
typedef struct _defaultACLInfo DefaultACLInfo
 
typedef struct _loInfo LoInfo
 
typedef struct _policyInfo PolicyInfo
 
typedef struct _PublicationInfo PublicationInfo
 
typedef struct _PublicationRelInfo PublicationRelInfo
 
typedef struct _PublicationSchemaInfo PublicationSchemaInfo
 
typedef struct _SubscriptionInfo SubscriptionInfo
 
typedef struct _SubRelInfo SubRelInfo
 

Enumerations

enum  DumpableObjectType {
  DO_NAMESPACE , DO_EXTENSION , DO_TYPE , DO_SHELL_TYPE ,
  DO_FUNC , DO_AGG , DO_OPERATOR , DO_ACCESS_METHOD ,
  DO_OPCLASS , DO_OPFAMILY , DO_COLLATION , DO_CONVERSION ,
  DO_TABLE , DO_TABLE_ATTACH , DO_ATTRDEF , DO_INDEX ,
  DO_INDEX_ATTACH , DO_STATSEXT , DO_RULE , DO_TRIGGER ,
  DO_CONSTRAINT , DO_FK_CONSTRAINT , DO_PROCLANG , DO_CAST ,
  DO_TABLE_DATA , DO_SEQUENCE_SET , DO_DUMMY_TYPE , DO_TSPARSER ,
  DO_TSDICT , DO_TSTEMPLATE , DO_TSCONFIG , DO_FDW ,
  DO_FOREIGN_SERVER , DO_DEFAULT_ACL , DO_TRANSFORM , DO_LARGE_OBJECT ,
  DO_LARGE_OBJECT_DATA , DO_PRE_DATA_BOUNDARY , DO_POST_DATA_BOUNDARY , DO_EVENT_TRIGGER ,
  DO_REFRESH_MATVIEW , DO_POLICY , DO_PUBLICATION , DO_PUBLICATION_REL ,
  DO_PUBLICATION_TABLE_IN_SCHEMA , DO_REL_STATS , DO_SUBSCRIPTION , DO_SUBSCRIPTION_REL
}
 

Functions

TableInfogetSchemaData (Archive *fout, int *numTablesPtr)
 
void AssignDumpId (DumpableObject *dobj)
 
void recordAdditionalCatalogID (CatalogId catId, DumpableObject *dobj)
 
DumpId createDumpId (void)
 
DumpId getMaxDumpId (void)
 
DumpableObjectfindObjectByDumpId (DumpId dumpId)
 
DumpableObjectfindObjectByCatalogId (CatalogId catalogId)
 
void getDumpableObjects (DumpableObject ***objs, int *numObjs)
 
void addObjectDependency (DumpableObject *dobj, DumpId refId)
 
void removeObjectDependency (DumpableObject *dobj, DumpId refId)
 
TableInfofindTableByOid (Oid oid)
 
TypeInfofindTypeByOid (Oid oid)
 
FuncInfofindFuncByOid (Oid oid)
 
OprInfofindOprByOid (Oid oid)
 
AccessMethodInfofindAccessMethodByOid (Oid oid)
 
CollInfofindCollationByOid (Oid oid)
 
NamespaceInfofindNamespaceByOid (Oid oid)
 
ExtensionInfofindExtensionByOid (Oid oid)
 
PublicationInfofindPublicationByOid (Oid oid)
 
SubscriptionInfofindSubscriptionByOid (Oid oid)
 
void recordExtensionMembership (CatalogId catId, ExtensionInfo *ext)
 
ExtensionInfofindOwningExtension (CatalogId catalogId)
 
void parseOidArray (const char *str, Oid *array, int arraysize)
 
void sortDumpableObjects (DumpableObject **objs, int numObjs, DumpId preBoundaryId, DumpId postBoundaryId)
 
void sortDumpableObjectsByTypeName (DumpableObject **objs, int numObjs)
 
void getNamespaces (Archive *fout)
 
ExtensionInfogetExtensions (Archive *fout, int *numExtensions)
 
void getTypes (Archive *fout)
 
void getFuncs (Archive *fout)
 
void getAggregates (Archive *fout)
 
void getOperators (Archive *fout)
 
void getAccessMethods (Archive *fout)
 
void getOpclasses (Archive *fout)
 
void getOpfamilies (Archive *fout)
 
void getCollations (Archive *fout)
 
void getConversions (Archive *fout)
 
TableInfogetTables (Archive *fout, int *numTables)
 
void getOwnedSeqs (Archive *fout, TableInfo tblinfo[], int numTables)
 
InhInfogetInherits (Archive *fout, int *numInherits)
 
void getPartitioningInfo (Archive *fout)
 
void getIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getExtendedStatistics (Archive *fout)
 
void getConstraints (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getRules (Archive *fout)
 
void getTriggers (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getProcLangs (Archive *fout)
 
void getCasts (Archive *fout)
 
void getTransforms (Archive *fout)
 
void getTableAttrs (Archive *fout, TableInfo *tblinfo, int numTables)
 
bool shouldPrintColumn (const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
 
void getTSParsers (Archive *fout)
 
void getTSDictionaries (Archive *fout)
 
void getTSTemplates (Archive *fout)
 
void getTSConfigurations (Archive *fout)
 
void getForeignDataWrappers (Archive *fout)
 
void getForeignServers (Archive *fout)
 
void getDefaultACLs (Archive *fout)
 
void getExtensionMembership (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void processExtensionTables (Archive *fout, ExtensionInfo extinfo[], int numExtensions)
 
void getEventTriggers (Archive *fout)
 
void getPolicies (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getPublications (Archive *fout)
 
void getPublicationNamespaces (Archive *fout)
 
void getPublicationTables (Archive *fout, TableInfo tblinfo[], int numTables)
 
void getSubscriptions (Archive *fout)
 
void getSubscriptionRelations (Archive *fout)
 

Macro Definition Documentation

◆ DUMP_COMPONENT_ACL

#define DUMP_COMPONENT_ACL   (1 << 4)

Definition at line 113 of file pg_dump.h.

◆ DUMP_COMPONENT_ALL

#define DUMP_COMPONENT_ALL   (0xFFFF)

Definition at line 117 of file pg_dump.h.

◆ DUMP_COMPONENT_COMMENT

#define DUMP_COMPONENT_COMMENT   (1 << 2)

Definition at line 111 of file pg_dump.h.

◆ DUMP_COMPONENT_DATA

#define DUMP_COMPONENT_DATA   (1 << 1)

Definition at line 110 of file pg_dump.h.

◆ DUMP_COMPONENT_DEFINITION

#define DUMP_COMPONENT_DEFINITION   (1 << 0)

Definition at line 109 of file pg_dump.h.

◆ DUMP_COMPONENT_NONE

#define DUMP_COMPONENT_NONE   (0)

Definition at line 108 of file pg_dump.h.

◆ DUMP_COMPONENT_POLICY

#define DUMP_COMPONENT_POLICY   (1 << 5)

Definition at line 114 of file pg_dump.h.

◆ DUMP_COMPONENT_SECLABEL

#define DUMP_COMPONENT_SECLABEL   (1 << 3)

Definition at line 112 of file pg_dump.h.

◆ DUMP_COMPONENT_STATISTICS

#define DUMP_COMPONENT_STATISTICS   (1 << 7)

Definition at line 116 of file pg_dump.h.

◆ DUMP_COMPONENT_USERMAP

#define DUMP_COMPONENT_USERMAP   (1 << 6)

Definition at line 115 of file pg_dump.h.

◆ DUMP_COMPONENTS_REQUIRING_LOCK

#define DUMP_COMPONENTS_REQUIRING_LOCK
Value:
(\
#define DUMP_COMPONENT_DATA
Definition pg_dump.h:110
#define DUMP_COMPONENT_POLICY
Definition pg_dump.h:114
#define DUMP_COMPONENT_DEFINITION
Definition pg_dump.h:109
#define DUMP_COMPONENT_STATISTICS
Definition pg_dump.h:116

Definition at line 141 of file pg_dump.h.

147{
148 DumpableObjectType objType;
149 CatalogId catId; /* zero if not a cataloged object */
150 DumpId dumpId; /* assigned by AssignDumpId() */
151 char *name; /* object name (should never be NULL) */
152 struct _namespaceInfo *namespace; /* containing namespace, or NULL */
153 DumpComponents dump; /* bitmask of components requested to dump */
154 DumpComponents dump_contains; /* as above, but for contained objects */
155 DumpComponents components; /* bitmask of components available to dump */
156 bool ext_member; /* true if object is member of extension */
157 bool depends_on_ext; /* true if object depends on an extension */
158 DumpId *dependencies; /* dumpIds of objects this one depends on */
159 int nDeps; /* number of valid dependencies */
160 int allocDeps; /* allocated size of dependencies[] */
162
163/*
164 * Object types that have ACLs must store them in a DumpableAcl sub-struct,
165 * which must immediately follow the DumpableObject base struct.
166 */
167typedef struct _dumpableAcl
168{
169 char *acl; /* the object's actual ACL string */
170 char *acldefault; /* default ACL for the object's type & owner */
171 /* these fields come from the object's pg_init_privs entry, if any: */
172 char privtype; /* entry type, 'i' or 'e'; 0 if no entry */
173 char *initprivs; /* the object's initial ACL string, or NULL */
175
176/* Generic struct that can be used to access any object type having an ACL */
177typedef struct _dumpableObjectWithAcl
178{
182
183typedef struct _namespaceInfo
184{
187 bool create; /* CREATE SCHEMA, or just set owner? */
188 Oid nspowner; /* OID of owner */
189 const char *rolname; /* name of owner */
191
192typedef struct _extensionInfo
193{
195 char *namespace; /* schema containing extension's objects */
196 bool relocatable;
197 char *extversion;
198 char *extconfig; /* info about configuration tables */
199 char *extcondition;
201
202typedef struct _typeInfo
203{
206
207 /*
208 * Note: dobj.name is the raw pg_type.typname entry. ftypname is the
209 * result of format_type(), which will be quoted if needed, and might be
210 * schema-qualified too.
211 */
212 char *ftypname;
213 const char *rolname;
214 Oid typelem;
217 char typrelkind; /* 'r', 'v', 'c', etc */
218 char typtype; /* 'b', 'c', etc */
219 bool isArray; /* true if auto-generated array type */
220 bool isMultirange; /* true if auto-generated multirange type */
221 bool isDefined; /* true if typisdefined */
222 /* If needed, we'll create a "shell type" entry for it; link that here: */
223 struct _shellTypeInfo *shellType; /* shell-type entry, or NULL */
224 /* If it's a domain, its not-null constraint is here: */
225 struct _constraintInfo *notnull;
226 /* If it's a domain, we store links to its CHECK constraints here: */
227 int nDomChecks;
229} TypeInfo;
230
231typedef struct _shellTypeInfo
232{
234
235 TypeInfo *baseType; /* back link to associated base type */
237
238typedef struct _funcInfo
239{
242 const char *rolname;
243 Oid lang;
244 int nargs;
245 Oid *argtypes;
247 bool postponed_def; /* function must be postponed into post-data */
248} FuncInfo;
249
250/* AggInfo is a superset of FuncInfo */
251typedef struct _aggInfo
252{
254 /* we don't require any other fields at the moment */
255} AggInfo;
256
257typedef struct _oprInfo
258{
260 const char *rolname;
261 char oprkind;
262 Oid oprleft;
264 Oid oprcode;
265} OprInfo;
266
267typedef struct _accessMethodInfo
268{
270 char amtype;
271 char *amhandler;
273
274typedef struct _opclassInfo
275{
278 const char *rolname;
280
281typedef struct _opfamilyInfo
282{
285 const char *rolname;
287
288typedef struct _collInfo
289{
291 const char *rolname;
292 int collencoding;
293} CollInfo;
294
295typedef struct _convInfo
296{
298 const char *rolname;
299} ConvInfo;
300
301typedef struct _tableInfo
302{
303 /*
304 * These fields are collected for every table in the database.
305 */
308 const char *rolname;
309 char relkind;
310 char relpersistence; /* relation persistence */
311 bool relispopulated; /* relation is populated */
312 char relreplident; /* replica identifier */
313 char *reltablespace; /* relation tablespace */
314 char *reloptions; /* options specified by WITH (...) */
315 char *checkoption; /* WITH CHECK OPTION, if any */
316 char *toast_reloptions; /* WITH options for the TOAST table */
317 bool hasindex; /* does it have any indexes? */
318 bool hasrules; /* does it have any rules? */
319 bool hastriggers; /* does it have any triggers? */
320 bool hascolumnACLs; /* do any columns have non-default ACLs? */
321 bool rowsec; /* is row security enabled? */
322 bool forcerowsec; /* is row security forced? */
323 bool hasoids; /* does it have OIDs? */
324 uint32 frozenxid; /* table's relfrozenxid */
325 uint32 minmxid; /* table's relminmxid */
326 Oid toast_oid; /* toast table's OID, or 0 if none */
327 uint32 toast_frozenxid; /* toast table's relfrozenxid, if any */
328 uint32 toast_minmxid; /* toast table's relminmxid */
329 int ncheck; /* # of CHECK expressions */
330 Oid reltype; /* OID of table's composite type, if any */
331 Oid reloftype; /* underlying type for typed table */
332 Oid foreign_server; /* foreign server oid, if applicable */
333 /* these two are set only if table is a sequence owned by a column: */
334 Oid owning_tab; /* OID of table owning sequence */
335 int owning_col; /* attr # of column owning sequence */
337 int32 relpages; /* table's size in pages (from pg_class) */
338 int toastpages; /* toast table's size in pages, if any */
339
340 bool interesting; /* true if need to collect more data */
341 bool dummy_view; /* view's real definition must be postponed */
342 bool postponed_def; /* matview must be postponed into post-data */
343 bool ispartition; /* is table a partition? */
344 bool unsafe_partitions; /* is it an unsafe partitioned table? */
345
346 int numParents; /* number of (immediate) parent tables */
347 struct _tableInfo **parents; /* TableInfos of immediate parents */
348
349 /*
350 * These fields are computed only if we decide the table is interesting
351 * (it's either a table to dump, or a direct parent of a dumpable table).
352 */
353 int numatts; /* number of attributes */
354 char **attnames; /* the attribute names */
355 char **atttypnames; /* attribute type names */
356 int *attstattarget; /* attribute statistics targets */
357 char *attstorage; /* attribute storage scheme */
358 char *typstorage; /* type storage scheme */
359 bool *attisdropped; /* true if attr is dropped; don't dump it */
360 char *attidentity;
361 char *attgenerated;
362 int *attlen; /* attribute length, used by binary_upgrade */
363 char *attalign; /* attribute align, used by binary_upgrade */
364 bool *attislocal; /* true if attr has local definition */
365 char **attoptions; /* per-attribute options */
366 Oid *attcollation; /* per-attribute collation selection */
367 char *attcompression; /* per-attribute compression method */
368 char **attfdwoptions; /* per-attribute fdw options */
369 char **attmissingval; /* per attribute missing value */
370 char **notnull_constrs; /* NOT NULL constraint names. If null,
371 * there isn't one on this column. If
372 * empty string, unnamed constraint
373 * (pre-v17) */
374 char **notnull_comment; /* comment thereof */
375 bool *notnull_invalid; /* true for NOT NULL NOT VALID */
376 bool *notnull_noinh; /* NOT NULL is NO INHERIT */
377 bool *notnull_islocal; /* true if NOT NULL has local definition */
378 struct _attrDefInfo **attrdefs; /* DEFAULT expressions */
379 struct _constraintInfo *checkexprs; /* CHECK constraints */
380 struct _relStatsInfo *stats; /* only set for matviews */
381 bool needs_override; /* has GENERATED ALWAYS AS IDENTITY */
382 char *amname; /* relation access method */
383
384 /*
385 * Stuff computed only for dumpable tables.
386 */
387 int numIndexes; /* number of indexes */
388 struct _indxInfo *indexes; /* indexes */
389 struct _tableDataInfo *dataObj; /* TableDataInfo, if dumping its data */
390 int numTriggers; /* number of triggers for table */
391 struct _triggerInfo *triggers; /* array of TriggerInfo structs */
392} TableInfo;
393
394typedef struct _tableAttachInfo
395{
397 TableInfo *parentTbl; /* link to partitioned table */
398 TableInfo *partitionTbl; /* link to partition */
400
401typedef struct _attrDefInfo
402{
403 DumpableObject dobj; /* note: dobj.name is name of table */
404 TableInfo *adtable; /* link to table of attribute */
405 int adnum;
406 char *adef_expr; /* decompiled DEFAULT expression */
407 bool separate; /* true if must dump as separate item */
409
410typedef struct _tableDataInfo
411{
413 TableInfo *tdtable; /* link to table to dump */
414 char *filtercond; /* WHERE condition to limit rows dumped */
416
417typedef struct _indxInfo
418{
420 TableInfo *indextable; /* link to table the index is for */
421 char *indexdef;
422 char *tablespace; /* tablespace in which index is stored */
423 char *indreloptions; /* options specified by WITH (...) */
424 char *indstatcols; /* column numbers with statistics */
425 char *indstatvals; /* statistic values for columns */
426 int indnkeyattrs; /* number of index key attributes */
427 int indnattrs; /* total number of index attributes */
428 Oid *indkeys; /* In spite of the name 'indkeys' this field
429 * contains both key and nonkey attributes */
430 bool indisclustered;
431 bool indisreplident;
433 Oid parentidx; /* if a partition, parent index OID */
434 SimplePtrList partattaches; /* if partitioned, partition attach objects */
435
436 /* if there is an associated constraint object, its dumpId: */
438} IndxInfo;
439
440typedef struct _indexAttachInfo
441{
443 IndxInfo *parentIdx; /* link to index on partitioned table */
444 IndxInfo *partitionIdx; /* link to index on partition */
446
447typedef struct _relStatsInfo
448{
451 char *reltuples;
454 char relkind; /* 'r', 'm', 'i', etc */
455
456 /*
457 * indAttNames/nindAttNames are populated only if the relation is an index
458 * with at least one expression column; we don't need them otherwise.
459 */
460 char **indAttNames; /* attnames of the index, in order */
461 int32 nindAttNames; /* number of attnames stored (can be 0) */
462 teSection section; /* stats may appear in data or post-data */
464
465typedef struct _statsExtInfo
466{
468 const char *rolname; /* owner */
469 TableInfo *stattable; /* link to table the stats are for */
470 int stattarget; /* statistics target */
472
473typedef struct _ruleInfo
474{
476 TableInfo *ruletable; /* link to table the rule is for */
477 char ev_type;
478 bool is_instead;
479 char ev_enabled;
480 bool separate; /* true if must dump as separate item */
481 /* separate is always true for non-ON SELECT rules */
482} RuleInfo;
483
484typedef struct _triggerInfo
485{
487 TableInfo *tgtable; /* link to table the trigger is for */
488 char tgenabled;
489 bool tgispartition;
490 char *tgdef;
492
493typedef struct _evttriggerInfo
494{
496 char *evtname;
497 char *evtevent;
498 const char *evtowner;
499 char *evttags;
500 char *evtfname;
501 char evtenabled;
503
504/*
505 * struct ConstraintInfo is used for all constraint types. However we
506 * use a different objType for foreign key constraints, to make it easier
507 * to sort them the way we want.
508 *
509 * Not-null constraints don't need this, unless they are NOT VALID.
510 *
511 * Note: condeferrable and condeferred are currently only valid for
512 * unique/primary-key constraints. Otherwise that info is in condef.
513 */
514typedef struct _constraintInfo
515{
517 TableInfo *contable; /* NULL if domain constraint */
518 TypeInfo *condomain; /* NULL if table constraint */
519 char contype;
520 char *condef; /* definition, if CHECK or FOREIGN KEY */
521 Oid confrelid; /* referenced table, if FOREIGN KEY */
522 DumpId conindex; /* identifies associated index if any */
523 bool condeferrable; /* true if constraint is DEFERRABLE */
524 bool condeferred; /* true if constraint is INITIALLY DEFERRED */
525 bool conperiod; /* true if the constraint is WITHOUT OVERLAPS */
526 bool conislocal; /* true if constraint has local definition */
527 bool separate; /* true if must dump as separate item */
529
530typedef struct _procLangInfo
531{
534 bool lanpltrusted;
538 const char *lanowner;
540
541typedef struct _castInfo
542{
547 char castcontext;
548 char castmethod;
549} CastInfo;
550
551typedef struct _transformInfo
552{
554 Oid trftype;
555 Oid trflang;
559
560/* InhInfo isn't a DumpableObject, just temporary state */
561typedef struct _inhInfo
562{
563 Oid inhrelid; /* OID of a child table */
564 Oid inhparent; /* OID of its parent */
565} InhInfo;
566
567typedef struct _prsInfo
568{
572 Oid prsend;
576
577typedef struct _dictInfo
578{
580 const char *rolname;
582 char *dictinitoption;
583} TSDictInfo;
584
585typedef struct _tmplInfo
586{
591
592typedef struct _cfgInfo
593{
595 const char *rolname;
598
599typedef struct _fdwInfo
600{
603 const char *rolname;
604 char *fdwhandler;
605 char *fdwvalidator;
606 char *fdwoptions;
607} FdwInfo;
608
609typedef struct _foreignServerInfo
610{
613 const char *rolname;
614 Oid srvfdw;
615 char *srvtype;
616 char *srvversion;
617 char *srvoptions;
619
620typedef struct _defaultACLInfo
621{
624 const char *defaclrole;
625 char defaclobjtype;
627
628/*
629 * LoInfo represents a group of large objects (blobs) that share the same
630 * owner and ACL setting. dobj.components has the DUMP_COMPONENT_COMMENT bit
631 * set if any blob in the group has a comment; similarly for sec labels.
632 * If there are many blobs with the same owner/ACL, we can divide them into
633 * multiple LoInfo groups, which will each spawn a BLOB METADATA and a BLOBS
634 * (data) TOC entry. This allows more parallelism during restore.
635 */
636typedef struct _loInfo
637{
640 const char *rolname;
641 int numlos;
643} LoInfo;
644
645/*
646 * The PolicyInfo struct is used to represent policies on a table and
647 * to indicate if a table has RLS enabled (ENABLE ROW SECURITY). If
648 * polname is NULL, then the record indicates ENABLE ROW SECURITY, while if
649 * it's non-NULL then this is a regular policy definition.
650 */
651typedef struct _policyInfo
652{
655 char *polname; /* null indicates RLS is enabled on rel */
656 char polcmd;
657 bool polpermissive;
658 char *polroles;
659 char *polqual;
660 char *polwithcheck;
661} PolicyInfo;
662
663/*
664 * The PublicationInfo struct is used to represent publications.
665 */
666typedef struct _PublicationInfo
667{
669 const char *rolname;
670 bool puballtables;
671 bool puballsequences;
672 bool pubinsert;
673 bool pubupdate;
674 bool pubdelete;
675 bool pubtruncate;
676 bool pubviaroot;
679
680/*
681 * The PublicationRelInfo struct is used to represent publication table
682 * mapping.
683 */
684typedef struct _PublicationRelInfo
685{
689 char *pubrelqual;
690 char *pubrattrs;
692
693/*
694 * The PublicationSchemaInfo struct is used to represent publication schema
695 * mapping.
696 */
697typedef struct _PublicationSchemaInfo
698{
703
704/*
705 * The SubscriptionInfo struct is used to represent subscription.
706 */
707typedef struct _SubscriptionInfo
708{
710 const char *rolname;
711 bool subenabled;
712 bool subbinary;
713 char substream;
714 char subtwophasestate;
715 bool subdisableonerr;
717 bool subrunasowner;
718 bool subfailover;
720 int submaxretention;
721 char *subconninfo;
722 char *subslotname;
723 char *subsynccommit;
724 char *subpublications;
725 char *suborigin;
726 char *suboriginremotelsn;
728
729/*
730 * The SubRelInfo struct is used to represent a subscription relation.
731 *
732 * XXX Currently, the subscription tables are added to the subscription after
733 * enabling the subscription in binary-upgrade mode. As the apply workers will
734 * not be started in binary_upgrade mode the ordering of enable subscription
735 * does not matter. The order of adding the subscription tables to the
736 * subscription and enabling the subscription should be taken care of if this
737 * feature will be supported in a non-binary-upgrade mode in the future.
738 */
739typedef struct _SubRelInfo
740{
744 char srsubstate;
745 char *srsublsn;
746} SubRelInfo;
747
748/*
749 * common utility functions
750 */
751
753
754extern void AssignDumpId(DumpableObject *dobj);
755extern void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj);
756extern DumpId createDumpId(void);
757extern DumpId getMaxDumpId(void);
760extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
761
764
765extern TableInfo *findTableByOid(Oid oid);
766extern TypeInfo *findTypeByOid(Oid oid);
767extern FuncInfo *findFuncByOid(Oid oid);
768extern OprInfo *findOprByOid(Oid oid);
770extern CollInfo *findCollationByOid(Oid oid);
775
776extern void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext);
778
779extern void parseOidArray(const char *str, Oid *array, int arraysize);
780
784
785/*
786 * version specific routines
787 */
788extern void getNamespaces(Archive *fout);
790extern void getTypes(Archive *fout);
791extern void getFuncs(Archive *fout);
792extern void getAggregates(Archive *fout);
793extern void getOperators(Archive *fout);
794extern void getAccessMethods(Archive *fout);
795extern void getOpclasses(Archive *fout);
796extern void getOpfamilies(Archive *fout);
797extern void getCollations(Archive *fout);
798extern void getConversions(Archive *fout);
800extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
802extern void getPartitioningInfo(Archive *fout);
803extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
805extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
806extern void getRules(Archive *fout);
807extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
808extern void getProcLangs(Archive *fout);
809extern void getCasts(Archive *fout);
810extern void getTransforms(Archive *fout);
811extern void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables);
812extern bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno);
813extern void getTSParsers(Archive *fout);
814extern void getTSDictionaries(Archive *fout);
815extern void getTSTemplates(Archive *fout);
816extern void getTSConfigurations(Archive *fout);
818extern void getForeignServers(Archive *fout);
819extern void getDefaultACLs(Archive *fout);
821 int numExtensions);
823 int numExtensions);
824extern void getEventTriggers(Archive *fout);
825extern void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables);
826extern void getPublications(Archive *fout);
828extern void getPublicationTables(Archive *fout, TableInfo tblinfo[],
829 int numTables);
830extern void getSubscriptions(Archive *fout);
832
833#endif /* PG_DUMP_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:480
int32_t int32
Definition c.h:542
uint32_t uint32
Definition c.h:546
const char * str
int DumpId
Definition pg_backup.h:285
enum _teSection teSection
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8295
struct _collInfo CollInfo
void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj)
Definition common.c:719
struct _transformInfo TransformInfo
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6124
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition common.c:1063
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4757
struct _opfamilyInfo OpfamilyInfo
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7784
struct _indxInfo IndxInfo
struct _fdwInfo FdwInfo
struct _triggerInfo TriggerInfo
struct _tmplInfo TSTemplateInfo
struct _tableInfo TableInfo
FuncInfo * findFuncByOid(Oid oid)
Definition common.c:918
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7728
TableInfo * findTableByOid(Oid oid)
Definition common.c:863
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10415
struct _aggInfo AggInfo
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4248
ExtensionInfo * findExtensionByOid(Oid oid)
Definition common.c:1008
struct _castInfo CastInfo
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19932
CollInfo * findCollationByOid(Oid oid)
Definition common.c:972
struct _tableDataInfo TableDataInfo
struct _cfgInfo TSConfigInfo
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition common.c:1044
void getTypes(Archive *fout)
Definition pg_dump.c:6199
struct _dumpableObject DumpableObject
struct _accessMethodInfo AccessMethodInfo
struct _attrDefInfo AttrDefInfo
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7663
void getOpclasses(Archive *fout)
Definition pg_dump.c:6645
void getForeignServers(Archive *fout)
Definition pg_dump.c:10499
void getFuncs(Archive *fout)
Definition pg_dump.c:6914
OprInfo * findOprByOid(Oid oid)
Definition common.c:936
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10231
struct _ruleInfo RuleInfo
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4837
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition common.c:990
struct _relStatsInfo RelStatsInfo
void getCasts(Archive *fout)
Definition pg_dump.c:9044
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7844
AccessMethodInfo * findAccessMethodByOid(Oid oid)
Definition common.c:954
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:818
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10356
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition common.c:765
struct _foreignServerInfo ForeignServerInfo
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition common.c:1111
struct _inhInfo InhInfo
struct _indexAttachInfo IndexAttachInfo
struct _SubRelInfo SubRelInfo
struct _procLangInfo ProcLangInfo
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6571
void getConversions(Archive *fout)
Definition pg_dump.c:6509
void getRules(Archive *fout)
Definition pg_dump.c:8589
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition common.c:1087
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9238
struct _prsInfo TSParserInfo
struct _policyInfo PolicyInfo
TableInfo * getSchemaData(Archive *fout, int *numTablesPtr)
Definition common.c:98
struct _PublicationInfo PublicationInfo
void getCollations(Archive *fout)
Definition pg_dump.c:6443
struct _namespaceInfo NamespaceInfo
void getAggregates(Archive *fout)
Definition pg_dump.c:6773
struct _shellTypeInfo ShellTypeInfo
void getNamespaces(Archive *fout)
Definition pg_dump.c:5992
void getPublications(Archive *fout)
Definition pg_dump.c:4538
void getTSParsers(Archive *fout)
Definition pg_dump.c:10157
TypeInfo * findTypeByOid(Oid oid)
Definition common.c:899
struct _dumpableObjectWithAcl DumpableObjectWithAcl
struct _defaultACLInfo DefaultACLInfo
DumpId createDumpId(void)
Definition common.c:745
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7186
struct _loInfo LoInfo
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition common.c:778
void AssignDumpId(DumpableObject *dobj)
Definition common.c:657
struct _evttriggerInfo EventTriggerInfo
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8213
struct _dumpableAcl DumpableAcl
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20025
DumpId getMaxDumpId(void)
Definition common.c:754
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10587
uint32 DumpComponents
Definition pg_dump.h:107
struct _typeInfo TypeInfo
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5108
void sortDumpableObjects(DumpableObject **objs, int numObjs, DumpId preBoundaryId, DumpId postBoundaryId)
struct _SubscriptionInfo SubscriptionInfo
struct _extensionInfo ExtensionInfo
struct _dictInfo TSDictInfo
struct _funcInfo FuncInfo
struct _opclassInfo OpclassInfo
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition common.c:797
struct _statsExtInfo StatsExtInfo
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8686
void getTransforms(Archive *fout)
Definition pg_dump.c:9154
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8882
DumpableObjectType
Definition pg_dump.h:39
struct _PublicationRelInfo PublicationRelInfo
PublicationInfo * findPublicationByOid(Oid oid)
Definition common.c:1026
void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
struct _convInfo ConvInfo
struct _constraintInfo ConstraintInfo
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10297
void getProcLangs(Archive *fout)
Definition pg_dump.c:8960
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10142
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5328
struct _tableAttachInfo TableAttachInfo
void removeObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:843
void getOperators(Archive *fout)
Definition pg_dump.c:6367
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6708
struct _oprInfo OprInfo
struct _PublicationSchemaInfo PublicationSchemaInfo
unsigned int Oid
static int fb(int x)
const char * rolname
Definition pg_dump.h:670
bool puballsequences
Definition pg_dump.h:672
PublishGencolsType pubgencols_type
Definition pg_dump.h:678
DumpableObject dobj
Definition pg_dump.h:669
TableInfo * pubtable
Definition pg_dump.h:689
PublicationInfo * publication
Definition pg_dump.h:688
DumpableObject dobj
Definition pg_dump.h:687
NamespaceInfo * pubschema
Definition pg_dump.h:702
DumpableObject dobj
Definition pg_dump.h:700
PublicationInfo * publication
Definition pg_dump.h:701
DumpableObject dobj
Definition pg_dump.h:742
char * srsublsn
Definition pg_dump.h:746
SubscriptionInfo * subinfo
Definition pg_dump.h:743
TableInfo * tblinfo
Definition pg_dump.h:744
char srsubstate
Definition pg_dump.h:745
char * suboriginremotelsn
Definition pg_dump.h:727
bool subpasswordrequired
Definition pg_dump.h:717
const char * rolname
Definition pg_dump.h:711
char * subsynccommit
Definition pg_dump.h:724
char * subpublications
Definition pg_dump.h:725
char * subslotname
Definition pg_dump.h:723
char subtwophasestate
Definition pg_dump.h:715
bool subretaindeadtuples
Definition pg_dump.h:720
char * subconninfo
Definition pg_dump.h:722
DumpableObject dobj
Definition pg_dump.h:710
DumpableObject dobj
Definition pg_dump.h:270
FuncInfo aggfn
Definition pg_dump.h:254
DumpableObject dobj
Definition pg_dump.h:404
char * adef_expr
Definition pg_dump.h:407
TableInfo * adtable
Definition pg_dump.h:405
bool separate
Definition pg_dump.h:408
char castmethod
Definition pg_dump.h:549
Oid casttarget
Definition pg_dump.h:546
char castcontext
Definition pg_dump.h:548
DumpableObject dobj
Definition pg_dump.h:544
Oid castsource
Definition pg_dump.h:545
Oid castfunc
Definition pg_dump.h:547
Oid cfgparser
Definition pg_dump.h:597
DumpableObject dobj
Definition pg_dump.h:595
const char * rolname
Definition pg_dump.h:596
int collencoding
Definition pg_dump.h:293
const char * rolname
Definition pg_dump.h:292
DumpableObject dobj
Definition pg_dump.h:291
TypeInfo * condomain
Definition pg_dump.h:519
TableInfo * contable
Definition pg_dump.h:518
DumpableObject dobj
Definition pg_dump.h:517
DumpId conindex
Definition pg_dump.h:523
bool condeferrable
Definition pg_dump.h:524
char * condef
Definition pg_dump.h:521
DumpableObject dobj
Definition pg_dump.h:298
const char * rolname
Definition pg_dump.h:299
DumpableObject dobj
Definition pg_dump.h:623
DumpableAcl dacl
Definition pg_dump.h:624
const char * defaclrole
Definition pg_dump.h:625
char defaclobjtype
Definition pg_dump.h:626
char * dictinitoption
Definition pg_dump.h:583
DumpableObject dobj
Definition pg_dump.h:580
const char * rolname
Definition pg_dump.h:581
Oid dicttemplate
Definition pg_dump.h:582
char privtype
Definition pg_dump.h:173
char * acldefault
Definition pg_dump.h:171
char * acl
Definition pg_dump.h:170
char * initprivs
Definition pg_dump.h:174
DumpableObject dobj
Definition pg_dump.h:180
char * evtevent
Definition pg_dump.h:498
char * evtfname
Definition pg_dump.h:501
char * evtname
Definition pg_dump.h:497
const char * evtowner
Definition pg_dump.h:499
char * evttags
Definition pg_dump.h:500
DumpableObject dobj
Definition pg_dump.h:496
bool relocatable
Definition pg_dump.h:196
char * extversion
Definition pg_dump.h:198
DumpableObject dobj
Definition pg_dump.h:195
char * extcondition
Definition pg_dump.h:200
char * extconfig
Definition pg_dump.h:199
char * fdwhandler
Definition pg_dump.h:605
const char * rolname
Definition pg_dump.h:604
char * fdwvalidator
Definition pg_dump.h:606
char * fdwoptions
Definition pg_dump.h:607
DumpableAcl dacl
Definition pg_dump.h:603
DumpableObject dobj
Definition pg_dump.h:602
DumpableAcl dacl
Definition pg_dump.h:613
DumpableObject dobj
Definition pg_dump.h:612
const char * rolname
Definition pg_dump.h:614
bool postponed_def
Definition pg_dump.h:248
Oid lang
Definition pg_dump.h:244
const char * rolname
Definition pg_dump.h:243
Oid * argtypes
Definition pg_dump.h:246
Oid prorettype
Definition pg_dump.h:247
DumpableObject dobj
Definition pg_dump.h:241
int nargs
Definition pg_dump.h:245
DumpableAcl dacl
Definition pg_dump.h:242
IndxInfo * partitionIdx
Definition pg_dump.h:445
DumpableObject dobj
Definition pg_dump.h:443
IndxInfo * parentIdx
Definition pg_dump.h:444
bool indisreplident
Definition pg_dump.h:432
int indnkeyattrs
Definition pg_dump.h:427
char * indstatvals
Definition pg_dump.h:426
char * indstatcols
Definition pg_dump.h:425
int indnattrs
Definition pg_dump.h:428
TableInfo * indextable
Definition pg_dump.h:421
Oid parentidx
Definition pg_dump.h:434
Oid * indkeys
Definition pg_dump.h:429
char * indreloptions
Definition pg_dump.h:424
DumpId indexconstraint
Definition pg_dump.h:438
bool indisclustered
Definition pg_dump.h:431
SimplePtrList partattaches
Definition pg_dump.h:435
char * tablespace
Definition pg_dump.h:423
bool indnullsnotdistinct
Definition pg_dump.h:433
char * indexdef
Definition pg_dump.h:422
DumpableObject dobj
Definition pg_dump.h:420
Oid inhparent
Definition pg_dump.h:565
Oid inhrelid
Definition pg_dump.h:564
const char * rolname
Definition pg_dump.h:641
DumpableObject dobj
Definition pg_dump.h:639
DumpableAcl dacl
Definition pg_dump.h:640
Oid looids[FLEXIBLE_ARRAY_MEMBER]
Definition pg_dump.h:643
int numlos
Definition pg_dump.h:642
DumpableObject dobj
Definition pg_dump.h:186
DumpableAcl dacl
Definition pg_dump.h:187
const char * rolname
Definition pg_dump.h:190
Oid opcmethod
Definition pg_dump.h:278
DumpableObject dobj
Definition pg_dump.h:277
const char * rolname
Definition pg_dump.h:279
const char * rolname
Definition pg_dump.h:286
DumpableObject dobj
Definition pg_dump.h:284
DumpableObject dobj
Definition pg_dump.h:260
Oid oprleft
Definition pg_dump.h:263
char oprkind
Definition pg_dump.h:262
Oid oprcode
Definition pg_dump.h:265
Oid oprright
Definition pg_dump.h:264
const char * rolname
Definition pg_dump.h:261
TableInfo * poltable
Definition pg_dump.h:655
char * polqual
Definition pg_dump.h:660
char polcmd
Definition pg_dump.h:657
char * polroles
Definition pg_dump.h:659
char * polwithcheck
Definition pg_dump.h:661
DumpableObject dobj
Definition pg_dump.h:654
bool polpermissive
Definition pg_dump.h:658
char * polname
Definition pg_dump.h:656
Oid lanvalidator
Definition pg_dump.h:538
DumpableAcl dacl
Definition pg_dump.h:534
DumpableObject dobj
Definition pg_dump.h:533
const char * lanowner
Definition pg_dump.h:539
Oid lanplcallfoid
Definition pg_dump.h:536
bool lanpltrusted
Definition pg_dump.h:535
DumpableObject dobj
Definition pg_dump.h:570
Oid prstoken
Definition pg_dump.h:572
Oid prslextype
Definition pg_dump.h:575
Oid prsheadline
Definition pg_dump.h:574
Oid prsstart
Definition pg_dump.h:571
Oid prsend
Definition pg_dump.h:573
int32 nindAttNames
Definition pg_dump.h:462
char ** indAttNames
Definition pg_dump.h:461
int32 relpages
Definition pg_dump.h:451
int32 relallfrozen
Definition pg_dump.h:454
char * reltuples
Definition pg_dump.h:452
teSection section
Definition pg_dump.h:463
int32 relallvisible
Definition pg_dump.h:453
DumpableObject dobj
Definition pg_dump.h:450
DumpableObject dobj
Definition pg_dump.h:476
bool separate
Definition pg_dump.h:481
char ev_enabled
Definition pg_dump.h:480
bool is_instead
Definition pg_dump.h:479
TableInfo * ruletable
Definition pg_dump.h:477
char ev_type
Definition pg_dump.h:478
TypeInfo * baseType
Definition pg_dump.h:236
DumpableObject dobj
Definition pg_dump.h:234
TableInfo * stattable
Definition pg_dump.h:470
const char * rolname
Definition pg_dump.h:469
DumpableObject dobj
Definition pg_dump.h:468
TableInfo * partitionTbl
Definition pg_dump.h:399
DumpableObject dobj
Definition pg_dump.h:397
TableInfo * parentTbl
Definition pg_dump.h:398
TableInfo * tdtable
Definition pg_dump.h:414
DumpableObject dobj
Definition pg_dump.h:413
char * filtercond
Definition pg_dump.h:415
bool * notnull_invalid
Definition pg_dump.h:376
char * attidentity
Definition pg_dump.h:361
char * reltablespace
Definition pg_dump.h:314
char ** notnull_constrs
Definition pg_dump.h:371
struct _relStatsInfo * stats
Definition pg_dump.h:381
int ncheck
Definition pg_dump.h:330
bool ispartition
Definition pg_dump.h:344
struct _indxInfo * indexes
Definition pg_dump.h:389
bool * attislocal
Definition pg_dump.h:365
DumpableObject dobj
Definition pg_dump.h:307
bool is_identity_sequence
Definition pg_dump.h:337
Oid reloftype
Definition pg_dump.h:332
int numParents
Definition pg_dump.h:347
bool interesting
Definition pg_dump.h:341
char * toast_reloptions
Definition pg_dump.h:317
struct _tableInfo ** parents
Definition pg_dump.h:348
DumpableAcl dacl
Definition pg_dump.h:308
bool relispopulated
Definition pg_dump.h:312
char * attgenerated
Definition pg_dump.h:362
int * attlen
Definition pg_dump.h:363
Oid reltype
Definition pg_dump.h:331
char ** attfdwoptions
Definition pg_dump.h:369
bool hasoids
Definition pg_dump.h:324
Oid toast_oid
Definition pg_dump.h:327
Oid foreign_server
Definition pg_dump.h:333
char ** notnull_comment
Definition pg_dump.h:375
bool hasrules
Definition pg_dump.h:319
struct _triggerInfo * triggers
Definition pg_dump.h:392
bool * attisdropped
Definition pg_dump.h:360
bool needs_override
Definition pg_dump.h:382
struct _constraintInfo * checkexprs
Definition pg_dump.h:380
int * attstattarget
Definition pg_dump.h:357
bool * notnull_islocal
Definition pg_dump.h:378
uint32 frozenxid
Definition pg_dump.h:325
char * typstorage
Definition pg_dump.h:359
int owning_col
Definition pg_dump.h:336
char * checkoption
Definition pg_dump.h:316
int numatts
Definition pg_dump.h:354
bool hastriggers
Definition pg_dump.h:320
const char * rolname
Definition pg_dump.h:309
struct _attrDefInfo ** attrdefs
Definition pg_dump.h:379
char ** attoptions
Definition pg_dump.h:366
char relreplident
Definition pg_dump.h:313
int numTriggers
Definition pg_dump.h:391
uint32 minmxid
Definition pg_dump.h:326
Oid * attcollation
Definition pg_dump.h:367
bool * notnull_noinh
Definition pg_dump.h:377
char * attstorage
Definition pg_dump.h:358
int toastpages
Definition pg_dump.h:339
Oid owning_tab
Definition pg_dump.h:335
struct _tableDataInfo * dataObj
Definition pg_dump.h:390
char * amname
Definition pg_dump.h:383
bool dummy_view
Definition pg_dump.h:342
int32 relpages
Definition pg_dump.h:338
bool forcerowsec
Definition pg_dump.h:323
bool hascolumnACLs
Definition pg_dump.h:321
char ** atttypnames
Definition pg_dump.h:356
char ** attmissingval
Definition pg_dump.h:370
char relpersistence
Definition pg_dump.h:311
char ** attnames
Definition pg_dump.h:355
char relkind
Definition pg_dump.h:310
bool hasindex
Definition pg_dump.h:318
bool unsafe_partitions
Definition pg_dump.h:345
char * reloptions
Definition pg_dump.h:315
int numIndexes
Definition pg_dump.h:388
uint32 toast_frozenxid
Definition pg_dump.h:328
uint32 toast_minmxid
Definition pg_dump.h:329
char * attalign
Definition pg_dump.h:364
char * attcompression
Definition pg_dump.h:368
bool postponed_def
Definition pg_dump.h:343
bool rowsec
Definition pg_dump.h:322
Oid tmpllexize
Definition pg_dump.h:590
Oid tmplinit
Definition pg_dump.h:589
DumpableObject dobj
Definition pg_dump.h:588
DumpableObject dobj
Definition pg_dump.h:554
TableInfo * tgtable
Definition pg_dump.h:488
DumpableObject dobj
Definition pg_dump.h:487
char tgenabled
Definition pg_dump.h:489
char * tgdef
Definition pg_dump.h:491
bool tgispartition
Definition pg_dump.h:490
bool isMultirange
Definition pg_dump.h:221
struct _constraintInfo * domChecks
Definition pg_dump.h:229
DumpableAcl dacl
Definition pg_dump.h:206
DumpableObject dobj
Definition pg_dump.h:205
bool isDefined
Definition pg_dump.h:222
char * ftypname
Definition pg_dump.h:213
char typrelkind
Definition pg_dump.h:218
Oid typarray
Definition pg_dump.h:217
Oid typelem
Definition pg_dump.h:215
struct _shellTypeInfo * shellType
Definition pg_dump.h:224
int nDomChecks
Definition pg_dump.h:228
struct _constraintInfo * notnull
Definition pg_dump.h:226
char typtype
Definition pg_dump.h:219
const char * rolname
Definition pg_dump.h:214
Oid typrelid
Definition pg_dump.h:216
bool isArray
Definition pg_dump.h:220
const char * name

◆ NUM_DUMPABLE_OBJECT_TYPES

#define NUM_DUMPABLE_OBJECT_TYPES   (DO_SUBSCRIPTION_REL + 1)

Definition at line 91 of file pg_dump.h.

◆ oidcmp

#define oidcmp (   x,
  y 
)    ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )

Definition at line 21 of file pg_dump.h.

Typedef Documentation

◆ AccessMethodInfo

◆ AggInfo

◆ AttrDefInfo

◆ CastInfo

◆ CollInfo

◆ ConstraintInfo

◆ ConvInfo

◆ DefaultACLInfo

◆ DumpableAcl

◆ DumpableObject

◆ DumpableObjectWithAcl

◆ DumpComponents

Definition at line 107 of file pg_dump.h.

◆ EventTriggerInfo

◆ ExtensionInfo

◆ FdwInfo

◆ ForeignServerInfo

◆ FuncInfo

◆ IndexAttachInfo

◆ IndxInfo

◆ InhInfo

◆ LoInfo

◆ NamespaceInfo

◆ OpclassInfo

◆ OpfamilyInfo

◆ OprInfo

◆ PolicyInfo

◆ ProcLangInfo

◆ PublicationInfo

◆ PublicationRelInfo

◆ PublicationSchemaInfo

◆ RelStatsInfo

◆ RuleInfo

◆ ShellTypeInfo

◆ StatsExtInfo

◆ SubRelInfo

◆ SubscriptionInfo

◆ TableAttachInfo

◆ TableDataInfo

◆ TableInfo

◆ TransformInfo

◆ TriggerInfo

◆ TSConfigInfo

◆ TSDictInfo

◆ TSParserInfo

◆ TSTemplateInfo

◆ TypeInfo

Enumeration Type Documentation

◆ DumpableObjectType

Enumerator
DO_NAMESPACE 
DO_EXTENSION 
DO_TYPE 
DO_SHELL_TYPE 
DO_FUNC 
DO_AGG 
DO_OPERATOR 
DO_ACCESS_METHOD 
DO_OPCLASS 
DO_OPFAMILY 
DO_COLLATION 
DO_CONVERSION 
DO_TABLE 
DO_TABLE_ATTACH 
DO_ATTRDEF 
DO_INDEX 
DO_INDEX_ATTACH 
DO_STATSEXT 
DO_RULE 
DO_TRIGGER 
DO_CONSTRAINT 
DO_FK_CONSTRAINT 
DO_PROCLANG 
DO_CAST 
DO_TABLE_DATA 
DO_SEQUENCE_SET 
DO_DUMMY_TYPE 
DO_TSPARSER 
DO_TSDICT 
DO_TSTEMPLATE 
DO_TSCONFIG 
DO_FDW 
DO_FOREIGN_SERVER 
DO_DEFAULT_ACL 
DO_TRANSFORM 
DO_LARGE_OBJECT 
DO_LARGE_OBJECT_DATA 
DO_PRE_DATA_BOUNDARY 
DO_POST_DATA_BOUNDARY 
DO_EVENT_TRIGGER 
DO_REFRESH_MATVIEW 
DO_POLICY 
DO_PUBLICATION 
DO_PUBLICATION_REL 
DO_PUBLICATION_TABLE_IN_SCHEMA 
DO_REL_STATS 
DO_SUBSCRIPTION 
DO_SUBSCRIPTION_REL 

Definition at line 38 of file pg_dump.h.

39{
40 /* When modifying this enum, update priority tables in pg_dump_sort.c! */
43 DO_TYPE,
45 DO_FUNC,
46 DO_AGG,
59 DO_RULE,
62 DO_FK_CONSTRAINT, /* see note for ConstraintInfo */
64 DO_CAST,
72 DO_FDW,
88 DO_SUBSCRIPTION_REL, /* see note for SubRelInfo */
@ DO_EVENT_TRIGGER
Definition pg_dump.h:80
@ DO_REFRESH_MATVIEW
Definition pg_dump.h:81
@ DO_POLICY
Definition pg_dump.h:82
@ DO_CAST
Definition pg_dump.h:64
@ DO_FOREIGN_SERVER
Definition pg_dump.h:73
@ DO_PRE_DATA_BOUNDARY
Definition pg_dump.h:78
@ DO_PROCLANG
Definition pg_dump.h:63
@ DO_TYPE
Definition pg_dump.h:43
@ DO_INDEX
Definition pg_dump.h:56
@ DO_COLLATION
Definition pg_dump.h:51
@ DO_LARGE_OBJECT
Definition pg_dump.h:76
@ DO_TSCONFIG
Definition pg_dump.h:71
@ DO_OPERATOR
Definition pg_dump.h:47
@ DO_FK_CONSTRAINT
Definition pg_dump.h:62
@ DO_CONSTRAINT
Definition pg_dump.h:61
@ DO_SUBSCRIPTION
Definition pg_dump.h:87
@ DO_DEFAULT_ACL
Definition pg_dump.h:74
@ DO_FDW
Definition pg_dump.h:72
@ DO_SUBSCRIPTION_REL
Definition pg_dump.h:88
@ DO_REL_STATS
Definition pg_dump.h:86
@ DO_SEQUENCE_SET
Definition pg_dump.h:66
@ DO_ATTRDEF
Definition pg_dump.h:55
@ DO_PUBLICATION_REL
Definition pg_dump.h:84
@ DO_TABLE_ATTACH
Definition pg_dump.h:54
@ DO_OPCLASS
Definition pg_dump.h:49
@ DO_INDEX_ATTACH
Definition pg_dump.h:57
@ DO_TSTEMPLATE
Definition pg_dump.h:70
@ DO_STATSEXT
Definition pg_dump.h:58
@ DO_FUNC
Definition pg_dump.h:45
@ DO_POST_DATA_BOUNDARY
Definition pg_dump.h:79
@ DO_LARGE_OBJECT_DATA
Definition pg_dump.h:77
@ DO_OPFAMILY
Definition pg_dump.h:50
@ DO_TRANSFORM
Definition pg_dump.h:75
@ DO_ACCESS_METHOD
Definition pg_dump.h:48
@ DO_PUBLICATION_TABLE_IN_SCHEMA
Definition pg_dump.h:85
@ DO_CONVERSION
Definition pg_dump.h:52
@ DO_TRIGGER
Definition pg_dump.h:60
@ DO_RULE
Definition pg_dump.h:59
@ DO_DUMMY_TYPE
Definition pg_dump.h:67
@ DO_TSDICT
Definition pg_dump.h:69
@ DO_TSPARSER
Definition pg_dump.h:68
@ DO_EXTENSION
Definition pg_dump.h:42
@ DO_TABLE_DATA
Definition pg_dump.h:65
@ DO_PUBLICATION
Definition pg_dump.h:83
@ DO_TABLE
Definition pg_dump.h:53
@ DO_NAMESPACE
Definition pg_dump.h:41
@ DO_AGG
Definition pg_dump.h:46
@ DO_SHELL_TYPE
Definition pg_dump.h:44

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)
extern

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)
extern

Definition at line 657 of file common.c.

658{
659 dobj->dumpId = ++lastDumpId;
660 dobj->name = NULL; /* must be set later */
661 dobj->namespace = NULL; /* may be set later */
662 dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
663 dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
664 /* All objects have definitions; we may set more components bits later */
666 dobj->ext_member = false; /* default assumption */
667 dobj->depends_on_ext = false; /* default assumption */
668 dobj->dependencies = NULL;
669 dobj->nDeps = 0;
670 dobj->allocDeps = 0;
671
672 /* Add object to dumpIdMap[], enlarging that array if need be */
673 while (dobj->dumpId >= allocedDumpIds)
674 {
675 int newAlloc;
676
677 if (allocedDumpIds <= 0)
678 {
679 newAlloc = 256;
681 }
682 else
683 {
686 }
688 (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
690 }
691 dumpIdMap[dobj->dumpId] = dobj;
692
693 /* If it has a valid CatalogId, enter it into the hash table */
694 if (OidIsValid(dobj->catId.tableoid))
695 {
696 CatalogIdMapEntry *entry;
697 bool found;
698
699 /* Initialize CatalogId hash table if not done yet */
700 if (catalogIdHash == NULL)
702
703 entry = catalogid_insert(catalogIdHash, dobj->catId, &found);
704 if (!found)
705 {
706 entry->dobj = NULL;
707 entry->ext = NULL;
708 }
709 Assert(entry->dobj == NULL);
710 entry->dobj = dobj;
711 }
712}
static int allocedDumpIds
Definition common.c:38
static DumpableObject ** dumpIdMap
Definition common.c:37
#define CATALOGIDHASH_INITIAL_SIZE
Definition common.c:80
static catalogid_hash * catalogIdHash
Definition common.c:82
static DumpId lastDumpId
Definition common.c:39
#define Assert(condition)
Definition c.h:873
#define OidIsValid(objectId)
Definition c.h:788
#define DUMP_COMPONENT_ALL
Definition pg_dump.h:117
Oid tableoid
Definition pg_backup.h:281
ExtensionInfo * ext
Definition common.c:63
DumpableObject * dobj
Definition common.c:62
DumpComponents dump
Definition pg_dump.h:153
DumpId dumpId
Definition pg_dump.h:151
DumpComponents components
Definition pg_dump.h:156
CatalogId catId
Definition pg_dump.h:150
DumpComponents dump_contains
Definition pg_dump.h:155
bool depends_on_ext
Definition pg_dump.h:158

References _dumpableObject::allocDeps, allocedDumpIds, Assert, catalogIdHash, CATALOGIDHASH_INITIAL_SIZE, _dumpableObject::catId, _dumpableObject::components, _dumpableObject::dependencies, _dumpableObject::depends_on_ext, _catalogIdMapEntry::dobj, _dumpableObject::dump, DUMP_COMPONENT_ALL, DUMP_COMPONENT_DEFINITION, _dumpableObject::dump_contains, _dumpableObject::dumpId, dumpIdMap, _catalogIdMapEntry::ext, _dumpableObject::ext_member, fb(), lastDumpId, _dumpableObject::name, _dumpableObject::nDeps, OidIsValid, pg_malloc_array, pg_realloc_array, and CatalogId::tableoid.

Referenced by createBoundaryObjects(), flagInhAttrs(), flagInhIndexes(), flagInhTables(), getAccessMethods(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getLOs(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPolicies(), getProcLangs(), getPublicationNamespaces(), getPublications(), getPublicationTables(), getRelationStatistics(), getRules(), getSubscriptionRelations(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), and makeTableDataInfo().

◆ createDumpId()

◆ findAccessMethodByOid()

AccessMethodInfo * findAccessMethodByOid ( Oid  oid)
extern

Definition at line 954 of file common.c.

955{
956 CatalogId catId;
957 DumpableObject *dobj;
958
960 catId.oid = oid;
961 dobj = findObjectByCatalogId(catId);
962 Assert(dobj == NULL || dobj->objType == DO_ACCESS_METHOD);
963 return (AccessMethodInfo *) dobj;
964}
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition common.c:778
DumpableObjectType objType
Definition pg_dump.h:149

References Assert, DO_ACCESS_METHOD, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by accessMethodNameCompare().

◆ findCollationByOid()

CollInfo * findCollationByOid ( Oid  oid)
extern

Definition at line 972 of file common.c.

973{
974 CatalogId catId;
975 DumpableObject *dobj;
976
978 catId.oid = oid;
979 dobj = findObjectByCatalogId(catId);
980 Assert(dobj == NULL || dobj->objType == DO_COLLATION);
981 return (CollInfo *) dobj;
982}

References Assert, DO_COLLATION, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by createDummyViewAsClause(), dumpCompositeType(), dumpDomain(), dumpRangeType(), and dumpTableSchema().

◆ findExtensionByOid()

ExtensionInfo * findExtensionByOid ( Oid  oid)
extern

Definition at line 1008 of file common.c.

1009{
1010 CatalogId catId;
1011 DumpableObject *dobj;
1012
1014 catId.oid = oid;
1015 dobj = findObjectByCatalogId(catId);
1016 Assert(dobj == NULL || dobj->objType == DO_EXTENSION);
1017 return (ExtensionInfo *) dobj;
1018}

References Assert, DO_EXTENSION, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getExtensionMembership().

◆ findFuncByOid()

FuncInfo * findFuncByOid ( Oid  oid)
extern

Definition at line 918 of file common.c.

919{
920 CatalogId catId;
921 DumpableObject *dobj;
922
924 catId.oid = oid;
925 dobj = findObjectByCatalogId(catId);
926 Assert(dobj == NULL || dobj->objType == DO_FUNC);
927 return (FuncInfo *) dobj;
928}

References Assert, DO_FUNC, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by dumpCast(), dumpProcLang(), and dumpTransform().

◆ findNamespaceByOid()

NamespaceInfo * findNamespaceByOid ( Oid  oid)
extern

Definition at line 990 of file common.c.

991{
992 CatalogId catId;
993 DumpableObject *dobj;
994
996 catId.oid = oid;
997 dobj = findObjectByCatalogId(catId);
998 Assert(dobj == NULL || dobj->objType == DO_NAMESPACE);
999 return (NamespaceInfo *) dobj;
1000}

References Assert, DO_NAMESPACE, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by findNamespace(), and getPublicationNamespaces().

◆ findObjectByCatalogId()

DumpableObject * findObjectByCatalogId ( CatalogId  catalogId)
extern

◆ findObjectByDumpId()

DumpableObject * findObjectByDumpId ( DumpId  dumpId)
extern

Definition at line 765 of file common.c.

766{
768 return NULL; /* out of range? */
769 return dumpIdMap[dumpId];
770}

References allocedDumpIds, dumpIdMap, and fb().

Referenced by binary_upgrade_extension_member(), BuildArchiveDependencies(), dumpConstraint(), dumpDumpableObject(), dumpExtension(), findDumpableDependencies(), and findLoop().

◆ findOprByOid()

OprInfo * findOprByOid ( Oid  oid)
extern

Definition at line 936 of file common.c.

937{
938 CatalogId catId;
939 DumpableObject *dobj;
940
942 catId.oid = oid;
943 dobj = findObjectByCatalogId(catId);
944 Assert(dobj == NULL || dobj->objType == DO_OPERATOR);
945 return (OprInfo *) dobj;
946}

References Assert, DO_OPERATOR, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getFormattedOperatorName().

◆ findOwningExtension()

ExtensionInfo * findOwningExtension ( CatalogId  catalogId)
extern

Definition at line 1087 of file common.c.

1088{
1089 CatalogIdMapEntry *entry;
1090
1091 if (catalogIdHash == NULL)
1092 return NULL; /* no objects exist yet */
1093
1094 entry = catalogid_lookup(catalogIdHash, catalogId);
1095 if (entry == NULL)
1096 return NULL;
1097 return entry->ext;
1098}

References catalogIdHash, _catalogIdMapEntry::ext, and fb().

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo * findPublicationByOid ( Oid  oid)
extern

Definition at line 1026 of file common.c.

1027{
1028 CatalogId catId;
1029 DumpableObject *dobj;
1030
1032 catId.oid = oid;
1033 dobj = findObjectByCatalogId(catId);
1034 Assert(dobj == NULL || dobj->objType == DO_PUBLICATION);
1035 return (PublicationInfo *) dobj;
1036}

References Assert, DO_PUBLICATION, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getPublicationNamespaces(), and getPublicationTables().

◆ findSubscriptionByOid()

SubscriptionInfo * findSubscriptionByOid ( Oid  oid)
extern

Definition at line 1044 of file common.c.

1045{
1046 CatalogId catId;
1047 DumpableObject *dobj;
1048
1050 catId.oid = oid;
1051 dobj = findObjectByCatalogId(catId);
1052 Assert(dobj == NULL || dobj->objType == DO_SUBSCRIPTION);
1053 return (SubscriptionInfo *) dobj;
1054}

References Assert, DO_SUBSCRIPTION, fb(), findObjectByCatalogId(), _dumpableObject::objType, CatalogId::oid, and CatalogId::tableoid.

Referenced by getSubscriptionRelations().

◆ findTableByOid()

◆ findTypeByOid()

TypeInfo * findTypeByOid ( Oid  oid)
extern

◆ getAccessMethods()

void getAccessMethods ( Archive fout)
extern

Definition at line 6571 of file pg_dump.c.

6572{
6573 PGresult *res;
6574 int ntups;
6575 int i;
6576 PQExpBuffer query;
6578 int i_tableoid;
6579 int i_oid;
6580 int i_amname;
6581 int i_amhandler;
6582 int i_amtype;
6583
6584 query = createPQExpBuffer();
6585
6586 /*
6587 * Select all access methods from pg_am table. v9.6 introduced CREATE
6588 * ACCESS METHOD, so earlier versions usually have only built-in access
6589 * methods. v9.6 also changed the access method API, replacing dozens of
6590 * pg_am columns with amhandler. Even if a user created an access method
6591 * by "INSERT INTO pg_am", we have no way to translate pre-v9.6 pg_am
6592 * columns to a v9.6+ CREATE ACCESS METHOD. Hence, before v9.6, read
6593 * pg_am just to facilitate findAccessMethodByOid() providing the
6594 * OID-to-name mapping.
6595 */
6596 appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, ");
6597 if (fout->remoteVersion >= 90600)
6599 "amtype, "
6600 "amhandler::pg_catalog.regproc AS amhandler ");
6601 else
6603 "'i'::pg_catalog.\"char\" AS amtype, "
6604 "'-'::pg_catalog.regproc AS amhandler ");
6605 appendPQExpBufferStr(query, "FROM pg_am");
6606
6607 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6608
6609 ntups = PQntuples(res);
6610
6611 aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
6612
6613 i_tableoid = PQfnumber(res, "tableoid");
6614 i_oid = PQfnumber(res, "oid");
6615 i_amname = PQfnumber(res, "amname");
6616 i_amhandler = PQfnumber(res, "amhandler");
6617 i_amtype = PQfnumber(res, "amtype");
6618
6619 for (i = 0; i < ntups; i++)
6620 {
6621 aminfo[i].dobj.objType = DO_ACCESS_METHOD;
6622 aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6623 aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6624 AssignDumpId(&aminfo[i].dobj);
6625 aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
6626 aminfo[i].dobj.namespace = NULL;
6627 aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
6628 aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
6629
6630 /* Decide whether we want to dump it */
6632 }
6633
6634 PQclear(res);
6635
6636 destroyPQExpBuffer(query);
6637}
void AssignDumpId(DumpableObject *dobj)
Definition common.c:657
int PQfnumber(const PGresult *res, const char *field_name)
Definition fe-exec.c:3606
void * pg_malloc(size_t size)
Definition fe_memutils.c:47
char * pg_strdup(const char *in)
Definition fe_memutils.c:85
int i
Definition isn.c:77
#define PQgetvalue
#define PQclear
#define PQntuples
@ PGRES_TUPLES_OK
Definition libpq-fe.h:128
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition pg_dump.c:2247
#define atooid(x)
PQExpBuffer createPQExpBuffer(void)
Definition pqexpbuffer.c:72
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_ACCESS_METHOD, ExecuteSqlQuery(), fb(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableAccessMethod().

Referenced by getSchemaData().

◆ getAggregates()

void getAggregates ( Archive fout)
extern

Definition at line 6773 of file pg_dump.c.

6774{
6775 DumpOptions *dopt = fout->dopt;
6776 PGresult *res;
6777 int ntups;
6778 int i;
6781 int i_tableoid;
6782 int i_oid;
6783 int i_aggname;
6784 int i_aggnamespace;
6785 int i_pronargs;
6786 int i_proargtypes;
6787 int i_proowner;
6788 int i_aggacl;
6789 int i_acldefault;
6790
6791 /*
6792 * Find all interesting aggregates. See comment in getFuncs() for the
6793 * rationale behind the filtering logic.
6794 */
6795 if (fout->remoteVersion >= 90600)
6796 {
6797 const char *agg_check;
6798
6799 agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
6800 : "p.proisagg");
6801
6802 appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
6803 "p.proname AS aggname, "
6804 "p.pronamespace AS aggnamespace, "
6805 "p.pronargs, p.proargtypes, "
6806 "p.proowner, "
6807 "p.proacl AS aggacl, "
6808 "acldefault('f', p.proowner) AS acldefault "
6809 "FROM pg_proc p "
6810 "LEFT JOIN pg_init_privs pip ON "
6811 "(p.oid = pip.objoid "
6812 "AND pip.classoid = 'pg_proc'::regclass "
6813 "AND pip.objsubid = 0) "
6814 "WHERE %s AND ("
6815 "p.pronamespace != "
6816 "(SELECT oid FROM pg_namespace "
6817 "WHERE nspname = 'pg_catalog') OR "
6818 "p.proacl IS DISTINCT FROM pip.initprivs",
6819 agg_check);
6820 if (dopt->binary_upgrade)
6822 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6823 "classid = 'pg_proc'::regclass AND "
6824 "objid = p.oid AND "
6825 "refclassid = 'pg_extension'::regclass AND "
6826 "deptype = 'e')");
6827 appendPQExpBufferChar(query, ')');
6828 }
6829 else
6830 {
6831 appendPQExpBufferStr(query, "SELECT tableoid, oid, proname AS aggname, "
6832 "pronamespace AS aggnamespace, "
6833 "pronargs, proargtypes, "
6834 "proowner, "
6835 "proacl AS aggacl, "
6836 "acldefault('f', proowner) AS acldefault "
6837 "FROM pg_proc p "
6838 "WHERE proisagg AND ("
6839 "pronamespace != "
6840 "(SELECT oid FROM pg_namespace "
6841 "WHERE nspname = 'pg_catalog')");
6842 if (dopt->binary_upgrade)
6844 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6845 "classid = 'pg_proc'::regclass AND "
6846 "objid = p.oid AND "
6847 "refclassid = 'pg_extension'::regclass AND "
6848 "deptype = 'e')");
6849 appendPQExpBufferChar(query, ')');
6850 }
6851
6852 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6853
6854 ntups = PQntuples(res);
6855
6856 agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
6857
6858 i_tableoid = PQfnumber(res, "tableoid");
6859 i_oid = PQfnumber(res, "oid");
6860 i_aggname = PQfnumber(res, "aggname");
6861 i_aggnamespace = PQfnumber(res, "aggnamespace");
6862 i_pronargs = PQfnumber(res, "pronargs");
6863 i_proargtypes = PQfnumber(res, "proargtypes");
6864 i_proowner = PQfnumber(res, "proowner");
6865 i_aggacl = PQfnumber(res, "aggacl");
6866 i_acldefault = PQfnumber(res, "acldefault");
6867
6868 for (i = 0; i < ntups; i++)
6869 {
6870 agginfo[i].aggfn.dobj.objType = DO_AGG;
6871 agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6872 agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6873 AssignDumpId(&agginfo[i].aggfn.dobj);
6874 agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
6875 agginfo[i].aggfn.dobj.namespace =
6877 agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
6878 agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6879 agginfo[i].aggfn.dacl.privtype = 0;
6880 agginfo[i].aggfn.dacl.initprivs = NULL;
6881 agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6882 agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
6883 agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
6884 agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
6885 if (agginfo[i].aggfn.nargs == 0)
6886 agginfo[i].aggfn.argtypes = NULL;
6887 else
6888 {
6889 agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
6891 agginfo[i].aggfn.argtypes,
6892 agginfo[i].aggfn.nargs);
6893 }
6894 agginfo[i].aggfn.postponed_def = false; /* might get set during sort */
6895
6896 /* Decide whether we want to dump it */
6897 selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
6898
6899 /* Mark whether aggregate has an ACL */
6900 if (!PQgetisnull(res, i, i_aggacl))
6901 agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
6902 }
6903
6904 PQclear(res);
6905
6906 destroyPQExpBuffer(query);
6907}
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition common.c:1111
#define PQgetisnull
static const char * getRoleName(const char *roleoid_str)
Definition pg_dump.c:10684
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition pg_dump.c:2357
static NamespaceInfo * findNamespace(Oid nsoid)
Definition pg_dump.c:6106
#define DUMP_COMPONENT_ACL
Definition pg_dump.h:113
#define InvalidOid
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
int binary_upgrade
Definition pg_backup.h:175

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_AGG, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, InvalidOid, parseOidArray(), pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getCasts()

void getCasts ( Archive fout)
extern

Definition at line 9044 of file pg_dump.c.

9045{
9046 PGresult *res;
9047 int ntups;
9048 int i;
9051 int i_tableoid;
9052 int i_oid;
9053 int i_castsource;
9054 int i_casttarget;
9055 int i_castfunc;
9056 int i_castcontext;
9057 int i_castmethod;
9058
9059 if (fout->remoteVersion >= 140000)
9060 {
9061 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9062 "castsource, casttarget, castfunc, castcontext, "
9063 "castmethod "
9064 "FROM pg_cast c "
9065 "WHERE NOT EXISTS ( "
9066 "SELECT 1 FROM pg_range r "
9067 "WHERE c.castsource = r.rngtypid "
9068 "AND c.casttarget = r.rngmultitypid "
9069 ") "
9070 "ORDER BY 3,4");
9071 }
9072 else
9073 {
9074 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9075 "castsource, casttarget, castfunc, castcontext, "
9076 "castmethod "
9077 "FROM pg_cast ORDER BY 3,4");
9078 }
9079
9080 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9081
9082 ntups = PQntuples(res);
9083
9084 castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
9085
9086 i_tableoid = PQfnumber(res, "tableoid");
9087 i_oid = PQfnumber(res, "oid");
9088 i_castsource = PQfnumber(res, "castsource");
9089 i_casttarget = PQfnumber(res, "casttarget");
9090 i_castfunc = PQfnumber(res, "castfunc");
9091 i_castcontext = PQfnumber(res, "castcontext");
9092 i_castmethod = PQfnumber(res, "castmethod");
9093
9094 for (i = 0; i < ntups; i++)
9095 {
9099
9101 castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9102 castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9103 AssignDumpId(&castinfo[i].dobj);
9104 castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
9105 castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
9106 castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
9107 castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
9108 castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
9109
9110 /*
9111 * Try to name cast as concatenation of typnames. This is only used
9112 * for purposes of sorting. If we fail to find either type, the name
9113 * will be an empty string.
9114 */
9116 sTypeInfo = findTypeByOid(castinfo[i].castsource);
9117 tTypeInfo = findTypeByOid(castinfo[i].casttarget);
9118 if (sTypeInfo && tTypeInfo)
9119 appendPQExpBuffer(&namebuf, "%s %s",
9120 sTypeInfo->dobj.name, tTypeInfo->dobj.name);
9121 castinfo[i].dobj.name = namebuf.data;
9122
9123 /* Decide whether we want to dump it */
9125 }
9126
9127 PQclear(res);
9128
9129 destroyPQExpBuffer(query);
9130}
TypeInfo * findTypeByOid(Oid oid)
Definition common.c:899
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition pg_dump.c:2189
void initPQExpBuffer(PQExpBuffer str)
Definition pqexpbuffer.c:90

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CAST, _typeInfo::dobj, ExecuteSqlQuery(), fb(), findTypeByOid(), i, initPQExpBuffer(), _dumpableObject::objType, pg_malloc(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableCast().

Referenced by getSchemaData().

◆ getCollations()

void getCollations ( Archive fout)
extern

Definition at line 6443 of file pg_dump.c.

6444{
6445 PGresult *res;
6446 int ntups;
6447 int i;
6448 PQExpBuffer query;
6450 int i_tableoid;
6451 int i_oid;
6452 int i_collname;
6453 int i_collnamespace;
6454 int i_collowner;
6455 int i_collencoding;
6456
6457 query = createPQExpBuffer();
6458
6459 /*
6460 * find all collations, including builtin collations; we filter out
6461 * system-defined collations at dump-out time.
6462 */
6463
6464 appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
6465 "collnamespace, "
6466 "collowner, "
6467 "collencoding "
6468 "FROM pg_collation");
6469
6470 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6471
6472 ntups = PQntuples(res);
6473
6474 collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
6475
6476 i_tableoid = PQfnumber(res, "tableoid");
6477 i_oid = PQfnumber(res, "oid");
6478 i_collname = PQfnumber(res, "collname");
6479 i_collnamespace = PQfnumber(res, "collnamespace");
6480 i_collowner = PQfnumber(res, "collowner");
6481 i_collencoding = PQfnumber(res, "collencoding");
6482
6483 for (i = 0; i < ntups; i++)
6484 {
6485 collinfo[i].dobj.objType = DO_COLLATION;
6486 collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6487 collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6488 AssignDumpId(&collinfo[i].dobj);
6489 collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
6490 collinfo[i].dobj.namespace =
6492 collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
6493 collinfo[i].collencoding = atoi(PQgetvalue(res, i, i_collencoding));
6494
6495 /* Decide whether we want to dump it */
6497 }
6498
6499 PQclear(res);
6500
6501 destroyPQExpBuffer(query);
6502}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_COLLATION, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getConstraints()

void getConstraints ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)
extern

Definition at line 8295 of file pg_dump.c.

8296{
8299 PGresult *res;
8300 int ntups;
8301 int curtblindx;
8304 int i_contableoid,
8305 i_conoid,
8306 i_conrelid,
8307 i_conname,
8309 i_conindid,
8310 i_condef;
8311
8312 /*
8313 * We want to perform just one query against pg_constraint. However, we
8314 * mustn't try to select every row of the catalog and then sort it out on
8315 * the client side, because some of the server-side functions we need
8316 * would be unsafe to apply to tables we don't have lock on. Hence, we
8317 * build an array of the OIDs of tables we care about (and now have lock
8318 * on!), and use a WHERE clause to constrain which rows are selected.
8319 */
8321 for (int i = 0; i < numTables; i++)
8322 {
8323 TableInfo *tinfo = &tblinfo[i];
8324
8325 if (!(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8326 continue;
8327
8328 /* OK, we need info for this table */
8329 if (tbloids->len > 1) /* do we have more than the '{'? */
8331 appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
8332 }
8334
8336 "SELECT c.tableoid, c.oid, "
8337 "conrelid, conname, confrelid, ");
8338 if (fout->remoteVersion >= 110000)
8339 appendPQExpBufferStr(query, "conindid, ");
8340 else
8341 appendPQExpBufferStr(query, "0 AS conindid, ");
8342 appendPQExpBuffer(query,
8343 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
8344 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8345 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
8346 "WHERE contype = 'f' ",
8347 tbloids->data);
8348 if (fout->remoteVersion >= 110000)
8350 "AND conparentid = 0 ");
8352 "ORDER BY conrelid, conname");
8353
8354 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8355
8356 ntups = PQntuples(res);
8357
8358 i_contableoid = PQfnumber(res, "tableoid");
8359 i_conoid = PQfnumber(res, "oid");
8360 i_conrelid = PQfnumber(res, "conrelid");
8361 i_conname = PQfnumber(res, "conname");
8362 i_confrelid = PQfnumber(res, "confrelid");
8363 i_conindid = PQfnumber(res, "conindid");
8364 i_condef = PQfnumber(res, "condef");
8365
8366 constrinfo = (ConstraintInfo *) pg_malloc(ntups * sizeof(ConstraintInfo));
8367
8368 curtblindx = -1;
8369 for (int j = 0; j < ntups; j++)
8370 {
8371 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
8373
8374 /*
8375 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8376 * order.
8377 */
8378 if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
8379 {
8380 while (++curtblindx < numTables)
8381 {
8382 tbinfo = &tblinfo[curtblindx];
8383 if (tbinfo->dobj.catId.oid == conrelid)
8384 break;
8385 }
8386 if (curtblindx >= numTables)
8387 pg_fatal("unrecognized table OID %u", conrelid);
8388 }
8389
8390 constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
8391 constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8392 constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8393 AssignDumpId(&constrinfo[j].dobj);
8394 constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8395 constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8396 constrinfo[j].contable = tbinfo;
8397 constrinfo[j].condomain = NULL;
8398 constrinfo[j].contype = 'f';
8399 constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
8400 constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
8401 constrinfo[j].conindex = 0;
8402 constrinfo[j].condeferrable = false;
8403 constrinfo[j].condeferred = false;
8404 constrinfo[j].conislocal = true;
8405 constrinfo[j].separate = true;
8406
8407 /*
8408 * Restoring an FK that points to a partitioned table requires that
8409 * all partition indexes have been attached beforehand. Ensure that
8410 * happens by making the constraint depend on each index partition
8411 * attach object.
8412 */
8413 reftable = findTableByOid(constrinfo[j].confrelid);
8414 if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
8415 {
8416 Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
8417
8418 if (indexOid != InvalidOid)
8419 {
8420 for (int k = 0; k < reftable->numIndexes; k++)
8421 {
8423
8424 /* not our index? */
8425 if (reftable->indexes[k].dobj.catId.oid != indexOid)
8426 continue;
8427
8428 refidx = &reftable->indexes[k];
8430 break;
8431 }
8432 }
8433 }
8434 }
8435
8436 PQclear(res);
8437
8438 destroyPQExpBuffer(query);
8440}
TableInfo * findTableByOid(Oid oid)
Definition common.c:863
static const gbtree_vinfo tinfo
Definition btree_bit.c:109
int j
Definition isn.c:78
#define pg_fatal(...)
static void addConstrChildIdxDeps(DumpableObject *dobj, const IndxInfo *refidx)
Definition pg_dump.c:8454

References addConstrChildIdxDeps(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FK_CONSTRAINT, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), fb(), findTableByOid(), i, InvalidOid, j, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and tinfo.

Referenced by getSchemaData().

◆ getConversions()

void getConversions ( Archive fout)
extern

Definition at line 6509 of file pg_dump.c.

6510{
6511 PGresult *res;
6512 int ntups;
6513 int i;
6514 PQExpBuffer query;
6516 int i_tableoid;
6517 int i_oid;
6518 int i_conname;
6519 int i_connamespace;
6520 int i_conowner;
6521
6522 query = createPQExpBuffer();
6523
6524 /*
6525 * find all conversions, including builtin conversions; we filter out
6526 * system-defined conversions at dump-out time.
6527 */
6528
6529 appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
6530 "connamespace, "
6531 "conowner "
6532 "FROM pg_conversion");
6533
6534 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6535
6536 ntups = PQntuples(res);
6537
6538 convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
6539
6540 i_tableoid = PQfnumber(res, "tableoid");
6541 i_oid = PQfnumber(res, "oid");
6542 i_conname = PQfnumber(res, "conname");
6543 i_connamespace = PQfnumber(res, "connamespace");
6544 i_conowner = PQfnumber(res, "conowner");
6545
6546 for (i = 0; i < ntups; i++)
6547 {
6548 convinfo[i].dobj.objType = DO_CONVERSION;
6549 convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6550 convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6551 AssignDumpId(&convinfo[i].dobj);
6552 convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
6553 convinfo[i].dobj.namespace =
6555 convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
6556
6557 /* Decide whether we want to dump it */
6559 }
6560
6561 PQclear(res);
6562
6563 destroyPQExpBuffer(query);
6564}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CONVERSION, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getDefaultACLs()

void getDefaultACLs ( Archive fout)
extern

Definition at line 10587 of file pg_dump.c.

10588{
10589 DumpOptions *dopt = fout->dopt;
10591 PQExpBuffer query;
10592 PGresult *res;
10593 int i_oid;
10594 int i_tableoid;
10595 int i_defaclrole;
10597 int i_defaclobjtype;
10598 int i_defaclacl;
10599 int i_acldefault;
10600 int i,
10601 ntups;
10602
10603 query = createPQExpBuffer();
10604
10605 /*
10606 * Global entries (with defaclnamespace=0) replace the hard-wired default
10607 * ACL for their object type. We should dump them as deltas from the
10608 * default ACL, since that will be used as a starting point for
10609 * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
10610 * non-global entries can only add privileges not revoke them. We must
10611 * dump those as-is (i.e., as deltas from an empty ACL).
10612 *
10613 * We can use defaclobjtype as the object type for acldefault(), except
10614 * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
10615 * 's'.
10616 */
10618 "SELECT oid, tableoid, "
10619 "defaclrole, "
10620 "defaclnamespace, "
10621 "defaclobjtype, "
10622 "defaclacl, "
10623 "CASE WHEN defaclnamespace = 0 THEN "
10624 "acldefault(CASE WHEN defaclobjtype = 'S' "
10625 "THEN 's'::\"char\" ELSE defaclobjtype END, "
10626 "defaclrole) ELSE '{}' END AS acldefault "
10627 "FROM pg_default_acl");
10628
10629 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10630
10631 ntups = PQntuples(res);
10632
10633 daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
10634
10635 i_oid = PQfnumber(res, "oid");
10636 i_tableoid = PQfnumber(res, "tableoid");
10637 i_defaclrole = PQfnumber(res, "defaclrole");
10638 i_defaclnamespace = PQfnumber(res, "defaclnamespace");
10639 i_defaclobjtype = PQfnumber(res, "defaclobjtype");
10640 i_defaclacl = PQfnumber(res, "defaclacl");
10641 i_acldefault = PQfnumber(res, "acldefault");
10642
10643 for (i = 0; i < ntups; i++)
10644 {
10646
10647 daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
10648 daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10649 daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10650 AssignDumpId(&daclinfo[i].dobj);
10651 /* cheesy ... is it worth coming up with a better object name? */
10652 daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
10653
10654 if (nspid != InvalidOid)
10655 daclinfo[i].dobj.namespace = findNamespace(nspid);
10656 else
10657 daclinfo[i].dobj.namespace = NULL;
10658
10659 daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
10660 daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10661 daclinfo[i].dacl.privtype = 0;
10662 daclinfo[i].dacl.initprivs = NULL;
10663 daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
10664 daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
10665
10666 /* Default ACLs are ACLs, of course */
10667 daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10668
10669 /* Decide whether we want to dump it */
10671 }
10672
10673 PQclear(res);
10674
10675 destroyPQExpBuffer(query);
10676}
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition pg_dump.c:2167

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_DEFAULT_ACL, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, InvalidOid, nspid, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableDefaultACL().

Referenced by getSchemaData().

◆ getDumpableObjects()

void getDumpableObjects ( DumpableObject ***  objs,
int numObjs 
)
extern

Definition at line 797 of file common.c.

798{
799 int i,
800 j;
801
803 j = 0;
804 for (i = 1; i < allocedDumpIds; i++)
805 {
806 if (dumpIdMap[i])
807 (*objs)[j++] = dumpIdMap[i];
808 }
809 *numObjs = j;
810}

References allocedDumpIds, dumpIdMap, fb(), i, j, and pg_malloc_array.

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

void getEventTriggers ( Archive fout)
extern

Definition at line 8882 of file pg_dump.c.

8883{
8884 int i;
8885 PQExpBuffer query;
8886 PGresult *res;
8888 int i_tableoid,
8889 i_oid,
8890 i_evtname,
8891 i_evtevent,
8892 i_evtowner,
8893 i_evttags,
8894 i_evtfname,
8896 int ntups;
8897
8898 /* Before 9.3, there are no event triggers */
8899 if (fout->remoteVersion < 90300)
8900 return;
8901
8902 query = createPQExpBuffer();
8903
8905 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8906 "evtevent, evtowner, "
8907 "array_to_string(array("
8908 "select quote_literal(x) "
8909 " from unnest(evttags) as t(x)), ', ') as evttags, "
8910 "e.evtfoid::regproc as evtfname "
8911 "FROM pg_event_trigger e "
8912 "ORDER BY e.oid");
8913
8914 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8915
8916 ntups = PQntuples(res);
8917
8918 evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
8919
8920 i_tableoid = PQfnumber(res, "tableoid");
8921 i_oid = PQfnumber(res, "oid");
8922 i_evtname = PQfnumber(res, "evtname");
8923 i_evtevent = PQfnumber(res, "evtevent");
8924 i_evtowner = PQfnumber(res, "evtowner");
8925 i_evttags = PQfnumber(res, "evttags");
8926 i_evtfname = PQfnumber(res, "evtfname");
8927 i_evtenabled = PQfnumber(res, "evtenabled");
8928
8929 for (i = 0; i < ntups; i++)
8930 {
8931 evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
8932 evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8933 evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8934 AssignDumpId(&evtinfo[i].dobj);
8935 evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
8936 evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
8937 evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
8938 evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
8939 evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
8940 evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
8941 evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
8942
8943 /* Decide whether we want to dump it */
8945 }
8946
8947 PQclear(res);
8948
8949 destroyPQExpBuffer(query);
8950}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_EVENT_TRIGGER, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)
extern

Definition at line 8213 of file pg_dump.c.

8214{
8215 PQExpBuffer query;
8216 PGresult *res;
8218 int ntups;
8219 int i_tableoid;
8220 int i_oid;
8221 int i_stxname;
8222 int i_stxnamespace;
8223 int i_stxowner;
8224 int i_stxrelid;
8225 int i_stattarget;
8226 int i;
8227
8228 /* Extended statistics were new in v10 */
8229 if (fout->remoteVersion < 100000)
8230 return;
8231
8232 query = createPQExpBuffer();
8233
8234 if (fout->remoteVersion < 130000)
8235 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8236 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
8237 "FROM pg_catalog.pg_statistic_ext");
8238 else
8239 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8240 "stxnamespace, stxowner, stxrelid, stxstattarget "
8241 "FROM pg_catalog.pg_statistic_ext");
8242
8243 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8244
8245 ntups = PQntuples(res);
8246
8247 i_tableoid = PQfnumber(res, "tableoid");
8248 i_oid = PQfnumber(res, "oid");
8249 i_stxname = PQfnumber(res, "stxname");
8250 i_stxnamespace = PQfnumber(res, "stxnamespace");
8251 i_stxowner = PQfnumber(res, "stxowner");
8252 i_stxrelid = PQfnumber(res, "stxrelid");
8253 i_stattarget = PQfnumber(res, "stxstattarget");
8254
8255 statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
8256
8257 for (i = 0; i < ntups; i++)
8258 {
8259 statsextinfo[i].dobj.objType = DO_STATSEXT;
8260 statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8261 statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8262 AssignDumpId(&statsextinfo[i].dobj);
8263 statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
8264 statsextinfo[i].dobj.namespace =
8266 statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
8267 statsextinfo[i].stattable =
8269 if (PQgetisnull(res, i, i_stattarget))
8270 statsextinfo[i].stattarget = -1;
8271 else
8272 statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
8273
8274 /* Decide whether we want to dump it */
8276
8277 if (fout->dopt->dumpStatistics)
8278 statsextinfo[i].dobj.components |= DUMP_COMPONENT_STATISTICS;
8279 }
8280
8281 PQclear(res);
8282 destroyPQExpBuffer(query);
8283}
static void selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
Definition pg_dump.c:2339

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_STATSEXT, DUMP_COMPONENT_STATISTICS, ExecuteSqlQuery(), fb(), findNamespace(), findTableByOid(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableStatisticsObject().

Referenced by getSchemaData().

◆ getExtensionMembership()

void getExtensionMembership ( Archive fout,
ExtensionInfo  extinfo[],
int  numExtensions 
)
extern

Definition at line 19932 of file pg_dump.c.

19934{
19935 PQExpBuffer query;
19936 PGresult *res;
19937 int ntups,
19938 i;
19939 int i_classid,
19940 i_objid,
19941 i_refobjid;
19942 ExtensionInfo *ext;
19943
19944 /* Nothing to do if no extensions */
19945 if (numExtensions == 0)
19946 return;
19947
19948 query = createPQExpBuffer();
19949
19950 /* refclassid constraint is redundant but may speed the search */
19951 appendPQExpBufferStr(query, "SELECT "
19952 "classid, objid, refobjid "
19953 "FROM pg_depend "
19954 "WHERE refclassid = 'pg_extension'::regclass "
19955 "AND deptype = 'e' "
19956 "ORDER BY 3");
19957
19958 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
19959
19960 ntups = PQntuples(res);
19961
19962 i_classid = PQfnumber(res, "classid");
19963 i_objid = PQfnumber(res, "objid");
19964 i_refobjid = PQfnumber(res, "refobjid");
19965
19966 /*
19967 * Since we ordered the SELECT by referenced ID, we can expect that
19968 * multiple entries for the same extension will appear together; this
19969 * saves on searches.
19970 */
19971 ext = NULL;
19972
19973 for (i = 0; i < ntups; i++)
19974 {
19975 CatalogId objId;
19976 Oid extId;
19977
19978 objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
19979 objId.oid = atooid(PQgetvalue(res, i, i_objid));
19981
19982 if (ext == NULL ||
19983 ext->dobj.catId.oid != extId)
19985
19986 if (ext == NULL)
19987 {
19988 /* shouldn't happen */
19989 pg_log_warning("could not find referenced extension %u", extId);
19990 continue;
19991 }
19992
19993 recordExtensionMembership(objId, ext);
19994 }
19995
19996 PQclear(res);
19997
19998 destroyPQExpBuffer(query);
19999}
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition common.c:1063
ExtensionInfo * findExtensionByOid(Oid oid)
Definition common.c:1008
#define pg_log_warning(...)
Definition pgfnames.c:24

References appendPQExpBufferStr(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), _extensionInfo::dobj, ExecuteSqlQuery(), fb(), findExtensionByOid(), i, CatalogId::oid, pg_log_warning, PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, recordExtensionMembership(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getExtensions()

ExtensionInfo * getExtensions ( Archive fout,
int numExtensions 
)
extern

Definition at line 6124 of file pg_dump.c.

6125{
6126 DumpOptions *dopt = fout->dopt;
6127 PGresult *res;
6128 int ntups;
6129 int i;
6130 PQExpBuffer query;
6132 int i_tableoid;
6133 int i_oid;
6134 int i_extname;
6135 int i_nspname;
6136 int i_extrelocatable;
6137 int i_extversion;
6138 int i_extconfig;
6139 int i_extcondition;
6140
6141 query = createPQExpBuffer();
6142
6143 appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
6144 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
6145 "FROM pg_extension x "
6146 "JOIN pg_namespace n ON n.oid = x.extnamespace");
6147
6148 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6149
6150 ntups = PQntuples(res);
6151 if (ntups == 0)
6152 goto cleanup;
6153
6154 extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
6155
6156 i_tableoid = PQfnumber(res, "tableoid");
6157 i_oid = PQfnumber(res, "oid");
6158 i_extname = PQfnumber(res, "extname");
6159 i_nspname = PQfnumber(res, "nspname");
6160 i_extrelocatable = PQfnumber(res, "extrelocatable");
6161 i_extversion = PQfnumber(res, "extversion");
6162 i_extconfig = PQfnumber(res, "extconfig");
6163 i_extcondition = PQfnumber(res, "extcondition");
6164
6165 for (i = 0; i < ntups; i++)
6166 {
6167 extinfo[i].dobj.objType = DO_EXTENSION;
6168 extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6169 extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6170 AssignDumpId(&extinfo[i].dobj);
6171 extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
6172 extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
6173 extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
6174 extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
6175 extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
6176 extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
6177
6178 /* Decide whether we want to dump it */
6180 }
6181
6182cleanup:
6183 PQclear(res);
6184 destroyPQExpBuffer(query);
6185
6186 *numExtensions = ntups;
6187
6188 return extinfo;
6189}
static void cleanup(void)
Definition bootstrap.c:717
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition pg_dump.c:2282

References appendPQExpBufferStr(), AssignDumpId(), atooid, cleanup(), createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_EXTENSION, ExecuteSqlQuery(), fb(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableExtension().

Referenced by getSchemaData().

◆ getForeignDataWrappers()

void getForeignDataWrappers ( Archive fout)
extern

Definition at line 10415 of file pg_dump.c.

10416{
10417 PGresult *res;
10418 int ntups;
10419 int i;
10420 PQExpBuffer query;
10422 int i_tableoid;
10423 int i_oid;
10424 int i_fdwname;
10425 int i_fdwowner;
10426 int i_fdwhandler;
10427 int i_fdwvalidator;
10428 int i_fdwacl;
10429 int i_acldefault;
10430 int i_fdwoptions;
10431
10432 query = createPQExpBuffer();
10433
10434 appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
10435 "fdwowner, "
10436 "fdwhandler::pg_catalog.regproc, "
10437 "fdwvalidator::pg_catalog.regproc, "
10438 "fdwacl, "
10439 "acldefault('F', fdwowner) AS acldefault, "
10440 "array_to_string(ARRAY("
10441 "SELECT quote_ident(option_name) || ' ' || "
10442 "quote_literal(option_value) "
10443 "FROM pg_options_to_table(fdwoptions) "
10444 "ORDER BY option_name"
10445 "), E',\n ') AS fdwoptions "
10446 "FROM pg_foreign_data_wrapper");
10447
10448 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10449
10450 ntups = PQntuples(res);
10451
10452 fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
10453
10454 i_tableoid = PQfnumber(res, "tableoid");
10455 i_oid = PQfnumber(res, "oid");
10456 i_fdwname = PQfnumber(res, "fdwname");
10457 i_fdwowner = PQfnumber(res, "fdwowner");
10458 i_fdwhandler = PQfnumber(res, "fdwhandler");
10459 i_fdwvalidator = PQfnumber(res, "fdwvalidator");
10460 i_fdwacl = PQfnumber(res, "fdwacl");
10461 i_acldefault = PQfnumber(res, "acldefault");
10462 i_fdwoptions = PQfnumber(res, "fdwoptions");
10463
10464 for (i = 0; i < ntups; i++)
10465 {
10466 fdwinfo[i].dobj.objType = DO_FDW;
10467 fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10468 fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10469 AssignDumpId(&fdwinfo[i].dobj);
10470 fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
10471 fdwinfo[i].dobj.namespace = NULL;
10472 fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
10473 fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10474 fdwinfo[i].dacl.privtype = 0;
10475 fdwinfo[i].dacl.initprivs = NULL;
10476 fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
10477 fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
10478 fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
10479 fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
10480
10481 /* Decide whether we want to dump it */
10483
10484 /* Mark whether FDW has an ACL */
10485 if (!PQgetisnull(res, i, i_fdwacl))
10486 fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10487 }
10488
10489 PQclear(res);
10490
10491 destroyPQExpBuffer(query);
10492}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FDW, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getForeignServers()

void getForeignServers ( Archive fout)
extern

Definition at line 10499 of file pg_dump.c.

10500{
10501 PGresult *res;
10502 int ntups;
10503 int i;
10504 PQExpBuffer query;
10506 int i_tableoid;
10507 int i_oid;
10508 int i_srvname;
10509 int i_srvowner;
10510 int i_srvfdw;
10511 int i_srvtype;
10512 int i_srvversion;
10513 int i_srvacl;
10514 int i_acldefault;
10515 int i_srvoptions;
10516
10517 query = createPQExpBuffer();
10518
10519 appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
10520 "srvowner, "
10521 "srvfdw, srvtype, srvversion, srvacl, "
10522 "acldefault('S', srvowner) AS acldefault, "
10523 "array_to_string(ARRAY("
10524 "SELECT quote_ident(option_name) || ' ' || "
10525 "quote_literal(option_value) "
10526 "FROM pg_options_to_table(srvoptions) "
10527 "ORDER BY option_name"
10528 "), E',\n ') AS srvoptions "
10529 "FROM pg_foreign_server");
10530
10531 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10532
10533 ntups = PQntuples(res);
10534
10536
10537 i_tableoid = PQfnumber(res, "tableoid");
10538 i_oid = PQfnumber(res, "oid");
10539 i_srvname = PQfnumber(res, "srvname");
10540 i_srvowner = PQfnumber(res, "srvowner");
10541 i_srvfdw = PQfnumber(res, "srvfdw");
10542 i_srvtype = PQfnumber(res, "srvtype");
10543 i_srvversion = PQfnumber(res, "srvversion");
10544 i_srvacl = PQfnumber(res, "srvacl");
10545 i_acldefault = PQfnumber(res, "acldefault");
10546 i_srvoptions = PQfnumber(res, "srvoptions");
10547
10548 for (i = 0; i < ntups; i++)
10549 {
10550 srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
10551 srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10552 srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10553 AssignDumpId(&srvinfo[i].dobj);
10554 srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
10555 srvinfo[i].dobj.namespace = NULL;
10556 srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
10557 srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10558 srvinfo[i].dacl.privtype = 0;
10559 srvinfo[i].dacl.initprivs = NULL;
10560 srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
10561 srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
10562 srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
10563 srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
10564 srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
10565
10566 /* Decide whether we want to dump it */
10568
10569 /* Servers have user mappings */
10570 srvinfo[i].dobj.components |= DUMP_COMPONENT_USERMAP;
10571
10572 /* Mark whether server has an ACL */
10573 if (!PQgetisnull(res, i, i_srvacl))
10574 srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10575 }
10576
10577 PQclear(res);
10578
10579 destroyPQExpBuffer(query);
10580}
#define DUMP_COMPONENT_USERMAP
Definition pg_dump.h:115

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_FOREIGN_SERVER, DUMP_COMPONENT_ACL, DUMP_COMPONENT_USERMAP, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getFuncs()

void getFuncs ( Archive fout)
extern

Definition at line 6914 of file pg_dump.c.

6915{
6916 DumpOptions *dopt = fout->dopt;
6917 PGresult *res;
6918 int ntups;
6919 int i;
6921 FuncInfo *finfo;
6922 int i_tableoid;
6923 int i_oid;
6924 int i_proname;
6925 int i_pronamespace;
6926 int i_proowner;
6927 int i_prolang;
6928 int i_pronargs;
6929 int i_proargtypes;
6930 int i_prorettype;
6931 int i_proacl;
6932 int i_acldefault;
6933
6934 /*
6935 * Find all interesting functions. This is a bit complicated:
6936 *
6937 * 1. Always exclude aggregates; those are handled elsewhere.
6938 *
6939 * 2. Always exclude functions that are internally dependent on something
6940 * else, since presumably those will be created as a result of creating
6941 * the something else. This currently acts only to suppress constructor
6942 * functions for range types. Note this is OK only because the
6943 * constructors don't have any dependencies the range type doesn't have;
6944 * otherwise we might not get creation ordering correct.
6945 *
6946 * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
6947 * they're members of extensions and we are in binary-upgrade mode then
6948 * include them, since we want to dump extension members individually in
6949 * that mode. Also, if they are used by casts or transforms then we need
6950 * to gather the information about them, though they won't be dumped if
6951 * they are built-in. Also, in 9.6 and up, include functions in
6952 * pg_catalog if they have an ACL different from what's shown in
6953 * pg_init_privs (so we have to join to pg_init_privs; annoying).
6954 */
6955 if (fout->remoteVersion >= 90600)
6956 {
6957 const char *not_agg_check;
6958
6959 not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
6960 : "NOT p.proisagg");
6961
6962 appendPQExpBuffer(query,
6963 "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
6964 "p.pronargs, p.proargtypes, p.prorettype, "
6965 "p.proacl, "
6966 "acldefault('f', p.proowner) AS acldefault, "
6967 "p.pronamespace, "
6968 "p.proowner "
6969 "FROM pg_proc p "
6970 "LEFT JOIN pg_init_privs pip ON "
6971 "(p.oid = pip.objoid "
6972 "AND pip.classoid = 'pg_proc'::regclass "
6973 "AND pip.objsubid = 0) "
6974 "WHERE %s"
6975 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
6976 "WHERE classid = 'pg_proc'::regclass AND "
6977 "objid = p.oid AND deptype = 'i')"
6978 "\n AND ("
6979 "\n pronamespace != "
6980 "(SELECT oid FROM pg_namespace "
6981 "WHERE nspname = 'pg_catalog')"
6982 "\n OR EXISTS (SELECT 1 FROM pg_cast"
6983 "\n WHERE pg_cast.oid > %u "
6984 "\n AND p.oid = pg_cast.castfunc)"
6985 "\n OR EXISTS (SELECT 1 FROM pg_transform"
6986 "\n WHERE pg_transform.oid > %u AND "
6987 "\n (p.oid = pg_transform.trffromsql"
6988 "\n OR p.oid = pg_transform.trftosql))",
6992 if (dopt->binary_upgrade)
6994 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6995 "classid = 'pg_proc'::regclass AND "
6996 "objid = p.oid AND "
6997 "refclassid = 'pg_extension'::regclass AND "
6998 "deptype = 'e')");
7000 "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
7001 appendPQExpBufferChar(query, ')');
7002 }
7003 else
7004 {
7005 appendPQExpBuffer(query,
7006 "SELECT tableoid, oid, proname, prolang, "
7007 "pronargs, proargtypes, prorettype, proacl, "
7008 "acldefault('f', proowner) AS acldefault, "
7009 "pronamespace, "
7010 "proowner "
7011 "FROM pg_proc p "
7012 "WHERE NOT proisagg"
7013 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
7014 "WHERE classid = 'pg_proc'::regclass AND "
7015 "objid = p.oid AND deptype = 'i')"
7016 "\n AND ("
7017 "\n pronamespace != "
7018 "(SELECT oid FROM pg_namespace "
7019 "WHERE nspname = 'pg_catalog')"
7020 "\n OR EXISTS (SELECT 1 FROM pg_cast"
7021 "\n WHERE pg_cast.oid > '%u'::oid"
7022 "\n AND p.oid = pg_cast.castfunc)",
7024
7025 if (fout->remoteVersion >= 90500)
7026 appendPQExpBuffer(query,
7027 "\n OR EXISTS (SELECT 1 FROM pg_transform"
7028 "\n WHERE pg_transform.oid > '%u'::oid"
7029 "\n AND (p.oid = pg_transform.trffromsql"
7030 "\n OR p.oid = pg_transform.trftosql))",
7032
7033 if (dopt->binary_upgrade)
7035 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
7036 "classid = 'pg_proc'::regclass AND "
7037 "objid = p.oid AND "
7038 "refclassid = 'pg_extension'::regclass AND "
7039 "deptype = 'e')");
7040 appendPQExpBufferChar(query, ')');
7041 }
7042
7043 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7044
7045 ntups = PQntuples(res);
7046
7047 finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
7048
7049 i_tableoid = PQfnumber(res, "tableoid");
7050 i_oid = PQfnumber(res, "oid");
7051 i_proname = PQfnumber(res, "proname");
7052 i_pronamespace = PQfnumber(res, "pronamespace");
7053 i_proowner = PQfnumber(res, "proowner");
7054 i_prolang = PQfnumber(res, "prolang");
7055 i_pronargs = PQfnumber(res, "pronargs");
7056 i_proargtypes = PQfnumber(res, "proargtypes");
7057 i_prorettype = PQfnumber(res, "prorettype");
7058 i_proacl = PQfnumber(res, "proacl");
7059 i_acldefault = PQfnumber(res, "acldefault");
7060
7061 for (i = 0; i < ntups; i++)
7062 {
7063 finfo[i].dobj.objType = DO_FUNC;
7064 finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7065 finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7066 AssignDumpId(&finfo[i].dobj);
7067 finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
7068 finfo[i].dobj.namespace =
7070 finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
7072 finfo[i].dacl.privtype = 0;
7073 finfo[i].dacl.initprivs = NULL;
7074 finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
7075 finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
7076 finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
7077 finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
7078 if (finfo[i].nargs == 0)
7079 finfo[i].argtypes = NULL;
7080 else
7081 {
7082 finfo[i].argtypes = (Oid *) pg_malloc(finfo[i].nargs * sizeof(Oid));
7084 finfo[i].argtypes, finfo[i].nargs);
7085 }
7086 finfo[i].postponed_def = false; /* might get set during sort */
7087
7088 /* Decide whether we want to dump it */
7089 selectDumpableObject(&(finfo[i].dobj), fout);
7090
7091 /* Mark whether function has an ACL */
7092 if (!PQgetisnull(res, i, i_proacl))
7094 }
7095
7096 PQclear(res);
7097
7098 destroyPQExpBuffer(query);
7099}
void * pg_malloc0(size_t size)
Definition fe_memutils.c:53
static Oid g_last_builtin_oid
Definition pg_dump.c:154

References _dumpableAcl::acl, _dumpableAcl::acldefault, appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), _funcInfo::argtypes, AssignDumpId(), atooid, _dumpOptions::binary_upgrade, _dumpableObject::catId, _dumpableObject::components, createPQExpBuffer(), _funcInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_FUNC, _funcInfo::dobj, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), findNamespace(), g_last_builtin_oid, getRoleName(), i, _dumpableAcl::initprivs, _funcInfo::lang, _dumpableObject::name, _funcInfo::nargs, _dumpableObject::objType, CatalogId::oid, parseOidArray(), pg_malloc(), pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, _funcInfo::postponed_def, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, _dumpableAcl::privtype, _funcInfo::prorettype, _funcInfo::rolname, selectDumpableObject(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getIndexes()

void getIndexes ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)
extern

Definition at line 7844 of file pg_dump.c.

7845{
7848 PGresult *res;
7849 int ntups;
7850 int curtblindx;
7852 int i_tableoid,
7853 i_oid,
7854 i_indrelid,
7856 i_relpages,
7861 i_indexdef,
7863 i_indnatts,
7864 i_indkey,
7868 i_contype,
7869 i_conname,
7874 i_conoid,
7875 i_condef,
7881
7882 /*
7883 * We want to perform just one query against pg_index. However, we
7884 * mustn't try to select every row of the catalog and then sort it out on
7885 * the client side, because some of the server-side functions we need
7886 * would be unsafe to apply to tables we don't have lock on. Hence, we
7887 * build an array of the OIDs of tables we care about (and now have lock
7888 * on!), and use a WHERE clause to constrain which rows are selected.
7889 */
7891 for (int i = 0; i < numTables; i++)
7892 {
7893 TableInfo *tbinfo = &tblinfo[i];
7894
7895 if (!tbinfo->hasindex)
7896 continue;
7897
7898 /*
7899 * We can ignore indexes of uninteresting tables.
7900 */
7901 if (!tbinfo->interesting)
7902 continue;
7903
7904 /* OK, we need info for this table */
7905 if (tbloids->len > 1) /* do we have more than the '{'? */
7907 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
7908 }
7910
7912 "SELECT t.tableoid, t.oid, i.indrelid, "
7913 "t.relname AS indexname, "
7914 "t.relpages, t.reltuples, t.relallvisible, ");
7915
7916 if (fout->remoteVersion >= 180000)
7917 appendPQExpBufferStr(query, "t.relallfrozen, ");
7918 else
7919 appendPQExpBufferStr(query, "0 AS relallfrozen, ");
7920
7922 "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
7923 "i.indkey, i.indisclustered, "
7924 "c.contype, c.conname, "
7925 "c.condeferrable, c.condeferred, "
7926 "c.tableoid AS contableoid, "
7927 "c.oid AS conoid, "
7928 "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
7929 "CASE WHEN i.indexprs IS NOT NULL THEN "
7930 "(SELECT pg_catalog.array_agg(attname ORDER BY attnum)"
7931 " FROM pg_catalog.pg_attribute "
7932 " WHERE attrelid = i.indexrelid) "
7933 "ELSE NULL END AS indattnames, "
7934 "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
7935 "t.reloptions AS indreloptions, ");
7936
7937
7938 if (fout->remoteVersion >= 90400)
7940 "i.indisreplident, ");
7941 else
7943 "false AS indisreplident, ");
7944
7945 if (fout->remoteVersion >= 110000)
7947 "inh.inhparent AS parentidx, "
7948 "i.indnkeyatts AS indnkeyatts, "
7949 "i.indnatts AS indnatts, "
7950 "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
7951 " FROM pg_catalog.pg_attribute "
7952 " WHERE attrelid = i.indexrelid AND "
7953 " attstattarget >= 0) AS indstatcols, "
7954 "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
7955 " FROM pg_catalog.pg_attribute "
7956 " WHERE attrelid = i.indexrelid AND "
7957 " attstattarget >= 0) AS indstatvals, ");
7958 else
7960 "0 AS parentidx, "
7961 "i.indnatts AS indnkeyatts, "
7962 "i.indnatts AS indnatts, "
7963 "'' AS indstatcols, "
7964 "'' AS indstatvals, ");
7965
7966 if (fout->remoteVersion >= 150000)
7968 "i.indnullsnotdistinct, ");
7969 else
7971 "false AS indnullsnotdistinct, ");
7972
7973 if (fout->remoteVersion >= 180000)
7975 "c.conperiod ");
7976 else
7978 "NULL AS conperiod ");
7979
7980 /*
7981 * The point of the messy-looking outer join is to find a constraint that
7982 * is related by an internal dependency link to the index. If we find one,
7983 * create a CONSTRAINT entry linked to the INDEX entry. We assume an
7984 * index won't have more than one internal dependency.
7985 *
7986 * Note: the check on conrelid is redundant, but useful because that
7987 * column is indexed while conindid is not.
7988 */
7989 if (fout->remoteVersion >= 110000)
7990 {
7991 appendPQExpBuffer(query,
7992 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
7993 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
7994 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
7995 "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
7996 "LEFT JOIN pg_catalog.pg_constraint c "
7997 "ON (i.indrelid = c.conrelid AND "
7998 "i.indexrelid = c.conindid AND "
7999 "c.contype IN ('p','u','x')) "
8000 "LEFT JOIN pg_catalog.pg_inherits inh "
8001 "ON (inh.inhrelid = indexrelid) "
8002 "WHERE (i.indisvalid OR t2.relkind = 'p') "
8003 "AND i.indisready "
8004 "ORDER BY i.indrelid, indexname",
8005 tbloids->data);
8006 }
8007 else
8008 {
8009 /*
8010 * the test on indisready is necessary in 9.2, and harmless in
8011 * earlier/later versions
8012 */
8013 appendPQExpBuffer(query,
8014 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8015 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
8016 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
8017 "LEFT JOIN pg_catalog.pg_constraint c "
8018 "ON (i.indrelid = c.conrelid AND "
8019 "i.indexrelid = c.conindid AND "
8020 "c.contype IN ('p','u','x')) "
8021 "WHERE i.indisvalid AND i.indisready "
8022 "ORDER BY i.indrelid, indexname",
8023 tbloids->data);
8024 }
8025
8026 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8027
8028 ntups = PQntuples(res);
8029
8030 i_tableoid = PQfnumber(res, "tableoid");
8031 i_oid = PQfnumber(res, "oid");
8032 i_indrelid = PQfnumber(res, "indrelid");
8033 i_indexname = PQfnumber(res, "indexname");
8034 i_relpages = PQfnumber(res, "relpages");
8035 i_reltuples = PQfnumber(res, "reltuples");
8036 i_relallvisible = PQfnumber(res, "relallvisible");
8037 i_relallfrozen = PQfnumber(res, "relallfrozen");
8038 i_parentidx = PQfnumber(res, "parentidx");
8039 i_indexdef = PQfnumber(res, "indexdef");
8040 i_indnkeyatts = PQfnumber(res, "indnkeyatts");
8041 i_indnatts = PQfnumber(res, "indnatts");
8042 i_indkey = PQfnumber(res, "indkey");
8043 i_indisclustered = PQfnumber(res, "indisclustered");
8044 i_indisreplident = PQfnumber(res, "indisreplident");
8045 i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
8046 i_contype = PQfnumber(res, "contype");
8047 i_conname = PQfnumber(res, "conname");
8048 i_condeferrable = PQfnumber(res, "condeferrable");
8049 i_condeferred = PQfnumber(res, "condeferred");
8050 i_conperiod = PQfnumber(res, "conperiod");
8051 i_contableoid = PQfnumber(res, "contableoid");
8052 i_conoid = PQfnumber(res, "conoid");
8053 i_condef = PQfnumber(res, "condef");
8054 i_indattnames = PQfnumber(res, "indattnames");
8055 i_tablespace = PQfnumber(res, "tablespace");
8056 i_indreloptions = PQfnumber(res, "indreloptions");
8057 i_indstatcols = PQfnumber(res, "indstatcols");
8058 i_indstatvals = PQfnumber(res, "indstatvals");
8059
8060 indxinfo = (IndxInfo *) pg_malloc(ntups * sizeof(IndxInfo));
8061
8062 /*
8063 * Outer loop iterates once per table, not once per row. Incrementing of
8064 * j is handled by the inner loop.
8065 */
8066 curtblindx = -1;
8067 for (int j = 0; j < ntups;)
8068 {
8071 char **indAttNames = NULL;
8072 int nindAttNames = 0;
8073 int numinds;
8074
8075 /* Count rows for this table */
8076 for (numinds = 1; numinds < ntups - j; numinds++)
8077 if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
8078 break;
8079
8080 /*
8081 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8082 * order.
8083 */
8084 while (++curtblindx < numTables)
8085 {
8086 tbinfo = &tblinfo[curtblindx];
8087 if (tbinfo->dobj.catId.oid == indrelid)
8088 break;
8089 }
8090 if (curtblindx >= numTables)
8091 pg_fatal("unrecognized table OID %u", indrelid);
8092 /* cross-check that we only got requested tables */
8093 if (!tbinfo->hasindex ||
8094 !tbinfo->interesting)
8095 pg_fatal("unexpected index data for table \"%s\"",
8096 tbinfo->dobj.name);
8097
8098 /* Save data for this table */
8099 tbinfo->indexes = indxinfo + j;
8100 tbinfo->numIndexes = numinds;
8101
8102 for (int c = 0; c < numinds; c++, j++)
8103 {
8104 char contype;
8105 char indexkind;
8107 int32 relpages = atoi(PQgetvalue(res, j, i_relpages));
8108 int32 relallvisible = atoi(PQgetvalue(res, j, i_relallvisible));
8109 int32 relallfrozen = atoi(PQgetvalue(res, j, i_relallfrozen));
8110
8111 indxinfo[j].dobj.objType = DO_INDEX;
8112 indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8113 indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8114 AssignDumpId(&indxinfo[j].dobj);
8115 indxinfo[j].dobj.dump = tbinfo->dobj.dump;
8116 indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
8117 indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8118 indxinfo[j].indextable = tbinfo;
8119 indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
8120 indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
8121 indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
8122 indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
8123 indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
8124 indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
8125 indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
8126 indxinfo[j].indkeys = (Oid *) pg_malloc(indxinfo[j].indnattrs * sizeof(Oid));
8128 indxinfo[j].indkeys, indxinfo[j].indnattrs);
8129 indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
8130 indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
8131 indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
8132 indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
8133 indxinfo[j].partattaches = (SimplePtrList)
8134 {
8135 NULL, NULL
8136 };
8137
8138 if (indxinfo[j].parentidx == 0)
8140 else
8142
8143 if (!PQgetisnull(res, j, i_indattnames))
8144 {
8146 &indAttNames, &nindAttNames))
8147 pg_fatal("could not parse %s array", "indattnames");
8148 }
8149
8150 relstats = getRelationStatistics(fout, &indxinfo[j].dobj, relpages,
8151 PQgetvalue(res, j, i_reltuples),
8152 relallvisible, relallfrozen, indexkind,
8153 indAttNames, nindAttNames);
8154
8155 contype = *(PQgetvalue(res, j, i_contype));
8156 if (contype == 'p' || contype == 'u' || contype == 'x')
8157 {
8158 /*
8159 * If we found a constraint matching the index, create an
8160 * entry for it.
8161 */
8163
8166 constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8167 constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8168 AssignDumpId(&constrinfo->dobj);
8169 constrinfo->dobj.dump = tbinfo->dobj.dump;
8170 constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8171 constrinfo->dobj.namespace = tbinfo->dobj.namespace;
8172 constrinfo->contable = tbinfo;
8173 constrinfo->condomain = NULL;
8174 constrinfo->contype = contype;
8175 if (contype == 'x')
8176 constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
8177 else
8178 constrinfo->condef = NULL;
8179 constrinfo->confrelid = InvalidOid;
8180 constrinfo->conindex = indxinfo[j].dobj.dumpId;
8181 constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
8182 constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
8183 constrinfo->conperiod = *(PQgetvalue(res, j, i_conperiod)) == 't';
8184 constrinfo->conislocal = true;
8185 constrinfo->separate = true;
8186
8187 indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
8188 if (relstats != NULL)
8189 addObjectDependency(&relstats->dobj, constrinfo->dobj.dumpId);
8190 }
8191 else
8192 {
8193 /* Plain secondary index */
8194 indxinfo[j].indexconstraint = 0;
8195 }
8196 }
8197 }
8198
8199 PQclear(res);
8200
8201 destroyPQExpBuffer(query);
8203}
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:818
static RelStatsInfo * getRelationStatistics(Archive *fout, DumpableObject *rel, int32 relpages, char *reltuples, int32 relallvisible, int32 relallfrozen, char relkind, char **indAttNames, int nindAttNames)
Definition pg_dump.c:7109
char * c
bool parsePGArray(const char *atext, char ***itemarray, int *nitems)

References addObjectDependency(), appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_CONSTRAINT, DO_INDEX, _constraintInfo::dobj, ExecuteSqlQuery(), fb(), getRelationStatistics(), i, InvalidOid, j, _dumpableObject::objType, parseOidArray(), parsePGArray(), pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getInherits()

InhInfo * getInherits ( Archive fout,
int numInherits 
)
extern

Definition at line 7728 of file pg_dump.c.

7729{
7730 PGresult *res;
7731 int ntups;
7732 int i;
7735
7736 int i_inhrelid;
7737 int i_inhparent;
7738
7739 /* find all the inheritance information */
7740 appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7741
7742 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7743
7744 ntups = PQntuples(res);
7745
7746 *numInherits = ntups;
7747
7748 inhinfo = (InhInfo *) pg_malloc(ntups * sizeof(InhInfo));
7749
7750 i_inhrelid = PQfnumber(res, "inhrelid");
7751 i_inhparent = PQfnumber(res, "inhparent");
7752
7753 for (i = 0; i < ntups; i++)
7754 {
7755 inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7756 inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7757 }
7758
7759 PQclear(res);
7760
7761 destroyPQExpBuffer(query);
7762
7763 return inhinfo;
7764}

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), fb(), i, pg_malloc(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )
extern

Definition at line 754 of file common.c.

755{
756 return lastDumpId;
757}

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

void getNamespaces ( Archive fout)
extern

Definition at line 5992 of file pg_dump.c.

5993{
5994 PGresult *res;
5995 int ntups;
5996 int i;
5997 PQExpBuffer query;
5999 int i_tableoid;
6000 int i_oid;
6001 int i_nspname;
6002 int i_nspowner;
6003 int i_nspacl;
6004 int i_acldefault;
6005
6006 query = createPQExpBuffer();
6007
6008 /*
6009 * we fetch all namespaces including system ones, so that every object we
6010 * read in can be linked to a containing namespace.
6011 */
6012 appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
6013 "n.nspowner, "
6014 "n.nspacl, "
6015 "acldefault('n', n.nspowner) AS acldefault "
6016 "FROM pg_namespace n");
6017
6018 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6019
6020 ntups = PQntuples(res);
6021
6022 nsinfo = (NamespaceInfo *) pg_malloc(ntups * sizeof(NamespaceInfo));
6023
6024 i_tableoid = PQfnumber(res, "tableoid");
6025 i_oid = PQfnumber(res, "oid");
6026 i_nspname = PQfnumber(res, "nspname");
6027 i_nspowner = PQfnumber(res, "nspowner");
6028 i_nspacl = PQfnumber(res, "nspacl");
6029 i_acldefault = PQfnumber(res, "acldefault");
6030
6031 for (i = 0; i < ntups; i++)
6032 {
6033 const char *nspowner;
6034
6035 nsinfo[i].dobj.objType = DO_NAMESPACE;
6036 nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6037 nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6038 AssignDumpId(&nsinfo[i].dobj);
6039 nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
6040 nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
6041 nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6042 nsinfo[i].dacl.privtype = 0;
6043 nsinfo[i].dacl.initprivs = NULL;
6044 nspowner = PQgetvalue(res, i, i_nspowner);
6045 nsinfo[i].nspowner = atooid(nspowner);
6046 nsinfo[i].rolname = getRoleName(nspowner);
6047
6048 /* Decide whether to dump this namespace */
6050
6051 /* Mark whether namespace has an ACL */
6052 if (!PQgetisnull(res, i, i_nspacl))
6053 nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6054
6055 /*
6056 * We ignore any pg_init_privs.initprivs entry for the public schema
6057 * and assume a predetermined default, for several reasons. First,
6058 * dropping and recreating the schema removes its pg_init_privs entry,
6059 * but an empty destination database starts with this ACL nonetheless.
6060 * Second, we support dump/reload of public schema ownership changes.
6061 * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
6062 * initprivs continues to reflect the initial owner. Hence,
6063 * synthesize the value that nspacl will have after the restore's
6064 * ALTER SCHEMA OWNER. Third, this makes the destination database
6065 * match the source's ACL, even if the latter was an initdb-default
6066 * ACL, which changed in v15. An upgrade pulls in changes to most
6067 * system object ACLs that the DBA had not customized. We've made the
6068 * public schema depart from that, because changing its ACL so easily
6069 * breaks applications.
6070 */
6071 if (strcmp(nsinfo[i].dobj.name, "public") == 0)
6072 {
6075
6076 /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
6087
6088 nsinfo[i].dacl.privtype = 'i';
6089 nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
6090 nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6091
6094 }
6095 }
6096
6097 PQclear(res);
6098 destroyPQExpBuffer(query);
6099}
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition dumputils.c:585
char * pstrdup(const char *in)
Definition mcxt.c:1781
NameData rolname
Definition pg_authid.h:34
static void selectDumpableNamespace(NamespaceInfo *nsinfo, Archive *fout)
Definition pg_dump.c:1997
void resetPQExpBuffer(PQExpBuffer str)
void appendPGArray(PQExpBuffer buffer, const char *value)

References appendPGArray(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_NAMESPACE, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, pstrdup(), quoteAclUserName(), resetPQExpBuffer(), rolname, and selectDumpableNamespace().

Referenced by getSchemaData().

◆ getOpclasses()

void getOpclasses ( Archive fout)
extern

Definition at line 6645 of file pg_dump.c.

6646{
6647 PGresult *res;
6648 int ntups;
6649 int i;
6652 int i_tableoid;
6653 int i_oid;
6654 int i_opcmethod;
6655 int i_opcname;
6656 int i_opcnamespace;
6657 int i_opcowner;
6658
6659 /*
6660 * find all opclasses, including builtin opclasses; we filter out
6661 * system-defined opclasses at dump-out time.
6662 */
6663
6664 appendPQExpBufferStr(query, "SELECT tableoid, oid, opcmethod, opcname, "
6665 "opcnamespace, "
6666 "opcowner "
6667 "FROM pg_opclass");
6668
6669 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6670
6671 ntups = PQntuples(res);
6672
6673 opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
6674
6675 i_tableoid = PQfnumber(res, "tableoid");
6676 i_oid = PQfnumber(res, "oid");
6677 i_opcmethod = PQfnumber(res, "opcmethod");
6678 i_opcname = PQfnumber(res, "opcname");
6679 i_opcnamespace = PQfnumber(res, "opcnamespace");
6680 i_opcowner = PQfnumber(res, "opcowner");
6681
6682 for (i = 0; i < ntups; i++)
6683 {
6684 opcinfo[i].dobj.objType = DO_OPCLASS;
6685 opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6686 opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6687 AssignDumpId(&opcinfo[i].dobj);
6688 opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
6689 opcinfo[i].dobj.namespace =
6691 opcinfo[i].opcmethod = atooid(PQgetvalue(res, i, i_opcmethod));
6692 opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
6693
6694 /* Decide whether we want to dump it */
6696 }
6697
6698 PQclear(res);
6699
6700 destroyPQExpBuffer(query);
6701}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPCLASS, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getOperators()

void getOperators ( Archive fout)
extern

Definition at line 6367 of file pg_dump.c.

6368{
6369 PGresult *res;
6370 int ntups;
6371 int i;
6374 int i_tableoid;
6375 int i_oid;
6376 int i_oprname;
6377 int i_oprnamespace;
6378 int i_oprowner;
6379 int i_oprkind;
6380 int i_oprleft;
6381 int i_oprright;
6382 int i_oprcode;
6383
6384 /*
6385 * find all operators, including builtin operators; we filter out
6386 * system-defined operators at dump-out time.
6387 */
6388
6389 appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
6390 "oprnamespace, "
6391 "oprowner, "
6392 "oprkind, "
6393 "oprleft, "
6394 "oprright, "
6395 "oprcode::oid AS oprcode "
6396 "FROM pg_operator");
6397
6398 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6399
6400 ntups = PQntuples(res);
6401
6402 oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
6403
6404 i_tableoid = PQfnumber(res, "tableoid");
6405 i_oid = PQfnumber(res, "oid");
6406 i_oprname = PQfnumber(res, "oprname");
6407 i_oprnamespace = PQfnumber(res, "oprnamespace");
6408 i_oprowner = PQfnumber(res, "oprowner");
6409 i_oprkind = PQfnumber(res, "oprkind");
6410 i_oprleft = PQfnumber(res, "oprleft");
6411 i_oprright = PQfnumber(res, "oprright");
6412 i_oprcode = PQfnumber(res, "oprcode");
6413
6414 for (i = 0; i < ntups; i++)
6415 {
6416 oprinfo[i].dobj.objType = DO_OPERATOR;
6417 oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6418 oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6419 AssignDumpId(&oprinfo[i].dobj);
6420 oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
6421 oprinfo[i].dobj.namespace =
6423 oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
6424 oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
6425 oprinfo[i].oprleft = atooid(PQgetvalue(res, i, i_oprleft));
6426 oprinfo[i].oprright = atooid(PQgetvalue(res, i, i_oprright));
6427 oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
6428
6429 /* Decide whether we want to dump it */
6431 }
6432
6433 PQclear(res);
6434
6435 destroyPQExpBuffer(query);
6436}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPERATOR, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getOpfamilies()

void getOpfamilies ( Archive fout)
extern

Definition at line 6708 of file pg_dump.c.

6709{
6710 PGresult *res;
6711 int ntups;
6712 int i;
6713 PQExpBuffer query;
6715 int i_tableoid;
6716 int i_oid;
6717 int i_opfmethod;
6718 int i_opfname;
6719 int i_opfnamespace;
6720 int i_opfowner;
6721
6722 query = createPQExpBuffer();
6723
6724 /*
6725 * find all opfamilies, including builtin opfamilies; we filter out
6726 * system-defined opfamilies at dump-out time.
6727 */
6728
6729 appendPQExpBufferStr(query, "SELECT tableoid, oid, opfmethod, opfname, "
6730 "opfnamespace, "
6731 "opfowner "
6732 "FROM pg_opfamily");
6733
6734 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6735
6736 ntups = PQntuples(res);
6737
6738 opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
6739
6740 i_tableoid = PQfnumber(res, "tableoid");
6741 i_oid = PQfnumber(res, "oid");
6742 i_opfname = PQfnumber(res, "opfname");
6743 i_opfmethod = PQfnumber(res, "opfmethod");
6744 i_opfnamespace = PQfnumber(res, "opfnamespace");
6745 i_opfowner = PQfnumber(res, "opfowner");
6746
6747 for (i = 0; i < ntups; i++)
6748 {
6749 opfinfo[i].dobj.objType = DO_OPFAMILY;
6750 opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6751 opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6752 AssignDumpId(&opfinfo[i].dobj);
6753 opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
6754 opfinfo[i].dobj.namespace =
6756 opfinfo[i].opfmethod = atooid(PQgetvalue(res, i, i_opfmethod));
6757 opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
6758
6759 /* Decide whether we want to dump it */
6761 }
6762
6763 PQclear(res);
6764
6765 destroyPQExpBuffer(query);
6766}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPFAMILY, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getOwnedSeqs()

void getOwnedSeqs ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)
extern

Definition at line 7663 of file pg_dump.c.

7664{
7665 int i;
7666
7667 /*
7668 * Force sequences that are "owned" by table columns to be dumped whenever
7669 * their owning table is being dumped.
7670 */
7671 for (i = 0; i < numTables; i++)
7672 {
7673 TableInfo *seqinfo = &tblinfo[i];
7674 TableInfo *owning_tab;
7675
7676 if (!OidIsValid(seqinfo->owning_tab))
7677 continue; /* not an owned sequence */
7678
7679 owning_tab = findTableByOid(seqinfo->owning_tab);
7680 if (owning_tab == NULL)
7681 pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
7682 seqinfo->owning_tab, seqinfo->dobj.catId.oid);
7683
7684 /*
7685 * For an identity sequence, dump exactly the same components for the
7686 * sequence as for the owning table. This is important because we
7687 * treat the identity sequence as an integral part of the table. For
7688 * example, there is not any DDL command that allows creation of such
7689 * a sequence independently of the table.
7690 *
7691 * For other owned sequences such as serial sequences, we need to dump
7692 * the components that are being dumped for the table and any
7693 * components that the sequence is explicitly marked with.
7694 *
7695 * We can't simply use the set of components which are being dumped
7696 * for the table as the table might be in an extension (and only the
7697 * non-extension components, eg: ACLs if changed, security labels, and
7698 * policies, are being dumped) while the sequence is not (and
7699 * therefore the definition and other components should also be
7700 * dumped).
7701 *
7702 * If the sequence is part of the extension then it should be properly
7703 * marked by checkExtensionMembership() and this will be a no-op as
7704 * the table will be equivalently marked.
7705 */
7706 if (seqinfo->is_identity_sequence)
7707 seqinfo->dobj.dump = owning_tab->dobj.dump;
7708 else
7709 seqinfo->dobj.dump |= owning_tab->dobj.dump;
7710
7711 /* Make sure that necessary data is available if we're dumping it */
7712 if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
7713 {
7714 seqinfo->interesting = true;
7715 owning_tab->interesting = true;
7716 }
7717 }
7718}
#define DUMP_COMPONENT_NONE
Definition pg_dump.h:108

References _tableInfo::dobj, _dumpableObject::dump, DUMP_COMPONENT_NONE, fb(), findTableByOid(), i, _tableInfo::interesting, OidIsValid, and pg_fatal.

Referenced by getSchemaData().

◆ getPartitioningInfo()

void getPartitioningInfo ( Archive fout)
extern

Definition at line 7784 of file pg_dump.c.

7785{
7786 PQExpBuffer query;
7787 PGresult *res;
7788 int ntups;
7789
7790 /* hash partitioning didn't exist before v11 */
7791 if (fout->remoteVersion < 110000)
7792 return;
7793 /* needn't bother if not dumping data */
7794 if (!fout->dopt->dumpData)
7795 return;
7796
7797 query = createPQExpBuffer();
7798
7799 /*
7800 * Unsafe partitioning schemes are exactly those for which hash enum_ops
7801 * appears among the partition opclasses. We needn't check partstrat.
7802 *
7803 * Note that this query may well retrieve info about tables we aren't
7804 * going to dump and hence have no lock on. That's okay since we need not
7805 * invoke any unsafe server-side functions.
7806 */
7808 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7809 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7810 "ON c.opcmethod = a.oid\n"
7811 "WHERE opcname = 'enum_ops' "
7812 "AND opcnamespace = 'pg_catalog'::regnamespace "
7813 "AND amname = 'hash') = ANY(partclass)");
7814
7815 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7816
7817 ntups = PQntuples(res);
7818
7819 for (int i = 0; i < ntups; i++)
7820 {
7821 Oid tabrelid = atooid(PQgetvalue(res, i, 0));
7823
7825 if (tbinfo == NULL)
7826 pg_fatal("failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7827 tabrelid);
7828 tbinfo->unsafe_partitions = true;
7829 }
7830
7831 PQclear(res);
7832
7833 destroyPQExpBuffer(query);
7834}

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), fb(), findTableByOid(), i, pg_fatal, PGRES_TUPLES_OK, PQclear, PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getPolicies()

void getPolicies ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)
extern

Definition at line 4248 of file pg_dump.c.

4249{
4250 DumpOptions *dopt = fout->dopt;
4251 PQExpBuffer query;
4253 PGresult *res;
4255 int i_oid;
4256 int i_tableoid;
4257 int i_polrelid;
4258 int i_polname;
4259 int i_polcmd;
4260 int i_polpermissive;
4261 int i_polroles;
4262 int i_polqual;
4263 int i_polwithcheck;
4264 int i,
4265 j,
4266 ntups;
4267
4268 /* No policies before 9.5 */
4269 if (fout->remoteVersion < 90500)
4270 return;
4271
4272 /* Skip if --no-policies was specified */
4273 if (dopt->no_policies)
4274 return;
4275
4276 query = createPQExpBuffer();
4278
4279 /*
4280 * Identify tables of interest, and check which ones have RLS enabled.
4281 */
4283 for (i = 0; i < numTables; i++)
4284 {
4285 TableInfo *tbinfo = &tblinfo[i];
4286
4287 /* Ignore row security on tables not to be dumped */
4288 if (!(tbinfo->dobj.dump & DUMP_COMPONENT_POLICY))
4289 continue;
4290
4291 /* It can't have RLS or policies if it's not a table */
4292 if (tbinfo->relkind != RELKIND_RELATION &&
4294 continue;
4295
4296 /* Add it to the list of table OIDs to be probed below */
4297 if (tbloids->len > 1) /* do we have more than the '{'? */
4299 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
4300
4301 /* Is RLS enabled? (That's separate from whether it has policies) */
4302 if (tbinfo->rowsec)
4303 {
4304 tbinfo->dobj.components |= DUMP_COMPONENT_POLICY;
4305
4306 /*
4307 * We represent RLS being enabled on a table by creating a
4308 * PolicyInfo object with null polname.
4309 *
4310 * Note: use tableoid 0 so that this object won't be mistaken for
4311 * something that pg_depend entries apply to.
4312 */
4313 polinfo = pg_malloc(sizeof(PolicyInfo));
4314 polinfo->dobj.objType = DO_POLICY;
4315 polinfo->dobj.catId.tableoid = 0;
4316 polinfo->dobj.catId.oid = tbinfo->dobj.catId.oid;
4317 AssignDumpId(&polinfo->dobj);
4318 polinfo->dobj.namespace = tbinfo->dobj.namespace;
4319 polinfo->dobj.name = pg_strdup(tbinfo->dobj.name);
4320 polinfo->poltable = tbinfo;
4321 polinfo->polname = NULL;
4322 polinfo->polcmd = '\0';
4323 polinfo->polpermissive = 0;
4324 polinfo->polroles = NULL;
4325 polinfo->polqual = NULL;
4326 polinfo->polwithcheck = NULL;
4327 }
4328 }
4330
4331 /*
4332 * Now, read all RLS policies belonging to the tables of interest, and
4333 * create PolicyInfo objects for them. (Note that we must filter the
4334 * results server-side not locally, because we dare not apply pg_get_expr
4335 * to tables we don't have lock on.)
4336 */
4337 pg_log_info("reading row-level security policies");
4338
4339 printfPQExpBuffer(query,
4340 "SELECT pol.oid, pol.tableoid, pol.polrelid, pol.polname, pol.polcmd, ");
4341 if (fout->remoteVersion >= 100000)
4342 appendPQExpBufferStr(query, "pol.polpermissive, ");
4343 else
4344 appendPQExpBufferStr(query, "'t' as polpermissive, ");
4345 appendPQExpBuffer(query,
4346 "CASE WHEN pol.polroles = '{0}' THEN NULL ELSE "
4347 " pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(rolname) from pg_catalog.pg_roles WHERE oid = ANY(pol.polroles)), ', ') END AS polroles, "
4348 "pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS polqual, "
4349 "pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS polwithcheck "
4350 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
4351 "JOIN pg_catalog.pg_policy pol ON (src.tbloid = pol.polrelid)",
4352 tbloids->data);
4353
4354 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4355
4356 ntups = PQntuples(res);
4357 if (ntups > 0)
4358 {
4359 i_oid = PQfnumber(res, "oid");
4360 i_tableoid = PQfnumber(res, "tableoid");
4361 i_polrelid = PQfnumber(res, "polrelid");
4362 i_polname = PQfnumber(res, "polname");
4363 i_polcmd = PQfnumber(res, "polcmd");
4364 i_polpermissive = PQfnumber(res, "polpermissive");
4365 i_polroles = PQfnumber(res, "polroles");
4366 i_polqual = PQfnumber(res, "polqual");
4367 i_polwithcheck = PQfnumber(res, "polwithcheck");
4368
4369 polinfo = pg_malloc(ntups * sizeof(PolicyInfo));
4370
4371 for (j = 0; j < ntups; j++)
4372 {
4375
4376 tbinfo->dobj.components |= DUMP_COMPONENT_POLICY;
4377
4378 polinfo[j].dobj.objType = DO_POLICY;
4379 polinfo[j].dobj.catId.tableoid =
4380 atooid(PQgetvalue(res, j, i_tableoid));
4381 polinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
4382 AssignDumpId(&polinfo[j].dobj);
4383 polinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4384 polinfo[j].poltable = tbinfo;
4385 polinfo[j].polname = pg_strdup(PQgetvalue(res, j, i_polname));
4386 polinfo[j].dobj.name = pg_strdup(polinfo[j].polname);
4387
4388 polinfo[j].polcmd = *(PQgetvalue(res, j, i_polcmd));
4389 polinfo[j].polpermissive = *(PQgetvalue(res, j, i_polpermissive)) == 't';
4390
4391 if (PQgetisnull(res, j, i_polroles))
4392 polinfo[j].polroles = NULL;
4393 else
4394 polinfo[j].polroles = pg_strdup(PQgetvalue(res, j, i_polroles));
4395
4396 if (PQgetisnull(res, j, i_polqual))
4397 polinfo[j].polqual = NULL;
4398 else
4399 polinfo[j].polqual = pg_strdup(PQgetvalue(res, j, i_polqual));
4400
4401 if (PQgetisnull(res, j, i_polwithcheck))
4402 polinfo[j].polwithcheck = NULL;
4403 else
4404 polinfo[j].polwithcheck
4406 }
4407 }
4408
4409 PQclear(res);
4410
4411 destroyPQExpBuffer(query);
4413}
#define pg_log_info(...)
Definition logging.h:124
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)

References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_POLICY, DUMP_COMPONENT_POLICY, ExecuteSqlQuery(), fb(), findTableByOid(), i, j, _dumpOptions::no_policies, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and printfPQExpBuffer().

Referenced by getSchemaData().

◆ getProcLangs()

void getProcLangs ( Archive fout)
extern

Definition at line 8960 of file pg_dump.c.

8961{
8962 PGresult *res;
8963 int ntups;
8964 int i;
8967 int i_tableoid;
8968 int i_oid;
8969 int i_lanname;
8970 int i_lanpltrusted;
8971 int i_lanplcallfoid;
8972 int i_laninline;
8973 int i_lanvalidator;
8974 int i_lanacl;
8975 int i_acldefault;
8976 int i_lanowner;
8977
8978 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
8979 "lanname, lanpltrusted, lanplcallfoid, "
8980 "laninline, lanvalidator, "
8981 "lanacl, "
8982 "acldefault('l', lanowner) AS acldefault, "
8983 "lanowner "
8984 "FROM pg_language "
8985 "WHERE lanispl "
8986 "ORDER BY oid");
8987
8988 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8989
8990 ntups = PQntuples(res);
8991
8992 planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
8993
8994 i_tableoid = PQfnumber(res, "tableoid");
8995 i_oid = PQfnumber(res, "oid");
8996 i_lanname = PQfnumber(res, "lanname");
8997 i_lanpltrusted = PQfnumber(res, "lanpltrusted");
8998 i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
8999 i_laninline = PQfnumber(res, "laninline");
9000 i_lanvalidator = PQfnumber(res, "lanvalidator");
9001 i_lanacl = PQfnumber(res, "lanacl");
9002 i_acldefault = PQfnumber(res, "acldefault");
9003 i_lanowner = PQfnumber(res, "lanowner");
9004
9005 for (i = 0; i < ntups; i++)
9006 {
9007 planginfo[i].dobj.objType = DO_PROCLANG;
9008 planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9009 planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9010 AssignDumpId(&planginfo[i].dobj);
9011
9012 planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
9013 planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
9014 planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9015 planginfo[i].dacl.privtype = 0;
9016 planginfo[i].dacl.initprivs = NULL;
9017 planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
9018 planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
9019 planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
9020 planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
9021 planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
9022
9023 /* Decide whether we want to dump it */
9025
9026 /* Mark whether language has an ACL */
9027 if (!PQgetisnull(res, i, i_lanacl))
9028 planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9029 }
9030
9031 PQclear(res);
9032
9033 destroyPQExpBuffer(query);
9034}
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition pg_dump.c:2214

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PROCLANG, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableProcLang().

Referenced by getSchemaData().

◆ getPublicationNamespaces()

void getPublicationNamespaces ( Archive fout)
extern

Definition at line 4757 of file pg_dump.c.

4758{
4759 PQExpBuffer query;
4760 PGresult *res;
4762 DumpOptions *dopt = fout->dopt;
4763 int i_tableoid;
4764 int i_oid;
4765 int i_pnpubid;
4766 int i_pnnspid;
4767 int i,
4768 j,
4769 ntups;
4770
4771 if (dopt->no_publications || fout->remoteVersion < 150000)
4772 return;
4773
4774 query = createPQExpBuffer();
4775
4776 /* Collect all publication membership info. */
4778 "SELECT tableoid, oid, pnpubid, pnnspid "
4779 "FROM pg_catalog.pg_publication_namespace");
4780 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4781
4782 ntups = PQntuples(res);
4783
4784 i_tableoid = PQfnumber(res, "tableoid");
4785 i_oid = PQfnumber(res, "oid");
4786 i_pnpubid = PQfnumber(res, "pnpubid");
4787 i_pnnspid = PQfnumber(res, "pnnspid");
4788
4789 /* this allocation may be more than we need */
4790 pubsinfo = pg_malloc(ntups * sizeof(PublicationSchemaInfo));
4791 j = 0;
4792
4793 for (i = 0; i < ntups; i++)
4794 {
4799
4800 /*
4801 * Ignore any entries for which we aren't interested in either the
4802 * publication or the rel.
4803 */
4805 if (pubinfo == NULL)
4806 continue;
4808 if (nspinfo == NULL)
4809 continue;
4810
4811 /* OK, make a DumpableObject for this relationship */
4813 pubsinfo[j].dobj.catId.tableoid =
4814 atooid(PQgetvalue(res, i, i_tableoid));
4815 pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4816 AssignDumpId(&pubsinfo[j].dobj);
4817 pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4818 pubsinfo[j].dobj.name = nspinfo->dobj.name;
4819 pubsinfo[j].publication = pubinfo;
4820 pubsinfo[j].pubschema = nspinfo;
4821
4822 /* Decide whether we want to dump it */
4824
4825 j++;
4826 }
4827
4828 PQclear(res);
4829 destroyPQExpBuffer(query);
4830}
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition common.c:990
PublicationInfo * findPublicationByOid(Oid oid)
Definition common.c:1026
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition pg_dump.c:2321
int no_publications
Definition pg_backup.h:189

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION_TABLE_IN_SCHEMA, ExecuteSqlQuery(), fb(), findNamespaceByOid(), findPublicationByOid(), i, j, _dumpOptions::no_publications, pg_malloc(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpablePublicationObject().

Referenced by getSchemaData().

◆ getPublications()

void getPublications ( Archive fout)
extern

Definition at line 4538 of file pg_dump.c.

4539{
4540 DumpOptions *dopt = fout->dopt;
4541 PQExpBuffer query;
4542 PGresult *res;
4544 int i_tableoid;
4545 int i_oid;
4546 int i_pubname;
4547 int i_pubowner;
4548 int i_puballtables;
4550 int i_pubinsert;
4551 int i_pubupdate;
4552 int i_pubdelete;
4553 int i_pubtruncate;
4554 int i_pubviaroot;
4555 int i_pubgencols;
4556 int i,
4557 ntups;
4558
4559 if (dopt->no_publications || fout->remoteVersion < 100000)
4560 return;
4561
4562 query = createPQExpBuffer();
4563
4564 /* Get the publications. */
4565 appendPQExpBufferStr(query, "SELECT p.tableoid, p.oid, p.pubname, "
4566 "p.pubowner, p.puballtables, p.pubinsert, "
4567 "p.pubupdate, p.pubdelete, ");
4568
4569 if (fout->remoteVersion >= 110000)
4570 appendPQExpBufferStr(query, "p.pubtruncate, ");
4571 else
4572 appendPQExpBufferStr(query, "false AS pubtruncate, ");
4573
4574 if (fout->remoteVersion >= 130000)
4575 appendPQExpBufferStr(query, "p.pubviaroot, ");
4576 else
4577 appendPQExpBufferStr(query, "false AS pubviaroot, ");
4578
4579 if (fout->remoteVersion >= 180000)
4580 appendPQExpBufferStr(query, "p.pubgencols, ");
4581 else
4582 appendPQExpBuffer(query, "'%c' AS pubgencols, ", PUBLISH_GENCOLS_NONE);
4583
4584 if (fout->remoteVersion >= 190000)
4585 appendPQExpBufferStr(query, "p.puballsequences ");
4586 else
4587 appendPQExpBufferStr(query, "false AS puballsequences ");
4588
4589 appendPQExpBufferStr(query, "FROM pg_publication p");
4590
4591 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4592
4593 ntups = PQntuples(res);
4594
4595 if (ntups == 0)
4596 goto cleanup;
4597
4598 i_tableoid = PQfnumber(res, "tableoid");
4599 i_oid = PQfnumber(res, "oid");
4600 i_pubname = PQfnumber(res, "pubname");
4601 i_pubowner = PQfnumber(res, "pubowner");
4602 i_puballtables = PQfnumber(res, "puballtables");
4603 i_puballsequences = PQfnumber(res, "puballsequences");
4604 i_pubinsert = PQfnumber(res, "pubinsert");
4605 i_pubupdate = PQfnumber(res, "pubupdate");
4606 i_pubdelete = PQfnumber(res, "pubdelete");
4607 i_pubtruncate = PQfnumber(res, "pubtruncate");
4608 i_pubviaroot = PQfnumber(res, "pubviaroot");
4609 i_pubgencols = PQfnumber(res, "pubgencols");
4610
4611 pubinfo = pg_malloc(ntups * sizeof(PublicationInfo));
4612
4613 for (i = 0; i < ntups; i++)
4614 {
4615 pubinfo[i].dobj.objType = DO_PUBLICATION;
4616 pubinfo[i].dobj.catId.tableoid =
4617 atooid(PQgetvalue(res, i, i_tableoid));
4618 pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4619 AssignDumpId(&pubinfo[i].dobj);
4620 pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4621 pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4622 pubinfo[i].puballtables =
4623 (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4624 pubinfo[i].puballsequences =
4625 (strcmp(PQgetvalue(res, i, i_puballsequences), "t") == 0);
4626 pubinfo[i].pubinsert =
4627 (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4628 pubinfo[i].pubupdate =
4629 (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4630 pubinfo[i].pubdelete =
4631 (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4632 pubinfo[i].pubtruncate =
4633 (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4634 pubinfo[i].pubviaroot =
4635 (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4636 pubinfo[i].pubgencols_type =
4637 *(PQgetvalue(res, i, i_pubgencols));
4638
4639 /* Decide whether we want to dump it */
4641 }
4642
4643cleanup:
4644 PQclear(res);
4645
4646 destroyPQExpBuffer(query);
4647}

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, cleanup(), createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION, ExecuteSqlQuery(), fb(), getRoleName(), i, _dumpOptions::no_publications, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getPublicationTables()

void getPublicationTables ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)
extern

Definition at line 4837 of file pg_dump.c.

4838{
4839 PQExpBuffer query;
4840 PGresult *res;
4842 DumpOptions *dopt = fout->dopt;
4843 int i_tableoid;
4844 int i_oid;
4845 int i_prpubid;
4846 int i_prrelid;
4847 int i_prrelqual;
4848 int i_prattrs;
4849 int i,
4850 j,
4851 ntups;
4852
4853 if (dopt->no_publications || fout->remoteVersion < 100000)
4854 return;
4855
4856 query = createPQExpBuffer();
4857
4858 /* Collect all publication membership info. */
4859 if (fout->remoteVersion >= 150000)
4861 "SELECT tableoid, oid, prpubid, prrelid, "
4862 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4863 "(CASE\n"
4864 " WHEN pr.prattrs IS NOT NULL THEN\n"
4865 " (SELECT array_agg(attname)\n"
4866 " FROM\n"
4867 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4868 " pg_catalog.pg_attribute\n"
4869 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4870 " ELSE NULL END) prattrs "
4871 "FROM pg_catalog.pg_publication_rel pr");
4872 else
4874 "SELECT tableoid, oid, prpubid, prrelid, "
4875 "NULL AS prrelqual, NULL AS prattrs "
4876 "FROM pg_catalog.pg_publication_rel");
4877 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4878
4879 ntups = PQntuples(res);
4880
4881 i_tableoid = PQfnumber(res, "tableoid");
4882 i_oid = PQfnumber(res, "oid");
4883 i_prpubid = PQfnumber(res, "prpubid");
4884 i_prrelid = PQfnumber(res, "prrelid");
4885 i_prrelqual = PQfnumber(res, "prrelqual");
4886 i_prattrs = PQfnumber(res, "prattrs");
4887
4888 /* this allocation may be more than we need */
4889 pubrinfo = pg_malloc(ntups * sizeof(PublicationRelInfo));
4890 j = 0;
4891
4892 for (i = 0; i < ntups; i++)
4893 {
4898
4899 /*
4900 * Ignore any entries for which we aren't interested in either the
4901 * publication or the rel.
4902 */
4904 if (pubinfo == NULL)
4905 continue;
4907 if (tbinfo == NULL)
4908 continue;
4909
4910 /* OK, make a DumpableObject for this relationship */
4911 pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4912 pubrinfo[j].dobj.catId.tableoid =
4913 atooid(PQgetvalue(res, i, i_tableoid));
4914 pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4915 AssignDumpId(&pubrinfo[j].dobj);
4916 pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4917 pubrinfo[j].dobj.name = tbinfo->dobj.name;
4918 pubrinfo[j].publication = pubinfo;
4919 pubrinfo[j].pubtable = tbinfo;
4920 if (PQgetisnull(res, i, i_prrelqual))
4921 pubrinfo[j].pubrelqual = NULL;
4922 else
4923 pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4924
4925 if (!PQgetisnull(res, i, i_prattrs))
4926 {
4927 char **attnames;
4928 int nattnames;
4930
4931 if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4932 &attnames, &nattnames))
4933 pg_fatal("could not parse %s array", "prattrs");
4935 for (int k = 0; k < nattnames; k++)
4936 {
4937 if (k > 0)
4939
4940 appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4941 }
4942 pubrinfo[j].pubrattrs = attribs->data;
4943 free(attribs); /* but not attribs->data */
4944 free(attnames);
4945 }
4946 else
4947 pubrinfo[j].pubrattrs = NULL;
4948
4949 /* Decide whether we want to dump it */
4951
4952 j++;
4953 }
4954
4955 PQclear(res);
4956 destroyPQExpBuffer(query);
4957}
#define free(a)
const char * fmtId(const char *rawid)

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_PUBLICATION_REL, ExecuteSqlQuery(), fb(), findPublicationByOid(), findTableByOid(), fmtId(), free, i, j, _dumpOptions::no_publications, parsePGArray(), pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpablePublicationObject().

Referenced by getSchemaData().

◆ getRules()

void getRules ( Archive fout)
extern

Definition at line 8589 of file pg_dump.c.

8590{
8591 PGresult *res;
8592 int ntups;
8593 int i;
8596 int i_tableoid;
8597 int i_oid;
8598 int i_rulename;
8599 int i_ruletable;
8600 int i_ev_type;
8601 int i_is_instead;
8602 int i_ev_enabled;
8603
8604 appendPQExpBufferStr(query, "SELECT "
8605 "tableoid, oid, rulename, "
8606 "ev_class AS ruletable, ev_type, is_instead, "
8607 "ev_enabled "
8608 "FROM pg_rewrite "
8609 "ORDER BY oid");
8610
8611 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8612
8613 ntups = PQntuples(res);
8614
8615 ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
8616
8617 i_tableoid = PQfnumber(res, "tableoid");
8618 i_oid = PQfnumber(res, "oid");
8619 i_rulename = PQfnumber(res, "rulename");
8620 i_ruletable = PQfnumber(res, "ruletable");
8621 i_ev_type = PQfnumber(res, "ev_type");
8622 i_is_instead = PQfnumber(res, "is_instead");
8623 i_ev_enabled = PQfnumber(res, "ev_enabled");
8624
8625 for (i = 0; i < ntups; i++)
8626 {
8628
8629 ruleinfo[i].dobj.objType = DO_RULE;
8630 ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8631 ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8632 AssignDumpId(&ruleinfo[i].dobj);
8633 ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
8635 ruleinfo[i].ruletable = findTableByOid(ruletableoid);
8636 if (ruleinfo[i].ruletable == NULL)
8637 pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8638 ruletableoid, ruleinfo[i].dobj.catId.oid);
8639 ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
8640 ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
8641 ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
8642 ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
8643 ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
8644 if (ruleinfo[i].ruletable)
8645 {
8646 /*
8647 * If the table is a view or materialized view, force its ON
8648 * SELECT rule to be sorted before the view itself --- this
8649 * ensures that any dependencies for the rule affect the table's
8650 * positioning. Other rules are forced to appear after their
8651 * table.
8652 */
8653 if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
8654 ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
8655 ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
8656 {
8657 addObjectDependency(&ruleinfo[i].ruletable->dobj,
8658 ruleinfo[i].dobj.dumpId);
8659 /* We'll merge the rule into CREATE VIEW, if possible */
8660 ruleinfo[i].separate = false;
8661 }
8662 else
8663 {
8665 ruleinfo[i].ruletable->dobj.dumpId);
8666 ruleinfo[i].separate = true;
8667 }
8668 }
8669 else
8670 ruleinfo[i].separate = true;
8671 }
8672
8673 PQclear(res);
8674
8675 destroyPQExpBuffer(query);
8676}

References addObjectDependency(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_RULE, ExecuteSqlQuery(), fb(), findTableByOid(), i, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getSchemaData()

TableInfo * getSchemaData ( Archive fout,
int numTablesPtr 
)
extern

Definition at line 98 of file common.c.

99{
100 TableInfo *tblinfo;
103 int numTables;
104 int numExtensions;
105 int numInherits;
106
107 /*
108 * We must read extensions and extension membership info first, because
109 * extension membership needs to be consultable during decisions about
110 * whether other objects are to be dumped.
111 */
112 pg_log_info("reading extensions");
114
115 pg_log_info("identifying extension members");
117
118 pg_log_info("reading schemas");
120
121 /*
122 * getTables should be done as soon as possible, so as to minimize the
123 * window between starting our transaction and acquiring per-table locks.
124 * However, we have to do getNamespaces first because the tables get
125 * linked to their containing namespaces during getTables.
126 */
127 pg_log_info("reading user-defined tables");
128 tblinfo = getTables(fout, &numTables);
129
130 getOwnedSeqs(fout, tblinfo, numTables);
131
132 pg_log_info("reading user-defined functions");
133 getFuncs(fout);
134
135 /* this must be after getTables and getFuncs */
136 pg_log_info("reading user-defined types");
137 getTypes(fout);
138
139 /* this must be after getFuncs, too */
140 pg_log_info("reading procedural languages");
142
143 pg_log_info("reading user-defined aggregate functions");
145
146 pg_log_info("reading user-defined operators");
148
149 pg_log_info("reading user-defined access methods");
151
152 pg_log_info("reading user-defined operator classes");
154
155 pg_log_info("reading user-defined operator families");
157
158 pg_log_info("reading user-defined text search parsers");
160
161 pg_log_info("reading user-defined text search templates");
163
164 pg_log_info("reading user-defined text search dictionaries");
166
167 pg_log_info("reading user-defined text search configurations");
169
170 pg_log_info("reading user-defined foreign-data wrappers");
172
173 pg_log_info("reading user-defined foreign servers");
175
176 pg_log_info("reading default privileges");
178
179 pg_log_info("reading user-defined collations");
181
182 pg_log_info("reading user-defined conversions");
184
185 pg_log_info("reading type casts");
186 getCasts(fout);
187
188 pg_log_info("reading transforms");
190
191 pg_log_info("reading table inheritance information");
193
194 pg_log_info("reading event triggers");
196
197 /* Identify extension configuration tables that should be dumped */
198 pg_log_info("finding extension tables");
200
201 /* Link tables to parents, mark parents of target tables interesting */
202 pg_log_info("finding inheritance relationships");
204
205 pg_log_info("reading column info for interesting tables");
206 getTableAttrs(fout, tblinfo, numTables);
207
208 pg_log_info("flagging inherited columns in subtables");
209 flagInhAttrs(fout, fout->dopt, tblinfo, numTables);
210
211 pg_log_info("reading partitioning data");
213
214 pg_log_info("reading indexes");
215 getIndexes(fout, tblinfo, numTables);
216
217 pg_log_info("flagging indexes in partitioned tables");
218 flagInhIndexes(fout, tblinfo, numTables);
219
220 pg_log_info("reading extended statistics");
222
223 pg_log_info("reading constraints");
224 getConstraints(fout, tblinfo, numTables);
225
226 pg_log_info("reading triggers");
227 getTriggers(fout, tblinfo, numTables);
228
229 pg_log_info("reading rewrite rules");
230 getRules(fout);
231
232 pg_log_info("reading policies");
233 getPolicies(fout, tblinfo, numTables);
234
235 pg_log_info("reading publications");
237
238 pg_log_info("reading publication membership of tables");
240
241 pg_log_info("reading publication membership of schemas");
243
244 pg_log_info("reading subscriptions");
246
247 pg_log_info("reading subscription membership of relations");
249
250 free(inhinfo); /* not needed any longer */
251
253 return tblinfo;
254}
static void flagInhAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tblinfo, int numTables)
Definition common.c:478
static void flagInhTables(Archive *fout, TableInfo *tblinfo, int numTables, InhInfo *inhinfo, int numInherits)
Definition common.c:269
static void flagInhIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8295
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6124
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4757
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7784
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7728
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10415
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4248
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19932
void getTypes(Archive *fout)
Definition pg_dump.c:6199
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7663
void getOpclasses(Archive *fout)
Definition pg_dump.c:6645
void getForeignServers(Archive *fout)
Definition pg_dump.c:10499
void getFuncs(Archive *fout)
Definition pg_dump.c:6914
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10231
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4837
void getCasts(Archive *fout)
Definition pg_dump.c:9044
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7844
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10356
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6571
void getConversions(Archive *fout)
Definition pg_dump.c:6509
void getRules(Archive *fout)
Definition pg_dump.c:8589
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9238
void getCollations(Archive *fout)
Definition pg_dump.c:6443
void getAggregates(Archive *fout)
Definition pg_dump.c:6773
void getNamespaces(Archive *fout)
Definition pg_dump.c:5992
void getPublications(Archive *fout)
Definition pg_dump.c:4538
void getTSParsers(Archive *fout)
Definition pg_dump.c:10157
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7186
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8213
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20025
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10587
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5108
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8686
void getTransforms(Archive *fout)
Definition pg_dump.c:9154
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8882
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10297
void getProcLangs(Archive *fout)
Definition pg_dump.c:8960
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5328
void getOperators(Archive *fout)
Definition pg_dump.c:6367
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6708

References fb(), flagInhAttrs(), flagInhIndexes(), flagInhTables(), free, getAccessMethods(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getEventTriggers(), getExtendedStatistics(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getInherits(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getOwnedSeqs(), getPartitioningInfo(), getPolicies(), getProcLangs(), getPublicationNamespaces(), getPublications(), getPublicationTables(), getRules(), getSubscriptionRelations(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), pg_log_info, and processExtensionTables().

Referenced by main().

◆ getSubscriptionRelations()

void getSubscriptionRelations ( Archive fout)
extern

Definition at line 5328 of file pg_dump.c.

5329{
5330 DumpOptions *dopt = fout->dopt;
5331 SubscriptionInfo *subinfo = NULL;
5333 PGresult *res;
5334 int i_srsubid;
5335 int i_srrelid;
5336 int i_srsubstate;
5337 int i_srsublsn;
5338 int ntups;
5340
5341 if (dopt->no_subscriptions || !dopt->binary_upgrade ||
5342 fout->remoteVersion < 170000)
5343 return;
5344
5345 res = ExecuteSqlQuery(fout,
5346 "SELECT srsubid, srrelid, srsubstate, srsublsn "
5347 "FROM pg_catalog.pg_subscription_rel "
5348 "ORDER BY srsubid",
5350 ntups = PQntuples(res);
5351 if (ntups == 0)
5352 goto cleanup;
5353
5354 /* Get pg_subscription_rel attributes */
5355 i_srsubid = PQfnumber(res, "srsubid");
5356 i_srrelid = PQfnumber(res, "srrelid");
5357 i_srsubstate = PQfnumber(res, "srsubstate");
5358 i_srsublsn = PQfnumber(res, "srsublsn");
5359
5360 subrinfo = pg_malloc(ntups * sizeof(SubRelInfo));
5361 for (int i = 0; i < ntups; i++)
5362 {
5364 Oid relid = atooid(PQgetvalue(res, i, i_srrelid));
5365 TableInfo *tblinfo;
5366
5367 /*
5368 * If we switched to a new subscription, check if the subscription
5369 * exists.
5370 */
5372 {
5374 if (subinfo == NULL)
5375 pg_fatal("subscription with OID %u does not exist", cur_srsubid);
5376
5378 }
5379
5380 tblinfo = findTableByOid(relid);
5381 if (tblinfo == NULL)
5382 pg_fatal("failed sanity check, relation with OID %u not found",
5383 relid);
5384
5385 /* OK, make a DumpableObject for this relationship */
5386 subrinfo[i].dobj.objType = DO_SUBSCRIPTION_REL;
5387 subrinfo[i].dobj.catId.tableoid = relid;
5388 subrinfo[i].dobj.catId.oid = cur_srsubid;
5389 AssignDumpId(&subrinfo[i].dobj);
5390 subrinfo[i].dobj.namespace = tblinfo->dobj.namespace;
5391 subrinfo[i].dobj.name = tblinfo->dobj.name;
5392 subrinfo[i].subinfo = subinfo;
5393 subrinfo[i].tblinfo = tblinfo;
5394 subrinfo[i].srsubstate = PQgetvalue(res, i, i_srsubstate)[0];
5395 if (PQgetisnull(res, i, i_srsublsn))
5396 subrinfo[i].srsublsn = NULL;
5397 else
5398 subrinfo[i].srsublsn = pg_strdup(PQgetvalue(res, i, i_srsublsn));
5399
5400 /* Decide whether we want to dump it */
5402 }
5403
5404cleanup:
5405 PQclear(res);
5406}
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition common.c:1044
int no_subscriptions
Definition pg_backup.h:191

References AssignDumpId(), atooid, _dumpOptions::binary_upgrade, cleanup(), DO_SUBSCRIPTION_REL, _tableInfo::dobj, ExecuteSqlQuery(), fb(), findSubscriptionByOid(), findTableByOid(), i, InvalidOid, _dumpableObject::name, _dumpOptions::no_subscriptions, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getSubscriptions()

void getSubscriptions ( Archive fout)
extern

Definition at line 5108 of file pg_dump.c.

5109{
5110 DumpOptions *dopt = fout->dopt;
5111 PQExpBuffer query;
5112 PGresult *res;
5113 SubscriptionInfo *subinfo;
5114 int i_tableoid;
5115 int i_oid;
5116 int i_subname;
5117 int i_subowner;
5118 int i_subbinary;
5119 int i_substream;
5123 int i_subrunasowner;
5124 int i_subconninfo;
5125 int i_subslotname;
5126 int i_subsynccommit;
5128 int i_suborigin;
5130 int i_subenabled;
5131 int i_subfailover;
5134 int i,
5135 ntups;
5136
5137 if (dopt->no_subscriptions || fout->remoteVersion < 100000)
5138 return;
5139
5140 if (!is_superuser(fout))
5141 {
5142 int n;
5143
5144 res = ExecuteSqlQuery(fout,
5145 "SELECT count(*) FROM pg_subscription "
5146 "WHERE subdbid = (SELECT oid FROM pg_database"
5147 " WHERE datname = current_database())",
5149 n = atoi(PQgetvalue(res, 0, 0));
5150 if (n > 0)
5151 pg_log_warning("subscriptions not dumped because current user is not a superuser");
5152 PQclear(res);
5153 return;
5154 }
5155
5156 query = createPQExpBuffer();
5157
5158 /* Get the subscriptions in current database. */
5160 "SELECT s.tableoid, s.oid, s.subname,\n"
5161 " s.subowner,\n"
5162 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
5163 " s.subpublications,\n");
5164
5165 if (fout->remoteVersion >= 140000)
5166 appendPQExpBufferStr(query, " s.subbinary,\n");
5167 else
5168 appendPQExpBufferStr(query, " false AS subbinary,\n");
5169
5170 if (fout->remoteVersion >= 140000)
5171 appendPQExpBufferStr(query, " s.substream,\n");
5172 else
5173 appendPQExpBufferStr(query, " 'f' AS substream,\n");
5174
5175 if (fout->remoteVersion >= 150000)
5177 " s.subtwophasestate,\n"
5178 " s.subdisableonerr,\n");
5179 else
5180 appendPQExpBuffer(query,
5181 " '%c' AS subtwophasestate,\n"
5182 " false AS subdisableonerr,\n",
5184
5185 if (fout->remoteVersion >= 160000)
5187 " s.subpasswordrequired,\n"
5188 " s.subrunasowner,\n"
5189 " s.suborigin,\n");
5190 else
5191 appendPQExpBuffer(query,
5192 " 't' AS subpasswordrequired,\n"
5193 " 't' AS subrunasowner,\n"
5194 " '%s' AS suborigin,\n",
5196
5197 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5198 appendPQExpBufferStr(query, " o.remote_lsn AS suboriginremotelsn,\n"
5199 " s.subenabled,\n");
5200 else
5201 appendPQExpBufferStr(query, " NULL AS suboriginremotelsn,\n"
5202 " false AS subenabled,\n");
5203
5204 if (fout->remoteVersion >= 170000)
5206 " s.subfailover,\n");
5207 else
5209 " false AS subfailover,\n");
5210
5211 if (fout->remoteVersion >= 190000)
5213 " s.subretaindeadtuples,\n");
5214 else
5216 " false AS subretaindeadtuples,\n");
5217
5218 if (fout->remoteVersion >= 190000)
5220 " s.submaxretention\n");
5221 else
5222 appendPQExpBuffer(query,
5223 " 0 AS submaxretention\n");
5224
5226 "FROM pg_subscription s\n");
5227
5228 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5230 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
5231 " ON o.external_id = 'pg_' || s.oid::text \n");
5232
5234 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
5235 " WHERE datname = current_database())");
5236
5237 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5238
5239 ntups = PQntuples(res);
5240
5241 /*
5242 * Get subscription fields. We don't include subskiplsn in the dump as
5243 * after restoring the dump this value may no longer be relevant.
5244 */
5245 i_tableoid = PQfnumber(res, "tableoid");
5246 i_oid = PQfnumber(res, "oid");
5247 i_subname = PQfnumber(res, "subname");
5248 i_subowner = PQfnumber(res, "subowner");
5249 i_subenabled = PQfnumber(res, "subenabled");
5250 i_subbinary = PQfnumber(res, "subbinary");
5251 i_substream = PQfnumber(res, "substream");
5252 i_subtwophasestate = PQfnumber(res, "subtwophasestate");
5253 i_subdisableonerr = PQfnumber(res, "subdisableonerr");
5254 i_subpasswordrequired = PQfnumber(res, "subpasswordrequired");
5255 i_subrunasowner = PQfnumber(res, "subrunasowner");
5256 i_subfailover = PQfnumber(res, "subfailover");
5257 i_subretaindeadtuples = PQfnumber(res, "subretaindeadtuples");
5258 i_submaxretention = PQfnumber(res, "submaxretention");
5259 i_subconninfo = PQfnumber(res, "subconninfo");
5260 i_subslotname = PQfnumber(res, "subslotname");
5261 i_subsynccommit = PQfnumber(res, "subsynccommit");
5262 i_subpublications = PQfnumber(res, "subpublications");
5263 i_suborigin = PQfnumber(res, "suborigin");
5264 i_suboriginremotelsn = PQfnumber(res, "suboriginremotelsn");
5265
5266 subinfo = pg_malloc(ntups * sizeof(SubscriptionInfo));
5267
5268 for (i = 0; i < ntups; i++)
5269 {
5270 subinfo[i].dobj.objType = DO_SUBSCRIPTION;
5271 subinfo[i].dobj.catId.tableoid =
5272 atooid(PQgetvalue(res, i, i_tableoid));
5273 subinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5274 AssignDumpId(&subinfo[i].dobj);
5275 subinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_subname));
5276 subinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_subowner));
5277
5278 subinfo[i].subenabled =
5279 (strcmp(PQgetvalue(res, i, i_subenabled), "t") == 0);
5280 subinfo[i].subbinary =
5281 (strcmp(PQgetvalue(res, i, i_subbinary), "t") == 0);
5282 subinfo[i].substream = *(PQgetvalue(res, i, i_substream));
5283 subinfo[i].subtwophasestate = *(PQgetvalue(res, i, i_subtwophasestate));
5284 subinfo[i].subdisableonerr =
5285 (strcmp(PQgetvalue(res, i, i_subdisableonerr), "t") == 0);
5286 subinfo[i].subpasswordrequired =
5287 (strcmp(PQgetvalue(res, i, i_subpasswordrequired), "t") == 0);
5288 subinfo[i].subrunasowner =
5289 (strcmp(PQgetvalue(res, i, i_subrunasowner), "t") == 0);
5290 subinfo[i].subfailover =
5291 (strcmp(PQgetvalue(res, i, i_subfailover), "t") == 0);
5292 subinfo[i].subretaindeadtuples =
5293 (strcmp(PQgetvalue(res, i, i_subretaindeadtuples), "t") == 0);
5294 subinfo[i].submaxretention =
5296 subinfo[i].subconninfo =
5298 if (PQgetisnull(res, i, i_subslotname))
5299 subinfo[i].subslotname = NULL;
5300 else
5301 subinfo[i].subslotname =
5303 subinfo[i].subsynccommit =
5305 subinfo[i].subpublications =
5307 subinfo[i].suborigin = pg_strdup(PQgetvalue(res, i, i_suborigin));
5309 subinfo[i].suboriginremotelsn = NULL;
5310 else
5311 subinfo[i].suboriginremotelsn =
5313
5314 /* Decide whether we want to dump it */
5315 selectDumpableObject(&(subinfo[i].dobj), fout);
5316 }
5317 PQclear(res);
5318
5319 destroyPQExpBuffer(query);
5320}
bool is_superuser(void)
Definition common.c:2480

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpOptions::binary_upgrade, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_SUBSCRIPTION, _SubscriptionInfo::dobj, ExecuteSqlQuery(), fb(), getRoleName(), i, is_superuser(), _dumpableObject::name, _dumpOptions::no_subscriptions, _dumpableObject::objType, CatalogId::oid, pg_log_warning, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, _SubscriptionInfo::rolname, selectDumpableObject(), _SubscriptionInfo::subbinary, _SubscriptionInfo::subconninfo, _SubscriptionInfo::subdisableonerr, _SubscriptionInfo::subenabled, _SubscriptionInfo::subfailover, _SubscriptionInfo::submaxretention, _SubscriptionInfo::suborigin, _SubscriptionInfo::suboriginremotelsn, _SubscriptionInfo::subpasswordrequired, _SubscriptionInfo::subpublications, _SubscriptionInfo::subretaindeadtuples, _SubscriptionInfo::subrunasowner, _SubscriptionInfo::subslotname, _SubscriptionInfo::substream, _SubscriptionInfo::subsynccommit, _SubscriptionInfo::subtwophasestate, and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getTableAttrs()

void getTableAttrs ( Archive fout,
TableInfo tblinfo,
int  numTables 
)
extern

Definition at line 9238 of file pg_dump.c.

9239{
9240 DumpOptions *dopt = fout->dopt;
9245 PGresult *res;
9246 int ntups;
9247 int curtblindx;
9248 int i_attrelid;
9249 int i_attnum;
9250 int i_attname;
9251 int i_atttypname;
9252 int i_attstattarget;
9253 int i_attstorage;
9254 int i_typstorage;
9255 int i_attidentity;
9256 int i_attgenerated;
9257 int i_attisdropped;
9258 int i_attlen;
9259 int i_attalign;
9260 int i_attislocal;
9261 int i_notnull_name;
9266 int i_attoptions;
9267 int i_attcollation;
9268 int i_attcompression;
9269 int i_attfdwoptions;
9270 int i_attmissingval;
9271 int i_atthasdef;
9272
9273 /*
9274 * We want to perform just one query against pg_attribute, and then just
9275 * one against pg_attrdef (for DEFAULTs) and two against pg_constraint
9276 * (for CHECK constraints and for NOT NULL constraints). However, we
9277 * mustn't try to select every row of those catalogs and then sort it out
9278 * on the client side, because some of the server-side functions we need
9279 * would be unsafe to apply to tables we don't have lock on. Hence, we
9280 * build an array of the OIDs of tables we care about (and now have lock
9281 * on!), and use a WHERE clause to constrain which rows are selected.
9282 */
9285 for (int i = 0; i < numTables; i++)
9286 {
9287 TableInfo *tbinfo = &tblinfo[i];
9288
9289 /* Don't bother to collect info for sequences */
9290 if (tbinfo->relkind == RELKIND_SEQUENCE)
9291 continue;
9292
9293 /*
9294 * Don't bother with uninteresting tables, either. For binary
9295 * upgrades, this is bypassed for pg_largeobject_metadata and
9296 * pg_shdepend so that the columns names are collected for the
9297 * corresponding COPY commands. Restoring the data for those catalogs
9298 * is faster than restoring the equivalent set of large object
9299 * commands. We can only do this for upgrades from v12 and newer; in
9300 * older versions, pg_largeobject_metadata was created WITH OIDS, so
9301 * the OID column is hidden and won't be dumped.
9302 */
9303 if (!tbinfo->interesting &&
9304 !(fout->dopt->binary_upgrade && fout->remoteVersion >= 120000 &&
9305 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9306 tbinfo->dobj.catId.oid == SharedDependRelationId)))
9307 continue;
9308
9309 /* OK, we need info for this table */
9310 if (tbloids->len > 1) /* do we have more than the '{'? */
9312 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9313
9314 if (tbinfo->ncheck > 0)
9315 {
9316 /* Also make a list of the ones with check constraints */
9317 if (checkoids->len > 1) /* do we have more than the '{'? */
9319 appendPQExpBuffer(checkoids, "%u", tbinfo->dobj.catId.oid);
9320 }
9321 }
9324
9325 /*
9326 * Find all the user attributes and their types.
9327 *
9328 * Since we only want to dump COLLATE clauses for attributes whose
9329 * collation is different from their type's default, we use a CASE here to
9330 * suppress uninteresting attcollations cheaply.
9331 */
9333 "SELECT\n"
9334 "a.attrelid,\n"
9335 "a.attnum,\n"
9336 "a.attname,\n"
9337 "a.attstattarget,\n"
9338 "a.attstorage,\n"
9339 "t.typstorage,\n"
9340 "a.atthasdef,\n"
9341 "a.attisdropped,\n"
9342 "a.attlen,\n"
9343 "a.attalign,\n"
9344 "a.attislocal,\n"
9345 "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
9346 "array_to_string(a.attoptions, ', ') AS attoptions,\n"
9347 "CASE WHEN a.attcollation <> t.typcollation "
9348 "THEN a.attcollation ELSE 0 END AS attcollation,\n"
9349 "pg_catalog.array_to_string(ARRAY("
9350 "SELECT pg_catalog.quote_ident(option_name) || "
9351 "' ' || pg_catalog.quote_literal(option_value) "
9352 "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
9353 "ORDER BY option_name"
9354 "), E',\n ') AS attfdwoptions,\n");
9355
9356 /*
9357 * Find out any NOT NULL markings for each column. In 18 and up we read
9358 * pg_constraint to obtain the constraint name, and for valid constraints
9359 * also pg_description to obtain its comment. notnull_noinherit is set
9360 * according to the NO INHERIT property. For versions prior to 18, we
9361 * store an empty string as the name when a constraint is marked as
9362 * attnotnull (this cues dumpTableSchema to print the NOT NULL clause
9363 * without a name); also, such cases are never NO INHERIT.
9364 *
9365 * For invalid constraints, we need to store their OIDs for processing
9366 * elsewhere, so we bring the pg_constraint.oid value when the constraint
9367 * is invalid, and NULL otherwise. Their comments are handled not here
9368 * but by collectComments, because they're their own dumpable object.
9369 *
9370 * We track in notnull_islocal whether the constraint was defined directly
9371 * in this table or via an ancestor, for binary upgrade. flagInhAttrs
9372 * might modify this later.
9373 */
9374 if (fout->remoteVersion >= 180000)
9376 "co.conname AS notnull_name,\n"
9377 "CASE WHEN co.convalidated THEN pt.description"
9378 " ELSE NULL END AS notnull_comment,\n"
9379 "CASE WHEN NOT co.convalidated THEN co.oid "
9380 "ELSE NULL END AS notnull_invalidoid,\n"
9381 "co.connoinherit AS notnull_noinherit,\n"
9382 "co.conislocal AS notnull_islocal,\n");
9383 else
9385 "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
9386 "NULL AS notnull_comment,\n"
9387 "NULL AS notnull_invalidoid,\n"
9388 "false AS notnull_noinherit,\n"
9389 "CASE WHEN a.attislocal THEN true\n"
9390 " WHEN a.attnotnull AND NOT a.attislocal THEN true\n"
9391 " ELSE false\n"
9392 "END AS notnull_islocal,\n");
9393
9394 if (fout->remoteVersion >= 140000)
9396 "a.attcompression AS attcompression,\n");
9397 else
9399 "'' AS attcompression,\n");
9400
9401 if (fout->remoteVersion >= 100000)
9403 "a.attidentity,\n");
9404 else
9406 "'' AS attidentity,\n");
9407
9408 if (fout->remoteVersion >= 110000)
9410 "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
9411 "THEN a.attmissingval ELSE null END AS attmissingval,\n");
9412 else
9414 "NULL AS attmissingval,\n");
9415
9416 if (fout->remoteVersion >= 120000)
9418 "a.attgenerated\n");
9419 else
9421 "'' AS attgenerated\n");
9422
9423 /* need left join to pg_type to not fail on dropped columns ... */
9425 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9426 "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
9427 "LEFT JOIN pg_catalog.pg_type t "
9428 "ON (a.atttypid = t.oid)\n",
9429 tbloids->data);
9430
9431 /*
9432 * In versions 18 and up, we need pg_constraint for explicit NOT NULL
9433 * entries and pg_description to get their comments.
9434 */
9435 if (fout->remoteVersion >= 180000)
9437 " LEFT JOIN pg_catalog.pg_constraint co ON "
9438 "(a.attrelid = co.conrelid\n"
9439 " AND co.contype = 'n' AND "
9440 "co.conkey = array[a.attnum])\n"
9441 " LEFT JOIN pg_catalog.pg_description pt ON "
9442 "(pt.classoid = co.tableoid AND pt.objoid = co.oid)\n");
9443
9445 "WHERE a.attnum > 0::pg_catalog.int2\n"
9446 "ORDER BY a.attrelid, a.attnum");
9447
9449
9450 ntups = PQntuples(res);
9451
9452 i_attrelid = PQfnumber(res, "attrelid");
9453 i_attnum = PQfnumber(res, "attnum");
9454 i_attname = PQfnumber(res, "attname");
9455 i_atttypname = PQfnumber(res, "atttypname");
9456 i_attstattarget = PQfnumber(res, "attstattarget");
9457 i_attstorage = PQfnumber(res, "attstorage");
9458 i_typstorage = PQfnumber(res, "typstorage");
9459 i_attidentity = PQfnumber(res, "attidentity");
9460 i_attgenerated = PQfnumber(res, "attgenerated");
9461 i_attisdropped = PQfnumber(res, "attisdropped");
9462 i_attlen = PQfnumber(res, "attlen");
9463 i_attalign = PQfnumber(res, "attalign");
9464 i_attislocal = PQfnumber(res, "attislocal");
9465 i_notnull_name = PQfnumber(res, "notnull_name");
9466 i_notnull_comment = PQfnumber(res, "notnull_comment");
9467 i_notnull_invalidoid = PQfnumber(res, "notnull_invalidoid");
9468 i_notnull_noinherit = PQfnumber(res, "notnull_noinherit");
9469 i_notnull_islocal = PQfnumber(res, "notnull_islocal");
9470 i_attoptions = PQfnumber(res, "attoptions");
9471 i_attcollation = PQfnumber(res, "attcollation");
9472 i_attcompression = PQfnumber(res, "attcompression");
9473 i_attfdwoptions = PQfnumber(res, "attfdwoptions");
9474 i_attmissingval = PQfnumber(res, "attmissingval");
9475 i_atthasdef = PQfnumber(res, "atthasdef");
9476
9477 /* Within the next loop, we'll accumulate OIDs of tables with defaults */
9480
9481 /*
9482 * Outer loop iterates once per table, not once per row. Incrementing of
9483 * r is handled by the inner loop.
9484 */
9485 curtblindx = -1;
9486 for (int r = 0; r < ntups;)
9487 {
9488 Oid attrelid = atooid(PQgetvalue(res, r, i_attrelid));
9490 int numatts;
9491 bool hasdefaults;
9492
9493 /* Count rows for this table */
9494 for (numatts = 1; numatts < ntups - r; numatts++)
9495 if (atooid(PQgetvalue(res, r + numatts, i_attrelid)) != attrelid)
9496 break;
9497
9498 /*
9499 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
9500 * order.
9501 */
9502 while (++curtblindx < numTables)
9503 {
9504 tbinfo = &tblinfo[curtblindx];
9505 if (tbinfo->dobj.catId.oid == attrelid)
9506 break;
9507 }
9508 if (curtblindx >= numTables)
9509 pg_fatal("unrecognized table OID %u", attrelid);
9510 /* cross-check that we only got requested tables */
9511 if (tbinfo->relkind == RELKIND_SEQUENCE ||
9512 (!tbinfo->interesting &&
9513 !(fout->dopt->binary_upgrade && fout->remoteVersion >= 120000 &&
9514 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9515 tbinfo->dobj.catId.oid == SharedDependRelationId))))
9516 pg_fatal("unexpected column data for table \"%s\"",
9517 tbinfo->dobj.name);
9518
9519 /* Save data for this table */
9520 tbinfo->numatts = numatts;
9521 tbinfo->attnames = (char **) pg_malloc(numatts * sizeof(char *));
9522 tbinfo->atttypnames = (char **) pg_malloc(numatts * sizeof(char *));
9523 tbinfo->attstattarget = (int *) pg_malloc(numatts * sizeof(int));
9524 tbinfo->attstorage = (char *) pg_malloc(numatts * sizeof(char));
9525 tbinfo->typstorage = (char *) pg_malloc(numatts * sizeof(char));
9526 tbinfo->attidentity = (char *) pg_malloc(numatts * sizeof(char));
9527 tbinfo->attgenerated = (char *) pg_malloc(numatts * sizeof(char));
9528 tbinfo->attisdropped = (bool *) pg_malloc(numatts * sizeof(bool));
9529 tbinfo->attlen = (int *) pg_malloc(numatts * sizeof(int));
9530 tbinfo->attalign = (char *) pg_malloc(numatts * sizeof(char));
9531 tbinfo->attislocal = (bool *) pg_malloc(numatts * sizeof(bool));
9532 tbinfo->attoptions = (char **) pg_malloc(numatts * sizeof(char *));
9533 tbinfo->attcollation = (Oid *) pg_malloc(numatts * sizeof(Oid));
9534 tbinfo->attcompression = (char *) pg_malloc(numatts * sizeof(char));
9535 tbinfo->attfdwoptions = (char **) pg_malloc(numatts * sizeof(char *));
9536 tbinfo->attmissingval = (char **) pg_malloc(numatts * sizeof(char *));
9537 tbinfo->notnull_constrs = (char **) pg_malloc(numatts * sizeof(char *));
9538 tbinfo->notnull_comment = (char **) pg_malloc(numatts * sizeof(char *));
9539 tbinfo->notnull_invalid = (bool *) pg_malloc(numatts * sizeof(bool));
9540 tbinfo->notnull_noinh = (bool *) pg_malloc(numatts * sizeof(bool));
9541 tbinfo->notnull_islocal = (bool *) pg_malloc(numatts * sizeof(bool));
9542 tbinfo->attrdefs = (AttrDefInfo **) pg_malloc(numatts * sizeof(AttrDefInfo *));
9543 hasdefaults = false;
9544
9545 for (int j = 0; j < numatts; j++, r++)
9546 {
9547 if (j + 1 != atoi(PQgetvalue(res, r, i_attnum)))
9548 pg_fatal("invalid column numbering in table \"%s\"",
9549 tbinfo->dobj.name);
9550 tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, r, i_attname));
9551 tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, r, i_atttypname));
9552 if (PQgetisnull(res, r, i_attstattarget))
9553 tbinfo->attstattarget[j] = -1;
9554 else
9555 tbinfo->attstattarget[j] = atoi(PQgetvalue(res, r, i_attstattarget));
9556 tbinfo->attstorage[j] = *(PQgetvalue(res, r, i_attstorage));
9557 tbinfo->typstorage[j] = *(PQgetvalue(res, r, i_typstorage));
9558 tbinfo->attidentity[j] = *(PQgetvalue(res, r, i_attidentity));
9559 tbinfo->attgenerated[j] = *(PQgetvalue(res, r, i_attgenerated));
9560 tbinfo->needs_override = tbinfo->needs_override || (tbinfo->attidentity[j] == ATTRIBUTE_IDENTITY_ALWAYS);
9561 tbinfo->attisdropped[j] = (PQgetvalue(res, r, i_attisdropped)[0] == 't');
9562 tbinfo->attlen[j] = atoi(PQgetvalue(res, r, i_attlen));
9563 tbinfo->attalign[j] = *(PQgetvalue(res, r, i_attalign));
9564 tbinfo->attislocal[j] = (PQgetvalue(res, r, i_attislocal)[0] == 't');
9565
9566 /* Handle not-null constraint name and flags */
9568 tbinfo, j,
9575
9576 tbinfo->notnull_comment[j] = PQgetisnull(res, r, i_notnull_comment) ?
9578 tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, r, i_attoptions));
9579 tbinfo->attcollation[j] = atooid(PQgetvalue(res, r, i_attcollation));
9580 tbinfo->attcompression[j] = *(PQgetvalue(res, r, i_attcompression));
9581 tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, r, i_attfdwoptions));
9582 tbinfo->attmissingval[j] = pg_strdup(PQgetvalue(res, r, i_attmissingval));
9583 tbinfo->attrdefs[j] = NULL; /* fix below */
9584 if (PQgetvalue(res, r, i_atthasdef)[0] == 't')
9585 hasdefaults = true;
9586 }
9587
9588 if (hasdefaults)
9589 {
9590 /* Collect OIDs of interesting tables that have defaults */
9591 if (tbloids->len > 1) /* do we have more than the '{'? */
9593 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9594 }
9595 }
9596
9597 /* If invalidnotnulloids has any data, finalize it */
9598 if (invalidnotnulloids != NULL)
9600
9601 PQclear(res);
9602
9603 /*
9604 * Now get info about column defaults. This is skipped for a data-only
9605 * dump, as it is only needed for table schemas.
9606 */
9607 if (dopt->dumpSchema && tbloids->len > 1)
9608 {
9609 AttrDefInfo *attrdefs;
9610 int numDefaults;
9612
9613 pg_log_info("finding table default expressions");
9614
9616
9617 printfPQExpBuffer(q, "SELECT a.tableoid, a.oid, adrelid, adnum, "
9618 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9619 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9620 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9621 "ORDER BY a.adrelid, a.adnum",
9622 tbloids->data);
9623
9625
9626 numDefaults = PQntuples(res);
9627 attrdefs = (AttrDefInfo *) pg_malloc(numDefaults * sizeof(AttrDefInfo));
9628
9629 curtblindx = -1;
9630 for (int j = 0; j < numDefaults; j++)
9631 {
9632 Oid adtableoid = atooid(PQgetvalue(res, j, 0));
9633 Oid adoid = atooid(PQgetvalue(res, j, 1));
9634 Oid adrelid = atooid(PQgetvalue(res, j, 2));
9635 int adnum = atoi(PQgetvalue(res, j, 3));
9636 char *adsrc = PQgetvalue(res, j, 4);
9637
9638 /*
9639 * Locate the associated TableInfo; we rely on tblinfo[] being in
9640 * OID order.
9641 */
9642 if (tbinfo == NULL || tbinfo->dobj.catId.oid != adrelid)
9643 {
9644 while (++curtblindx < numTables)
9645 {
9646 tbinfo = &tblinfo[curtblindx];
9647 if (tbinfo->dobj.catId.oid == adrelid)
9648 break;
9649 }
9650 if (curtblindx >= numTables)
9651 pg_fatal("unrecognized table OID %u", adrelid);
9652 }
9653
9654 if (adnum <= 0 || adnum > tbinfo->numatts)
9655 pg_fatal("invalid adnum value %d for table \"%s\"",
9656 adnum, tbinfo->dobj.name);
9657
9658 /*
9659 * dropped columns shouldn't have defaults, but just in case,
9660 * ignore 'em
9661 */
9662 if (tbinfo->attisdropped[adnum - 1])
9663 continue;
9664
9665 attrdefs[j].dobj.objType = DO_ATTRDEF;
9666 attrdefs[j].dobj.catId.tableoid = adtableoid;
9667 attrdefs[j].dobj.catId.oid = adoid;
9668 AssignDumpId(&attrdefs[j].dobj);
9669 attrdefs[j].adtable = tbinfo;
9670 attrdefs[j].adnum = adnum;
9671 attrdefs[j].adef_expr = pg_strdup(adsrc);
9672
9673 attrdefs[j].dobj.name = pg_strdup(tbinfo->dobj.name);
9674 attrdefs[j].dobj.namespace = tbinfo->dobj.namespace;
9675
9676 attrdefs[j].dobj.dump = tbinfo->dobj.dump;
9677
9678 /*
9679 * Figure out whether the default/generation expression should be
9680 * dumped as part of the main CREATE TABLE (or similar) command or
9681 * as a separate ALTER TABLE (or similar) command. The preference
9682 * is to put it into the CREATE command, but in some cases that's
9683 * not possible.
9684 */
9685 if (tbinfo->attgenerated[adnum - 1])
9686 {
9687 /*
9688 * Column generation expressions cannot be dumped separately,
9689 * because there is no syntax for it. By setting separate to
9690 * false here we prevent the "default" from being processed as
9691 * its own dumpable object. Later, flagInhAttrs() will mark
9692 * it as not to be dumped at all, if possible (that is, if it
9693 * can be inherited from a parent).
9694 */
9695 attrdefs[j].separate = false;
9696 }
9697 else if (tbinfo->relkind == RELKIND_VIEW)
9698 {
9699 /*
9700 * Defaults on a VIEW must always be dumped as separate ALTER
9701 * TABLE commands.
9702 */
9703 attrdefs[j].separate = true;
9704 }
9705 else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1))
9706 {
9707 /* column will be suppressed, print default separately */
9708 attrdefs[j].separate = true;
9709 }
9710 else
9711 {
9712 attrdefs[j].separate = false;
9713 }
9714
9715 if (!attrdefs[j].separate)
9716 {
9717 /*
9718 * Mark the default as needing to appear before the table, so
9719 * that any dependencies it has must be emitted before the
9720 * CREATE TABLE. If this is not possible, we'll change to
9721 * "separate" mode while sorting dependencies.
9722 */
9724 attrdefs[j].dobj.dumpId);
9725 }
9726
9727 tbinfo->attrdefs[adnum - 1] = &attrdefs[j];
9728 }
9729
9730 PQclear(res);
9731 }
9732
9733 /*
9734 * Get info about NOT NULL NOT VALID constraints. This is skipped for a
9735 * data-only dump, as it is only needed for table schemas.
9736 */
9737 if (dopt->dumpSchema && invalidnotnulloids)
9738 {
9740 int numConstrs;
9741 int i_tableoid;
9742 int i_oid;
9743 int i_conrelid;
9744 int i_conname;
9745 int i_consrc;
9746 int i_conislocal;
9747
9748 pg_log_info("finding invalid not-null constraints");
9749
9752 "SELECT c.tableoid, c.oid, conrelid, conname, "
9753 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9754 "conislocal, convalidated "
9755 "FROM unnest('%s'::pg_catalog.oid[]) AS src(conoid)\n"
9756 "JOIN pg_catalog.pg_constraint c ON (src.conoid = c.oid)\n"
9757 "ORDER BY c.conrelid, c.conname",
9758 invalidnotnulloids->data);
9759
9761
9762 numConstrs = PQntuples(res);
9764
9765 i_tableoid = PQfnumber(res, "tableoid");
9766 i_oid = PQfnumber(res, "oid");
9767 i_conrelid = PQfnumber(res, "conrelid");
9768 i_conname = PQfnumber(res, "conname");
9769 i_consrc = PQfnumber(res, "consrc");
9770 i_conislocal = PQfnumber(res, "conislocal");
9771
9772 /* As above, this loop iterates once per table, not once per row */
9773 curtblindx = -1;
9774 for (int j = 0; j < numConstrs;)
9775 {
9776 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9778 int numcons;
9779
9780 /* Count rows for this table */
9781 for (numcons = 1; numcons < numConstrs - j; numcons++)
9782 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9783 break;
9784
9785 /*
9786 * Locate the associated TableInfo; we rely on tblinfo[] being in
9787 * OID order.
9788 */
9789 while (++curtblindx < numTables)
9790 {
9791 tbinfo = &tblinfo[curtblindx];
9792 if (tbinfo->dobj.catId.oid == conrelid)
9793 break;
9794 }
9795 if (curtblindx >= numTables)
9796 pg_fatal("unrecognized table OID %u", conrelid);
9797
9798 for (int c = 0; c < numcons; c++, j++)
9799 {
9800 constrs[j].dobj.objType = DO_CONSTRAINT;
9801 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9802 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9803 AssignDumpId(&constrs[j].dobj);
9804 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9805 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9806 constrs[j].contable = tbinfo;
9807 constrs[j].condomain = NULL;
9808 constrs[j].contype = 'n';
9809 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9810 constrs[j].confrelid = InvalidOid;
9811 constrs[j].conindex = 0;
9812 constrs[j].condeferrable = false;
9813 constrs[j].condeferred = false;
9814 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9815
9816 /*
9817 * All invalid not-null constraints must be dumped separately,
9818 * because CREATE TABLE would not create them as invalid, and
9819 * also because they must be created after potentially
9820 * violating data has been loaded.
9821 */
9822 constrs[j].separate = true;
9823
9824 constrs[j].dobj.dump = tbinfo->dobj.dump;
9825 }
9826 }
9827 PQclear(res);
9828 }
9829
9830 /*
9831 * Get info about table CHECK constraints. This is skipped for a
9832 * data-only dump, as it is only needed for table schemas.
9833 */
9834 if (dopt->dumpSchema && checkoids->len > 2)
9835 {
9837 int numConstrs;
9838 int i_tableoid;
9839 int i_oid;
9840 int i_conrelid;
9841 int i_conname;
9842 int i_consrc;
9843 int i_conislocal;
9844 int i_convalidated;
9845
9846 pg_log_info("finding table check constraints");
9847
9850 "SELECT c.tableoid, c.oid, conrelid, conname, "
9851 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9852 "conislocal, convalidated "
9853 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9854 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9855 "WHERE contype = 'c' "
9856 "ORDER BY c.conrelid, c.conname",
9857 checkoids->data);
9858
9860
9861 numConstrs = PQntuples(res);
9863
9864 i_tableoid = PQfnumber(res, "tableoid");
9865 i_oid = PQfnumber(res, "oid");
9866 i_conrelid = PQfnumber(res, "conrelid");
9867 i_conname = PQfnumber(res, "conname");
9868 i_consrc = PQfnumber(res, "consrc");
9869 i_conislocal = PQfnumber(res, "conislocal");
9870 i_convalidated = PQfnumber(res, "convalidated");
9871
9872 /* As above, this loop iterates once per table, not once per row */
9873 curtblindx = -1;
9874 for (int j = 0; j < numConstrs;)
9875 {
9876 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9878 int numcons;
9879
9880 /* Count rows for this table */
9881 for (numcons = 1; numcons < numConstrs - j; numcons++)
9882 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9883 break;
9884
9885 /*
9886 * Locate the associated TableInfo; we rely on tblinfo[] being in
9887 * OID order.
9888 */
9889 while (++curtblindx < numTables)
9890 {
9891 tbinfo = &tblinfo[curtblindx];
9892 if (tbinfo->dobj.catId.oid == conrelid)
9893 break;
9894 }
9895 if (curtblindx >= numTables)
9896 pg_fatal("unrecognized table OID %u", conrelid);
9897
9898 if (numcons != tbinfo->ncheck)
9899 {
9900 pg_log_error(ngettext("expected %d check constraint on table \"%s\" but found %d",
9901 "expected %d check constraints on table \"%s\" but found %d",
9902 tbinfo->ncheck),
9903 tbinfo->ncheck, tbinfo->dobj.name, numcons);
9904 pg_log_error_hint("The system catalogs might be corrupted.");
9905 exit_nicely(1);
9906 }
9907
9908 tbinfo->checkexprs = constrs + j;
9909
9910 for (int c = 0; c < numcons; c++, j++)
9911 {
9912 bool validated = PQgetvalue(res, j, i_convalidated)[0] == 't';
9913
9914 constrs[j].dobj.objType = DO_CONSTRAINT;
9915 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9916 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9917 AssignDumpId(&constrs[j].dobj);
9918 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9919 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9920 constrs[j].contable = tbinfo;
9921 constrs[j].condomain = NULL;
9922 constrs[j].contype = 'c';
9923 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9924 constrs[j].confrelid = InvalidOid;
9925 constrs[j].conindex = 0;
9926 constrs[j].condeferrable = false;
9927 constrs[j].condeferred = false;
9928 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9929
9930 /*
9931 * An unvalidated constraint needs to be dumped separately, so
9932 * that potentially-violating existing data is loaded before
9933 * the constraint.
9934 */
9935 constrs[j].separate = !validated;
9936
9937 constrs[j].dobj.dump = tbinfo->dobj.dump;
9938
9939 /*
9940 * Mark the constraint as needing to appear before the table
9941 * --- this is so that any other dependencies of the
9942 * constraint will be emitted before we try to create the
9943 * table. If the constraint is to be dumped separately, it
9944 * will be dumped after data is loaded anyway, so don't do it.
9945 * (There's an automatic dependency in the opposite direction
9946 * anyway, so don't need to add one manually here.)
9947 */
9948 if (!constrs[j].separate)
9950 constrs[j].dobj.dumpId);
9951
9952 /*
9953 * We will detect later whether the constraint must be split
9954 * out from the table definition.
9955 */
9956 }
9957 }
9958
9959 PQclear(res);
9960 }
9961
9965}
#define ngettext(s, p, n)
Definition c.h:1176
#define pg_log_error(...)
Definition logging.h:106
#define pg_log_error_hint(...)
Definition logging.h:112
void exit_nicely(int code)
static void determineNotNullFlags(Archive *fout, PGresult *res, int r, TableInfo *tbinfo, int j, int i_notnull_name, int i_notnull_comment, int i_notnull_invalidoid, int i_notnull_noinherit, int i_notnull_islocal, PQExpBuffer *invalidnotnulloids)
Definition pg_dump.c:10015
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10142
bool dumpSchema
Definition pg_backup.h:216

References addObjectDependency(), _attrDefInfo::adef_expr, _attrDefInfo::adnum, _attrDefInfo::adtable, appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), AssignDumpId(), atooid, _dumpableObject::catId, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), determineNotNullFlags(), DO_ATTRDEF, DO_CONSTRAINT, _attrDefInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, _dumpOptions::dumpSchema, ExecuteSqlQuery(), exit_nicely(), fb(), i, InvalidOid, j, _dumpableObject::name, ngettext, _dumpableObject::objType, CatalogId::oid, pg_fatal, pg_log_error, pg_log_error_hint, pg_log_info, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, printfPQExpBuffer(), resetPQExpBuffer(), _attrDefInfo::separate, shouldPrintColumn(), and CatalogId::tableoid.

Referenced by getSchemaData().

◆ getTables()

TableInfo * getTables ( Archive fout,
int numTables 
)
extern

Definition at line 7186 of file pg_dump.c.

7187{
7188 DumpOptions *dopt = fout->dopt;
7189 PGresult *res;
7190 int ntups;
7191 int i;
7193 TableInfo *tblinfo;
7194 int i_reltableoid;
7195 int i_reloid;
7196 int i_relname;
7197 int i_relnamespace;
7198 int i_relkind;
7199 int i_reltype;
7200 int i_relowner;
7201 int i_relchecks;
7202 int i_relhasindex;
7203 int i_relhasrules;
7204 int i_relpages;
7205 int i_reltuples;
7206 int i_relallvisible;
7207 int i_relallfrozen;
7208 int i_toastpages;
7209 int i_owning_tab;
7210 int i_owning_col;
7211 int i_reltablespace;
7212 int i_relhasoids;
7213 int i_relhastriggers;
7214 int i_relpersistence;
7215 int i_relispopulated;
7216 int i_relreplident;
7217 int i_relrowsec;
7218 int i_relforcerowsec;
7219 int i_relfrozenxid;
7220 int i_toastfrozenxid;
7221 int i_toastoid;
7222 int i_relminmxid;
7223 int i_toastminmxid;
7224 int i_reloptions;
7225 int i_checkoption;
7227 int i_reloftype;
7228 int i_foreignserver;
7229 int i_amname;
7231 int i_relacl;
7232 int i_acldefault;
7233 int i_ispartition;
7234
7235 /*
7236 * Find all the tables and table-like objects.
7237 *
7238 * We must fetch all tables in this phase because otherwise we cannot
7239 * correctly identify inherited columns, owned sequences, etc.
7240 *
7241 * We include system catalogs, so that we can work if a user table is
7242 * defined to inherit from a system catalog (pretty weird, but...)
7243 *
7244 * Note: in this phase we should collect only a minimal amount of
7245 * information about each table, basically just enough to decide if it is
7246 * interesting. In particular, since we do not yet have lock on any user
7247 * table, we MUST NOT invoke any server-side data collection functions
7248 * (for instance, pg_get_partkeydef()). Those are likely to fail or give
7249 * wrong answers if any concurrent DDL is happening.
7250 */
7251
7253 "SELECT c.tableoid, c.oid, c.relname, "
7254 "c.relnamespace, c.relkind, c.reltype, "
7255 "c.relowner, "
7256 "c.relchecks, "
7257 "c.relhasindex, c.relhasrules, c.relpages, "
7258 "c.reltuples, c.relallvisible, ");
7259
7260 if (fout->remoteVersion >= 180000)
7261 appendPQExpBufferStr(query, "c.relallfrozen, ");
7262 else
7263 appendPQExpBufferStr(query, "0 AS relallfrozen, ");
7264
7266 "c.relhastriggers, c.relpersistence, "
7267 "c.reloftype, "
7268 "c.relacl, "
7269 "acldefault(CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
7270 " THEN 's'::\"char\" ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
7271 "CASE WHEN c.relkind = " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN "
7272 "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
7273 "ELSE 0 END AS foreignserver, "
7274 "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
7275 "tc.oid AS toid, "
7276 "tc.relpages AS toastpages, "
7277 "tc.reloptions AS toast_reloptions, "
7278 "d.refobjid AS owning_tab, "
7279 "d.refobjsubid AS owning_col, "
7280 "tsp.spcname AS reltablespace, ");
7281
7282 if (fout->remoteVersion >= 120000)
7284 "false AS relhasoids, ");
7285 else
7287 "c.relhasoids, ");
7288
7289 if (fout->remoteVersion >= 90300)
7291 "c.relispopulated, ");
7292 else
7294 "'t' as relispopulated, ");
7295
7296 if (fout->remoteVersion >= 90400)
7298 "c.relreplident, ");
7299 else
7301 "'d' AS relreplident, ");
7302
7303 if (fout->remoteVersion >= 90500)
7305 "c.relrowsecurity, c.relforcerowsecurity, ");
7306 else
7308 "false AS relrowsecurity, "
7309 "false AS relforcerowsecurity, ");
7310
7311 if (fout->remoteVersion >= 90300)
7313 "c.relminmxid, tc.relminmxid AS tminmxid, ");
7314 else
7316 "0 AS relminmxid, 0 AS tminmxid, ");
7317
7318 if (fout->remoteVersion >= 90300)
7320 "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
7321 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
7322 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
7323 else
7325 "c.reloptions, NULL AS checkoption, ");
7326
7327 if (fout->remoteVersion >= 90600)
7329 "am.amname, ");
7330 else
7332 "NULL AS amname, ");
7333
7334 if (fout->remoteVersion >= 90600)
7336 "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
7337 else
7339 "false AS is_identity_sequence, ");
7340
7341 if (fout->remoteVersion >= 100000)
7343 "c.relispartition AS ispartition ");
7344 else
7346 "false AS ispartition ");
7347
7348 /*
7349 * Left join to pg_depend to pick up dependency info linking sequences to
7350 * their owning column, if any (note this dependency is AUTO except for
7351 * identity sequences, where it's INTERNAL). Also join to pg_tablespace to
7352 * collect the spcname.
7353 */
7355 "\nFROM pg_class c\n"
7356 "LEFT JOIN pg_depend d ON "
7357 "(c.relkind = " CppAsString2(RELKIND_SEQUENCE) " AND "
7358 "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
7359 "d.objsubid = 0 AND "
7360 "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
7361 "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
7362
7363 /*
7364 * In 9.6 and up, left join to pg_am to pick up the amname.
7365 */
7366 if (fout->remoteVersion >= 90600)
7368 "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
7369
7370 /*
7371 * We purposefully ignore toast OIDs for partitioned tables; the reason is
7372 * that versions 10 and 11 have them, but later versions do not, so
7373 * emitting them causes the upgrade to fail.
7374 */
7376 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
7377 " AND tc.relkind = " CppAsString2(RELKIND_TOASTVALUE)
7378 " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
7379
7380 /*
7381 * Restrict to interesting relkinds (in particular, not indexes). Not all
7382 * relkinds are possible in older servers, but it's not worth the trouble
7383 * to emit a version-dependent list.
7384 *
7385 * Composite-type table entries won't be dumped as such, but we have to
7386 * make a DumpableObject for them so that we can track dependencies of the
7387 * composite type (pg_depend entries for columns of the composite type
7388 * link to the pg_class entry not the pg_type entry).
7389 */
7391 "WHERE c.relkind IN ("
7399 "ORDER BY c.oid");
7400
7401 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7402
7403 ntups = PQntuples(res);
7404
7405 *numTables = ntups;
7406
7407 /*
7408 * Extract data from result and lock dumpable tables. We do the locking
7409 * before anything else, to minimize the window wherein a table could
7410 * disappear under us.
7411 *
7412 * Note that we have to save info about all tables here, even when dumping
7413 * only one, because we don't yet know which tables might be inheritance
7414 * ancestors of the target table.
7415 */
7416 tblinfo = (TableInfo *) pg_malloc0(ntups * sizeof(TableInfo));
7417
7418 i_reltableoid = PQfnumber(res, "tableoid");
7419 i_reloid = PQfnumber(res, "oid");
7420 i_relname = PQfnumber(res, "relname");
7421 i_relnamespace = PQfnumber(res, "relnamespace");
7422 i_relkind = PQfnumber(res, "relkind");
7423 i_reltype = PQfnumber(res, "reltype");
7424 i_relowner = PQfnumber(res, "relowner");
7425 i_relchecks = PQfnumber(res, "relchecks");
7426 i_relhasindex = PQfnumber(res, "relhasindex");
7427 i_relhasrules = PQfnumber(res, "relhasrules");
7428 i_relpages = PQfnumber(res, "relpages");
7429 i_reltuples = PQfnumber(res, "reltuples");
7430 i_relallvisible = PQfnumber(res, "relallvisible");
7431 i_relallfrozen = PQfnumber(res, "relallfrozen");
7432 i_toastpages = PQfnumber(res, "toastpages");
7433 i_owning_tab = PQfnumber(res, "owning_tab");
7434 i_owning_col = PQfnumber(res, "owning_col");
7435 i_reltablespace = PQfnumber(res, "reltablespace");
7436 i_relhasoids = PQfnumber(res, "relhasoids");
7437 i_relhastriggers = PQfnumber(res, "relhastriggers");
7438 i_relpersistence = PQfnumber(res, "relpersistence");
7439 i_relispopulated = PQfnumber(res, "relispopulated");
7440 i_relreplident = PQfnumber(res, "relreplident");
7441 i_relrowsec = PQfnumber(res, "relrowsecurity");
7442 i_relforcerowsec = PQfnumber(res, "relforcerowsecurity");
7443 i_relfrozenxid = PQfnumber(res, "relfrozenxid");
7444 i_toastfrozenxid = PQfnumber(res, "tfrozenxid");
7445 i_toastoid = PQfnumber(res, "toid");
7446 i_relminmxid = PQfnumber(res, "relminmxid");
7447 i_toastminmxid = PQfnumber(res, "tminmxid");
7448 i_reloptions = PQfnumber(res, "reloptions");
7449 i_checkoption = PQfnumber(res, "checkoption");
7450 i_toastreloptions = PQfnumber(res, "toast_reloptions");
7451 i_reloftype = PQfnumber(res, "reloftype");
7452 i_foreignserver = PQfnumber(res, "foreignserver");
7453 i_amname = PQfnumber(res, "amname");
7454 i_is_identity_sequence = PQfnumber(res, "is_identity_sequence");
7455 i_relacl = PQfnumber(res, "relacl");
7456 i_acldefault = PQfnumber(res, "acldefault");
7457 i_ispartition = PQfnumber(res, "ispartition");
7458
7459 if (dopt->lockWaitTimeout)
7460 {
7461 /*
7462 * Arrange to fail instead of waiting forever for a table lock.
7463 *
7464 * NB: this coding assumes that the only queries issued within the
7465 * following loop are LOCK TABLEs; else the timeout may be undesirably
7466 * applied to other things too.
7467 */
7468 resetPQExpBuffer(query);
7469 appendPQExpBufferStr(query, "SET statement_timeout = ");
7471 ExecuteSqlStatement(fout, query->data);
7472 }
7473
7474 resetPQExpBuffer(query);
7475
7476 for (i = 0; i < ntups; i++)
7477 {
7478 int32 relallvisible = atoi(PQgetvalue(res, i, i_relallvisible));
7479 int32 relallfrozen = atoi(PQgetvalue(res, i, i_relallfrozen));
7480
7481 tblinfo[i].dobj.objType = DO_TABLE;
7482 tblinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_reltableoid));
7483 tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid));
7484 AssignDumpId(&tblinfo[i].dobj);
7485 tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname));
7486 tblinfo[i].dobj.namespace =
7488 tblinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_relacl));
7489 tblinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
7490 tblinfo[i].dacl.privtype = 0;
7491 tblinfo[i].dacl.initprivs = NULL;
7492 tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind));
7493 tblinfo[i].reltype = atooid(PQgetvalue(res, i, i_reltype));
7494 tblinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_relowner));
7495 tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
7496 tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0);
7497 tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0);
7498 tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages));
7499 if (PQgetisnull(res, i, i_toastpages))
7500 tblinfo[i].toastpages = 0;
7501 else
7502 tblinfo[i].toastpages = atoi(PQgetvalue(res, i, i_toastpages));
7503 if (PQgetisnull(res, i, i_owning_tab))
7504 {
7505 tblinfo[i].owning_tab = InvalidOid;
7506 tblinfo[i].owning_col = 0;
7507 }
7508 else
7509 {
7510 tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab));
7511 tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col));
7512 }
7514 tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);
7515 tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);
7516 tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence));
7517 tblinfo[i].relispopulated = (strcmp(PQgetvalue(res, i, i_relispopulated), "t") == 0);
7518 tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident));
7519 tblinfo[i].rowsec = (strcmp(PQgetvalue(res, i, i_relrowsec), "t") == 0);
7520 tblinfo[i].forcerowsec = (strcmp(PQgetvalue(res, i, i_relforcerowsec), "t") == 0);
7521 tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid));
7523 tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid));
7524 tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid));
7525 tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid));
7526 tblinfo[i].reloptions = pg_strdup(PQgetvalue(res, i, i_reloptions));
7527 if (PQgetisnull(res, i, i_checkoption))
7528 tblinfo[i].checkoption = NULL;
7529 else
7530 tblinfo[i].checkoption = pg_strdup(PQgetvalue(res, i, i_checkoption));
7532 tblinfo[i].reloftype = atooid(PQgetvalue(res, i, i_reloftype));
7534 if (PQgetisnull(res, i, i_amname))
7535 tblinfo[i].amname = NULL;
7536 else
7537 tblinfo[i].amname = pg_strdup(PQgetvalue(res, i, i_amname));
7538 tblinfo[i].is_identity_sequence = (strcmp(PQgetvalue(res, i, i_is_identity_sequence), "t") == 0);
7539 tblinfo[i].ispartition = (strcmp(PQgetvalue(res, i, i_ispartition), "t") == 0);
7540
7541 /* other fields were zeroed above */
7542
7543 /*
7544 * Decide whether we want to dump this table.
7545 */
7546 if (tblinfo[i].relkind == RELKIND_COMPOSITE_TYPE)
7547 tblinfo[i].dobj.dump = DUMP_COMPONENT_NONE;
7548 else
7549 selectDumpableTable(&tblinfo[i], fout);
7550
7551 /*
7552 * Now, consider the table "interesting" if we need to dump its
7553 * definition, data or its statistics. Later on, we'll skip a lot of
7554 * data collection for uninteresting tables.
7555 *
7556 * Note: the "interesting" flag will also be set by flagInhTables for
7557 * parents of interesting tables, so that we collect necessary
7558 * inheritance info even when the parents are not themselves being
7559 * dumped. This is the main reason why we need an "interesting" flag
7560 * that's separate from the components-to-dump bitmask.
7561 */
7562 tblinfo[i].interesting = (tblinfo[i].dobj.dump &
7566
7567 tblinfo[i].dummy_view = false; /* might get set during sort */
7568 tblinfo[i].postponed_def = false; /* might get set during sort */
7569
7570 /* Tables have data */
7572
7573 /* Mark whether table has an ACL */
7574 if (!PQgetisnull(res, i, i_relacl))
7575 tblinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
7576 tblinfo[i].hascolumnACLs = false; /* may get set later */
7577
7578 /* Add statistics */
7579 if (tblinfo[i].interesting)
7580 {
7581 RelStatsInfo *stats;
7582
7583 stats = getRelationStatistics(fout, &tblinfo[i].dobj,
7584 tblinfo[i].relpages,
7585 PQgetvalue(res, i, i_reltuples),
7586 relallvisible, relallfrozen,
7587 tblinfo[i].relkind, NULL, 0);
7588 if (tblinfo[i].relkind == RELKIND_MATVIEW)
7589 tblinfo[i].stats = stats;
7590 }
7591
7592 /*
7593 * Read-lock target tables to make sure they aren't DROPPED or altered
7594 * in schema before we get around to dumping them.
7595 *
7596 * Note that we don't explicitly lock parents of the target tables; we
7597 * assume our lock on the child is enough to prevent schema
7598 * alterations to parent tables.
7599 *
7600 * NOTE: it'd be kinda nice to lock other relations too, not only
7601 * plain or partitioned tables, but the backend doesn't presently
7602 * allow that.
7603 *
7604 * We only need to lock the table for certain components; see
7605 * pg_dump.h
7606 */
7607 if ((tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK) &&
7608 (tblinfo[i].relkind == RELKIND_RELATION ||
7609 tblinfo[i].relkind == RELKIND_PARTITIONED_TABLE))
7610 {
7611 /*
7612 * Tables are locked in batches. When dumping from a remote
7613 * server this can save a significant amount of time by reducing
7614 * the number of round trips.
7615 */
7616 if (query->len == 0)
7617 appendPQExpBuffer(query, "LOCK TABLE %s",
7618 fmtQualifiedDumpable(&tblinfo[i]));
7619 else
7620 {
7621 appendPQExpBuffer(query, ", %s",
7622 fmtQualifiedDumpable(&tblinfo[i]));
7623
7624 /* Arbitrarily end a batch when query length reaches 100K. */
7625 if (query->len >= 100000)
7626 {
7627 /* Lock another batch of tables. */
7628 appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7629 ExecuteSqlStatement(fout, query->data);
7630 resetPQExpBuffer(query);
7631 }
7632 }
7633 }
7634 }
7635
7636 if (query->len != 0)
7637 {
7638 /* Lock the tables in the last batch. */
7639 appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7640 ExecuteSqlStatement(fout, query->data);
7641 }
7642
7643 if (dopt->lockWaitTimeout)
7644 {
7645 ExecuteSqlStatement(fout, "SET statement_timeout = 0");
7646 }
7647
7648 PQclear(res);
7649
7650 destroyPQExpBuffer(query);
7651
7652 return tblinfo;
7653}
#define CppAsString2(x)
Definition c.h:428
void ExecuteSqlStatement(Archive *AHX, const char *query)
static void selectDumpableTable(TableInfo *tbinfo, Archive *fout)
Definition pg_dump.c:2083
#define fmtQualifiedDumpable(obj)
Definition pg_dump.c:236
#define DUMP_COMPONENTS_REQUIRING_LOCK
Definition pg_dump.h:141
PGconn * GetConnection(void)
Definition streamutil.c:60
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
const char * lockWaitTimeout
Definition pg_backup.h:180

References _dumpableAcl::acl, _dumpableAcl::acldefault, _tableInfo::amname, appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralConn(), AssignDumpId(), atooid, _dumpableObject::catId, _tableInfo::checkoption, _dumpableObject::components, CppAsString2, createPQExpBuffer(), _tableInfo::dacl, PQExpBufferData::data, destroyPQExpBuffer(), DO_TABLE, _tableInfo::dobj, _tableInfo::dummy_view, _dumpableObject::dump, DUMP_COMPONENT_ACL, DUMP_COMPONENT_DATA, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_NONE, DUMP_COMPONENT_STATISTICS, DUMP_COMPONENTS_REQUIRING_LOCK, ExecuteSqlQuery(), ExecuteSqlStatement(), fb(), findNamespace(), fmtQualifiedDumpable, _tableInfo::forcerowsec, _tableInfo::foreign_server, _tableInfo::frozenxid, GetConnection(), getRelationStatistics(), getRoleName(), _tableInfo::hascolumnACLs, _tableInfo::hasindex, _tableInfo::hasoids, _tableInfo::hasrules, _tableInfo::hastriggers, i, _dumpableAcl::initprivs, _tableInfo::interesting, InvalidOid, _tableInfo::is_identity_sequence, _tableInfo::ispartition, PQExpBufferData::len, _dumpOptions::lockWaitTimeout, _tableInfo::minmxid, _dumpableObject::name, _tableInfo::ncheck, _dumpableObject::objType, CatalogId::oid, _tableInfo::owning_col, _tableInfo::owning_tab, pg_malloc0(), pg_strdup(), PGRES_TUPLES_OK, _tableInfo::postponed_def, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, _dumpableAcl::privtype, _tableInfo::relispopulated, _tableInfo::relkind, _tableInfo::reloftype, _tableInfo::reloptions, _tableInfo::relpages, _tableInfo::relpersistence, _tableInfo::relreplident, _tableInfo::reltablespace, _tableInfo::reltype, resetPQExpBuffer(), _tableInfo::rolname, _tableInfo::rowsec, selectDumpableTable(), _tableInfo::stats, CatalogId::tableoid, _tableInfo::toast_frozenxid, _tableInfo::toast_minmxid, _tableInfo::toast_oid, _tableInfo::toast_reloptions, and _tableInfo::toastpages.

Referenced by getSchemaData().

◆ getTransforms()

void getTransforms ( Archive fout)
extern

Definition at line 9154 of file pg_dump.c.

9155{
9156 PGresult *res;
9157 int ntups;
9158 int i;
9159 PQExpBuffer query;
9161 int i_tableoid;
9162 int i_oid;
9163 int i_trftype;
9164 int i_trflang;
9165 int i_trffromsql;
9166 int i_trftosql;
9167
9168 /* Transforms didn't exist pre-9.5 */
9169 if (fout->remoteVersion < 90500)
9170 return;
9171
9172 query = createPQExpBuffer();
9173
9174 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9175 "trftype, trflang, trffromsql::oid, trftosql::oid "
9176 "FROM pg_transform "
9177 "ORDER BY 3,4");
9178
9179 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9180
9181 ntups = PQntuples(res);
9182
9183 transforminfo = (TransformInfo *) pg_malloc(ntups * sizeof(TransformInfo));
9184
9185 i_tableoid = PQfnumber(res, "tableoid");
9186 i_oid = PQfnumber(res, "oid");
9187 i_trftype = PQfnumber(res, "trftype");
9188 i_trflang = PQfnumber(res, "trflang");
9189 i_trffromsql = PQfnumber(res, "trffromsql");
9190 i_trftosql = PQfnumber(res, "trftosql");
9191
9192 for (i = 0; i < ntups; i++)
9193 {
9196 char *lanname;
9197
9199 transforminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9200 transforminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9202 transforminfo[i].trftype = atooid(PQgetvalue(res, i, i_trftype));
9203 transforminfo[i].trflang = atooid(PQgetvalue(res, i, i_trflang));
9204 transforminfo[i].trffromsql = atooid(PQgetvalue(res, i, i_trffromsql));
9205 transforminfo[i].trftosql = atooid(PQgetvalue(res, i, i_trftosql));
9206
9207 /*
9208 * Try to name transform as concatenation of type and language name.
9209 * This is only used for purposes of sorting. If we fail to find
9210 * either, the name will be an empty string.
9211 */
9215 if (typeInfo && lanname)
9216 appendPQExpBuffer(&namebuf, "%s %s",
9217 typeInfo->dobj.name, lanname);
9218 transforminfo[i].dobj.name = namebuf.data;
9219 free(lanname);
9220
9221 /* Decide whether we want to dump it */
9223 }
9224
9225 PQclear(res);
9226
9227 destroyPQExpBuffer(query);
9228}
static char * get_language_name(Archive *fout, Oid langid)
Definition pg_dump.c:9133

References appendPQExpBuffer(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TRANSFORM, _typeInfo::dobj, ExecuteSqlQuery(), fb(), findTypeByOid(), free, get_language_name(), i, initPQExpBuffer(), _dumpableObject::objType, pg_malloc(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTriggers()

void getTriggers ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)
extern

Definition at line 8686 of file pg_dump.c.

8687{
8690 PGresult *res;
8691 int ntups;
8692 int curtblindx;
8694 int i_tableoid,
8695 i_oid,
8696 i_tgrelid,
8697 i_tgname,
8700 i_tgdef;
8701
8702 /*
8703 * We want to perform just one query against pg_trigger. However, we
8704 * mustn't try to select every row of the catalog and then sort it out on
8705 * the client side, because some of the server-side functions we need
8706 * would be unsafe to apply to tables we don't have lock on. Hence, we
8707 * build an array of the OIDs of tables we care about (and now have lock
8708 * on!), and use a WHERE clause to constrain which rows are selected.
8709 */
8711 for (int i = 0; i < numTables; i++)
8712 {
8713 TableInfo *tbinfo = &tblinfo[i];
8714
8715 if (!tbinfo->hastriggers ||
8716 !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8717 continue;
8718
8719 /* OK, we need info for this table */
8720 if (tbloids->len > 1) /* do we have more than the '{'? */
8722 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
8723 }
8725
8726 if (fout->remoteVersion >= 150000)
8727 {
8728 /*
8729 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8730 * result in non-forward-compatible dumps of WHEN clauses due to
8731 * under-parenthesization.
8732 *
8733 * NB: We need to see partition triggers in case the tgenabled flag
8734 * has been changed from the parent.
8735 */
8736 appendPQExpBuffer(query,
8737 "SELECT t.tgrelid, t.tgname, "
8738 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8739 "t.tgenabled, t.tableoid, t.oid, "
8740 "t.tgparentid <> 0 AS tgispartition\n"
8741 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8742 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8743 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8744 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8745 "OR t.tgenabled != u.tgenabled) "
8746 "ORDER BY t.tgrelid, t.tgname",
8747 tbloids->data);
8748 }
8749 else if (fout->remoteVersion >= 130000)
8750 {
8751 /*
8752 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8753 * result in non-forward-compatible dumps of WHEN clauses due to
8754 * under-parenthesization.
8755 *
8756 * NB: We need to see tgisinternal triggers in partitions, in case the
8757 * tgenabled flag has been changed from the parent.
8758 */
8759 appendPQExpBuffer(query,
8760 "SELECT t.tgrelid, t.tgname, "
8761 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8762 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8763 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8764 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8765 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8766 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8767 "ORDER BY t.tgrelid, t.tgname",
8768 tbloids->data);
8769 }
8770 else if (fout->remoteVersion >= 110000)
8771 {
8772 /*
8773 * NB: We need to see tgisinternal triggers in partitions, in case the
8774 * tgenabled flag has been changed from the parent. No tgparentid in
8775 * version 11-12, so we have to match them via pg_depend.
8776 *
8777 * See above about pretty=true in pg_get_triggerdef.
8778 */
8779 appendPQExpBuffer(query,
8780 "SELECT t.tgrelid, t.tgname, "
8781 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8782 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8783 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8784 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8785 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8786 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8787 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8788 " d.objid = t.oid "
8789 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8790 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8791 "ORDER BY t.tgrelid, t.tgname",
8792 tbloids->data);
8793 }
8794 else
8795 {
8796 /* See above about pretty=true in pg_get_triggerdef */
8797 appendPQExpBuffer(query,
8798 "SELECT t.tgrelid, t.tgname, "
8799 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8800 "t.tgenabled, false as tgispartition, "
8801 "t.tableoid, t.oid "
8802 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8803 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8804 "WHERE NOT tgisinternal "
8805 "ORDER BY t.tgrelid, t.tgname",
8806 tbloids->data);
8807 }
8808
8809 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8810
8811 ntups = PQntuples(res);
8812
8813 i_tableoid = PQfnumber(res, "tableoid");
8814 i_oid = PQfnumber(res, "oid");
8815 i_tgrelid = PQfnumber(res, "tgrelid");
8816 i_tgname = PQfnumber(res, "tgname");
8817 i_tgenabled = PQfnumber(res, "tgenabled");
8818 i_tgispartition = PQfnumber(res, "tgispartition");
8819 i_tgdef = PQfnumber(res, "tgdef");
8820
8821 tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo));
8822
8823 /*
8824 * Outer loop iterates once per table, not once per row. Incrementing of
8825 * j is handled by the inner loop.
8826 */
8827 curtblindx = -1;
8828 for (int j = 0; j < ntups;)
8829 {
8832 int numtrigs;
8833
8834 /* Count rows for this table */
8835 for (numtrigs = 1; numtrigs < ntups - j; numtrigs++)
8836 if (atooid(PQgetvalue(res, j + numtrigs, i_tgrelid)) != tgrelid)
8837 break;
8838
8839 /*
8840 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8841 * order.
8842 */
8843 while (++curtblindx < numTables)
8844 {
8845 tbinfo = &tblinfo[curtblindx];
8846 if (tbinfo->dobj.catId.oid == tgrelid)
8847 break;
8848 }
8849 if (curtblindx >= numTables)
8850 pg_fatal("unrecognized table OID %u", tgrelid);
8851
8852 /* Save data for this table */
8853 tbinfo->triggers = tginfo + j;
8854 tbinfo->numTriggers = numtrigs;
8855
8856 for (int c = 0; c < numtrigs; c++, j++)
8857 {
8858 tginfo[j].dobj.objType = DO_TRIGGER;
8859 tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8860 tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8861 AssignDumpId(&tginfo[j].dobj);
8862 tginfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_tgname));
8863 tginfo[j].dobj.namespace = tbinfo->dobj.namespace;
8864 tginfo[j].tgtable = tbinfo;
8865 tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
8866 tginfo[j].tgispartition = *(PQgetvalue(res, j, i_tgispartition)) == 't';
8867 tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
8868 }
8869 }
8870
8871 PQclear(res);
8872
8873 destroyPQExpBuffer(query);
8875}

References appendPQExpBuffer(), appendPQExpBufferChar(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TRIGGER, DUMP_COMPONENT_DEFINITION, ExecuteSqlQuery(), fb(), i, j, pg_fatal, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, and PQntuples.

Referenced by getSchemaData().

◆ getTSConfigurations()

void getTSConfigurations ( Archive fout)
extern

Definition at line 10356 of file pg_dump.c.

10357{
10358 PGresult *res;
10359 int ntups;
10360 int i;
10361 PQExpBuffer query;
10363 int i_tableoid;
10364 int i_oid;
10365 int i_cfgname;
10366 int i_cfgnamespace;
10367 int i_cfgowner;
10368 int i_cfgparser;
10369
10370 query = createPQExpBuffer();
10371
10372 appendPQExpBufferStr(query, "SELECT tableoid, oid, cfgname, "
10373 "cfgnamespace, cfgowner, cfgparser "
10374 "FROM pg_ts_config");
10375
10376 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10377
10378 ntups = PQntuples(res);
10379
10380 cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo));
10381
10382 i_tableoid = PQfnumber(res, "tableoid");
10383 i_oid = PQfnumber(res, "oid");
10384 i_cfgname = PQfnumber(res, "cfgname");
10385 i_cfgnamespace = PQfnumber(res, "cfgnamespace");
10386 i_cfgowner = PQfnumber(res, "cfgowner");
10387 i_cfgparser = PQfnumber(res, "cfgparser");
10388
10389 for (i = 0; i < ntups; i++)
10390 {
10391 cfginfo[i].dobj.objType = DO_TSCONFIG;
10392 cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10393 cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10394 AssignDumpId(&cfginfo[i].dobj);
10395 cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
10396 cfginfo[i].dobj.namespace =
10398 cfginfo[i].rolname = getRoleName(PQgetvalue(res, i, i_cfgowner));
10399 cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
10400
10401 /* Decide whether we want to dump it */
10403 }
10404
10405 PQclear(res);
10406
10407 destroyPQExpBuffer(query);
10408}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSCONFIG, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTSDictionaries()

void getTSDictionaries ( Archive fout)
extern

Definition at line 10231 of file pg_dump.c.

10232{
10233 PGresult *res;
10234 int ntups;
10235 int i;
10236 PQExpBuffer query;
10238 int i_tableoid;
10239 int i_oid;
10240 int i_dictname;
10241 int i_dictnamespace;
10242 int i_dictowner;
10243 int i_dicttemplate;
10244 int i_dictinitoption;
10245
10246 query = createPQExpBuffer();
10247
10248 appendPQExpBufferStr(query, "SELECT tableoid, oid, dictname, "
10249 "dictnamespace, dictowner, "
10250 "dicttemplate, dictinitoption "
10251 "FROM pg_ts_dict");
10252
10253 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10254
10255 ntups = PQntuples(res);
10256
10257 dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo));
10258
10259 i_tableoid = PQfnumber(res, "tableoid");
10260 i_oid = PQfnumber(res, "oid");
10261 i_dictname = PQfnumber(res, "dictname");
10262 i_dictnamespace = PQfnumber(res, "dictnamespace");
10263 i_dictowner = PQfnumber(res, "dictowner");
10264 i_dictinitoption = PQfnumber(res, "dictinitoption");
10265 i_dicttemplate = PQfnumber(res, "dicttemplate");
10266
10267 for (i = 0; i < ntups; i++)
10268 {
10269 dictinfo[i].dobj.objType = DO_TSDICT;
10270 dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10271 dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10272 AssignDumpId(&dictinfo[i].dobj);
10273 dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
10274 dictinfo[i].dobj.namespace =
10276 dictinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_dictowner));
10277 dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
10278 if (PQgetisnull(res, i, i_dictinitoption))
10279 dictinfo[i].dictinitoption = NULL;
10280 else
10281 dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
10282
10283 /* Decide whether we want to dump it */
10285 }
10286
10287 PQclear(res);
10288
10289 destroyPQExpBuffer(query);
10290}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSDICT, ExecuteSqlQuery(), fb(), findNamespace(), getRoleName(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTSParsers()

void getTSParsers ( Archive fout)
extern

Definition at line 10157 of file pg_dump.c.

10158{
10159 PGresult *res;
10160 int ntups;
10161 int i;
10162 PQExpBuffer query;
10164 int i_tableoid;
10165 int i_oid;
10166 int i_prsname;
10167 int i_prsnamespace;
10168 int i_prsstart;
10169 int i_prstoken;
10170 int i_prsend;
10171 int i_prsheadline;
10172 int i_prslextype;
10173
10174 query = createPQExpBuffer();
10175
10176 /*
10177 * find all text search objects, including builtin ones; we filter out
10178 * system-defined objects at dump-out time.
10179 */
10180
10181 appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, "
10182 "prsstart::oid, prstoken::oid, "
10183 "prsend::oid, prsheadline::oid, prslextype::oid "
10184 "FROM pg_ts_parser");
10185
10186 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10187
10188 ntups = PQntuples(res);
10189
10190 prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo));
10191
10192 i_tableoid = PQfnumber(res, "tableoid");
10193 i_oid = PQfnumber(res, "oid");
10194 i_prsname = PQfnumber(res, "prsname");
10195 i_prsnamespace = PQfnumber(res, "prsnamespace");
10196 i_prsstart = PQfnumber(res, "prsstart");
10197 i_prstoken = PQfnumber(res, "prstoken");
10198 i_prsend = PQfnumber(res, "prsend");
10199 i_prsheadline = PQfnumber(res, "prsheadline");
10200 i_prslextype = PQfnumber(res, "prslextype");
10201
10202 for (i = 0; i < ntups; i++)
10203 {
10204 prsinfo[i].dobj.objType = DO_TSPARSER;
10205 prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10206 prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10207 AssignDumpId(&prsinfo[i].dobj);
10208 prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
10209 prsinfo[i].dobj.namespace =
10211 prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
10212 prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
10213 prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend));
10214 prsinfo[i].prsheadline = atooid(PQgetvalue(res, i, i_prsheadline));
10215 prsinfo[i].prslextype = atooid(PQgetvalue(res, i, i_prslextype));
10216
10217 /* Decide whether we want to dump it */
10219 }
10220
10221 PQclear(res);
10222
10223 destroyPQExpBuffer(query);
10224}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSPARSER, ExecuteSqlQuery(), fb(), findNamespace(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTSTemplates()

void getTSTemplates ( Archive fout)
extern

Definition at line 10297 of file pg_dump.c.

10298{
10299 PGresult *res;
10300 int ntups;
10301 int i;
10302 PQExpBuffer query;
10304 int i_tableoid;
10305 int i_oid;
10306 int i_tmplname;
10307 int i_tmplnamespace;
10308 int i_tmplinit;
10309 int i_tmpllexize;
10310
10311 query = createPQExpBuffer();
10312
10313 appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
10314 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
10315 "FROM pg_ts_template");
10316
10317 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10318
10319 ntups = PQntuples(res);
10320
10321 tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo));
10322
10323 i_tableoid = PQfnumber(res, "tableoid");
10324 i_oid = PQfnumber(res, "oid");
10325 i_tmplname = PQfnumber(res, "tmplname");
10326 i_tmplnamespace = PQfnumber(res, "tmplnamespace");
10327 i_tmplinit = PQfnumber(res, "tmplinit");
10328 i_tmpllexize = PQfnumber(res, "tmpllexize");
10329
10330 for (i = 0; i < ntups; i++)
10331 {
10332 tmplinfo[i].dobj.objType = DO_TSTEMPLATE;
10333 tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10334 tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10335 AssignDumpId(&tmplinfo[i].dobj);
10336 tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
10337 tmplinfo[i].dobj.namespace =
10339 tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
10340 tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
10341
10342 /* Decide whether we want to dump it */
10344 }
10345
10346 PQclear(res);
10347
10348 destroyPQExpBuffer(query);
10349}

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_TSTEMPLATE, ExecuteSqlQuery(), fb(), findNamespace(), i, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, and selectDumpableObject().

Referenced by getSchemaData().

◆ getTypes()

void getTypes ( Archive fout)
extern

Definition at line 6199 of file pg_dump.c.

6200{
6201 PGresult *res;
6202 int ntups;
6203 int i;
6207 int i_tableoid;
6208 int i_oid;
6209 int i_typname;
6210 int i_typnamespace;
6211 int i_typacl;
6212 int i_acldefault;
6213 int i_typowner;
6214 int i_typelem;
6215 int i_typrelid;
6216 int i_typrelkind;
6217 int i_typtype;
6218 int i_typisdefined;
6219 int i_isarray;
6220 int i_typarray;
6221
6222 /*
6223 * we include even the built-in types because those may be used as array
6224 * elements by user-defined types
6225 *
6226 * we filter out the built-in types when we dump out the types
6227 *
6228 * same approach for undefined (shell) types and array types
6229 *
6230 * Note: as of 8.3 we can reliably detect whether a type is an
6231 * auto-generated array type by checking the element type's typarray.
6232 * (Before that the test is capable of generating false positives.) We
6233 * still check for name beginning with '_', though, so as to avoid the
6234 * cost of the subselect probe for all standard types. This would have to
6235 * be revisited if the backend ever allows renaming of array types.
6236 */
6237 appendPQExpBufferStr(query, "SELECT tableoid, oid, typname, "
6238 "typnamespace, typacl, "
6239 "acldefault('T', typowner) AS acldefault, "
6240 "typowner, "
6241 "typelem, typrelid, typarray, "
6242 "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
6243 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
6244 "typtype, typisdefined, "
6245 "typname[0] = '_' AND typelem != 0 AND "
6246 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
6247 "FROM pg_type");
6248
6249 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6250
6251 ntups = PQntuples(res);
6252
6253 tyinfo = (TypeInfo *) pg_malloc(ntups * sizeof(TypeInfo));
6254
6255 i_tableoid = PQfnumber(res, "tableoid");
6256 i_oid = PQfnumber(res, "oid");
6257 i_typname = PQfnumber(res, "typname");
6258 i_typnamespace = PQfnumber(res, "typnamespace");
6259 i_typacl = PQfnumber(res, "typacl");
6260 i_acldefault = PQfnumber(res, "acldefault");
6261 i_typowner = PQfnumber(res, "typowner");
6262 i_typelem = PQfnumber(res, "typelem");
6263 i_typrelid = PQfnumber(res, "typrelid");
6264 i_typrelkind = PQfnumber(res, "typrelkind");
6265 i_typtype = PQfnumber(res, "typtype");
6266 i_typisdefined = PQfnumber(res, "typisdefined");
6267 i_isarray = PQfnumber(res, "isarray");
6268 i_typarray = PQfnumber(res, "typarray");
6269
6270 for (i = 0; i < ntups; i++)
6271 {
6272 tyinfo[i].dobj.objType = DO_TYPE;
6273 tyinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6274 tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6275 AssignDumpId(&tyinfo[i].dobj);
6276 tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
6277 tyinfo[i].dobj.namespace =
6279 tyinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_typacl));
6280 tyinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6281 tyinfo[i].dacl.privtype = 0;
6282 tyinfo[i].dacl.initprivs = NULL;
6283 tyinfo[i].ftypname = NULL; /* may get filled later */
6284 tyinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_typowner));
6285 tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
6286 tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid));
6287 tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind);
6288 tyinfo[i].typtype = *PQgetvalue(res, i, i_typtype);
6289 tyinfo[i].shellType = NULL;
6290
6291 if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0)
6292 tyinfo[i].isDefined = true;
6293 else
6294 tyinfo[i].isDefined = false;
6295
6296 if (strcmp(PQgetvalue(res, i, i_isarray), "t") == 0)
6297 tyinfo[i].isArray = true;
6298 else
6299 tyinfo[i].isArray = false;
6300
6301 tyinfo[i].typarray = atooid(PQgetvalue(res, i, i_typarray));
6302
6303 if (tyinfo[i].typtype == TYPTYPE_MULTIRANGE)
6304 tyinfo[i].isMultirange = true;
6305 else
6306 tyinfo[i].isMultirange = false;
6307
6308 /* Decide whether we want to dump it */
6310
6311 /* Mark whether type has an ACL */
6312 if (!PQgetisnull(res, i, i_typacl))
6313 tyinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6314
6315 /*
6316 * If it's a domain, fetch info about its constraints, if any
6317 */
6318 tyinfo[i].nDomChecks = 0;
6319 tyinfo[i].domChecks = NULL;
6320 tyinfo[i].notnull = NULL;
6321 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6322 tyinfo[i].typtype == TYPTYPE_DOMAIN)
6324
6325 /*
6326 * If it's a base type, make a DumpableObject representing a shell
6327 * definition of the type. We will need to dump that ahead of the I/O
6328 * functions for the type. Similarly, range types need a shell
6329 * definition in case they have a canonicalize function.
6330 *
6331 * Note: the shell type doesn't have a catId. You might think it
6332 * should copy the base type's catId, but then it might capture the
6333 * pg_depend entries for the type, which we don't want.
6334 */
6335 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6336 (tyinfo[i].typtype == TYPTYPE_BASE ||
6337 tyinfo[i].typtype == TYPTYPE_RANGE))
6338 {
6340 stinfo->dobj.objType = DO_SHELL_TYPE;
6341 stinfo->dobj.catId = nilCatalogId;
6342 AssignDumpId(&stinfo->dobj);
6343 stinfo->dobj.name = pg_strdup(tyinfo[i].dobj.name);
6344 stinfo->dobj.namespace = tyinfo[i].dobj.namespace;
6345 stinfo->baseType = &(tyinfo[i]);
6346 tyinfo[i].shellType = stinfo;
6347
6348 /*
6349 * Initially mark the shell type as not to be dumped. We'll only
6350 * dump it if the I/O or canonicalize functions need to be dumped;
6351 * this is taken care of while sorting dependencies.
6352 */
6353 stinfo->dobj.dump = DUMP_COMPONENT_NONE;
6354 }
6355 }
6356
6357 PQclear(res);
6358
6359 destroyPQExpBuffer(query);
6360}
static const CatalogId nilCatalogId
Definition pg_dump.c:191
static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
Definition pg_dump.c:8477
static void selectDumpableType(TypeInfo *tyinfo, Archive *fout)
Definition pg_dump.c:2122

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_SHELL_TYPE, DO_TYPE, DUMP_COMPONENT_ACL, DUMP_COMPONENT_DEFINITION, DUMP_COMPONENT_NONE, ExecuteSqlQuery(), fb(), findNamespace(), getDomainConstraints(), getRoleName(), i, nilCatalogId, pg_malloc(), pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, and selectDumpableType().

Referenced by getSchemaData().

◆ parseOidArray()

void parseOidArray ( const char str,
Oid array,
int  arraysize 
)
extern

Definition at line 1111 of file common.c.

1112{
1113 int j,
1114 argNum;
1115 char temp[100];
1116 char s;
1117
1118 argNum = 0;
1119 j = 0;
1120 for (;;)
1121 {
1122 s = *str++;
1123 if (s == ' ' || s == '\0')
1124 {
1125 if (j > 0)
1126 {
1127 if (argNum >= arraysize)
1128 pg_fatal("could not parse numeric array \"%s\": too many numbers", str);
1129 temp[j] = '\0';
1130 array[argNum++] = atooid(temp);
1131 j = 0;
1132 }
1133 if (s == '\0')
1134 break;
1135 }
1136 else
1137 {
1138 if (!(isdigit((unsigned char) s) || s == '-') ||
1139 j >= sizeof(temp) - 1)
1140 pg_fatal("could not parse numeric array \"%s\": invalid character in number", str);
1141 temp[j++] = s;
1142 }
1143 }
1144
1145 while (argNum < arraysize)
1146 array[argNum++] = InvalidOid;
1147}

References atooid, fb(), InvalidOid, j, pg_fatal, and str.

Referenced by dumpFunc(), getAggregates(), getFuncs(), and getIndexes().

◆ processExtensionTables()

void processExtensionTables ( Archive fout,
ExtensionInfo  extinfo[],
int  numExtensions 
)
extern

Definition at line 20025 of file pg_dump.c.

20027{
20028 DumpOptions *dopt = fout->dopt;
20029 PQExpBuffer query;
20030 PGresult *res;
20031 int ntups,
20032 i;
20033 int i_conrelid,
20035
20036 /* Nothing to do if no extensions */
20037 if (numExtensions == 0)
20038 return;
20039
20040 /*
20041 * Identify extension configuration tables and create TableDataInfo
20042 * objects for them, ensuring their data will be dumped even though the
20043 * tables themselves won't be.
20044 *
20045 * Note that we create TableDataInfo objects even in schema-only mode, ie,
20046 * user data in a configuration table is treated like schema data. This
20047 * seems appropriate since system data in a config table would get
20048 * reloaded by CREATE EXTENSION. If the extension is not listed in the
20049 * list of extensions to be included, none of its data is dumped.
20050 */
20051 for (i = 0; i < numExtensions; i++)
20052 {
20054 char *extconfig = curext->extconfig;
20055 char *extcondition = curext->extcondition;
20056 char **extconfigarray = NULL;
20057 char **extconditionarray = NULL;
20058 int nconfigitems = 0;
20059 int nconditionitems = 0;
20060
20061 /*
20062 * Check if this extension is listed as to include in the dump. If
20063 * not, any table data associated with it is discarded.
20064 */
20067 curext->dobj.catId.oid))
20068 continue;
20069
20070 /*
20071 * Check if this extension is listed as to exclude in the dump. If
20072 * yes, any table data associated with it is discarded.
20073 */
20076 curext->dobj.catId.oid))
20077 continue;
20078
20079 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
20080 {
20081 int j;
20082
20083 if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
20084 pg_fatal("could not parse %s array", "extconfig");
20085 if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
20086 pg_fatal("could not parse %s array", "extcondition");
20088 pg_fatal("mismatched number of configurations and conditions for extension");
20089
20090 for (j = 0; j < nconfigitems; j++)
20091 {
20094 bool dumpobj =
20095 curext->dobj.dump & DUMP_COMPONENT_DEFINITION;
20096
20098 if (configtbl == NULL)
20099 continue;
20100
20101 /*
20102 * Tables of not-to-be-dumped extensions shouldn't be dumped
20103 * unless the table or its schema is explicitly included
20104 */
20105 if (!(curext->dobj.dump & DUMP_COMPONENT_DEFINITION))
20106 {
20107 /* check table explicitly requested */
20108 if (table_include_oids.head != NULL &&
20110 configtbloid))
20111 dumpobj = true;
20112
20113 /* check table's schema explicitly requested */
20114 if (configtbl->dobj.namespace->dobj.dump &
20116 dumpobj = true;
20117 }
20118
20119 /* check table excluded by an exclusion switch */
20120 if (table_exclude_oids.head != NULL &&
20122 configtbloid))
20123 dumpobj = false;
20124
20125 /* check schema excluded by an exclusion switch */
20127 configtbl->dobj.namespace->dobj.catId.oid))
20128 dumpobj = false;
20129
20130 if (dumpobj)
20131 {
20133 if (configtbl->dataObj != NULL)
20134 {
20135 if (strlen(extconditionarray[j]) > 0)
20136 configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
20137 }
20138 }
20139 }
20140 }
20141 if (extconfigarray)
20145 }
20146
20147 /*
20148 * Now that all the TableDataInfo objects have been created for all the
20149 * extensions, check their FK dependencies and register them to try and
20150 * dump the data out in an order that they can be restored in.
20151 *
20152 * Note that this is not a problem for user tables as their FKs are
20153 * recreated after the data has been loaded.
20154 */
20155
20156 query = createPQExpBuffer();
20157
20158 printfPQExpBuffer(query,
20159 "SELECT conrelid, confrelid "
20160 "FROM pg_constraint "
20161 "JOIN pg_depend ON (objid = confrelid) "
20162 "WHERE contype = 'f' "
20163 "AND refclassid = 'pg_extension'::regclass "
20164 "AND classid = 'pg_class'::regclass;");
20165
20166 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
20167 ntups = PQntuples(res);
20168
20169 i_conrelid = PQfnumber(res, "conrelid");
20170 i_confrelid = PQfnumber(res, "confrelid");
20171
20172 /* Now get the dependencies and register them */
20173 for (i = 0; i < ntups; i++)
20174 {
20175 Oid conrelid,
20176 confrelid;
20178 *contable;
20179
20180 conrelid = atooid(PQgetvalue(res, i, i_conrelid));
20181 confrelid = atooid(PQgetvalue(res, i, i_confrelid));
20182 contable = findTableByOid(conrelid);
20183 reftable = findTableByOid(confrelid);
20184
20185 if (reftable == NULL ||
20186 reftable->dataObj == NULL ||
20187 contable == NULL ||
20188 contable->dataObj == NULL)
20189 continue;
20190
20191 /*
20192 * Make referencing TABLE_DATA object depend on the referenced table's
20193 * TABLE_DATA object.
20194 */
20195 addObjectDependency(&contable->dataObj->dobj,
20196 reftable->dataObj->dobj.dumpId);
20197 }
20198 PQclear(res);
20199 destroyPQExpBuffer(query);
20200}
static SimpleOidList schema_exclude_oids
Definition pg_dump.c:170
static SimpleOidList extension_include_oids
Definition pg_dump.c:186
static SimpleOidList extension_exclude_oids
Definition pg_dump.c:189
static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo)
Definition pg_dump.c:3038
static SimpleOidList table_exclude_oids
Definition pg_dump.c:177
static SimpleOidList table_include_oids
Definition pg_dump.c:174
bool simple_oid_list_member(SimpleOidList *list, Oid val)
Definition simple_list.c:45
SimpleOidListCell * head
Definition simple_list.h:28

References addObjectDependency(), atooid, createPQExpBuffer(), PQExpBufferData::data, _tableInfo::dataObj, destroyPQExpBuffer(), _tableDataInfo::dobj, DUMP_COMPONENT_DATA, DUMP_COMPONENT_DEFINITION, _dumpableObject::dumpId, ExecuteSqlQuery(), _extensionInfo::extconfig, extension_exclude_oids, extension_include_oids, fb(), findTableByOid(), free, SimpleOidList::head, i, j, makeTableDataInfo(), parsePGArray(), pg_fatal, pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetvalue, PQntuples, printfPQExpBuffer(), schema_exclude_oids, simple_oid_list_member(), table_exclude_oids, and table_include_oids.

Referenced by getSchemaData().

◆ recordAdditionalCatalogID()

void recordAdditionalCatalogID ( CatalogId  catId,
DumpableObject dobj 
)
extern

Definition at line 719 of file common.c.

720{
721 CatalogIdMapEntry *entry;
722 bool found;
723
724 /* CatalogId hash table must exist, if we have a DumpableObject */
726
727 /* Add reference to CatalogId hash */
728 entry = catalogid_insert(catalogIdHash, catId, &found);
729 if (!found)
730 {
731 entry->dobj = NULL;
732 entry->ext = NULL;
733 }
734 Assert(entry->dobj == NULL);
735 entry->dobj = dobj;
736}

References Assert, catalogIdHash, _catalogIdMapEntry::dobj, _catalogIdMapEntry::ext, and fb().

Referenced by getLOs().

◆ recordExtensionMembership()

void recordExtensionMembership ( CatalogId  catId,
ExtensionInfo ext 
)
extern

Definition at line 1063 of file common.c.

1064{
1065 CatalogIdMapEntry *entry;
1066 bool found;
1067
1068 /* CatalogId hash table must exist, if we have an ExtensionInfo */
1070
1071 /* Add reference to CatalogId hash */
1072 entry = catalogid_insert(catalogIdHash, catId, &found);
1073 if (!found)
1074 {
1075 entry->dobj = NULL;
1076 entry->ext = NULL;
1077 }
1078 Assert(entry->ext == NULL);
1079 entry->ext = ext;
1080}

References Assert, catalogIdHash, _catalogIdMapEntry::dobj, _catalogIdMapEntry::ext, and fb().

Referenced by getExtensionMembership().

◆ removeObjectDependency()

◆ shouldPrintColumn()

bool shouldPrintColumn ( const DumpOptions dopt,
const TableInfo tbinfo,
int  colno 
)
extern

Definition at line 10142 of file pg_dump.c.

10143{
10144 if (dopt->binary_upgrade)
10145 return true;
10146 if (tbinfo->attisdropped[colno])
10147 return false;
10148 return (tbinfo->attislocal[colno] || tbinfo->ispartition);
10149}

References _dumpOptions::binary_upgrade, and fb().

Referenced by dumpTableSchema(), flagInhAttrs(), and getTableAttrs().

◆ sortDumpableObjects()

void sortDumpableObjects ( DumpableObject **  objs,
int  numObjs,
DumpId  preBoundaryId,
DumpId  postBoundaryId 
)
extern

Definition at line 559 of file pg_dump_sort.c.

561{
562 DumpableObject **ordering;
563 int nOrdering;
564
565 if (numObjs <= 0) /* can't happen anymore ... */
566 return;
567
568 /*
569 * Saving the boundary IDs in static variables is a bit grotty, but seems
570 * better than adding them to parameter lists of subsidiary functions.
571 */
574
575 ordering = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
576 while (!TopoSort(objs, numObjs, ordering, &nOrdering))
578
579 memcpy(objs, ordering, numObjs * sizeof(DumpableObject *));
580
581 free(ordering);
582}
static void findDependencyLoops(DumpableObject **objs, int nObjs, int totObjs)
static DumpId preDataBoundId
static bool TopoSort(DumpableObject **objs, int numObjs, DumpableObject **ordering, int *nOrdering)
static DumpId postDataBoundId

References fb(), findDependencyLoops(), free, pg_malloc(), postDataBoundId, preDataBoundId, and TopoSort().

Referenced by main().

◆ sortDumpableObjectsByTypeName()

void sortDumpableObjectsByTypeName ( DumpableObject **  objs,
int  numObjs 
)
extern

Definition at line 192 of file pg_dump_sort.c.

193{
194 if (numObjs > 1)
195 qsort(objs, numObjs, sizeof(DumpableObject *),
197}
static int DOTypeNameCompare(const void *p1, const void *p2)
#define qsort(a, b, c, d)
Definition port.h:495

References DOTypeNameCompare(), fb(), and qsort.

Referenced by main().