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 *subwalrcvtimeout;
725 char *subpublications;
726 char *suborigin;
727 char *suboriginremotelsn;
729
730/*
731 * The SubRelInfo struct is used to represent a subscription relation.
732 *
733 * XXX Currently, the subscription tables are added to the subscription after
734 * enabling the subscription in binary-upgrade mode. As the apply workers will
735 * not be started in binary_upgrade mode the ordering of enable subscription
736 * does not matter. The order of adding the subscription tables to the
737 * subscription and enabling the subscription should be taken care of if this
738 * feature will be supported in a non-binary-upgrade mode in the future.
739 */
740typedef struct _SubRelInfo
741{
745 char srsubstate;
746 char *srsublsn;
747} SubRelInfo;
748
749/*
750 * common utility functions
751 */
752
754
755extern void AssignDumpId(DumpableObject *dobj);
756extern void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj);
757extern DumpId createDumpId(void);
758extern DumpId getMaxDumpId(void);
761extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
762
765
766extern TableInfo *findTableByOid(Oid oid);
767extern TypeInfo *findTypeByOid(Oid oid);
768extern FuncInfo *findFuncByOid(Oid oid);
769extern OprInfo *findOprByOid(Oid oid);
771extern CollInfo *findCollationByOid(Oid oid);
776
777extern void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext);
779
780extern void parseOidArray(const char *str, Oid *array, int arraysize);
781
785
786/*
787 * version specific routines
788 */
789extern void getNamespaces(Archive *fout);
791extern void getTypes(Archive *fout);
792extern void getFuncs(Archive *fout);
793extern void getAggregates(Archive *fout);
794extern void getOperators(Archive *fout);
795extern void getAccessMethods(Archive *fout);
796extern void getOpclasses(Archive *fout);
797extern void getOpfamilies(Archive *fout);
798extern void getCollations(Archive *fout);
799extern void getConversions(Archive *fout);
801extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
803extern void getPartitioningInfo(Archive *fout);
804extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
806extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
807extern void getRules(Archive *fout);
808extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
809extern void getProcLangs(Archive *fout);
810extern void getCasts(Archive *fout);
811extern void getTransforms(Archive *fout);
812extern void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables);
813extern bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno);
814extern void getTSParsers(Archive *fout);
815extern void getTSDictionaries(Archive *fout);
816extern void getTSTemplates(Archive *fout);
817extern void getTSConfigurations(Archive *fout);
819extern void getForeignServers(Archive *fout);
820extern void getDefaultACLs(Archive *fout);
822 int numExtensions);
824 int numExtensions);
825extern void getEventTriggers(Archive *fout);
826extern void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables);
827extern void getPublications(Archive *fout);
829extern void getPublicationTables(Archive *fout, TableInfo tblinfo[],
830 int numTables);
831extern void getSubscriptions(Archive *fout);
833
834#endif /* PG_DUMP_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:513
int32_t int32
Definition c.h:575
uint32_t uint32
Definition c.h:579
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:8297
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:6126
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition common.c:1063
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4745
struct _opfamilyInfo OpfamilyInfo
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7786
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:7730
TableInfo * findTableByOid(Oid oid)
Definition common.c:863
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10428
struct _aggInfo AggInfo
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4236
ExtensionInfo * findExtensionByOid(Oid oid)
Definition common.c:1008
struct _castInfo CastInfo
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19948
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:6201
struct _dumpableObject DumpableObject
struct _accessMethodInfo AccessMethodInfo
struct _attrDefInfo AttrDefInfo
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7665
void getOpclasses(Archive *fout)
Definition pg_dump.c:6647
void getForeignServers(Archive *fout)
Definition pg_dump.c:10512
void getFuncs(Archive *fout)
Definition pg_dump.c:6916
OprInfo * findOprByOid(Oid oid)
Definition common.c:936
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10244
struct _ruleInfo RuleInfo
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4825
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition common.c:990
struct _relStatsInfo RelStatsInfo
void getCasts(Archive *fout)
Definition pg_dump.c:9046
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7846
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:10369
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:6573
void getConversions(Archive *fout)
Definition pg_dump.c:6511
void getRules(Archive *fout)
Definition pg_dump.c:8591
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition common.c:1087
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9240
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:6445
struct _namespaceInfo NamespaceInfo
void getAggregates(Archive *fout)
Definition pg_dump.c:6775
struct _shellTypeInfo ShellTypeInfo
void getNamespaces(Archive *fout)
Definition pg_dump.c:5994
void getPublications(Archive *fout)
Definition pg_dump.c:4526
void getTSParsers(Archive *fout)
Definition pg_dump.c:10170
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:7188
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:8215
struct _dumpableAcl DumpableAcl
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20041
DumpId getMaxDumpId(void)
Definition common.c:754
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10600
uint32 DumpComponents
Definition pg_dump.h:107
struct _typeInfo TypeInfo
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5096
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:8688
void getTransforms(Archive *fout)
Definition pg_dump.c:9156
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8884
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:10310
void getProcLangs(Archive *fout)
Definition pg_dump.c:8962
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10155
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5327
struct _tableAttachInfo TableAttachInfo
void removeObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:843
void getOperators(Archive *fout)
Definition pg_dump.c:6369
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6710
struct _oprInfo OprInfo
struct _PublicationSchemaInfo PublicationSchemaInfo
static Archive * fout
Definition pg_dumpall.c:138
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:743
char * srsublsn
Definition pg_dump.h:747
SubscriptionInfo * subinfo
Definition pg_dump.h:744
TableInfo * tblinfo
Definition pg_dump.h:745
char srsubstate
Definition pg_dump.h:746
char * suboriginremotelsn
Definition pg_dump.h:728
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:726
char * subwalrcvtimeout
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:906
#define OidIsValid(objectId)
Definition c.h:821
#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 6573 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getAggregates()

void getAggregates ( Archive fout)
extern

Definition at line 6775 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getCasts()

void getCasts ( Archive fout)
extern

Definition at line 9046 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getCollations()

void getCollations ( Archive fout)
extern

Definition at line 6445 of file pg_dump.c.

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

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_COLLATION, ExecuteSqlQuery(), fb(), findNamespace(), fout, getRoleName(), i, pg_malloc_array, 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 8297 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getConversions()

void getConversions ( Archive fout)
extern

Definition at line 6511 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getDefaultACLs()

void getDefaultACLs ( Archive fout)
extern

Definition at line 10600 of file pg_dump.c.

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

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_DEFAULT_ACL, Archive::dopt, DUMP_COMPONENT_ACL, ExecuteSqlQuery(), fb(), findNamespace(), fout, getRoleName(), i, InvalidOid, nspid, pg_malloc_array, 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 8884 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getExtendedStatistics()

void getExtendedStatistics ( Archive fout)
extern

Definition at line 8215 of file pg_dump.c.

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

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_STATSEXT, Archive::dopt, DUMP_COMPONENT_STATISTICS, _dumpOptions::dumpStatistics, ExecuteSqlQuery(), fb(), findNamespace(), findTableByOid(), fout, getRoleName(), i, pg_malloc_array, pg_strdup(), PGRES_TUPLES_OK, PQclear, PQfnumber(), PQgetisnull, PQgetvalue, PQntuples, Archive::remoteVersion, and selectDumpableStatisticsObject().

Referenced by getSchemaData().

◆ getExtensionMembership()

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

Definition at line 19948 of file pg_dump.c.

19950{
19951 PQExpBuffer query;
19952 PGresult *res;
19953 int ntups,
19954 i;
19955 int i_classid,
19956 i_objid,
19957 i_refobjid;
19958 ExtensionInfo *ext;
19959
19960 /* Nothing to do if no extensions */
19961 if (numExtensions == 0)
19962 return;
19963
19964 query = createPQExpBuffer();
19965
19966 /* refclassid constraint is redundant but may speed the search */
19967 appendPQExpBufferStr(query, "SELECT "
19968 "classid, objid, refobjid "
19969 "FROM pg_depend "
19970 "WHERE refclassid = 'pg_extension'::regclass "
19971 "AND deptype = 'e' "
19972 "ORDER BY 3");
19973
19974 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
19975
19976 ntups = PQntuples(res);
19977
19978 i_classid = PQfnumber(res, "classid");
19979 i_objid = PQfnumber(res, "objid");
19980 i_refobjid = PQfnumber(res, "refobjid");
19981
19982 /*
19983 * Since we ordered the SELECT by referenced ID, we can expect that
19984 * multiple entries for the same extension will appear together; this
19985 * saves on searches.
19986 */
19987 ext = NULL;
19988
19989 for (i = 0; i < ntups; i++)
19990 {
19991 CatalogId objId;
19992 Oid extId;
19993
19994 objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
19995 objId.oid = atooid(PQgetvalue(res, i, i_objid));
19997
19998 if (ext == NULL ||
19999 ext->dobj.catId.oid != extId)
20001
20002 if (ext == NULL)
20003 {
20004 /* shouldn't happen */
20005 pg_log_warning("could not find referenced extension %u", extId);
20006 continue;
20007 }
20008
20009 recordExtensionMembership(objId, ext);
20010 }
20011
20012 PQclear(res);
20013
20014 destroyPQExpBuffer(query);
20015}
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(), fout, 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 6126 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getForeignDataWrappers()

void getForeignDataWrappers ( Archive fout)
extern

Definition at line 10428 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getForeignServers()

void getForeignServers ( Archive fout)
extern

Definition at line 10512 of file pg_dump.c.

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

Referenced by getSchemaData().

◆ getFuncs()

void getFuncs ( Archive fout)
extern

Definition at line 6916 of file pg_dump.c.

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

Referenced by getSchemaData().

◆ getIndexes()

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

Definition at line 7846 of file pg_dump.c.

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

Referenced by getSchemaData().

◆ getInherits()

InhInfo * getInherits ( Archive fout,
int numInherits 
)
extern

Definition at line 7730 of file pg_dump.c.

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

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), ExecuteSqlQuery(), fb(), fout, i, pg_malloc_array, 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 5994 of file pg_dump.c.

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

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

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

Referenced by getSchemaData().

◆ getOperators()

void getOperators ( Archive fout)
extern

Definition at line 6369 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getOpfamilies()

void getOpfamilies ( Archive fout)
extern

Definition at line 6710 of file pg_dump.c.

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

References appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_OPFAMILY, ExecuteSqlQuery(), fb(), findNamespace(), fout, getRoleName(), i, pg_malloc_array, 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 7665 of file pg_dump.c.

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

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

References appendPQExpBufferStr(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), Archive::dopt, _dumpOptions::dumpData, ExecuteSqlQuery(), fb(), findTableByOid(), fout, i, pg_fatal, PGRES_TUPLES_OK, PQclear, PQgetvalue, PQntuples, and Archive::remoteVersion.

Referenced by getSchemaData().

◆ getPolicies()

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

Definition at line 4236 of file pg_dump.c.

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

Referenced by getSchemaData().

◆ getProcLangs()

void getProcLangs ( Archive fout)
extern

Definition at line 8962 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getPublicationNamespaces()

void getPublicationNamespaces ( Archive fout)
extern

Definition at line 4745 of file pg_dump.c.

4746{
4747 PQExpBuffer query;
4748 PGresult *res;
4750 DumpOptions *dopt = fout->dopt;
4751 int i_tableoid;
4752 int i_oid;
4753 int i_pnpubid;
4754 int i_pnnspid;
4755 int i,
4756 j,
4757 ntups;
4758
4759 if (dopt->no_publications || fout->remoteVersion < 150000)
4760 return;
4761
4762 query = createPQExpBuffer();
4763
4764 /* Collect all publication membership info. */
4766 "SELECT tableoid, oid, pnpubid, pnnspid "
4767 "FROM pg_catalog.pg_publication_namespace");
4768 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4769
4770 ntups = PQntuples(res);
4771
4772 i_tableoid = PQfnumber(res, "tableoid");
4773 i_oid = PQfnumber(res, "oid");
4774 i_pnpubid = PQfnumber(res, "pnpubid");
4775 i_pnnspid = PQfnumber(res, "pnnspid");
4776
4777 /* this allocation may be more than we need */
4779 j = 0;
4780
4781 for (i = 0; i < ntups; i++)
4782 {
4787
4788 /*
4789 * Ignore any entries for which we aren't interested in either the
4790 * publication or the rel.
4791 */
4793 if (pubinfo == NULL)
4794 continue;
4796 if (nspinfo == NULL)
4797 continue;
4798
4799 /* OK, make a DumpableObject for this relationship */
4801 pubsinfo[j].dobj.catId.tableoid =
4802 atooid(PQgetvalue(res, i, i_tableoid));
4803 pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4804 AssignDumpId(&pubsinfo[j].dobj);
4805 pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4806 pubsinfo[j].dobj.name = nspinfo->dobj.name;
4807 pubsinfo[j].publication = pubinfo;
4808 pubsinfo[j].pubschema = nspinfo;
4809
4810 /* Decide whether we want to dump it */
4812
4813 j++;
4814 }
4815
4816 PQclear(res);
4817 destroyPQExpBuffer(query);
4818}
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:2319
int no_publications
Definition pg_backup.h:189

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

Referenced by getSchemaData().

◆ getPublications()

void getPublications ( Archive fout)
extern

Definition at line 4526 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getPublicationTables()

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

Definition at line 4825 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getRules()

void getRules ( Archive fout)
extern

Definition at line 8591 of file pg_dump.c.

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

References addObjectDependency(), appendPQExpBufferStr(), AssignDumpId(), atooid, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), DO_RULE, ExecuteSqlQuery(), fb(), findTableByOid(), fout, i, pg_fatal, pg_malloc_array, 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:8297
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6126
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4745
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7786
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7730
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10428
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4236
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:19948
void getTypes(Archive *fout)
Definition pg_dump.c:6201
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7665
void getOpclasses(Archive *fout)
Definition pg_dump.c:6647
void getForeignServers(Archive *fout)
Definition pg_dump.c:10512
void getFuncs(Archive *fout)
Definition pg_dump.c:6916
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10244
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4825
void getCasts(Archive *fout)
Definition pg_dump.c:9046
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7846
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10369
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6573
void getConversions(Archive *fout)
Definition pg_dump.c:6511
void getRules(Archive *fout)
Definition pg_dump.c:8591
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9240
void getCollations(Archive *fout)
Definition pg_dump.c:6445
void getAggregates(Archive *fout)
Definition pg_dump.c:6775
void getNamespaces(Archive *fout)
Definition pg_dump.c:5994
void getPublications(Archive *fout)
Definition pg_dump.c:4526
void getTSParsers(Archive *fout)
Definition pg_dump.c:10170
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7188
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8215
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20041
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10600
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5096
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8688
void getTransforms(Archive *fout)
Definition pg_dump.c:9156
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8884
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10310
void getProcLangs(Archive *fout)
Definition pg_dump.c:8962
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5327
void getOperators(Archive *fout)
Definition pg_dump.c:6369
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6710

References Archive::dopt, fb(), flagInhAttrs(), flagInhIndexes(), flagInhTables(), fout, 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 5327 of file pg_dump.c.

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

Referenced by getSchemaData().

◆ getSubscriptions()

void getSubscriptions ( Archive fout)
extern

Definition at line 5096 of file pg_dump.c.

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

Referenced by getSchemaData().

◆ getTableAttrs()

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

Definition at line 9240 of file pg_dump.c.

9241{
9242 DumpOptions *dopt = fout->dopt;
9247 PGresult *res;
9248 int ntups;
9249 int curtblindx;
9250 int i_attrelid;
9251 int i_attnum;
9252 int i_attname;
9253 int i_atttypname;
9254 int i_attstattarget;
9255 int i_attstorage;
9256 int i_typstorage;
9257 int i_attidentity;
9258 int i_attgenerated;
9259 int i_attisdropped;
9260 int i_attlen;
9261 int i_attalign;
9262 int i_attislocal;
9263 int i_notnull_name;
9268 int i_attoptions;
9269 int i_attcollation;
9270 int i_attcompression;
9271 int i_attfdwoptions;
9272 int i_attmissingval;
9273 int i_atthasdef;
9274
9275 /*
9276 * We want to perform just one query against pg_attribute, and then just
9277 * one against pg_attrdef (for DEFAULTs) and two against pg_constraint
9278 * (for CHECK constraints and for NOT NULL constraints). However, we
9279 * mustn't try to select every row of those catalogs and then sort it out
9280 * on the client side, because some of the server-side functions we need
9281 * would be unsafe to apply to tables we don't have lock on. Hence, we
9282 * build an array of the OIDs of tables we care about (and now have lock
9283 * on!), and use a WHERE clause to constrain which rows are selected.
9284 */
9287 for (int i = 0; i < numTables; i++)
9288 {
9289 TableInfo *tbinfo = &tblinfo[i];
9290
9291 /* Don't bother to collect info for sequences */
9292 if (tbinfo->relkind == RELKIND_SEQUENCE)
9293 continue;
9294
9295 /*
9296 * Don't bother with uninteresting tables, either. For binary
9297 * upgrades, this is bypassed for pg_largeobject_metadata and
9298 * pg_shdepend so that the columns names are collected for the
9299 * corresponding COPY commands. Restoring the data for those catalogs
9300 * is faster than restoring the equivalent set of large object
9301 * commands.
9302 */
9303 if (!tbinfo->interesting &&
9304 !(fout->dopt->binary_upgrade &&
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
9447 /*
9448 * For binary upgrades from <v12, be sure to pick up
9449 * pg_largeobject_metadata's oid column.
9450 */
9451 if (fout->dopt->binary_upgrade && fout->remoteVersion < 120000)
9453 "OR (a.attnum = -2::pg_catalog.int2 AND src.tbloid = "
9455
9457 "ORDER BY a.attrelid, a.attnum");
9458
9460
9461 ntups = PQntuples(res);
9462
9463 i_attrelid = PQfnumber(res, "attrelid");
9464 i_attnum = PQfnumber(res, "attnum");
9465 i_attname = PQfnumber(res, "attname");
9466 i_atttypname = PQfnumber(res, "atttypname");
9467 i_attstattarget = PQfnumber(res, "attstattarget");
9468 i_attstorage = PQfnumber(res, "attstorage");
9469 i_typstorage = PQfnumber(res, "typstorage");
9470 i_attidentity = PQfnumber(res, "attidentity");
9471 i_attgenerated = PQfnumber(res, "attgenerated");
9472 i_attisdropped = PQfnumber(res, "attisdropped");
9473 i_attlen = PQfnumber(res, "attlen");
9474 i_attalign = PQfnumber(res, "attalign");
9475 i_attislocal = PQfnumber(res, "attislocal");
9476 i_notnull_name = PQfnumber(res, "notnull_name");
9477 i_notnull_comment = PQfnumber(res, "notnull_comment");
9478 i_notnull_invalidoid = PQfnumber(res, "notnull_invalidoid");
9479 i_notnull_noinherit = PQfnumber(res, "notnull_noinherit");
9480 i_notnull_islocal = PQfnumber(res, "notnull_islocal");
9481 i_attoptions = PQfnumber(res, "attoptions");
9482 i_attcollation = PQfnumber(res, "attcollation");
9483 i_attcompression = PQfnumber(res, "attcompression");
9484 i_attfdwoptions = PQfnumber(res, "attfdwoptions");
9485 i_attmissingval = PQfnumber(res, "attmissingval");
9486 i_atthasdef = PQfnumber(res, "atthasdef");
9487
9488 /* Within the next loop, we'll accumulate OIDs of tables with defaults */
9491
9492 /*
9493 * Outer loop iterates once per table, not once per row. Incrementing of
9494 * r is handled by the inner loop.
9495 */
9496 curtblindx = -1;
9497 for (int r = 0; r < ntups;)
9498 {
9499 Oid attrelid = atooid(PQgetvalue(res, r, i_attrelid));
9501 int numatts;
9502 bool hasdefaults;
9503
9504 /* Count rows for this table */
9505 for (numatts = 1; numatts < ntups - r; numatts++)
9506 if (atooid(PQgetvalue(res, r + numatts, i_attrelid)) != attrelid)
9507 break;
9508
9509 /*
9510 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
9511 * order.
9512 */
9513 while (++curtblindx < numTables)
9514 {
9515 tbinfo = &tblinfo[curtblindx];
9516 if (tbinfo->dobj.catId.oid == attrelid)
9517 break;
9518 }
9519 if (curtblindx >= numTables)
9520 pg_fatal("unrecognized table OID %u", attrelid);
9521 /* cross-check that we only got requested tables */
9522 if (tbinfo->relkind == RELKIND_SEQUENCE ||
9523 (!tbinfo->interesting &&
9524 !(fout->dopt->binary_upgrade &&
9525 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9526 tbinfo->dobj.catId.oid == SharedDependRelationId))))
9527 pg_fatal("unexpected column data for table \"%s\"",
9528 tbinfo->dobj.name);
9529
9530 /* Save data for this table */
9531 tbinfo->numatts = numatts;
9532 tbinfo->attnames = pg_malloc_array(char *, numatts);
9533 tbinfo->atttypnames = pg_malloc_array(char *, numatts);
9534 tbinfo->attstattarget = pg_malloc_array(int, numatts);
9535 tbinfo->attstorage = pg_malloc_array(char, numatts);
9536 tbinfo->typstorage = pg_malloc_array(char, numatts);
9537 tbinfo->attidentity = pg_malloc_array(char, numatts);
9538 tbinfo->attgenerated = pg_malloc_array(char, numatts);
9539 tbinfo->attisdropped = pg_malloc_array(bool, numatts);
9540 tbinfo->attlen = pg_malloc_array(int, numatts);
9541 tbinfo->attalign = pg_malloc_array(char, numatts);
9542 tbinfo->attislocal = pg_malloc_array(bool, numatts);
9543 tbinfo->attoptions = pg_malloc_array(char *, numatts);
9544 tbinfo->attcollation = pg_malloc_array(Oid, numatts);
9545 tbinfo->attcompression = pg_malloc_array(char, numatts);
9546 tbinfo->attfdwoptions = pg_malloc_array(char *, numatts);
9547 tbinfo->attmissingval = pg_malloc_array(char *, numatts);
9548 tbinfo->notnull_constrs = pg_malloc_array(char *, numatts);
9549 tbinfo->notnull_comment = pg_malloc_array(char *, numatts);
9550 tbinfo->notnull_invalid = pg_malloc_array(bool, numatts);
9551 tbinfo->notnull_noinh = pg_malloc_array(bool, numatts);
9552 tbinfo->notnull_islocal = pg_malloc_array(bool, numatts);
9553 tbinfo->attrdefs = pg_malloc_array(AttrDefInfo *, numatts);
9554 hasdefaults = false;
9555
9556 for (int j = 0; j < numatts; j++, r++)
9557 {
9558 if (j + 1 != atoi(PQgetvalue(res, r, i_attnum)) &&
9559 !(fout->dopt->binary_upgrade && fout->remoteVersion < 120000 &&
9560 tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId))
9561 pg_fatal("invalid column numbering in table \"%s\"",
9562 tbinfo->dobj.name);
9563 tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, r, i_attname));
9564 tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, r, i_atttypname));
9565 if (PQgetisnull(res, r, i_attstattarget))
9566 tbinfo->attstattarget[j] = -1;
9567 else
9568 tbinfo->attstattarget[j] = atoi(PQgetvalue(res, r, i_attstattarget));
9569 tbinfo->attstorage[j] = *(PQgetvalue(res, r, i_attstorage));
9570 tbinfo->typstorage[j] = *(PQgetvalue(res, r, i_typstorage));
9571 tbinfo->attidentity[j] = *(PQgetvalue(res, r, i_attidentity));
9572 tbinfo->attgenerated[j] = *(PQgetvalue(res, r, i_attgenerated));
9573 tbinfo->needs_override = tbinfo->needs_override || (tbinfo->attidentity[j] == ATTRIBUTE_IDENTITY_ALWAYS);
9574 tbinfo->attisdropped[j] = (PQgetvalue(res, r, i_attisdropped)[0] == 't');
9575 tbinfo->attlen[j] = atoi(PQgetvalue(res, r, i_attlen));
9576 tbinfo->attalign[j] = *(PQgetvalue(res, r, i_attalign));
9577 tbinfo->attislocal[j] = (PQgetvalue(res, r, i_attislocal)[0] == 't');
9578
9579 /* Handle not-null constraint name and flags */
9581 tbinfo, j,
9588
9589 tbinfo->notnull_comment[j] = PQgetisnull(res, r, i_notnull_comment) ?
9591 tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, r, i_attoptions));
9592 tbinfo->attcollation[j] = atooid(PQgetvalue(res, r, i_attcollation));
9593 tbinfo->attcompression[j] = *(PQgetvalue(res, r, i_attcompression));
9594 tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, r, i_attfdwoptions));
9595 tbinfo->attmissingval[j] = pg_strdup(PQgetvalue(res, r, i_attmissingval));
9596 tbinfo->attrdefs[j] = NULL; /* fix below */
9597 if (PQgetvalue(res, r, i_atthasdef)[0] == 't')
9598 hasdefaults = true;
9599 }
9600
9601 if (hasdefaults)
9602 {
9603 /* Collect OIDs of interesting tables that have defaults */
9604 if (tbloids->len > 1) /* do we have more than the '{'? */
9606 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9607 }
9608 }
9609
9610 /* If invalidnotnulloids has any data, finalize it */
9611 if (invalidnotnulloids != NULL)
9613
9614 PQclear(res);
9615
9616 /*
9617 * Now get info about column defaults. This is skipped for a data-only
9618 * dump, as it is only needed for table schemas.
9619 */
9620 if (dopt->dumpSchema && tbloids->len > 1)
9621 {
9622 AttrDefInfo *attrdefs;
9623 int numDefaults;
9625
9626 pg_log_info("finding table default expressions");
9627
9629
9630 printfPQExpBuffer(q, "SELECT a.tableoid, a.oid, adrelid, adnum, "
9631 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9632 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9633 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9634 "ORDER BY a.adrelid, a.adnum",
9635 tbloids->data);
9636
9638
9639 numDefaults = PQntuples(res);
9641
9642 curtblindx = -1;
9643 for (int j = 0; j < numDefaults; j++)
9644 {
9645 Oid adtableoid = atooid(PQgetvalue(res, j, 0));
9646 Oid adoid = atooid(PQgetvalue(res, j, 1));
9647 Oid adrelid = atooid(PQgetvalue(res, j, 2));
9648 int adnum = atoi(PQgetvalue(res, j, 3));
9649 char *adsrc = PQgetvalue(res, j, 4);
9650
9651 /*
9652 * Locate the associated TableInfo; we rely on tblinfo[] being in
9653 * OID order.
9654 */
9655 if (tbinfo == NULL || tbinfo->dobj.catId.oid != adrelid)
9656 {
9657 while (++curtblindx < numTables)
9658 {
9659 tbinfo = &tblinfo[curtblindx];
9660 if (tbinfo->dobj.catId.oid == adrelid)
9661 break;
9662 }
9663 if (curtblindx >= numTables)
9664 pg_fatal("unrecognized table OID %u", adrelid);
9665 }
9666
9667 if (adnum <= 0 || adnum > tbinfo->numatts)
9668 pg_fatal("invalid adnum value %d for table \"%s\"",
9669 adnum, tbinfo->dobj.name);
9670
9671 /*
9672 * dropped columns shouldn't have defaults, but just in case,
9673 * ignore 'em
9674 */
9675 if (tbinfo->attisdropped[adnum - 1])
9676 continue;
9677
9678 attrdefs[j].dobj.objType = DO_ATTRDEF;
9679 attrdefs[j].dobj.catId.tableoid = adtableoid;
9680 attrdefs[j].dobj.catId.oid = adoid;
9681 AssignDumpId(&attrdefs[j].dobj);
9682 attrdefs[j].adtable = tbinfo;
9683 attrdefs[j].adnum = adnum;
9684 attrdefs[j].adef_expr = pg_strdup(adsrc);
9685
9686 attrdefs[j].dobj.name = pg_strdup(tbinfo->dobj.name);
9687 attrdefs[j].dobj.namespace = tbinfo->dobj.namespace;
9688
9689 attrdefs[j].dobj.dump = tbinfo->dobj.dump;
9690
9691 /*
9692 * Figure out whether the default/generation expression should be
9693 * dumped as part of the main CREATE TABLE (or similar) command or
9694 * as a separate ALTER TABLE (or similar) command. The preference
9695 * is to put it into the CREATE command, but in some cases that's
9696 * not possible.
9697 */
9698 if (tbinfo->attgenerated[adnum - 1])
9699 {
9700 /*
9701 * Column generation expressions cannot be dumped separately,
9702 * because there is no syntax for it. By setting separate to
9703 * false here we prevent the "default" from being processed as
9704 * its own dumpable object. Later, flagInhAttrs() will mark
9705 * it as not to be dumped at all, if possible (that is, if it
9706 * can be inherited from a parent).
9707 */
9708 attrdefs[j].separate = false;
9709 }
9710 else if (tbinfo->relkind == RELKIND_VIEW)
9711 {
9712 /*
9713 * Defaults on a VIEW must always be dumped as separate ALTER
9714 * TABLE commands.
9715 */
9716 attrdefs[j].separate = true;
9717 }
9718 else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1))
9719 {
9720 /* column will be suppressed, print default separately */
9721 attrdefs[j].separate = true;
9722 }
9723 else
9724 {
9725 attrdefs[j].separate = false;
9726 }
9727
9728 if (!attrdefs[j].separate)
9729 {
9730 /*
9731 * Mark the default as needing to appear before the table, so
9732 * that any dependencies it has must be emitted before the
9733 * CREATE TABLE. If this is not possible, we'll change to
9734 * "separate" mode while sorting dependencies.
9735 */
9737 attrdefs[j].dobj.dumpId);
9738 }
9739
9740 tbinfo->attrdefs[adnum - 1] = &attrdefs[j];
9741 }
9742
9743 PQclear(res);
9744 }
9745
9746 /*
9747 * Get info about NOT NULL NOT VALID constraints. This is skipped for a
9748 * data-only dump, as it is only needed for table schemas.
9749 */
9750 if (dopt->dumpSchema && invalidnotnulloids)
9751 {
9753 int numConstrs;
9754 int i_tableoid;
9755 int i_oid;
9756 int i_conrelid;
9757 int i_conname;
9758 int i_consrc;
9759 int i_conislocal;
9760
9761 pg_log_info("finding invalid not-null constraints");
9762
9765 "SELECT c.tableoid, c.oid, conrelid, conname, "
9766 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9767 "conislocal, convalidated "
9768 "FROM unnest('%s'::pg_catalog.oid[]) AS src(conoid)\n"
9769 "JOIN pg_catalog.pg_constraint c ON (src.conoid = c.oid)\n"
9770 "ORDER BY c.conrelid, c.conname",
9771 invalidnotnulloids->data);
9772
9774
9775 numConstrs = PQntuples(res);
9777
9778 i_tableoid = PQfnumber(res, "tableoid");
9779 i_oid = PQfnumber(res, "oid");
9780 i_conrelid = PQfnumber(res, "conrelid");
9781 i_conname = PQfnumber(res, "conname");
9782 i_consrc = PQfnumber(res, "consrc");
9783 i_conislocal = PQfnumber(res, "conislocal");
9784
9785 /* As above, this loop iterates once per table, not once per row */
9786 curtblindx = -1;
9787 for (int j = 0; j < numConstrs;)
9788 {
9789 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9791 int numcons;
9792
9793 /* Count rows for this table */
9794 for (numcons = 1; numcons < numConstrs - j; numcons++)
9795 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9796 break;
9797
9798 /*
9799 * Locate the associated TableInfo; we rely on tblinfo[] being in
9800 * OID order.
9801 */
9802 while (++curtblindx < numTables)
9803 {
9804 tbinfo = &tblinfo[curtblindx];
9805 if (tbinfo->dobj.catId.oid == conrelid)
9806 break;
9807 }
9808 if (curtblindx >= numTables)
9809 pg_fatal("unrecognized table OID %u", conrelid);
9810
9811 for (int c = 0; c < numcons; c++, j++)
9812 {
9813 constrs[j].dobj.objType = DO_CONSTRAINT;
9814 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9815 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9816 AssignDumpId(&constrs[j].dobj);
9817 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9818 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9819 constrs[j].contable = tbinfo;
9820 constrs[j].condomain = NULL;
9821 constrs[j].contype = 'n';
9822 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9823 constrs[j].confrelid = InvalidOid;
9824 constrs[j].conindex = 0;
9825 constrs[j].condeferrable = false;
9826 constrs[j].condeferred = false;
9827 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9828
9829 /*
9830 * All invalid not-null constraints must be dumped separately,
9831 * because CREATE TABLE would not create them as invalid, and
9832 * also because they must be created after potentially
9833 * violating data has been loaded.
9834 */
9835 constrs[j].separate = true;
9836
9837 constrs[j].dobj.dump = tbinfo->dobj.dump;
9838 }
9839 }
9840 PQclear(res);
9841 }
9842
9843 /*
9844 * Get info about table CHECK constraints. This is skipped for a
9845 * data-only dump, as it is only needed for table schemas.
9846 */
9847 if (dopt->dumpSchema && checkoids->len > 2)
9848 {
9850 int numConstrs;
9851 int i_tableoid;
9852 int i_oid;
9853 int i_conrelid;
9854 int i_conname;
9855 int i_consrc;
9856 int i_conislocal;
9857 int i_convalidated;
9858
9859 pg_log_info("finding table check constraints");
9860
9863 "SELECT c.tableoid, c.oid, conrelid, conname, "
9864 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9865 "conislocal, convalidated "
9866 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9867 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9868 "WHERE contype = 'c' "
9869 "ORDER BY c.conrelid, c.conname",
9870 checkoids->data);
9871
9873
9874 numConstrs = PQntuples(res);
9876
9877 i_tableoid = PQfnumber(res, "tableoid");
9878 i_oid = PQfnumber(res, "oid");
9879 i_conrelid = PQfnumber(res, "conrelid");
9880 i_conname = PQfnumber(res, "conname");
9881 i_consrc = PQfnumber(res, "consrc");
9882 i_conislocal = PQfnumber(res, "conislocal");
9883 i_convalidated = PQfnumber(res, "convalidated");
9884
9885 /* As above, this loop iterates once per table, not once per row */
9886 curtblindx = -1;
9887 for (int j = 0; j < numConstrs;)
9888 {
9889 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9891 int numcons;
9892
9893 /* Count rows for this table */
9894 for (numcons = 1; numcons < numConstrs - j; numcons++)
9895 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9896 break;
9897
9898 /*
9899 * Locate the associated TableInfo; we rely on tblinfo[] being in
9900 * OID order.
9901 */
9902 while (++curtblindx < numTables)
9903 {
9904 tbinfo = &tblinfo[curtblindx];
9905 if (tbinfo->dobj.catId.oid == conrelid)
9906 break;
9907 }
9908 if (curtblindx >= numTables)
9909 pg_fatal("unrecognized table OID %u", conrelid);
9910
9911 if (numcons != tbinfo->ncheck)
9912 {
9913 pg_log_error(ngettext("expected %d check constraint on table \"%s\" but found %d",
9914 "expected %d check constraints on table \"%s\" but found %d",
9915 tbinfo->ncheck),
9916 tbinfo->ncheck, tbinfo->dobj.name, numcons);
9917 pg_log_error_hint("The system catalogs might be corrupted.");
9918 exit_nicely(1);
9919 }
9920
9921 tbinfo->checkexprs = constrs + j;
9922
9923 for (int c = 0; c < numcons; c++, j++)
9924 {
9925 bool validated = PQgetvalue(res, j, i_convalidated)[0] == 't';
9926
9927 constrs[j].dobj.objType = DO_CONSTRAINT;
9928 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9929 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9930 AssignDumpId(&constrs[j].dobj);
9931 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9932 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9933 constrs[j].contable = tbinfo;
9934 constrs[j].condomain = NULL;
9935 constrs[j].contype = 'c';
9936 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9937 constrs[j].confrelid = InvalidOid;
9938 constrs[j].conindex = 0;
9939 constrs[j].condeferrable = false;
9940 constrs[j].condeferred = false;
9941 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9942
9943 /*
9944 * An unvalidated constraint needs to be dumped separately, so
9945 * that potentially-violating existing data is loaded before
9946 * the constraint.
9947 */
9948 constrs[j].separate = !validated;
9949
9950 constrs[j].dobj.dump = tbinfo->dobj.dump;
9951
9952 /*
9953 * Mark the constraint as needing to appear before the table
9954 * --- this is so that any other dependencies of the
9955 * constraint will be emitted before we try to create the
9956 * table. If the constraint is to be dumped separately, it
9957 * will be dumped after data is loaded anyway, so don't do it.
9958 * (There's an automatic dependency in the opposite direction
9959 * anyway, so don't need to add one manually here.)
9960 */
9961 if (!constrs[j].separate)
9963 constrs[j].dobj.dumpId);
9964
9965 /*
9966 * We will detect later whether the constraint must be split
9967 * out from the table definition.
9968 */
9969 }
9970 }
9971
9972 PQclear(res);
9973 }
9974
9978}
#define ngettext(s, p, n)
Definition c.h:1219
#define CppAsString2(x)
Definition c.h:461
#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:10028
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10155
bool dumpSchema
Definition pg_backup.h:216

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

Referenced by getSchemaData().

◆ getTables()

TableInfo * getTables ( Archive fout,
int numTables 
)
extern

Definition at line 7188 of file pg_dump.c.

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

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

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

Referenced by getSchemaData().

◆ getTriggers()

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

Definition at line 8688 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getTSConfigurations()

void getTSConfigurations ( Archive fout)
extern

Definition at line 10369 of file pg_dump.c.

10370{
10371 PGresult *res;
10372 int ntups;
10373 int i;
10374 PQExpBuffer query;
10376 int i_tableoid;
10377 int i_oid;
10378 int i_cfgname;
10379 int i_cfgnamespace;
10380 int i_cfgowner;
10381 int i_cfgparser;
10382
10383 query = createPQExpBuffer();
10384
10385 appendPQExpBufferStr(query, "SELECT tableoid, oid, cfgname, "
10386 "cfgnamespace, cfgowner, cfgparser "
10387 "FROM pg_ts_config");
10388
10389 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10390
10391 ntups = PQntuples(res);
10392
10394
10395 i_tableoid = PQfnumber(res, "tableoid");
10396 i_oid = PQfnumber(res, "oid");
10397 i_cfgname = PQfnumber(res, "cfgname");
10398 i_cfgnamespace = PQfnumber(res, "cfgnamespace");
10399 i_cfgowner = PQfnumber(res, "cfgowner");
10400 i_cfgparser = PQfnumber(res, "cfgparser");
10401
10402 for (i = 0; i < ntups; i++)
10403 {
10404 cfginfo[i].dobj.objType = DO_TSCONFIG;
10405 cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10406 cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10407 AssignDumpId(&cfginfo[i].dobj);
10408 cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
10409 cfginfo[i].dobj.namespace =
10411 cfginfo[i].rolname = getRoleName(PQgetvalue(res, i, i_cfgowner));
10412 cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
10413
10414 /* Decide whether we want to dump it */
10416 }
10417
10418 PQclear(res);
10419
10420 destroyPQExpBuffer(query);
10421}

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

Referenced by getSchemaData().

◆ getTSDictionaries()

void getTSDictionaries ( Archive fout)
extern

Definition at line 10244 of file pg_dump.c.

10245{
10246 PGresult *res;
10247 int ntups;
10248 int i;
10249 PQExpBuffer query;
10251 int i_tableoid;
10252 int i_oid;
10253 int i_dictname;
10254 int i_dictnamespace;
10255 int i_dictowner;
10256 int i_dicttemplate;
10257 int i_dictinitoption;
10258
10259 query = createPQExpBuffer();
10260
10261 appendPQExpBufferStr(query, "SELECT tableoid, oid, dictname, "
10262 "dictnamespace, dictowner, "
10263 "dicttemplate, dictinitoption "
10264 "FROM pg_ts_dict");
10265
10266 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10267
10268 ntups = PQntuples(res);
10269
10271
10272 i_tableoid = PQfnumber(res, "tableoid");
10273 i_oid = PQfnumber(res, "oid");
10274 i_dictname = PQfnumber(res, "dictname");
10275 i_dictnamespace = PQfnumber(res, "dictnamespace");
10276 i_dictowner = PQfnumber(res, "dictowner");
10277 i_dictinitoption = PQfnumber(res, "dictinitoption");
10278 i_dicttemplate = PQfnumber(res, "dicttemplate");
10279
10280 for (i = 0; i < ntups; i++)
10281 {
10282 dictinfo[i].dobj.objType = DO_TSDICT;
10283 dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10284 dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10285 AssignDumpId(&dictinfo[i].dobj);
10286 dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
10287 dictinfo[i].dobj.namespace =
10289 dictinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_dictowner));
10290 dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
10291 if (PQgetisnull(res, i, i_dictinitoption))
10292 dictinfo[i].dictinitoption = NULL;
10293 else
10294 dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
10295
10296 /* Decide whether we want to dump it */
10298 }
10299
10300 PQclear(res);
10301
10302 destroyPQExpBuffer(query);
10303}

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

Referenced by getSchemaData().

◆ getTSParsers()

void getTSParsers ( Archive fout)
extern

Definition at line 10170 of file pg_dump.c.

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

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

Referenced by getSchemaData().

◆ getTSTemplates()

void getTSTemplates ( Archive fout)
extern

Definition at line 10310 of file pg_dump.c.

10311{
10312 PGresult *res;
10313 int ntups;
10314 int i;
10315 PQExpBuffer query;
10317 int i_tableoid;
10318 int i_oid;
10319 int i_tmplname;
10320 int i_tmplnamespace;
10321 int i_tmplinit;
10322 int i_tmpllexize;
10323
10324 query = createPQExpBuffer();
10325
10326 appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
10327 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
10328 "FROM pg_ts_template");
10329
10330 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10331
10332 ntups = PQntuples(res);
10333
10335
10336 i_tableoid = PQfnumber(res, "tableoid");
10337 i_oid = PQfnumber(res, "oid");
10338 i_tmplname = PQfnumber(res, "tmplname");
10339 i_tmplnamespace = PQfnumber(res, "tmplnamespace");
10340 i_tmplinit = PQfnumber(res, "tmplinit");
10341 i_tmpllexize = PQfnumber(res, "tmpllexize");
10342
10343 for (i = 0; i < ntups; i++)
10344 {
10345 tmplinfo[i].dobj.objType = DO_TSTEMPLATE;
10346 tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10347 tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10348 AssignDumpId(&tmplinfo[i].dobj);
10349 tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
10350 tmplinfo[i].dobj.namespace =
10352 tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
10353 tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
10354
10355 /* Decide whether we want to dump it */
10357 }
10358
10359 PQclear(res);
10360
10361 destroyPQExpBuffer(query);
10362}

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

Referenced by getSchemaData().

◆ getTypes()

void getTypes ( Archive fout)
extern

Definition at line 6201 of file pg_dump.c.

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

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(), fout, getDomainConstraints(), getRoleName(), i, nilCatalogId, pg_malloc_array, pg_malloc_object, 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 20041 of file pg_dump.c.

20043{
20044 DumpOptions *dopt = fout->dopt;
20045 PQExpBuffer query;
20046 PGresult *res;
20047 int ntups,
20048 i;
20049 int i_conrelid,
20051
20052 /* Nothing to do if no extensions */
20053 if (numExtensions == 0)
20054 return;
20055
20056 /*
20057 * Identify extension configuration tables and create TableDataInfo
20058 * objects for them, ensuring their data will be dumped even though the
20059 * tables themselves won't be.
20060 *
20061 * Note that we create TableDataInfo objects even in schema-only mode, ie,
20062 * user data in a configuration table is treated like schema data. This
20063 * seems appropriate since system data in a config table would get
20064 * reloaded by CREATE EXTENSION. If the extension is not listed in the
20065 * list of extensions to be included, none of its data is dumped.
20066 */
20067 for (i = 0; i < numExtensions; i++)
20068 {
20070 char *extconfig = curext->extconfig;
20071 char *extcondition = curext->extcondition;
20072 char **extconfigarray = NULL;
20073 char **extconditionarray = NULL;
20074 int nconfigitems = 0;
20075 int nconditionitems = 0;
20076
20077 /*
20078 * Check if this extension is listed as to include in the dump. If
20079 * not, any table data associated with it is discarded.
20080 */
20083 curext->dobj.catId.oid))
20084 continue;
20085
20086 /*
20087 * Check if this extension is listed as to exclude in the dump. If
20088 * yes, any table data associated with it is discarded.
20089 */
20092 curext->dobj.catId.oid))
20093 continue;
20094
20095 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
20096 {
20097 int j;
20098
20099 if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
20100 pg_fatal("could not parse %s array", "extconfig");
20101 if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
20102 pg_fatal("could not parse %s array", "extcondition");
20104 pg_fatal("mismatched number of configurations and conditions for extension");
20105
20106 for (j = 0; j < nconfigitems; j++)
20107 {
20110 bool dumpobj =
20111 curext->dobj.dump & DUMP_COMPONENT_DEFINITION;
20112
20114 if (configtbl == NULL)
20115 continue;
20116
20117 /*
20118 * Tables of not-to-be-dumped extensions shouldn't be dumped
20119 * unless the table or its schema is explicitly included
20120 */
20121 if (!(curext->dobj.dump & DUMP_COMPONENT_DEFINITION))
20122 {
20123 /* check table explicitly requested */
20124 if (table_include_oids.head != NULL &&
20126 configtbloid))
20127 dumpobj = true;
20128
20129 /* check table's schema explicitly requested */
20130 if (configtbl->dobj.namespace->dobj.dump &
20132 dumpobj = true;
20133 }
20134
20135 /* check table excluded by an exclusion switch */
20136 if (table_exclude_oids.head != NULL &&
20138 configtbloid))
20139 dumpobj = false;
20140
20141 /* check schema excluded by an exclusion switch */
20143 configtbl->dobj.namespace->dobj.catId.oid))
20144 dumpobj = false;
20145
20146 if (dumpobj)
20147 {
20149 if (configtbl->dataObj != NULL)
20150 {
20151 if (strlen(extconditionarray[j]) > 0)
20152 configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
20153 }
20154 }
20155 }
20156 }
20157 if (extconfigarray)
20161 }
20162
20163 /*
20164 * Now that all the TableDataInfo objects have been created for all the
20165 * extensions, check their FK dependencies and register them to try and
20166 * dump the data out in an order that they can be restored in.
20167 *
20168 * Note that this is not a problem for user tables as their FKs are
20169 * recreated after the data has been loaded.
20170 */
20171
20172 query = createPQExpBuffer();
20173
20174 printfPQExpBuffer(query,
20175 "SELECT conrelid, confrelid "
20176 "FROM pg_constraint "
20177 "JOIN pg_depend ON (objid = confrelid) "
20178 "WHERE contype = 'f' "
20179 "AND refclassid = 'pg_extension'::regclass "
20180 "AND classid = 'pg_class'::regclass;");
20181
20182 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
20183 ntups = PQntuples(res);
20184
20185 i_conrelid = PQfnumber(res, "conrelid");
20186 i_confrelid = PQfnumber(res, "confrelid");
20187
20188 /* Now get the dependencies and register them */
20189 for (i = 0; i < ntups; i++)
20190 {
20191 Oid conrelid,
20192 confrelid;
20194 *contable;
20195
20196 conrelid = atooid(PQgetvalue(res, i, i_conrelid));
20197 confrelid = atooid(PQgetvalue(res, i, i_confrelid));
20198 contable = findTableByOid(conrelid);
20199 reftable = findTableByOid(confrelid);
20200
20201 if (reftable == NULL ||
20202 reftable->dataObj == NULL ||
20203 contable == NULL ||
20204 contable->dataObj == NULL)
20205 continue;
20206
20207 /*
20208 * Make referencing TABLE_DATA object depend on the referenced table's
20209 * TABLE_DATA object.
20210 */
20211 addObjectDependency(&contable->dataObj->dobj,
20212 reftable->dataObj->dobj.dumpId);
20213 }
20214 PQclear(res);
20215 destroyPQExpBuffer(query);
20216}
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:3039
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, Archive::dopt, DUMP_COMPONENT_DATA, DUMP_COMPONENT_DEFINITION, _dumpableObject::dumpId, ExecuteSqlQuery(), _extensionInfo::extconfig, extension_exclude_oids, extension_include_oids, fb(), findTableByOid(), fout, 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 10155 of file pg_dump.c.

10156{
10157 if (dopt->binary_upgrade)
10158 return true;
10159 if (tbinfo->attisdropped[colno])
10160 return false;
10161 return (tbinfo->attislocal[colno] || tbinfo->ispartition);
10162}

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