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{
450 Oid relid;
452 char *reltuples;
455 char relkind; /* 'r', 'm', 'i', etc */
456
457 /*
458 * indAttNames/nindAttNames are populated only if the relation is an index
459 * with at least one expression column; we don't need them otherwise.
460 */
461 char **indAttNames; /* attnames of the index, in order */
462 int32 nindAttNames; /* number of attnames stored (can be 0) */
463 teSection section; /* stats may appear in data or post-data */
465
466typedef struct _statsExtInfo
467{
469 const char *rolname; /* owner */
470 TableInfo *stattable; /* link to table the stats are for */
471 int stattarget; /* statistics target */
473
474typedef struct _ruleInfo
475{
477 TableInfo *ruletable; /* link to table the rule is for */
478 char ev_type;
479 bool is_instead;
480 char ev_enabled;
481 bool separate; /* true if must dump as separate item */
482 /* separate is always true for non-ON SELECT rules */
483} RuleInfo;
484
485typedef struct _triggerInfo
486{
488 TableInfo *tgtable; /* link to table the trigger is for */
489 char tgenabled;
490 bool tgispartition;
491 char *tgdef;
493
494typedef struct _evttriggerInfo
495{
497 char *evtname;
498 char *evtevent;
499 const char *evtowner;
500 char *evttags;
501 char *evtfname;
502 char evtenabled;
504
505/*
506 * struct ConstraintInfo is used for all constraint types. However we
507 * use a different objType for foreign key constraints, to make it easier
508 * to sort them the way we want.
509 *
510 * Not-null constraints don't need this, unless they are NOT VALID.
511 *
512 * Note: condeferrable and condeferred are currently only valid for
513 * unique/primary-key constraints. Otherwise that info is in condef.
514 */
515typedef struct _constraintInfo
516{
518 TableInfo *contable; /* NULL if domain constraint */
519 TypeInfo *condomain; /* NULL if table constraint */
520 char contype;
521 char *condef; /* definition, if CHECK or FOREIGN KEY */
522 Oid confrelid; /* referenced table, if FOREIGN KEY */
523 DumpId conindex; /* identifies associated index if any */
524 bool condeferrable; /* true if constraint is DEFERRABLE */
525 bool condeferred; /* true if constraint is INITIALLY DEFERRED */
526 bool conperiod; /* true if the constraint is WITHOUT OVERLAPS */
527 bool conislocal; /* true if constraint has local definition */
528 bool separate; /* true if must dump as separate item */
530
531typedef struct _procLangInfo
532{
535 bool lanpltrusted;
539 const char *lanowner;
541
542typedef struct _castInfo
543{
548 char castcontext;
549 char castmethod;
550} CastInfo;
551
552typedef struct _transformInfo
553{
555 Oid trftype;
556 Oid trflang;
560
561/* InhInfo isn't a DumpableObject, just temporary state */
562typedef struct _inhInfo
563{
564 Oid inhrelid; /* OID of a child table */
565 Oid inhparent; /* OID of its parent */
566} InhInfo;
567
568typedef struct _prsInfo
569{
573 Oid prsend;
577
578typedef struct _dictInfo
579{
581 const char *rolname;
583 char *dictinitoption;
584} TSDictInfo;
585
586typedef struct _tmplInfo
587{
592
593typedef struct _cfgInfo
594{
596 const char *rolname;
599
600typedef struct _fdwInfo
601{
604 const char *rolname;
605 char *fdwhandler;
606 char *fdwvalidator;
607 char *fdwconnection;
608 char *fdwoptions;
609} FdwInfo;
610
611typedef struct _foreignServerInfo
612{
615 const char *rolname;
616 Oid srvfdw;
617 char *srvtype;
618 char *srvversion;
619 char *srvoptions;
621
622typedef struct _defaultACLInfo
623{
626 const char *defaclrole;
627 char defaclobjtype;
629
630/*
631 * LoInfo represents a group of large objects (blobs) that share the same
632 * owner and ACL setting. dobj.components has the DUMP_COMPONENT_COMMENT bit
633 * set if any blob in the group has a comment; similarly for sec labels.
634 * If there are many blobs with the same owner/ACL, we can divide them into
635 * multiple LoInfo groups, which will each spawn a BLOB METADATA and a BLOBS
636 * (data) TOC entry. This allows more parallelism during restore.
637 */
638typedef struct _loInfo
639{
642 const char *rolname;
643 int numlos;
645} LoInfo;
646
647/*
648 * The PolicyInfo struct is used to represent policies on a table and
649 * to indicate if a table has RLS enabled (ENABLE ROW SECURITY). If
650 * polname is NULL, then the record indicates ENABLE ROW SECURITY, while if
651 * it's non-NULL then this is a regular policy definition.
652 */
653typedef struct _policyInfo
654{
657 char *polname; /* null indicates RLS is enabled on rel */
658 char polcmd;
659 bool polpermissive;
660 char *polroles;
661 char *polqual;
662 char *polwithcheck;
663} PolicyInfo;
664
665/*
666 * The PublicationInfo struct is used to represent publications.
667 */
668typedef struct _PublicationInfo
669{
671 const char *rolname;
672 bool puballtables;
673 bool puballsequences;
674 bool pubinsert;
675 bool pubupdate;
676 bool pubdelete;
677 bool pubtruncate;
678 bool pubviaroot;
682
683/*
684 * The PublicationRelInfo struct is used to represent publication table
685 * mapping.
686 */
687typedef struct _PublicationRelInfo
688{
692 char *pubrelqual;
693 char *pubrattrs;
695
696/*
697 * The PublicationSchemaInfo struct is used to represent publication schema
698 * mapping.
699 */
700typedef struct _PublicationSchemaInfo
701{
706
707/*
708 * The SubscriptionInfo struct is used to represent subscription.
709 */
710typedef struct _SubscriptionInfo
711{
713 const char *rolname;
714 bool subenabled;
715 bool subbinary;
716 char substream;
717 char subtwophasestate;
718 bool subdisableonerr;
720 bool subrunasowner;
721 bool subfailover;
723 int submaxretention;
724 char *subservername;
725 char *subconninfo;
726 char *subslotname;
727 char *subsynccommit;
728 char *subwalrcvtimeout;
729 char *subpublications;
730 char *suborigin;
731 char *suboriginremotelsn;
733
734/*
735 * The SubRelInfo struct is used to represent a subscription relation.
736 *
737 * XXX Currently, the subscription tables are added to the subscription after
738 * enabling the subscription in binary-upgrade mode. As the apply workers will
739 * not be started in binary_upgrade mode the ordering of enable subscription
740 * does not matter. The order of adding the subscription tables to the
741 * subscription and enabling the subscription should be taken care of if this
742 * feature will be supported in a non-binary-upgrade mode in the future.
743 */
744typedef struct _SubRelInfo
745{
749 char srsubstate;
750 char *srsublsn;
751} SubRelInfo;
752
753/*
754 * common utility functions
755 */
756
758
759extern void AssignDumpId(DumpableObject *dobj);
760extern void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj);
761extern DumpId createDumpId(void);
762extern DumpId getMaxDumpId(void);
765extern void getDumpableObjects(DumpableObject ***objs, int *numObjs);
766
769
770extern TableInfo *findTableByOid(Oid oid);
771extern TypeInfo *findTypeByOid(Oid oid);
772extern FuncInfo *findFuncByOid(Oid oid);
773extern OprInfo *findOprByOid(Oid oid);
775extern CollInfo *findCollationByOid(Oid oid);
780
781extern void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext);
783
784extern void parseOidArray(const char *str, Oid *array, int arraysize);
785
789
790/*
791 * version specific routines
792 */
793extern void getNamespaces(Archive *fout);
795extern void getTypes(Archive *fout);
796extern void getFuncs(Archive *fout);
797extern void getAggregates(Archive *fout);
798extern void getOperators(Archive *fout);
799extern void getAccessMethods(Archive *fout);
800extern void getOpclasses(Archive *fout);
801extern void getOpfamilies(Archive *fout);
802extern void getCollations(Archive *fout);
803extern void getConversions(Archive *fout);
805extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
807extern void getPartitioningInfo(Archive *fout);
808extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
810extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
811extern void getRules(Archive *fout);
812extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
813extern void getProcLangs(Archive *fout);
814extern void getCasts(Archive *fout);
815extern void getTransforms(Archive *fout);
816extern void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables);
817extern bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno);
818extern void getTSParsers(Archive *fout);
819extern void getTSDictionaries(Archive *fout);
820extern void getTSTemplates(Archive *fout);
821extern void getTSConfigurations(Archive *fout);
823extern void getForeignServers(Archive *fout);
824extern void getDefaultACLs(Archive *fout);
826 int numExtensions);
828 int numExtensions);
829extern void getEventTriggers(Archive *fout);
830extern void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables);
831extern void getPublications(Archive *fout);
833extern void getPublicationTables(Archive *fout, TableInfo tblinfo[],
834 int numTables);
835extern void getSubscriptions(Archive *fout);
837
838#endif /* PG_DUMP_H */
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:558
int32_t int32
Definition c.h:620
uint32_t uint32
Definition c.h:624
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:8388
struct _collInfo CollInfo
void recordAdditionalCatalogID(CatalogId catId, DumpableObject *dobj)
Definition common.c:720
struct _transformInfo TransformInfo
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6215
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition common.c:1064
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4804
struct _opfamilyInfo OpfamilyInfo
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7877
struct _indxInfo IndxInfo
struct _fdwInfo FdwInfo
struct _triggerInfo TriggerInfo
struct _tmplInfo TSTemplateInfo
struct _tableInfo TableInfo
FuncInfo * findFuncByOid(Oid oid)
Definition common.c:919
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7821
TableInfo * findTableByOid(Oid oid)
Definition common.c:864
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10519
struct _aggInfo AggInfo
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4226
ExtensionInfo * findExtensionByOid(Oid oid)
Definition common.c:1009
struct _castInfo CastInfo
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20195
CollInfo * findCollationByOid(Oid oid)
Definition common.c:973
struct _tableDataInfo TableDataInfo
struct _cfgInfo TSConfigInfo
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition common.c:1045
void getTypes(Archive *fout)
Definition pg_dump.c:6290
struct _dumpableObject DumpableObject
struct _accessMethodInfo AccessMethodInfo
struct _attrDefInfo AttrDefInfo
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7756
void getOpclasses(Archive *fout)
Definition pg_dump.c:6736
void getForeignServers(Archive *fout)
Definition pg_dump.c:10613
void getFuncs(Archive *fout)
Definition pg_dump.c:7005
OprInfo * findOprByOid(Oid oid)
Definition common.c:937
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10335
struct _ruleInfo RuleInfo
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4884
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition common.c:991
struct _relStatsInfo RelStatsInfo
void getCasts(Archive *fout)
Definition pg_dump.c:9137
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7937
AccessMethodInfo * findAccessMethodByOid(Oid oid)
Definition common.c:955
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:819
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10460
DumpableObject * findObjectByDumpId(DumpId dumpId)
Definition common.c:766
struct _foreignServerInfo ForeignServerInfo
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition common.c:1112
struct _inhInfo InhInfo
struct _indexAttachInfo IndexAttachInfo
struct _SubRelInfo SubRelInfo
struct _procLangInfo ProcLangInfo
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6662
void getConversions(Archive *fout)
Definition pg_dump.c:6600
void getRules(Archive *fout)
Definition pg_dump.c:8682
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition common.c:1088
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9331
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:6534
struct _namespaceInfo NamespaceInfo
void getAggregates(Archive *fout)
Definition pg_dump.c:6864
struct _shellTypeInfo ShellTypeInfo
void getNamespaces(Archive *fout)
Definition pg_dump.c:6083
void getPublications(Archive *fout)
Definition pg_dump.c:4516
void getTSParsers(Archive *fout)
Definition pg_dump.c:10261
TypeInfo * findTypeByOid(Oid oid)
Definition common.c:900
struct _dumpableObjectWithAcl DumpableObjectWithAcl
struct _defaultACLInfo DefaultACLInfo
DumpId createDumpId(void)
Definition common.c:746
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7278
struct _loInfo LoInfo
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition common.c:779
void AssignDumpId(DumpableObject *dobj)
Definition common.c:658
struct _evttriggerInfo EventTriggerInfo
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8306
struct _dumpableAcl DumpableAcl
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20288
DumpId getMaxDumpId(void)
Definition common.c:755
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10701
uint32 DumpComponents
Definition pg_dump.h:107
struct _typeInfo TypeInfo
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5159
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:798
struct _statsExtInfo StatsExtInfo
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8779
void getTransforms(Archive *fout)
Definition pg_dump.c:9247
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8975
DumpableObjectType
Definition pg_dump.h:39
struct _PublicationRelInfo PublicationRelInfo
PublicationInfo * findPublicationByOid(Oid oid)
Definition common.c:1027
void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
struct _convInfo ConvInfo
struct _constraintInfo ConstraintInfo
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10401
void getProcLangs(Archive *fout)
Definition pg_dump.c:9053
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10246
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5408
struct _tableAttachInfo TableAttachInfo
void removeObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:844
void getOperators(Archive *fout)
Definition pg_dump.c:6458
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6799
struct _oprInfo OprInfo
struct _PublicationSchemaInfo PublicationSchemaInfo
static Archive * fout
Definition pg_dumpall.c:139
unsigned int Oid
static int fb(int x)
const char * rolname
Definition pg_dump.h:672
SimplePtrList except_tables
Definition pg_dump.h:681
bool puballsequences
Definition pg_dump.h:674
PublishGencolsType pubgencols_type
Definition pg_dump.h:680
DumpableObject dobj
Definition pg_dump.h:671
TableInfo * pubtable
Definition pg_dump.h:692
PublicationInfo * publication
Definition pg_dump.h:691
DumpableObject dobj
Definition pg_dump.h:690
NamespaceInfo * pubschema
Definition pg_dump.h:705
DumpableObject dobj
Definition pg_dump.h:703
PublicationInfo * publication
Definition pg_dump.h:704
DumpableObject dobj
Definition pg_dump.h:747
char * srsublsn
Definition pg_dump.h:751
SubscriptionInfo * subinfo
Definition pg_dump.h:748
TableInfo * tblinfo
Definition pg_dump.h:749
char srsubstate
Definition pg_dump.h:750
char * suboriginremotelsn
Definition pg_dump.h:732
bool subpasswordrequired
Definition pg_dump.h:720
const char * rolname
Definition pg_dump.h:714
char * subservername
Definition pg_dump.h:725
char * subsynccommit
Definition pg_dump.h:728
char * subpublications
Definition pg_dump.h:730
char * subwalrcvtimeout
Definition pg_dump.h:729
char * subslotname
Definition pg_dump.h:727
char subtwophasestate
Definition pg_dump.h:718
bool subretaindeadtuples
Definition pg_dump.h:723
char * subconninfo
Definition pg_dump.h:726
DumpableObject dobj
Definition pg_dump.h:713
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:550
Oid casttarget
Definition pg_dump.h:547
char castcontext
Definition pg_dump.h:549
DumpableObject dobj
Definition pg_dump.h:545
Oid castsource
Definition pg_dump.h:546
Oid castfunc
Definition pg_dump.h:548
Oid cfgparser
Definition pg_dump.h:598
DumpableObject dobj
Definition pg_dump.h:596
const char * rolname
Definition pg_dump.h:597
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:520
TableInfo * contable
Definition pg_dump.h:519
DumpableObject dobj
Definition pg_dump.h:518
DumpId conindex
Definition pg_dump.h:524
bool condeferrable
Definition pg_dump.h:525
char * condef
Definition pg_dump.h:522
DumpableObject dobj
Definition pg_dump.h:298
const char * rolname
Definition pg_dump.h:299
DumpableObject dobj
Definition pg_dump.h:625
DumpableAcl dacl
Definition pg_dump.h:626
const char * defaclrole
Definition pg_dump.h:627
char defaclobjtype
Definition pg_dump.h:628
char * dictinitoption
Definition pg_dump.h:584
DumpableObject dobj
Definition pg_dump.h:581
const char * rolname
Definition pg_dump.h:582
Oid dicttemplate
Definition pg_dump.h:583
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:499
char * evtfname
Definition pg_dump.h:502
char * evtname
Definition pg_dump.h:498
const char * evtowner
Definition pg_dump.h:500
char * evttags
Definition pg_dump.h:501
DumpableObject dobj
Definition pg_dump.h:497
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:606
const char * rolname
Definition pg_dump.h:605
char * fdwvalidator
Definition pg_dump.h:607
char * fdwoptions
Definition pg_dump.h:609
DumpableAcl dacl
Definition pg_dump.h:604
char * fdwconnection
Definition pg_dump.h:608
DumpableObject dobj
Definition pg_dump.h:603
DumpableAcl dacl
Definition pg_dump.h:615
DumpableObject dobj
Definition pg_dump.h:614
const char * rolname
Definition pg_dump.h:616
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:566
Oid inhrelid
Definition pg_dump.h:565
const char * rolname
Definition pg_dump.h:643
DumpableObject dobj
Definition pg_dump.h:641
DumpableAcl dacl
Definition pg_dump.h:642
Oid looids[FLEXIBLE_ARRAY_MEMBER]
Definition pg_dump.h:645
int numlos
Definition pg_dump.h:644
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:657
char * polqual
Definition pg_dump.h:662
char polcmd
Definition pg_dump.h:659
char * polroles
Definition pg_dump.h:661
char * polwithcheck
Definition pg_dump.h:663
DumpableObject dobj
Definition pg_dump.h:656
bool polpermissive
Definition pg_dump.h:660
char * polname
Definition pg_dump.h:658
Oid lanvalidator
Definition pg_dump.h:539
DumpableAcl dacl
Definition pg_dump.h:535
DumpableObject dobj
Definition pg_dump.h:534
const char * lanowner
Definition pg_dump.h:540
Oid lanplcallfoid
Definition pg_dump.h:537
bool lanpltrusted
Definition pg_dump.h:536
DumpableObject dobj
Definition pg_dump.h:571
Oid prstoken
Definition pg_dump.h:573
Oid prslextype
Definition pg_dump.h:576
Oid prsheadline
Definition pg_dump.h:575
Oid prsstart
Definition pg_dump.h:572
Oid prsend
Definition pg_dump.h:574
int32 nindAttNames
Definition pg_dump.h:463
char ** indAttNames
Definition pg_dump.h:462
int32 relpages
Definition pg_dump.h:452
int32 relallfrozen
Definition pg_dump.h:455
char * reltuples
Definition pg_dump.h:453
teSection section
Definition pg_dump.h:464
int32 relallvisible
Definition pg_dump.h:454
DumpableObject dobj
Definition pg_dump.h:450
DumpableObject dobj
Definition pg_dump.h:477
bool separate
Definition pg_dump.h:482
char ev_enabled
Definition pg_dump.h:481
bool is_instead
Definition pg_dump.h:480
TableInfo * ruletable
Definition pg_dump.h:478
char ev_type
Definition pg_dump.h:479
TypeInfo * baseType
Definition pg_dump.h:236
DumpableObject dobj
Definition pg_dump.h:234
TableInfo * stattable
Definition pg_dump.h:471
const char * rolname
Definition pg_dump.h:470
DumpableObject dobj
Definition pg_dump.h:469
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:591
Oid tmplinit
Definition pg_dump.h:590
DumpableObject dobj
Definition pg_dump.h:589
DumpableObject dobj
Definition pg_dump.h:555
TableInfo * tgtable
Definition pg_dump.h:489
DumpableObject dobj
Definition pg_dump.h:488
char tgenabled
Definition pg_dump.h:490
char * tgdef
Definition pg_dump.h:492
bool tgispartition
Definition pg_dump.h:491
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 658 of file common.c.

659{
660 dobj->dumpId = ++lastDumpId;
661 dobj->name = NULL; /* must be set later */
662 dobj->namespace = NULL; /* may be set later */
663 dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
664 dobj->dump_contains = DUMP_COMPONENT_ALL; /* default assumption */
665 /* All objects have definitions; we may set more components bits later */
667 dobj->ext_member = false; /* default assumption */
668 dobj->depends_on_ext = false; /* default assumption */
669 dobj->dependencies = NULL;
670 dobj->nDeps = 0;
671 dobj->allocDeps = 0;
672
673 /* Add object to dumpIdMap[], enlarging that array if need be */
674 while (dobj->dumpId >= allocedDumpIds)
675 {
676 int newAlloc;
677
678 if (allocedDumpIds <= 0)
679 {
680 newAlloc = 256;
682 }
683 else
684 {
687 }
689 (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
691 }
692 dumpIdMap[dobj->dumpId] = dobj;
693
694 /* If it has a valid CatalogId, enter it into the hash table */
695 if (OidIsValid(dobj->catId.tableoid))
696 {
697 CatalogIdMapEntry *entry;
698 bool found;
699
700 /* Initialize CatalogId hash table if not done yet */
701 if (catalogIdHash == NULL)
703
704 entry = catalogid_insert(catalogIdHash, dobj->catId, &found);
705 if (!found)
706 {
707 entry->dobj = NULL;
708 entry->ext = NULL;
709 }
710 Assert(entry->dobj == NULL);
711 entry->dobj = dobj;
712 }
713}
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:943
#define OidIsValid(objectId)
Definition c.h:858
#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 955 of file common.c.

956{
957 CatalogId catId;
958 DumpableObject *dobj;
959
961 catId.oid = oid;
962 dobj = findObjectByCatalogId(catId);
963 Assert(dobj == NULL || dobj->objType == DO_ACCESS_METHOD);
964 return (AccessMethodInfo *) dobj;
965}
DumpableObject * findObjectByCatalogId(CatalogId catalogId)
Definition common.c:779
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 973 of file common.c.

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

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 1009 of file common.c.

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

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 919 of file common.c.

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

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 991 of file common.c.

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

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 766 of file common.c.

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

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 937 of file common.c.

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

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 1088 of file common.c.

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

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

Referenced by checkExtensionMembership().

◆ findPublicationByOid()

PublicationInfo * findPublicationByOid ( Oid  oid)
extern

Definition at line 1027 of file common.c.

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

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 1045 of file common.c.

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

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 6662 of file pg_dump.c.

6663{
6664 PGresult *res;
6665 int ntups;
6666 int i;
6667 PQExpBuffer query;
6669 int i_tableoid;
6670 int i_oid;
6671 int i_amname;
6672 int i_amhandler;
6673 int i_amtype;
6674
6675 query = createPQExpBuffer();
6676
6677 /*
6678 * Select all access methods from pg_am table. v9.6 introduced CREATE
6679 * ACCESS METHOD, so earlier versions usually have only built-in access
6680 * methods. v9.6 also changed the access method API, replacing dozens of
6681 * pg_am columns with amhandler. Even if a user created an access method
6682 * by "INSERT INTO pg_am", we have no way to translate pre-v9.6 pg_am
6683 * columns to a v9.6+ CREATE ACCESS METHOD. Hence, before v9.6, read
6684 * pg_am just to facilitate findAccessMethodByOid() providing the
6685 * OID-to-name mapping.
6686 */
6687 appendPQExpBufferStr(query, "SELECT tableoid, oid, amname, ");
6688 if (fout->remoteVersion >= 90600)
6690 "amtype, "
6691 "amhandler::pg_catalog.regproc AS amhandler ");
6692 else
6694 "'i'::pg_catalog.\"char\" AS amtype, "
6695 "'-'::pg_catalog.regproc AS amhandler ");
6696 appendPQExpBufferStr(query, "FROM pg_am");
6697
6698 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6699
6700 ntups = PQntuples(res);
6701
6703
6704 i_tableoid = PQfnumber(res, "tableoid");
6705 i_oid = PQfnumber(res, "oid");
6706 i_amname = PQfnumber(res, "amname");
6707 i_amhandler = PQfnumber(res, "amhandler");
6708 i_amtype = PQfnumber(res, "amtype");
6709
6710 for (i = 0; i < ntups; i++)
6711 {
6712 aminfo[i].dobj.objType = DO_ACCESS_METHOD;
6713 aminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6714 aminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6715 AssignDumpId(&aminfo[i].dobj);
6716 aminfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_amname));
6717 aminfo[i].dobj.namespace = NULL;
6718 aminfo[i].amhandler = pg_strdup(PQgetvalue(res, i, i_amhandler));
6719 aminfo[i].amtype = *(PQgetvalue(res, i, i_amtype));
6720
6721 /* Decide whether we want to dump it */
6723 }
6724
6725 PQclear(res);
6726
6727 destroyPQExpBuffer(query);
6728}
void AssignDumpId(DumpableObject *dobj)
Definition common.c:658
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:134
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
static void selectDumpableAccessMethod(AccessMethodInfo *method, Archive *fout)
Definition pg_dump.c:2232
#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 6864 of file pg_dump.c.

6865{
6866 DumpOptions *dopt = fout->dopt;
6867 PGresult *res;
6868 int ntups;
6869 int i;
6872 int i_tableoid;
6873 int i_oid;
6874 int i_aggname;
6875 int i_aggnamespace;
6876 int i_pronargs;
6877 int i_proargtypes;
6878 int i_proowner;
6879 int i_aggacl;
6880 int i_acldefault;
6881
6882 /*
6883 * Find all interesting aggregates. See comment in getFuncs() for the
6884 * rationale behind the filtering logic.
6885 */
6886 if (fout->remoteVersion >= 90600)
6887 {
6888 const char *agg_check;
6889
6890 agg_check = (fout->remoteVersion >= 110000 ? "p.prokind = 'a'"
6891 : "p.proisagg");
6892
6893 appendPQExpBuffer(query, "SELECT p.tableoid, p.oid, "
6894 "p.proname AS aggname, "
6895 "p.pronamespace AS aggnamespace, "
6896 "p.pronargs, p.proargtypes, "
6897 "p.proowner, "
6898 "p.proacl AS aggacl, "
6899 "acldefault('f', p.proowner) AS acldefault "
6900 "FROM pg_proc p "
6901 "LEFT JOIN pg_init_privs pip ON "
6902 "(p.oid = pip.objoid "
6903 "AND pip.classoid = 'pg_proc'::regclass "
6904 "AND pip.objsubid = 0) "
6905 "WHERE %s AND ("
6906 "p.pronamespace != "
6907 "(SELECT oid FROM pg_namespace "
6908 "WHERE nspname = 'pg_catalog') OR "
6909 "p.proacl IS DISTINCT FROM pip.initprivs",
6910 agg_check);
6911 if (dopt->binary_upgrade)
6913 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6914 "classid = 'pg_proc'::regclass AND "
6915 "objid = p.oid AND "
6916 "refclassid = 'pg_extension'::regclass AND "
6917 "deptype = 'e')");
6918 appendPQExpBufferChar(query, ')');
6919 }
6920 else
6921 {
6922 appendPQExpBufferStr(query, "SELECT tableoid, oid, proname AS aggname, "
6923 "pronamespace AS aggnamespace, "
6924 "pronargs, proargtypes, "
6925 "proowner, "
6926 "proacl AS aggacl, "
6927 "acldefault('f', proowner) AS acldefault "
6928 "FROM pg_proc p "
6929 "WHERE proisagg AND ("
6930 "pronamespace != "
6931 "(SELECT oid FROM pg_namespace "
6932 "WHERE nspname = 'pg_catalog')");
6933 if (dopt->binary_upgrade)
6935 " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
6936 "classid = 'pg_proc'::regclass AND "
6937 "objid = p.oid AND "
6938 "refclassid = 'pg_extension'::regclass AND "
6939 "deptype = 'e')");
6940 appendPQExpBufferChar(query, ')');
6941 }
6942
6943 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6944
6945 ntups = PQntuples(res);
6946
6948
6949 i_tableoid = PQfnumber(res, "tableoid");
6950 i_oid = PQfnumber(res, "oid");
6951 i_aggname = PQfnumber(res, "aggname");
6952 i_aggnamespace = PQfnumber(res, "aggnamespace");
6953 i_pronargs = PQfnumber(res, "pronargs");
6954 i_proargtypes = PQfnumber(res, "proargtypes");
6955 i_proowner = PQfnumber(res, "proowner");
6956 i_aggacl = PQfnumber(res, "aggacl");
6957 i_acldefault = PQfnumber(res, "acldefault");
6958
6959 for (i = 0; i < ntups; i++)
6960 {
6961 agginfo[i].aggfn.dobj.objType = DO_AGG;
6962 agginfo[i].aggfn.dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6963 agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6964 AssignDumpId(&agginfo[i].aggfn.dobj);
6965 agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
6966 agginfo[i].aggfn.dobj.namespace =
6968 agginfo[i].aggfn.dacl.acl = pg_strdup(PQgetvalue(res, i, i_aggacl));
6969 agginfo[i].aggfn.dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6970 agginfo[i].aggfn.dacl.privtype = 0;
6971 agginfo[i].aggfn.dacl.initprivs = NULL;
6972 agginfo[i].aggfn.rolname = getRoleName(PQgetvalue(res, i, i_proowner));
6973 agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
6974 agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
6975 agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
6976 if (agginfo[i].aggfn.nargs == 0)
6977 agginfo[i].aggfn.argtypes = NULL;
6978 else
6979 {
6980 agginfo[i].aggfn.argtypes = pg_malloc_array(Oid, agginfo[i].aggfn.nargs);
6982 agginfo[i].aggfn.argtypes,
6983 agginfo[i].aggfn.nargs);
6984 }
6985 agginfo[i].aggfn.postponed_def = false; /* might get set during sort */
6986
6987 /* Decide whether we want to dump it */
6988 selectDumpableObject(&(agginfo[i].aggfn.dobj), fout);
6989
6990 /* Mark whether aggregate has an ACL */
6991 if (!PQgetisnull(res, i, i_aggacl))
6992 agginfo[i].aggfn.dobj.components |= DUMP_COMPONENT_ACL;
6993 }
6994
6995 PQclear(res);
6996
6997 destroyPQExpBuffer(query);
6998}
void parseOidArray(const char *str, Oid *array, int arraysize)
Definition common.c:1112
#define PQgetisnull
static const char * getRoleName(const char *roleoid_str)
Definition pg_dump.c:10798
static void selectDumpableObject(DumpableObject *dobj, Archive *fout)
Definition pg_dump.c:2342
static NamespaceInfo * findNamespace(Oid nsoid)
Definition pg_dump.c:6197
#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 9137 of file pg_dump.c.

9138{
9139 PGresult *res;
9140 int ntups;
9141 int i;
9144 int i_tableoid;
9145 int i_oid;
9146 int i_castsource;
9147 int i_casttarget;
9148 int i_castfunc;
9149 int i_castcontext;
9150 int i_castmethod;
9151
9152 if (fout->remoteVersion >= 140000)
9153 {
9154 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9155 "castsource, casttarget, castfunc, castcontext, "
9156 "castmethod "
9157 "FROM pg_cast c "
9158 "WHERE NOT EXISTS ( "
9159 "SELECT 1 FROM pg_range r "
9160 "WHERE c.castsource = r.rngtypid "
9161 "AND c.casttarget = r.rngmultitypid "
9162 ") "
9163 "ORDER BY 3,4");
9164 }
9165 else
9166 {
9167 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9168 "castsource, casttarget, castfunc, castcontext, "
9169 "castmethod "
9170 "FROM pg_cast ORDER BY 3,4");
9171 }
9172
9173 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9174
9175 ntups = PQntuples(res);
9176
9178
9179 i_tableoid = PQfnumber(res, "tableoid");
9180 i_oid = PQfnumber(res, "oid");
9181 i_castsource = PQfnumber(res, "castsource");
9182 i_casttarget = PQfnumber(res, "casttarget");
9183 i_castfunc = PQfnumber(res, "castfunc");
9184 i_castcontext = PQfnumber(res, "castcontext");
9185 i_castmethod = PQfnumber(res, "castmethod");
9186
9187 for (i = 0; i < ntups; i++)
9188 {
9192
9194 castinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9195 castinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9196 AssignDumpId(&castinfo[i].dobj);
9197 castinfo[i].castsource = atooid(PQgetvalue(res, i, i_castsource));
9198 castinfo[i].casttarget = atooid(PQgetvalue(res, i, i_casttarget));
9199 castinfo[i].castfunc = atooid(PQgetvalue(res, i, i_castfunc));
9200 castinfo[i].castcontext = *(PQgetvalue(res, i, i_castcontext));
9201 castinfo[i].castmethod = *(PQgetvalue(res, i, i_castmethod));
9202
9203 /*
9204 * Try to name cast as concatenation of typnames. This is only used
9205 * for purposes of sorting. If we fail to find either type, the name
9206 * will be an empty string.
9207 */
9209 sTypeInfo = findTypeByOid(castinfo[i].castsource);
9210 tTypeInfo = findTypeByOid(castinfo[i].casttarget);
9211 if (sTypeInfo && tTypeInfo)
9212 appendPQExpBuffer(&namebuf, "%s %s",
9213 sTypeInfo->dobj.name, tTypeInfo->dobj.name);
9214 castinfo[i].dobj.name = namebuf.data;
9215
9216 /* Decide whether we want to dump it */
9218 }
9219
9220 PQclear(res);
9221
9222 destroyPQExpBuffer(query);
9223}
TypeInfo * findTypeByOid(Oid oid)
Definition common.c:900
static void selectDumpableCast(CastInfo *cast, Archive *fout)
Definition pg_dump.c:2174
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 6534 of file pg_dump.c.

6535{
6536 PGresult *res;
6537 int ntups;
6538 int i;
6539 PQExpBuffer query;
6541 int i_tableoid;
6542 int i_oid;
6543 int i_collname;
6544 int i_collnamespace;
6545 int i_collowner;
6546 int i_collencoding;
6547
6548 query = createPQExpBuffer();
6549
6550 /*
6551 * find all collations, including builtin collations; we filter out
6552 * system-defined collations at dump-out time.
6553 */
6554
6555 appendPQExpBufferStr(query, "SELECT tableoid, oid, collname, "
6556 "collnamespace, "
6557 "collowner, "
6558 "collencoding "
6559 "FROM pg_collation");
6560
6561 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6562
6563 ntups = PQntuples(res);
6564
6566
6567 i_tableoid = PQfnumber(res, "tableoid");
6568 i_oid = PQfnumber(res, "oid");
6569 i_collname = PQfnumber(res, "collname");
6570 i_collnamespace = PQfnumber(res, "collnamespace");
6571 i_collowner = PQfnumber(res, "collowner");
6572 i_collencoding = PQfnumber(res, "collencoding");
6573
6574 for (i = 0; i < ntups; i++)
6575 {
6576 collinfo[i].dobj.objType = DO_COLLATION;
6577 collinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6578 collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6579 AssignDumpId(&collinfo[i].dobj);
6580 collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
6581 collinfo[i].dobj.namespace =
6583 collinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_collowner));
6584 collinfo[i].collencoding = atoi(PQgetvalue(res, i, i_collencoding));
6585
6586 /* Decide whether we want to dump it */
6588 }
6589
6590 PQclear(res);
6591
6592 destroyPQExpBuffer(query);
6593}

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 8388 of file pg_dump.c.

8389{
8392 PGresult *res;
8393 int ntups;
8394 int curtblindx;
8397 int i_contableoid,
8398 i_conoid,
8399 i_conrelid,
8400 i_conname,
8402 i_conindid,
8403 i_condef;
8404
8405 /*
8406 * We want to perform just one query against pg_constraint. However, we
8407 * mustn't try to select every row of the catalog and then sort it out on
8408 * the client side, because some of the server-side functions we need
8409 * would be unsafe to apply to tables we don't have lock on. Hence, we
8410 * build an array of the OIDs of tables we care about (and now have lock
8411 * on!), and use a WHERE clause to constrain which rows are selected.
8412 */
8414 for (int i = 0; i < numTables; i++)
8415 {
8416 TableInfo *tinfo = &tblinfo[i];
8417
8418 if (!(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8419 continue;
8420
8421 /* OK, we need info for this table */
8422 if (tbloids->len > 1) /* do we have more than the '{'? */
8424 appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
8425 }
8427
8429 "SELECT c.tableoid, c.oid, "
8430 "conrelid, conname, confrelid, ");
8431 if (fout->remoteVersion >= 110000)
8432 appendPQExpBufferStr(query, "conindid, ");
8433 else
8434 appendPQExpBufferStr(query, "0 AS conindid, ");
8435 appendPQExpBuffer(query,
8436 "pg_catalog.pg_get_constraintdef(c.oid) AS condef\n"
8437 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8438 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
8439 "WHERE contype = 'f' ",
8440 tbloids->data);
8441 if (fout->remoteVersion >= 110000)
8443 "AND conparentid = 0 ");
8445 "ORDER BY conrelid, conname");
8446
8447 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8448
8449 ntups = PQntuples(res);
8450
8451 i_contableoid = PQfnumber(res, "tableoid");
8452 i_conoid = PQfnumber(res, "oid");
8453 i_conrelid = PQfnumber(res, "conrelid");
8454 i_conname = PQfnumber(res, "conname");
8455 i_confrelid = PQfnumber(res, "confrelid");
8456 i_conindid = PQfnumber(res, "conindid");
8457 i_condef = PQfnumber(res, "condef");
8458
8460
8461 curtblindx = -1;
8462 for (int j = 0; j < ntups; j++)
8463 {
8464 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
8466
8467 /*
8468 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8469 * order.
8470 */
8471 if (tbinfo == NULL || tbinfo->dobj.catId.oid != conrelid)
8472 {
8473 while (++curtblindx < numTables)
8474 {
8475 tbinfo = &tblinfo[curtblindx];
8476 if (tbinfo->dobj.catId.oid == conrelid)
8477 break;
8478 }
8479 if (curtblindx >= numTables)
8480 pg_fatal("unrecognized table OID %u", conrelid);
8481 }
8482
8483 constrinfo[j].dobj.objType = DO_FK_CONSTRAINT;
8484 constrinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8485 constrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8486 AssignDumpId(&constrinfo[j].dobj);
8487 constrinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8488 constrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8489 constrinfo[j].contable = tbinfo;
8490 constrinfo[j].condomain = NULL;
8491 constrinfo[j].contype = 'f';
8492 constrinfo[j].condef = pg_strdup(PQgetvalue(res, j, i_condef));
8493 constrinfo[j].confrelid = atooid(PQgetvalue(res, j, i_confrelid));
8494 constrinfo[j].conindex = 0;
8495 constrinfo[j].condeferrable = false;
8496 constrinfo[j].condeferred = false;
8497 constrinfo[j].conislocal = true;
8498 constrinfo[j].separate = true;
8499
8500 /*
8501 * Restoring an FK that points to a partitioned table requires that
8502 * all partition indexes have been attached beforehand. Ensure that
8503 * happens by making the constraint depend on each index partition
8504 * attach object.
8505 */
8506 reftable = findTableByOid(constrinfo[j].confrelid);
8507 if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE)
8508 {
8509 Oid indexOid = atooid(PQgetvalue(res, j, i_conindid));
8510
8511 if (indexOid != InvalidOid)
8512 {
8513 for (int k = 0; k < reftable->numIndexes; k++)
8514 {
8516
8517 /* not our index? */
8518 if (reftable->indexes[k].dobj.catId.oid != indexOid)
8519 continue;
8520
8521 refidx = &reftable->indexes[k];
8523 break;
8524 }
8525 }
8526 }
8527 }
8528
8529 PQclear(res);
8530
8531 destroyPQExpBuffer(query);
8533}
TableInfo * findTableByOid(Oid oid)
Definition common.c:864
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:8547

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 6600 of file pg_dump.c.

6601{
6602 PGresult *res;
6603 int ntups;
6604 int i;
6605 PQExpBuffer query;
6607 int i_tableoid;
6608 int i_oid;
6609 int i_conname;
6610 int i_connamespace;
6611 int i_conowner;
6612
6613 query = createPQExpBuffer();
6614
6615 /*
6616 * find all conversions, including builtin conversions; we filter out
6617 * system-defined conversions at dump-out time.
6618 */
6619
6620 appendPQExpBufferStr(query, "SELECT tableoid, oid, conname, "
6621 "connamespace, "
6622 "conowner "
6623 "FROM pg_conversion");
6624
6625 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6626
6627 ntups = PQntuples(res);
6628
6630
6631 i_tableoid = PQfnumber(res, "tableoid");
6632 i_oid = PQfnumber(res, "oid");
6633 i_conname = PQfnumber(res, "conname");
6634 i_connamespace = PQfnumber(res, "connamespace");
6635 i_conowner = PQfnumber(res, "conowner");
6636
6637 for (i = 0; i < ntups; i++)
6638 {
6639 convinfo[i].dobj.objType = DO_CONVERSION;
6640 convinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6641 convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6642 AssignDumpId(&convinfo[i].dobj);
6643 convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
6644 convinfo[i].dobj.namespace =
6646 convinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_conowner));
6647
6648 /* Decide whether we want to dump it */
6650 }
6651
6652 PQclear(res);
6653
6654 destroyPQExpBuffer(query);
6655}

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 10701 of file pg_dump.c.

10702{
10703 DumpOptions *dopt = fout->dopt;
10705 PQExpBuffer query;
10706 PGresult *res;
10707 int i_oid;
10708 int i_tableoid;
10709 int i_defaclrole;
10711 int i_defaclobjtype;
10712 int i_defaclacl;
10713 int i_acldefault;
10714 int i,
10715 ntups;
10716
10717 query = createPQExpBuffer();
10718
10719 /*
10720 * Global entries (with defaclnamespace=0) replace the hard-wired default
10721 * ACL for their object type. We should dump them as deltas from the
10722 * default ACL, since that will be used as a starting point for
10723 * interpreting the ALTER DEFAULT PRIVILEGES commands. On the other hand,
10724 * non-global entries can only add privileges not revoke them. We must
10725 * dump those as-is (i.e., as deltas from an empty ACL).
10726 *
10727 * We can use defaclobjtype as the object type for acldefault(), except
10728 * for the case of 'S' (DEFACLOBJ_SEQUENCE) which must be converted to
10729 * 's'.
10730 */
10732 "SELECT oid, tableoid, "
10733 "defaclrole, "
10734 "defaclnamespace, "
10735 "defaclobjtype, "
10736 "defaclacl, "
10737 "CASE WHEN defaclnamespace = 0 THEN "
10738 "acldefault(CASE WHEN defaclobjtype = 'S' "
10739 "THEN 's'::\"char\" ELSE defaclobjtype END, "
10740 "defaclrole) ELSE '{}' END AS acldefault "
10741 "FROM pg_default_acl");
10742
10743 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10744
10745 ntups = PQntuples(res);
10746
10748
10749 i_oid = PQfnumber(res, "oid");
10750 i_tableoid = PQfnumber(res, "tableoid");
10751 i_defaclrole = PQfnumber(res, "defaclrole");
10752 i_defaclnamespace = PQfnumber(res, "defaclnamespace");
10753 i_defaclobjtype = PQfnumber(res, "defaclobjtype");
10754 i_defaclacl = PQfnumber(res, "defaclacl");
10755 i_acldefault = PQfnumber(res, "acldefault");
10756
10757 for (i = 0; i < ntups; i++)
10758 {
10760
10761 daclinfo[i].dobj.objType = DO_DEFAULT_ACL;
10762 daclinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10763 daclinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10764 AssignDumpId(&daclinfo[i].dobj);
10765 /* cheesy ... is it worth coming up with a better object name? */
10766 daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
10767
10768 if (nspid != InvalidOid)
10769 daclinfo[i].dobj.namespace = findNamespace(nspid);
10770 else
10771 daclinfo[i].dobj.namespace = NULL;
10772
10773 daclinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
10774 daclinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10775 daclinfo[i].dacl.privtype = 0;
10776 daclinfo[i].dacl.initprivs = NULL;
10777 daclinfo[i].defaclrole = getRoleName(PQgetvalue(res, i, i_defaclrole));
10778 daclinfo[i].defaclobjtype = *(PQgetvalue(res, i, i_defaclobjtype));
10779
10780 /* Default ACLs are ACLs, of course */
10781 daclinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10782
10783 /* Decide whether we want to dump it */
10785 }
10786
10787 PQclear(res);
10788
10789 destroyPQExpBuffer(query);
10790}
int nspid
static void selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt)
Definition pg_dump.c:2152

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 798 of file common.c.

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

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

Referenced by getTableDataFKConstraints(), and main().

◆ getEventTriggers()

void getEventTriggers ( Archive fout)
extern

Definition at line 8975 of file pg_dump.c.

8976{
8977 int i;
8978 PQExpBuffer query;
8979 PGresult *res;
8981 int i_tableoid,
8982 i_oid,
8983 i_evtname,
8984 i_evtevent,
8985 i_evtowner,
8986 i_evttags,
8987 i_evtfname,
8989 int ntups;
8990
8991 /* Before 9.3, there are no event triggers */
8992 if (fout->remoteVersion < 90300)
8993 return;
8994
8995 query = createPQExpBuffer();
8996
8998 "SELECT e.tableoid, e.oid, evtname, evtenabled, "
8999 "evtevent, evtowner, "
9000 "array_to_string(array("
9001 "select quote_literal(x) "
9002 " from unnest(evttags) as t(x)), ', ') as evttags, "
9003 "e.evtfoid::regproc as evtfname "
9004 "FROM pg_event_trigger e "
9005 "ORDER BY e.oid");
9006
9007 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9008
9009 ntups = PQntuples(res);
9010
9012
9013 i_tableoid = PQfnumber(res, "tableoid");
9014 i_oid = PQfnumber(res, "oid");
9015 i_evtname = PQfnumber(res, "evtname");
9016 i_evtevent = PQfnumber(res, "evtevent");
9017 i_evtowner = PQfnumber(res, "evtowner");
9018 i_evttags = PQfnumber(res, "evttags");
9019 i_evtfname = PQfnumber(res, "evtfname");
9020 i_evtenabled = PQfnumber(res, "evtenabled");
9021
9022 for (i = 0; i < ntups; i++)
9023 {
9024 evtinfo[i].dobj.objType = DO_EVENT_TRIGGER;
9025 evtinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9026 evtinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9027 AssignDumpId(&evtinfo[i].dobj);
9028 evtinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_evtname));
9029 evtinfo[i].evtname = pg_strdup(PQgetvalue(res, i, i_evtname));
9030 evtinfo[i].evtevent = pg_strdup(PQgetvalue(res, i, i_evtevent));
9031 evtinfo[i].evtowner = getRoleName(PQgetvalue(res, i, i_evtowner));
9032 evtinfo[i].evttags = pg_strdup(PQgetvalue(res, i, i_evttags));
9033 evtinfo[i].evtfname = pg_strdup(PQgetvalue(res, i, i_evtfname));
9034 evtinfo[i].evtenabled = *(PQgetvalue(res, i, i_evtenabled));
9035
9036 /* Decide whether we want to dump it */
9038 }
9039
9040 PQclear(res);
9041
9042 destroyPQExpBuffer(query);
9043}

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 8306 of file pg_dump.c.

8307{
8308 PQExpBuffer query;
8309 PGresult *res;
8311 int ntups;
8312 int i_tableoid;
8313 int i_oid;
8314 int i_stxname;
8315 int i_stxnamespace;
8316 int i_stxowner;
8317 int i_stxrelid;
8318 int i_stattarget;
8319 int i;
8320
8321 /* Extended statistics were new in v10 */
8322 if (fout->remoteVersion < 100000)
8323 return;
8324
8325 query = createPQExpBuffer();
8326
8327 if (fout->remoteVersion < 130000)
8328 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8329 "stxnamespace, stxowner, stxrelid, NULL AS stxstattarget "
8330 "FROM pg_catalog.pg_statistic_ext");
8331 else
8332 appendPQExpBufferStr(query, "SELECT tableoid, oid, stxname, "
8333 "stxnamespace, stxowner, stxrelid, stxstattarget "
8334 "FROM pg_catalog.pg_statistic_ext");
8335
8336 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8337
8338 ntups = PQntuples(res);
8339
8340 i_tableoid = PQfnumber(res, "tableoid");
8341 i_oid = PQfnumber(res, "oid");
8342 i_stxname = PQfnumber(res, "stxname");
8343 i_stxnamespace = PQfnumber(res, "stxnamespace");
8344 i_stxowner = PQfnumber(res, "stxowner");
8345 i_stxrelid = PQfnumber(res, "stxrelid");
8346 i_stattarget = PQfnumber(res, "stxstattarget");
8347
8349
8350 for (i = 0; i < ntups; i++)
8351 {
8352 statsextinfo[i].dobj.objType = DO_STATSEXT;
8353 statsextinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8354 statsextinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8355 AssignDumpId(&statsextinfo[i].dobj);
8356 statsextinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_stxname));
8357 statsextinfo[i].dobj.namespace =
8359 statsextinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_stxowner));
8360 statsextinfo[i].stattable =
8362 if (PQgetisnull(res, i, i_stattarget))
8363 statsextinfo[i].stattarget = -1;
8364 else
8365 statsextinfo[i].stattarget = atoi(PQgetvalue(res, i, i_stattarget));
8366
8367 /* Decide whether we want to dump it */
8369
8370 if (fout->dopt->dumpStatistics)
8371 statsextinfo[i].dobj.components |= DUMP_COMPONENT_STATISTICS;
8372 }
8373
8374 PQclear(res);
8375 destroyPQExpBuffer(query);
8376}
static void selectDumpableStatisticsObject(StatsExtInfo *sobj, Archive *fout)
Definition pg_dump.c:2324
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 20195 of file pg_dump.c.

20197{
20198 PQExpBuffer query;
20199 PGresult *res;
20200 int ntups,
20201 i;
20202 int i_classid,
20203 i_objid,
20204 i_refobjid;
20205 ExtensionInfo *ext;
20206
20207 /* Nothing to do if no extensions */
20208 if (numExtensions == 0)
20209 return;
20210
20211 query = createPQExpBuffer();
20212
20213 /* refclassid constraint is redundant but may speed the search */
20214 appendPQExpBufferStr(query, "SELECT "
20215 "classid, objid, refobjid "
20216 "FROM pg_depend "
20217 "WHERE refclassid = 'pg_extension'::regclass "
20218 "AND deptype = 'e' "
20219 "ORDER BY 3");
20220
20221 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
20222
20223 ntups = PQntuples(res);
20224
20225 i_classid = PQfnumber(res, "classid");
20226 i_objid = PQfnumber(res, "objid");
20227 i_refobjid = PQfnumber(res, "refobjid");
20228
20229 /*
20230 * Since we ordered the SELECT by referenced ID, we can expect that
20231 * multiple entries for the same extension will appear together; this
20232 * saves on searches.
20233 */
20234 ext = NULL;
20235
20236 for (i = 0; i < ntups; i++)
20237 {
20238 CatalogId objId;
20239 Oid extId;
20240
20241 objId.tableoid = atooid(PQgetvalue(res, i, i_classid));
20242 objId.oid = atooid(PQgetvalue(res, i, i_objid));
20244
20245 if (ext == NULL ||
20246 ext->dobj.catId.oid != extId)
20248
20249 if (ext == NULL)
20250 {
20251 /* shouldn't happen */
20252 pg_log_warning("could not find referenced extension %u", extId);
20253 continue;
20254 }
20255
20256 recordExtensionMembership(objId, ext);
20257 }
20258
20259 PQclear(res);
20260
20261 destroyPQExpBuffer(query);
20262}
void recordExtensionMembership(CatalogId catId, ExtensionInfo *ext)
Definition common.c:1064
ExtensionInfo * findExtensionByOid(Oid oid)
Definition common.c:1009
#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 6215 of file pg_dump.c.

6216{
6217 DumpOptions *dopt = fout->dopt;
6218 PGresult *res;
6219 int ntups;
6220 int i;
6221 PQExpBuffer query;
6223 int i_tableoid;
6224 int i_oid;
6225 int i_extname;
6226 int i_nspname;
6227 int i_extrelocatable;
6228 int i_extversion;
6229 int i_extconfig;
6230 int i_extcondition;
6231
6232 query = createPQExpBuffer();
6233
6234 appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
6235 "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
6236 "FROM pg_extension x "
6237 "JOIN pg_namespace n ON n.oid = x.extnamespace");
6238
6239 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6240
6241 ntups = PQntuples(res);
6242 if (ntups == 0)
6243 goto cleanup;
6244
6246
6247 i_tableoid = PQfnumber(res, "tableoid");
6248 i_oid = PQfnumber(res, "oid");
6249 i_extname = PQfnumber(res, "extname");
6250 i_nspname = PQfnumber(res, "nspname");
6251 i_extrelocatable = PQfnumber(res, "extrelocatable");
6252 i_extversion = PQfnumber(res, "extversion");
6253 i_extconfig = PQfnumber(res, "extconfig");
6254 i_extcondition = PQfnumber(res, "extcondition");
6255
6256 for (i = 0; i < ntups; i++)
6257 {
6258 extinfo[i].dobj.objType = DO_EXTENSION;
6259 extinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6260 extinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6261 AssignDumpId(&extinfo[i].dobj);
6262 extinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_extname));
6263 extinfo[i].namespace = pg_strdup(PQgetvalue(res, i, i_nspname));
6264 extinfo[i].relocatable = *(PQgetvalue(res, i, i_extrelocatable)) == 't';
6265 extinfo[i].extversion = pg_strdup(PQgetvalue(res, i, i_extversion));
6266 extinfo[i].extconfig = pg_strdup(PQgetvalue(res, i, i_extconfig));
6267 extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
6268
6269 /* Decide whether we want to dump it */
6271 }
6272
6273cleanup:
6274 PQclear(res);
6275 destroyPQExpBuffer(query);
6276
6277 *numExtensions = ntups;
6278
6279 return extinfo;
6280}
static void cleanup(void)
Definition bootstrap.c:886
static void selectDumpableExtension(ExtensionInfo *extinfo, DumpOptions *dopt)
Definition pg_dump.c:2267

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 10519 of file pg_dump.c.

10520{
10521 PGresult *res;
10522 int ntups;
10523 int i;
10524 PQExpBuffer query;
10526 int i_tableoid;
10527 int i_oid;
10528 int i_fdwname;
10529 int i_fdwowner;
10530 int i_fdwhandler;
10531 int i_fdwvalidator;
10532 int i_fdwconnection;
10533 int i_fdwacl;
10534 int i_acldefault;
10535 int i_fdwoptions;
10536
10537 query = createPQExpBuffer();
10538
10539 appendPQExpBufferStr(query, "SELECT tableoid, oid, fdwname, "
10540 "fdwowner, "
10541 "fdwhandler::pg_catalog.regproc, "
10542 "fdwvalidator::pg_catalog.regproc, ");
10543
10544 if (fout->remoteVersion >= 190000)
10545 appendPQExpBufferStr(query, "fdwconnection::pg_catalog.regproc, ");
10546 else
10547 appendPQExpBufferStr(query, "'-' AS fdwconnection, ");
10548
10550 "fdwacl, "
10551 "acldefault('F', fdwowner) AS acldefault, "
10552 "array_to_string(ARRAY("
10553 "SELECT quote_ident(option_name) || ' ' || "
10554 "quote_literal(option_value) "
10555 "FROM pg_options_to_table(fdwoptions) "
10556 "ORDER BY option_name"
10557 "), E',\n ') AS fdwoptions "
10558 "FROM pg_foreign_data_wrapper");
10559
10560 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10561
10562 ntups = PQntuples(res);
10563
10565
10566 i_tableoid = PQfnumber(res, "tableoid");
10567 i_oid = PQfnumber(res, "oid");
10568 i_fdwname = PQfnumber(res, "fdwname");
10569 i_fdwowner = PQfnumber(res, "fdwowner");
10570 i_fdwhandler = PQfnumber(res, "fdwhandler");
10571 i_fdwvalidator = PQfnumber(res, "fdwvalidator");
10572 i_fdwconnection = PQfnumber(res, "fdwconnection");
10573 i_fdwacl = PQfnumber(res, "fdwacl");
10574 i_acldefault = PQfnumber(res, "acldefault");
10575 i_fdwoptions = PQfnumber(res, "fdwoptions");
10576
10577 for (i = 0; i < ntups; i++)
10578 {
10579 fdwinfo[i].dobj.objType = DO_FDW;
10580 fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10581 fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10582 AssignDumpId(&fdwinfo[i].dobj);
10583 fdwinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_fdwname));
10584 fdwinfo[i].dobj.namespace = NULL;
10585 fdwinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_fdwacl));
10586 fdwinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10587 fdwinfo[i].dacl.privtype = 0;
10588 fdwinfo[i].dacl.initprivs = NULL;
10589 fdwinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_fdwowner));
10590 fdwinfo[i].fdwhandler = pg_strdup(PQgetvalue(res, i, i_fdwhandler));
10591 fdwinfo[i].fdwvalidator = pg_strdup(PQgetvalue(res, i, i_fdwvalidator));
10592 fdwinfo[i].fdwconnection = pg_strdup(PQgetvalue(res, i, i_fdwconnection));
10593 fdwinfo[i].fdwoptions = pg_strdup(PQgetvalue(res, i, i_fdwoptions));
10594
10595 /* Decide whether we want to dump it */
10597
10598 /* Mark whether FDW has an ACL */
10599 if (!PQgetisnull(res, i, i_fdwacl))
10600 fdwinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10601 }
10602
10603 PQclear(res);
10604
10605 destroyPQExpBuffer(query);
10606}

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, Archive::remoteVersion, and selectDumpableObject().

Referenced by getSchemaData().

◆ getForeignServers()

void getForeignServers ( Archive fout)
extern

Definition at line 10613 of file pg_dump.c.

10614{
10615 PGresult *res;
10616 int ntups;
10617 int i;
10618 PQExpBuffer query;
10620 int i_tableoid;
10621 int i_oid;
10622 int i_srvname;
10623 int i_srvowner;
10624 int i_srvfdw;
10625 int i_srvtype;
10626 int i_srvversion;
10627 int i_srvacl;
10628 int i_acldefault;
10629 int i_srvoptions;
10630
10631 query = createPQExpBuffer();
10632
10633 appendPQExpBufferStr(query, "SELECT tableoid, oid, srvname, "
10634 "srvowner, "
10635 "srvfdw, srvtype, srvversion, srvacl, "
10636 "acldefault('S', srvowner) AS acldefault, "
10637 "array_to_string(ARRAY("
10638 "SELECT quote_ident(option_name) || ' ' || "
10639 "quote_literal(option_value) "
10640 "FROM pg_options_to_table(srvoptions) "
10641 "ORDER BY option_name"
10642 "), E',\n ') AS srvoptions "
10643 "FROM pg_foreign_server");
10644
10645 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10646
10647 ntups = PQntuples(res);
10648
10650
10651 i_tableoid = PQfnumber(res, "tableoid");
10652 i_oid = PQfnumber(res, "oid");
10653 i_srvname = PQfnumber(res, "srvname");
10654 i_srvowner = PQfnumber(res, "srvowner");
10655 i_srvfdw = PQfnumber(res, "srvfdw");
10656 i_srvtype = PQfnumber(res, "srvtype");
10657 i_srvversion = PQfnumber(res, "srvversion");
10658 i_srvacl = PQfnumber(res, "srvacl");
10659 i_acldefault = PQfnumber(res, "acldefault");
10660 i_srvoptions = PQfnumber(res, "srvoptions");
10661
10662 for (i = 0; i < ntups; i++)
10663 {
10664 srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
10665 srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10666 srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10667 AssignDumpId(&srvinfo[i].dobj);
10668 srvinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_srvname));
10669 srvinfo[i].dobj.namespace = NULL;
10670 srvinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_srvacl));
10671 srvinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
10672 srvinfo[i].dacl.privtype = 0;
10673 srvinfo[i].dacl.initprivs = NULL;
10674 srvinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_srvowner));
10675 srvinfo[i].srvfdw = atooid(PQgetvalue(res, i, i_srvfdw));
10676 srvinfo[i].srvtype = pg_strdup(PQgetvalue(res, i, i_srvtype));
10677 srvinfo[i].srvversion = pg_strdup(PQgetvalue(res, i, i_srvversion));
10678 srvinfo[i].srvoptions = pg_strdup(PQgetvalue(res, i, i_srvoptions));
10679
10680 /* Decide whether we want to dump it */
10682
10683 /* Servers have user mappings */
10684 srvinfo[i].dobj.components |= DUMP_COMPONENT_USERMAP;
10685
10686 /* Mark whether server has an ACL */
10687 if (!PQgetisnull(res, i, i_srvacl))
10688 srvinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
10689 }
10690
10691 PQclear(res);
10692
10693 destroyPQExpBuffer(query);
10694}
#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 7005 of file pg_dump.c.

7006{
7007 DumpOptions *dopt = fout->dopt;
7008 PGresult *res;
7009 int ntups;
7010 int i;
7012 FuncInfo *finfo;
7013 int i_tableoid;
7014 int i_oid;
7015 int i_proname;
7016 int i_pronamespace;
7017 int i_proowner;
7018 int i_prolang;
7019 int i_pronargs;
7020 int i_proargtypes;
7021 int i_prorettype;
7022 int i_proacl;
7023 int i_acldefault;
7024
7025 /*
7026 * Find all interesting functions. This is a bit complicated:
7027 *
7028 * 1. Always exclude aggregates; those are handled elsewhere.
7029 *
7030 * 2. Always exclude functions that are internally dependent on something
7031 * else, since presumably those will be created as a result of creating
7032 * the something else. This currently acts only to suppress constructor
7033 * functions for range types. Note this is OK only because the
7034 * constructors don't have any dependencies the range type doesn't have;
7035 * otherwise we might not get creation ordering correct.
7036 *
7037 * 3. Otherwise, we normally exclude functions in pg_catalog. However, if
7038 * they're members of extensions and we are in binary-upgrade mode then
7039 * include them, since we want to dump extension members individually in
7040 * that mode. Also, if they are used by casts or transforms then we need
7041 * to gather the information about them, though they won't be dumped if
7042 * they are built-in. Also, in 9.6 and up, include functions in
7043 * pg_catalog if they have an ACL different from what's shown in
7044 * pg_init_privs (so we have to join to pg_init_privs; annoying).
7045 */
7046 if (fout->remoteVersion >= 90600)
7047 {
7048 const char *not_agg_check;
7049
7050 not_agg_check = (fout->remoteVersion >= 110000 ? "p.prokind <> 'a'"
7051 : "NOT p.proisagg");
7052
7053 appendPQExpBuffer(query,
7054 "SELECT p.tableoid, p.oid, p.proname, p.prolang, "
7055 "p.pronargs, p.proargtypes, p.prorettype, "
7056 "p.proacl, "
7057 "acldefault('f', p.proowner) AS acldefault, "
7058 "p.pronamespace, "
7059 "p.proowner "
7060 "FROM pg_proc p "
7061 "LEFT JOIN pg_init_privs pip ON "
7062 "(p.oid = pip.objoid "
7063 "AND pip.classoid = 'pg_proc'::regclass "
7064 "AND pip.objsubid = 0) "
7065 "WHERE %s"
7066 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
7067 "WHERE classid = 'pg_proc'::regclass AND "
7068 "objid = p.oid AND deptype = 'i')"
7069 "\n AND ("
7070 "\n pronamespace != "
7071 "(SELECT oid FROM pg_namespace "
7072 "WHERE nspname = 'pg_catalog')"
7073 "\n OR EXISTS (SELECT 1 FROM pg_cast"
7074 "\n WHERE pg_cast.oid > %u "
7075 "\n AND p.oid = pg_cast.castfunc)"
7076 "\n OR EXISTS (SELECT 1 FROM pg_transform"
7077 "\n WHERE pg_transform.oid > %u AND "
7078 "\n (p.oid = pg_transform.trffromsql"
7079 "\n OR p.oid = pg_transform.trftosql))",
7083 if (dopt->binary_upgrade)
7085 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
7086 "classid = 'pg_proc'::regclass AND "
7087 "objid = p.oid AND "
7088 "refclassid = 'pg_extension'::regclass AND "
7089 "deptype = 'e')");
7091 "\n OR p.proacl IS DISTINCT FROM pip.initprivs");
7092 appendPQExpBufferChar(query, ')');
7093 }
7094 else
7095 {
7096 appendPQExpBuffer(query,
7097 "SELECT tableoid, oid, proname, prolang, "
7098 "pronargs, proargtypes, prorettype, proacl, "
7099 "acldefault('f', proowner) AS acldefault, "
7100 "pronamespace, "
7101 "proowner "
7102 "FROM pg_proc p "
7103 "WHERE NOT proisagg"
7104 "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
7105 "WHERE classid = 'pg_proc'::regclass AND "
7106 "objid = p.oid AND deptype = 'i')"
7107 "\n AND ("
7108 "\n pronamespace != "
7109 "(SELECT oid FROM pg_namespace "
7110 "WHERE nspname = 'pg_catalog')"
7111 "\n OR EXISTS (SELECT 1 FROM pg_cast"
7112 "\n WHERE pg_cast.oid > '%u'::oid"
7113 "\n AND p.oid = pg_cast.castfunc)",
7115
7116 if (fout->remoteVersion >= 90500)
7117 appendPQExpBuffer(query,
7118 "\n OR EXISTS (SELECT 1 FROM pg_transform"
7119 "\n WHERE pg_transform.oid > '%u'::oid"
7120 "\n AND (p.oid = pg_transform.trffromsql"
7121 "\n OR p.oid = pg_transform.trftosql))",
7123
7124 if (dopt->binary_upgrade)
7126 "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
7127 "classid = 'pg_proc'::regclass AND "
7128 "objid = p.oid AND "
7129 "refclassid = 'pg_extension'::regclass AND "
7130 "deptype = 'e')");
7131 appendPQExpBufferChar(query, ')');
7132 }
7133
7134 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7135
7136 ntups = PQntuples(res);
7137
7138 finfo = pg_malloc0_array(FuncInfo, ntups);
7139
7140 i_tableoid = PQfnumber(res, "tableoid");
7141 i_oid = PQfnumber(res, "oid");
7142 i_proname = PQfnumber(res, "proname");
7143 i_pronamespace = PQfnumber(res, "pronamespace");
7144 i_proowner = PQfnumber(res, "proowner");
7145 i_prolang = PQfnumber(res, "prolang");
7146 i_pronargs = PQfnumber(res, "pronargs");
7147 i_proargtypes = PQfnumber(res, "proargtypes");
7148 i_prorettype = PQfnumber(res, "prorettype");
7149 i_proacl = PQfnumber(res, "proacl");
7150 i_acldefault = PQfnumber(res, "acldefault");
7151
7152 for (i = 0; i < ntups; i++)
7153 {
7154 finfo[i].dobj.objType = DO_FUNC;
7155 finfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
7156 finfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
7157 AssignDumpId(&finfo[i].dobj);
7158 finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
7159 finfo[i].dobj.namespace =
7161 finfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_proacl));
7163 finfo[i].dacl.privtype = 0;
7164 finfo[i].dacl.initprivs = NULL;
7165 finfo[i].rolname = getRoleName(PQgetvalue(res, i, i_proowner));
7166 finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
7167 finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
7168 finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
7169 if (finfo[i].nargs == 0)
7170 finfo[i].argtypes = NULL;
7171 else
7172 {
7173 finfo[i].argtypes = pg_malloc_array(Oid, finfo[i].nargs);
7175 finfo[i].argtypes, finfo[i].nargs);
7176 }
7177 finfo[i].postponed_def = false; /* might get set during sort */
7178
7179 /* Decide whether we want to dump it */
7180 selectDumpableObject(&(finfo[i].dobj), fout);
7181
7182 /* Mark whether function has an ACL */
7183 if (!PQgetisnull(res, i, i_proacl))
7185 }
7186
7187 PQclear(res);
7188
7189 destroyPQExpBuffer(query);
7190}
#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 7937 of file pg_dump.c.

7938{
7941 PGresult *res;
7942 int ntups;
7943 int curtblindx;
7945 int i_tableoid,
7946 i_oid,
7947 i_indrelid,
7949 i_relpages,
7954 i_indexdef,
7956 i_indnatts,
7957 i_indkey,
7961 i_contype,
7962 i_conname,
7967 i_conoid,
7968 i_condef,
7974
7975 /*
7976 * We want to perform just one query against pg_index. However, we
7977 * mustn't try to select every row of the catalog and then sort it out on
7978 * the client side, because some of the server-side functions we need
7979 * would be unsafe to apply to tables we don't have lock on. Hence, we
7980 * build an array of the OIDs of tables we care about (and now have lock
7981 * on!), and use a WHERE clause to constrain which rows are selected.
7982 */
7984 for (int i = 0; i < numTables; i++)
7985 {
7986 TableInfo *tbinfo = &tblinfo[i];
7987
7988 if (!tbinfo->hasindex)
7989 continue;
7990
7991 /*
7992 * We can ignore indexes of uninteresting tables.
7993 */
7994 if (!tbinfo->interesting)
7995 continue;
7996
7997 /* OK, we need info for this table */
7998 if (tbloids->len > 1) /* do we have more than the '{'? */
8000 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
8001 }
8003
8005 "SELECT t.tableoid, t.oid, i.indrelid, "
8006 "t.relname AS indexname, "
8007 "t.relpages, t.reltuples, t.relallvisible, ");
8008
8009 if (fout->remoteVersion >= 180000)
8010 appendPQExpBufferStr(query, "t.relallfrozen, ");
8011 else
8012 appendPQExpBufferStr(query, "0 AS relallfrozen, ");
8013
8015 "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
8016 "i.indkey, i.indisclustered, "
8017 "c.contype, c.conname, "
8018 "c.condeferrable, c.condeferred, "
8019 "c.tableoid AS contableoid, "
8020 "c.oid AS conoid, "
8021 "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
8022 "CASE WHEN i.indexprs IS NOT NULL THEN "
8023 "(SELECT pg_catalog.array_agg(attname ORDER BY attnum)"
8024 " FROM pg_catalog.pg_attribute "
8025 " WHERE attrelid = i.indexrelid) "
8026 "ELSE NULL END AS indattnames, "
8027 "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
8028 "t.reloptions AS indreloptions, ");
8029
8030
8031 if (fout->remoteVersion >= 90400)
8033 "i.indisreplident, ");
8034 else
8036 "false AS indisreplident, ");
8037
8038 if (fout->remoteVersion >= 110000)
8040 "inh.inhparent AS parentidx, "
8041 "i.indnkeyatts AS indnkeyatts, "
8042 "i.indnatts AS indnatts, "
8043 "(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
8044 " FROM pg_catalog.pg_attribute "
8045 " WHERE attrelid = i.indexrelid AND "
8046 " attstattarget >= 0) AS indstatcols, "
8047 "(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
8048 " FROM pg_catalog.pg_attribute "
8049 " WHERE attrelid = i.indexrelid AND "
8050 " attstattarget >= 0) AS indstatvals, ");
8051 else
8053 "0 AS parentidx, "
8054 "i.indnatts AS indnkeyatts, "
8055 "i.indnatts AS indnatts, "
8056 "'' AS indstatcols, "
8057 "'' AS indstatvals, ");
8058
8059 if (fout->remoteVersion >= 150000)
8061 "i.indnullsnotdistinct, ");
8062 else
8064 "false AS indnullsnotdistinct, ");
8065
8066 if (fout->remoteVersion >= 180000)
8068 "c.conperiod ");
8069 else
8071 "NULL AS conperiod ");
8072
8073 /*
8074 * The point of the messy-looking outer join is to find a constraint that
8075 * is related by an internal dependency link to the index. If we find one,
8076 * create a CONSTRAINT entry linked to the INDEX entry. We assume an
8077 * index won't have more than one internal dependency.
8078 *
8079 * Note: the check on conrelid is redundant, but useful because that
8080 * column is indexed while conindid is not.
8081 */
8082 if (fout->remoteVersion >= 110000)
8083 {
8084 appendPQExpBuffer(query,
8085 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8086 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
8087 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
8088 "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) "
8089 "LEFT JOIN pg_catalog.pg_constraint c "
8090 "ON (i.indrelid = c.conrelid AND "
8091 "i.indexrelid = c.conindid AND "
8092 "c.contype IN ('p','u','x')) "
8093 "LEFT JOIN pg_catalog.pg_inherits inh "
8094 "ON (inh.inhrelid = indexrelid) "
8095 "WHERE (i.indisvalid OR t2.relkind = 'p') "
8096 "AND i.indisready "
8097 "ORDER BY i.indrelid, indexname",
8098 tbloids->data);
8099 }
8100 else
8101 {
8102 /*
8103 * the test on indisready is necessary in 9.2, and harmless in
8104 * earlier/later versions
8105 */
8106 appendPQExpBuffer(query,
8107 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8108 "JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
8109 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
8110 "LEFT JOIN pg_catalog.pg_constraint c "
8111 "ON (i.indrelid = c.conrelid AND "
8112 "i.indexrelid = c.conindid AND "
8113 "c.contype IN ('p','u','x')) "
8114 "WHERE i.indisvalid AND i.indisready "
8115 "ORDER BY i.indrelid, indexname",
8116 tbloids->data);
8117 }
8118
8119 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8120
8121 ntups = PQntuples(res);
8122
8123 i_tableoid = PQfnumber(res, "tableoid");
8124 i_oid = PQfnumber(res, "oid");
8125 i_indrelid = PQfnumber(res, "indrelid");
8126 i_indexname = PQfnumber(res, "indexname");
8127 i_relpages = PQfnumber(res, "relpages");
8128 i_reltuples = PQfnumber(res, "reltuples");
8129 i_relallvisible = PQfnumber(res, "relallvisible");
8130 i_relallfrozen = PQfnumber(res, "relallfrozen");
8131 i_parentidx = PQfnumber(res, "parentidx");
8132 i_indexdef = PQfnumber(res, "indexdef");
8133 i_indnkeyatts = PQfnumber(res, "indnkeyatts");
8134 i_indnatts = PQfnumber(res, "indnatts");
8135 i_indkey = PQfnumber(res, "indkey");
8136 i_indisclustered = PQfnumber(res, "indisclustered");
8137 i_indisreplident = PQfnumber(res, "indisreplident");
8138 i_indnullsnotdistinct = PQfnumber(res, "indnullsnotdistinct");
8139 i_contype = PQfnumber(res, "contype");
8140 i_conname = PQfnumber(res, "conname");
8141 i_condeferrable = PQfnumber(res, "condeferrable");
8142 i_condeferred = PQfnumber(res, "condeferred");
8143 i_conperiod = PQfnumber(res, "conperiod");
8144 i_contableoid = PQfnumber(res, "contableoid");
8145 i_conoid = PQfnumber(res, "conoid");
8146 i_condef = PQfnumber(res, "condef");
8147 i_indattnames = PQfnumber(res, "indattnames");
8148 i_tablespace = PQfnumber(res, "tablespace");
8149 i_indreloptions = PQfnumber(res, "indreloptions");
8150 i_indstatcols = PQfnumber(res, "indstatcols");
8151 i_indstatvals = PQfnumber(res, "indstatvals");
8152
8154
8155 /*
8156 * Outer loop iterates once per table, not once per row. Incrementing of
8157 * j is handled by the inner loop.
8158 */
8159 curtblindx = -1;
8160 for (int j = 0; j < ntups;)
8161 {
8164 char **indAttNames = NULL;
8165 int nindAttNames = 0;
8166 int numinds;
8167
8168 /* Count rows for this table */
8169 for (numinds = 1; numinds < ntups - j; numinds++)
8170 if (atooid(PQgetvalue(res, j + numinds, i_indrelid)) != indrelid)
8171 break;
8172
8173 /*
8174 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8175 * order.
8176 */
8177 while (++curtblindx < numTables)
8178 {
8179 tbinfo = &tblinfo[curtblindx];
8180 if (tbinfo->dobj.catId.oid == indrelid)
8181 break;
8182 }
8183 if (curtblindx >= numTables)
8184 pg_fatal("unrecognized table OID %u", indrelid);
8185 /* cross-check that we only got requested tables */
8186 if (!tbinfo->hasindex ||
8187 !tbinfo->interesting)
8188 pg_fatal("unexpected index data for table \"%s\"",
8189 tbinfo->dobj.name);
8190
8191 /* Save data for this table */
8192 tbinfo->indexes = indxinfo + j;
8193 tbinfo->numIndexes = numinds;
8194
8195 for (int c = 0; c < numinds; c++, j++)
8196 {
8197 char contype;
8198 char indexkind;
8200 int32 relpages = atoi(PQgetvalue(res, j, i_relpages));
8201 int32 relallvisible = atoi(PQgetvalue(res, j, i_relallvisible));
8202 int32 relallfrozen = atoi(PQgetvalue(res, j, i_relallfrozen));
8203
8204 indxinfo[j].dobj.objType = DO_INDEX;
8205 indxinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8206 indxinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8207 AssignDumpId(&indxinfo[j].dobj);
8208 indxinfo[j].dobj.dump = tbinfo->dobj.dump;
8209 indxinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_indexname));
8210 indxinfo[j].dobj.namespace = tbinfo->dobj.namespace;
8211 indxinfo[j].indextable = tbinfo;
8212 indxinfo[j].indexdef = pg_strdup(PQgetvalue(res, j, i_indexdef));
8213 indxinfo[j].indnkeyattrs = atoi(PQgetvalue(res, j, i_indnkeyatts));
8214 indxinfo[j].indnattrs = atoi(PQgetvalue(res, j, i_indnatts));
8215 indxinfo[j].tablespace = pg_strdup(PQgetvalue(res, j, i_tablespace));
8216 indxinfo[j].indreloptions = pg_strdup(PQgetvalue(res, j, i_indreloptions));
8217 indxinfo[j].indstatcols = pg_strdup(PQgetvalue(res, j, i_indstatcols));
8218 indxinfo[j].indstatvals = pg_strdup(PQgetvalue(res, j, i_indstatvals));
8219 indxinfo[j].indkeys = pg_malloc_array(Oid, indxinfo[j].indnattrs);
8221 indxinfo[j].indkeys, indxinfo[j].indnattrs);
8222 indxinfo[j].indisclustered = (PQgetvalue(res, j, i_indisclustered)[0] == 't');
8223 indxinfo[j].indisreplident = (PQgetvalue(res, j, i_indisreplident)[0] == 't');
8224 indxinfo[j].indnullsnotdistinct = (PQgetvalue(res, j, i_indnullsnotdistinct)[0] == 't');
8225 indxinfo[j].parentidx = atooid(PQgetvalue(res, j, i_parentidx));
8226 indxinfo[j].partattaches = (SimplePtrList)
8227 {
8228 NULL, NULL
8229 };
8230
8231 if (indxinfo[j].parentidx == 0)
8233 else
8235
8236 if (!PQgetisnull(res, j, i_indattnames))
8237 {
8239 &indAttNames, &nindAttNames))
8240 pg_fatal("could not parse %s array", "indattnames");
8241 }
8242
8243 relstats = getRelationStatistics(fout, &indxinfo[j].dobj, relpages,
8244 PQgetvalue(res, j, i_reltuples),
8245 relallvisible, relallfrozen, indexkind,
8246 indAttNames, nindAttNames);
8247
8248 contype = *(PQgetvalue(res, j, i_contype));
8249 if (contype == 'p' || contype == 'u' || contype == 'x')
8250 {
8251 /*
8252 * If we found a constraint matching the index, create an
8253 * entry for it.
8254 */
8256
8258 constrinfo->dobj.objType = DO_CONSTRAINT;
8259 constrinfo->dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_contableoid));
8260 constrinfo->dobj.catId.oid = atooid(PQgetvalue(res, j, i_conoid));
8261 AssignDumpId(&constrinfo->dobj);
8262 constrinfo->dobj.dump = tbinfo->dobj.dump;
8263 constrinfo->dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
8264 constrinfo->dobj.namespace = tbinfo->dobj.namespace;
8265 constrinfo->contable = tbinfo;
8266 constrinfo->condomain = NULL;
8267 constrinfo->contype = contype;
8268 if (contype == 'x')
8269 constrinfo->condef = pg_strdup(PQgetvalue(res, j, i_condef));
8270 else
8271 constrinfo->condef = NULL;
8272 constrinfo->confrelid = InvalidOid;
8273 constrinfo->conindex = indxinfo[j].dobj.dumpId;
8274 constrinfo->condeferrable = *(PQgetvalue(res, j, i_condeferrable)) == 't';
8275 constrinfo->condeferred = *(PQgetvalue(res, j, i_condeferred)) == 't';
8276 constrinfo->conperiod = *(PQgetvalue(res, j, i_conperiod)) == 't';
8277 constrinfo->conislocal = true;
8278 constrinfo->separate = true;
8279
8280 indxinfo[j].indexconstraint = constrinfo->dobj.dumpId;
8281 if (relstats != NULL)
8282 addObjectDependency(&relstats->dobj, constrinfo->dobj.dumpId);
8283 }
8284 else
8285 {
8286 /* Plain secondary index */
8287 indxinfo[j].indexconstraint = 0;
8288 }
8289 }
8290 }
8291
8292 PQclear(res);
8293
8294 destroyPQExpBuffer(query);
8296}
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:819
#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:7200
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 7821 of file pg_dump.c.

7822{
7823 PGresult *res;
7824 int ntups;
7825 int i;
7828
7829 int i_inhrelid;
7830 int i_inhparent;
7831
7832 /* find all the inheritance information */
7833 appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
7834
7835 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7836
7837 ntups = PQntuples(res);
7838
7839 *numInherits = ntups;
7840
7842
7843 i_inhrelid = PQfnumber(res, "inhrelid");
7844 i_inhparent = PQfnumber(res, "inhparent");
7845
7846 for (i = 0; i < ntups; i++)
7847 {
7848 inhinfo[i].inhrelid = atooid(PQgetvalue(res, i, i_inhrelid));
7849 inhinfo[i].inhparent = atooid(PQgetvalue(res, i, i_inhparent));
7850 }
7851
7852 PQclear(res);
7853
7854 destroyPQExpBuffer(query);
7855
7856 return inhinfo;
7857}

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 755 of file common.c.

756{
757 return lastDumpId;
758}

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

◆ getNamespaces()

void getNamespaces ( Archive fout)
extern

Definition at line 6083 of file pg_dump.c.

6084{
6085 PGresult *res;
6086 int ntups;
6087 int i;
6088 PQExpBuffer query;
6090 int i_tableoid;
6091 int i_oid;
6092 int i_nspname;
6093 int i_nspowner;
6094 int i_nspacl;
6095 int i_acldefault;
6096
6097 query = createPQExpBuffer();
6098
6099 /*
6100 * we fetch all namespaces including system ones, so that every object we
6101 * read in can be linked to a containing namespace.
6102 */
6103 appendPQExpBufferStr(query, "SELECT n.tableoid, n.oid, n.nspname, "
6104 "n.nspowner, "
6105 "n.nspacl, "
6106 "acldefault('n', n.nspowner) AS acldefault "
6107 "FROM pg_namespace n");
6108
6109 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6110
6111 ntups = PQntuples(res);
6112
6114
6115 i_tableoid = PQfnumber(res, "tableoid");
6116 i_oid = PQfnumber(res, "oid");
6117 i_nspname = PQfnumber(res, "nspname");
6118 i_nspowner = PQfnumber(res, "nspowner");
6119 i_nspacl = PQfnumber(res, "nspacl");
6120 i_acldefault = PQfnumber(res, "acldefault");
6121
6122 for (i = 0; i < ntups; i++)
6123 {
6124 const char *nspowner;
6125
6126 nsinfo[i].dobj.objType = DO_NAMESPACE;
6127 nsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6128 nsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6129 AssignDumpId(&nsinfo[i].dobj);
6130 nsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_nspname));
6131 nsinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_nspacl));
6132 nsinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6133 nsinfo[i].dacl.privtype = 0;
6134 nsinfo[i].dacl.initprivs = NULL;
6135 nspowner = PQgetvalue(res, i, i_nspowner);
6136 nsinfo[i].nspowner = atooid(nspowner);
6137 nsinfo[i].rolname = getRoleName(nspowner);
6138
6139 /* Decide whether to dump this namespace */
6141
6142 /* Mark whether namespace has an ACL */
6143 if (!PQgetisnull(res, i, i_nspacl))
6144 nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6145
6146 /*
6147 * We ignore any pg_init_privs.initprivs entry for the public schema
6148 * and assume a predetermined default, for several reasons. First,
6149 * dropping and recreating the schema removes its pg_init_privs entry,
6150 * but an empty destination database starts with this ACL nonetheless.
6151 * Second, we support dump/reload of public schema ownership changes.
6152 * ALTER SCHEMA OWNER filters nspacl through aclnewowner(), but
6153 * initprivs continues to reflect the initial owner. Hence,
6154 * synthesize the value that nspacl will have after the restore's
6155 * ALTER SCHEMA OWNER. Third, this makes the destination database
6156 * match the source's ACL, even if the latter was an initdb-default
6157 * ACL, which changed in v15. An upgrade pulls in changes to most
6158 * system object ACLs that the DBA had not customized. We've made the
6159 * public schema depart from that, because changing its ACL so easily
6160 * breaks applications.
6161 */
6162 if (strcmp(nsinfo[i].dobj.name, "public") == 0)
6163 {
6166
6167 /* Standard ACL as of v15 is {owner=UC/owner,=U/owner} */
6178
6179 nsinfo[i].dacl.privtype = 'i';
6180 nsinfo[i].dacl.initprivs = pstrdup(aclarray->data);
6181 nsinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6182
6185 }
6186 }
6187
6188 PQclear(res);
6189 destroyPQExpBuffer(query);
6190}
void quoteAclUserName(PQExpBuffer output, const char *input)
Definition dumputils.c:588
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:1982
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 6736 of file pg_dump.c.

6737{
6738 PGresult *res;
6739 int ntups;
6740 int i;
6743 int i_tableoid;
6744 int i_oid;
6745 int i_opcmethod;
6746 int i_opcname;
6747 int i_opcnamespace;
6748 int i_opcowner;
6749
6750 /*
6751 * find all opclasses, including builtin opclasses; we filter out
6752 * system-defined opclasses at dump-out time.
6753 */
6754
6755 appendPQExpBufferStr(query, "SELECT tableoid, oid, opcmethod, opcname, "
6756 "opcnamespace, "
6757 "opcowner "
6758 "FROM pg_opclass");
6759
6760 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6761
6762 ntups = PQntuples(res);
6763
6765
6766 i_tableoid = PQfnumber(res, "tableoid");
6767 i_oid = PQfnumber(res, "oid");
6768 i_opcmethod = PQfnumber(res, "opcmethod");
6769 i_opcname = PQfnumber(res, "opcname");
6770 i_opcnamespace = PQfnumber(res, "opcnamespace");
6771 i_opcowner = PQfnumber(res, "opcowner");
6772
6773 for (i = 0; i < ntups; i++)
6774 {
6775 opcinfo[i].dobj.objType = DO_OPCLASS;
6776 opcinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6777 opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6778 AssignDumpId(&opcinfo[i].dobj);
6779 opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
6780 opcinfo[i].dobj.namespace =
6782 opcinfo[i].opcmethod = atooid(PQgetvalue(res, i, i_opcmethod));
6783 opcinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opcowner));
6784
6785 /* Decide whether we want to dump it */
6787 }
6788
6789 PQclear(res);
6790
6791 destroyPQExpBuffer(query);
6792}

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 6458 of file pg_dump.c.

6459{
6460 PGresult *res;
6461 int ntups;
6462 int i;
6465 int i_tableoid;
6466 int i_oid;
6467 int i_oprname;
6468 int i_oprnamespace;
6469 int i_oprowner;
6470 int i_oprkind;
6471 int i_oprleft;
6472 int i_oprright;
6473 int i_oprcode;
6474
6475 /*
6476 * find all operators, including builtin operators; we filter out
6477 * system-defined operators at dump-out time.
6478 */
6479
6480 appendPQExpBufferStr(query, "SELECT tableoid, oid, oprname, "
6481 "oprnamespace, "
6482 "oprowner, "
6483 "oprkind, "
6484 "oprleft, "
6485 "oprright, "
6486 "oprcode::oid AS oprcode "
6487 "FROM pg_operator");
6488
6489 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6490
6491 ntups = PQntuples(res);
6492
6494
6495 i_tableoid = PQfnumber(res, "tableoid");
6496 i_oid = PQfnumber(res, "oid");
6497 i_oprname = PQfnumber(res, "oprname");
6498 i_oprnamespace = PQfnumber(res, "oprnamespace");
6499 i_oprowner = PQfnumber(res, "oprowner");
6500 i_oprkind = PQfnumber(res, "oprkind");
6501 i_oprleft = PQfnumber(res, "oprleft");
6502 i_oprright = PQfnumber(res, "oprright");
6503 i_oprcode = PQfnumber(res, "oprcode");
6504
6505 for (i = 0; i < ntups; i++)
6506 {
6507 oprinfo[i].dobj.objType = DO_OPERATOR;
6508 oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6509 oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6510 AssignDumpId(&oprinfo[i].dobj);
6511 oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
6512 oprinfo[i].dobj.namespace =
6514 oprinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_oprowner));
6515 oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
6516 oprinfo[i].oprleft = atooid(PQgetvalue(res, i, i_oprleft));
6517 oprinfo[i].oprright = atooid(PQgetvalue(res, i, i_oprright));
6518 oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
6519
6520 /* Decide whether we want to dump it */
6522 }
6523
6524 PQclear(res);
6525
6526 destroyPQExpBuffer(query);
6527}

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 6799 of file pg_dump.c.

6800{
6801 PGresult *res;
6802 int ntups;
6803 int i;
6804 PQExpBuffer query;
6806 int i_tableoid;
6807 int i_oid;
6808 int i_opfmethod;
6809 int i_opfname;
6810 int i_opfnamespace;
6811 int i_opfowner;
6812
6813 query = createPQExpBuffer();
6814
6815 /*
6816 * find all opfamilies, including builtin opfamilies; we filter out
6817 * system-defined opfamilies at dump-out time.
6818 */
6819
6820 appendPQExpBufferStr(query, "SELECT tableoid, oid, opfmethod, opfname, "
6821 "opfnamespace, "
6822 "opfowner "
6823 "FROM pg_opfamily");
6824
6825 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6826
6827 ntups = PQntuples(res);
6828
6830
6831 i_tableoid = PQfnumber(res, "tableoid");
6832 i_oid = PQfnumber(res, "oid");
6833 i_opfname = PQfnumber(res, "opfname");
6834 i_opfmethod = PQfnumber(res, "opfmethod");
6835 i_opfnamespace = PQfnumber(res, "opfnamespace");
6836 i_opfowner = PQfnumber(res, "opfowner");
6837
6838 for (i = 0; i < ntups; i++)
6839 {
6840 opfinfo[i].dobj.objType = DO_OPFAMILY;
6841 opfinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6842 opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6843 AssignDumpId(&opfinfo[i].dobj);
6844 opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
6845 opfinfo[i].dobj.namespace =
6847 opfinfo[i].opfmethod = atooid(PQgetvalue(res, i, i_opfmethod));
6848 opfinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_opfowner));
6849
6850 /* Decide whether we want to dump it */
6852 }
6853
6854 PQclear(res);
6855
6856 destroyPQExpBuffer(query);
6857}

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 7756 of file pg_dump.c.

7757{
7758 int i;
7759
7760 /*
7761 * Force sequences that are "owned" by table columns to be dumped whenever
7762 * their owning table is being dumped.
7763 */
7764 for (i = 0; i < numTables; i++)
7765 {
7766 TableInfo *seqinfo = &tblinfo[i];
7767 TableInfo *owning_tab;
7768
7769 if (!OidIsValid(seqinfo->owning_tab))
7770 continue; /* not an owned sequence */
7771
7772 owning_tab = findTableByOid(seqinfo->owning_tab);
7773 if (owning_tab == NULL)
7774 pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",
7775 seqinfo->owning_tab, seqinfo->dobj.catId.oid);
7776
7777 /*
7778 * For an identity sequence, dump exactly the same components for the
7779 * sequence as for the owning table. This is important because we
7780 * treat the identity sequence as an integral part of the table. For
7781 * example, there is not any DDL command that allows creation of such
7782 * a sequence independently of the table.
7783 *
7784 * For other owned sequences such as serial sequences, we need to dump
7785 * the components that are being dumped for the table and any
7786 * components that the sequence is explicitly marked with.
7787 *
7788 * We can't simply use the set of components which are being dumped
7789 * for the table as the table might be in an extension (and only the
7790 * non-extension components, eg: ACLs if changed, security labels, and
7791 * policies, are being dumped) while the sequence is not (and
7792 * therefore the definition and other components should also be
7793 * dumped).
7794 *
7795 * If the sequence is part of the extension then it should be properly
7796 * marked by checkExtensionMembership() and this will be a no-op as
7797 * the table will be equivalently marked.
7798 */
7799 if (seqinfo->is_identity_sequence)
7800 seqinfo->dobj.dump = owning_tab->dobj.dump;
7801 else
7802 seqinfo->dobj.dump |= owning_tab->dobj.dump;
7803
7804 /* Make sure that necessary data is available if we're dumping it */
7805 if (seqinfo->dobj.dump != DUMP_COMPONENT_NONE)
7806 {
7807 seqinfo->interesting = true;
7808 owning_tab->interesting = true;
7809 }
7810 }
7811}
#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 7877 of file pg_dump.c.

7878{
7879 PQExpBuffer query;
7880 PGresult *res;
7881 int ntups;
7882
7883 /* hash partitioning didn't exist before v11 */
7884 if (fout->remoteVersion < 110000)
7885 return;
7886 /* needn't bother if not dumping data */
7887 if (!fout->dopt->dumpData)
7888 return;
7889
7890 query = createPQExpBuffer();
7891
7892 /*
7893 * Unsafe partitioning schemes are exactly those for which hash enum_ops
7894 * appears among the partition opclasses. We needn't check partstrat.
7895 *
7896 * Note that this query may well retrieve info about tables we aren't
7897 * going to dump and hence have no lock on. That's okay since we need not
7898 * invoke any unsafe server-side functions.
7899 */
7901 "SELECT partrelid FROM pg_partitioned_table WHERE\n"
7902 "(SELECT c.oid FROM pg_opclass c JOIN pg_am a "
7903 "ON c.opcmethod = a.oid\n"
7904 "WHERE opcname = 'enum_ops' "
7905 "AND opcnamespace = 'pg_catalog'::regnamespace "
7906 "AND amname = 'hash') = ANY(partclass)");
7907
7908 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7909
7910 ntups = PQntuples(res);
7911
7912 for (int i = 0; i < ntups; i++)
7913 {
7914 Oid tabrelid = atooid(PQgetvalue(res, i, 0));
7916
7918 if (tbinfo == NULL)
7919 pg_fatal("failed sanity check, table OID %u appearing in pg_partitioned_table not found",
7920 tabrelid);
7921 tbinfo->unsafe_partitions = true;
7922 }
7923
7924 PQclear(res);
7925
7926 destroyPQExpBuffer(query);
7927}

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 4226 of file pg_dump.c.

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

9054{
9055 PGresult *res;
9056 int ntups;
9057 int i;
9060 int i_tableoid;
9061 int i_oid;
9062 int i_lanname;
9063 int i_lanpltrusted;
9064 int i_lanplcallfoid;
9065 int i_laninline;
9066 int i_lanvalidator;
9067 int i_lanacl;
9068 int i_acldefault;
9069 int i_lanowner;
9070
9071 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9072 "lanname, lanpltrusted, lanplcallfoid, "
9073 "laninline, lanvalidator, "
9074 "lanacl, "
9075 "acldefault('l', lanowner) AS acldefault, "
9076 "lanowner "
9077 "FROM pg_language "
9078 "WHERE lanispl "
9079 "ORDER BY oid");
9080
9081 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9082
9083 ntups = PQntuples(res);
9084
9086
9087 i_tableoid = PQfnumber(res, "tableoid");
9088 i_oid = PQfnumber(res, "oid");
9089 i_lanname = PQfnumber(res, "lanname");
9090 i_lanpltrusted = PQfnumber(res, "lanpltrusted");
9091 i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
9092 i_laninline = PQfnumber(res, "laninline");
9093 i_lanvalidator = PQfnumber(res, "lanvalidator");
9094 i_lanacl = PQfnumber(res, "lanacl");
9095 i_acldefault = PQfnumber(res, "acldefault");
9096 i_lanowner = PQfnumber(res, "lanowner");
9097
9098 for (i = 0; i < ntups; i++)
9099 {
9100 planginfo[i].dobj.objType = DO_PROCLANG;
9101 planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9102 planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9103 AssignDumpId(&planginfo[i].dobj);
9104
9105 planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
9106 planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
9107 planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9108 planginfo[i].dacl.privtype = 0;
9109 planginfo[i].dacl.initprivs = NULL;
9110 planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
9111 planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
9112 planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
9113 planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
9114 planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
9115
9116 /* Decide whether we want to dump it */
9118
9119 /* Mark whether language has an ACL */
9120 if (!PQgetisnull(res, i, i_lanacl))
9121 planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9122 }
9123
9124 PQclear(res);
9125
9126 destroyPQExpBuffer(query);
9127}
static void selectDumpableProcLang(ProcLangInfo *plang, Archive *fout)
Definition pg_dump.c:2199

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 4804 of file pg_dump.c.

4805{
4806 PQExpBuffer query;
4807 PGresult *res;
4809 DumpOptions *dopt = fout->dopt;
4810 int i_tableoid;
4811 int i_oid;
4812 int i_pnpubid;
4813 int i_pnnspid;
4814 int i,
4815 j,
4816 ntups;
4817
4818 if (dopt->no_publications || fout->remoteVersion < 150000)
4819 return;
4820
4821 query = createPQExpBuffer();
4822
4823 /* Collect all publication membership info. */
4825 "SELECT tableoid, oid, pnpubid, pnnspid "
4826 "FROM pg_catalog.pg_publication_namespace");
4827 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4828
4829 ntups = PQntuples(res);
4830
4831 i_tableoid = PQfnumber(res, "tableoid");
4832 i_oid = PQfnumber(res, "oid");
4833 i_pnpubid = PQfnumber(res, "pnpubid");
4834 i_pnnspid = PQfnumber(res, "pnnspid");
4835
4836 /* this allocation may be more than we need */
4838 j = 0;
4839
4840 for (i = 0; i < ntups; i++)
4841 {
4846
4847 /*
4848 * Ignore any entries for which we aren't interested in either the
4849 * publication or the rel.
4850 */
4852 if (pubinfo == NULL)
4853 continue;
4855 if (nspinfo == NULL)
4856 continue;
4857
4858 /* OK, make a DumpableObject for this relationship */
4860 pubsinfo[j].dobj.catId.tableoid =
4861 atooid(PQgetvalue(res, i, i_tableoid));
4862 pubsinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4863 AssignDumpId(&pubsinfo[j].dobj);
4864 pubsinfo[j].dobj.namespace = nspinfo->dobj.namespace;
4865 pubsinfo[j].dobj.name = nspinfo->dobj.name;
4866 pubsinfo[j].publication = pubinfo;
4867 pubsinfo[j].pubschema = nspinfo;
4868
4869 /* Decide whether we want to dump it */
4871
4872 j++;
4873 }
4874
4875 PQclear(res);
4876 destroyPQExpBuffer(query);
4877}
NamespaceInfo * findNamespaceByOid(Oid oid)
Definition common.c:991
PublicationInfo * findPublicationByOid(Oid oid)
Definition common.c:1027
static void selectDumpablePublicationObject(DumpableObject *dobj, Archive *fout)
Definition pg_dump.c:2306
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 4516 of file pg_dump.c.

4517{
4518 DumpOptions *dopt = fout->dopt;
4519 PQExpBuffer query;
4520 PGresult *res;
4522 int i_tableoid;
4523 int i_oid;
4524 int i_pubname;
4525 int i_pubowner;
4526 int i_puballtables;
4528 int i_pubinsert;
4529 int i_pubupdate;
4530 int i_pubdelete;
4531 int i_pubtruncate;
4532 int i_pubviaroot;
4533 int i_pubgencols;
4534 int i,
4535 ntups;
4536
4537 if (dopt->no_publications || fout->remoteVersion < 100000)
4538 return;
4539
4540 query = createPQExpBuffer();
4541
4542 /* Get the publications. */
4543 appendPQExpBufferStr(query, "SELECT p.tableoid, p.oid, p.pubname, "
4544 "p.pubowner, p.puballtables, p.pubinsert, "
4545 "p.pubupdate, p.pubdelete, ");
4546
4547 if (fout->remoteVersion >= 110000)
4548 appendPQExpBufferStr(query, "p.pubtruncate, ");
4549 else
4550 appendPQExpBufferStr(query, "false AS pubtruncate, ");
4551
4552 if (fout->remoteVersion >= 130000)
4553 appendPQExpBufferStr(query, "p.pubviaroot, ");
4554 else
4555 appendPQExpBufferStr(query, "false AS pubviaroot, ");
4556
4557 if (fout->remoteVersion >= 180000)
4558 appendPQExpBufferStr(query, "p.pubgencols, ");
4559 else
4560 appendPQExpBuffer(query, "'%c' AS pubgencols, ", PUBLISH_GENCOLS_NONE);
4561
4562 if (fout->remoteVersion >= 190000)
4563 appendPQExpBufferStr(query, "p.puballsequences ");
4564 else
4565 appendPQExpBufferStr(query, "false AS puballsequences ");
4566
4567 appendPQExpBufferStr(query, "FROM pg_publication p");
4568
4569 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4570
4571 ntups = PQntuples(res);
4572
4573 if (ntups == 0)
4574 goto cleanup;
4575
4576 i_tableoid = PQfnumber(res, "tableoid");
4577 i_oid = PQfnumber(res, "oid");
4578 i_pubname = PQfnumber(res, "pubname");
4579 i_pubowner = PQfnumber(res, "pubowner");
4580 i_puballtables = PQfnumber(res, "puballtables");
4581 i_puballsequences = PQfnumber(res, "puballsequences");
4582 i_pubinsert = PQfnumber(res, "pubinsert");
4583 i_pubupdate = PQfnumber(res, "pubupdate");
4584 i_pubdelete = PQfnumber(res, "pubdelete");
4585 i_pubtruncate = PQfnumber(res, "pubtruncate");
4586 i_pubviaroot = PQfnumber(res, "pubviaroot");
4587 i_pubgencols = PQfnumber(res, "pubgencols");
4588
4590
4591 for (i = 0; i < ntups; i++)
4592 {
4593 pubinfo[i].dobj.objType = DO_PUBLICATION;
4594 pubinfo[i].dobj.catId.tableoid =
4595 atooid(PQgetvalue(res, i, i_tableoid));
4596 pubinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4597 AssignDumpId(&pubinfo[i].dobj);
4598 pubinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_pubname));
4599 pubinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_pubowner));
4600 pubinfo[i].puballtables =
4601 (strcmp(PQgetvalue(res, i, i_puballtables), "t") == 0);
4602 pubinfo[i].puballsequences =
4603 (strcmp(PQgetvalue(res, i, i_puballsequences), "t") == 0);
4604 pubinfo[i].pubinsert =
4605 (strcmp(PQgetvalue(res, i, i_pubinsert), "t") == 0);
4606 pubinfo[i].pubupdate =
4607 (strcmp(PQgetvalue(res, i, i_pubupdate), "t") == 0);
4608 pubinfo[i].pubdelete =
4609 (strcmp(PQgetvalue(res, i, i_pubdelete), "t") == 0);
4610 pubinfo[i].pubtruncate =
4611 (strcmp(PQgetvalue(res, i, i_pubtruncate), "t") == 0);
4612 pubinfo[i].pubviaroot =
4613 (strcmp(PQgetvalue(res, i, i_pubviaroot), "t") == 0);
4614 pubinfo[i].pubgencols_type =
4615 *(PQgetvalue(res, i, i_pubgencols));
4616 pubinfo[i].except_tables = (SimplePtrList)
4617 {
4618 NULL, NULL
4619 };
4620
4621 /* Decide whether we want to dump it */
4623
4624 /*
4625 * Get the list of tables for publications specified in the EXCEPT
4626 * TABLE clause.
4627 *
4628 * Although individual table entries in EXCEPT list could be stored in
4629 * PublicationRelInfo, dumpPublicationTable cannot be used to emit
4630 * them, because there is no ALTER PUBLICATION ... ADD command to add
4631 * individual table entries to the EXCEPT list.
4632 *
4633 * Therefore, the approach is to dump the complete EXCEPT list in a
4634 * single CREATE PUBLICATION statement. PublicationInfo is used to
4635 * collect this information, which is then emitted by
4636 * dumpPublication().
4637 */
4638 if (fout->remoteVersion >= 190000)
4639 {
4640 int ntbls;
4642
4643 resetPQExpBuffer(query);
4644 appendPQExpBuffer(query,
4645 "SELECT prrelid\n"
4646 "FROM pg_catalog.pg_publication_rel\n"
4647 "WHERE prpubid = %u AND prexcept",
4648 pubinfo[i].dobj.catId.oid);
4649
4651
4653
4654 for (int j = 0; j < ntbls; j++)
4655 {
4656 Oid prrelid;
4658
4660
4662
4663 if (tbinfo != NULL)
4664 simple_ptr_list_append(&pubinfo[i].except_tables, tbinfo);
4665 }
4666
4668 }
4669 }
4670
4671cleanup:
4672 PQclear(res);
4673
4674 destroyPQExpBuffer(query);
4675}
void simple_ptr_list_append(SimplePtrList *list, void *ptr)

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

Referenced by getSchemaData().

◆ getPublicationTables()

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

Definition at line 4884 of file pg_dump.c.

4885{
4886 PQExpBuffer query;
4887 PGresult *res;
4889 DumpOptions *dopt = fout->dopt;
4890 int i_tableoid;
4891 int i_oid;
4892 int i_prpubid;
4893 int i_prrelid;
4894 int i_prrelqual;
4895 int i_prattrs;
4896 int i,
4897 j,
4898 ntups;
4899
4900 if (dopt->no_publications || fout->remoteVersion < 100000)
4901 return;
4902
4903 query = createPQExpBuffer();
4904
4905 /* Collect all publication membership info. */
4906 if (fout->remoteVersion >= 150000)
4907 {
4909 "SELECT tableoid, oid, prpubid, prrelid, "
4910 "pg_catalog.pg_get_expr(prqual, prrelid) AS prrelqual, "
4911 "(CASE\n"
4912 " WHEN pr.prattrs IS NOT NULL THEN\n"
4913 " (SELECT array_agg(attname)\n"
4914 " FROM\n"
4915 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
4916 " pg_catalog.pg_attribute\n"
4917 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
4918 " ELSE NULL END) prattrs "
4919 "FROM pg_catalog.pg_publication_rel pr");
4920 if (fout->remoteVersion >= 190000)
4921 appendPQExpBufferStr(query, " WHERE NOT pr.prexcept");
4922 }
4923 else
4925 "SELECT tableoid, oid, prpubid, prrelid, "
4926 "NULL AS prrelqual, NULL AS prattrs "
4927 "FROM pg_catalog.pg_publication_rel");
4928 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
4929
4930 ntups = PQntuples(res);
4931
4932 i_tableoid = PQfnumber(res, "tableoid");
4933 i_oid = PQfnumber(res, "oid");
4934 i_prpubid = PQfnumber(res, "prpubid");
4935 i_prrelid = PQfnumber(res, "prrelid");
4936 i_prrelqual = PQfnumber(res, "prrelqual");
4937 i_prattrs = PQfnumber(res, "prattrs");
4938
4939 /* this allocation may be more than we need */
4941 j = 0;
4942
4943 for (i = 0; i < ntups; i++)
4944 {
4949
4950 /*
4951 * Ignore any entries for which we aren't interested in either the
4952 * publication or the rel.
4953 */
4955 if (pubinfo == NULL)
4956 continue;
4958 if (tbinfo == NULL)
4959 continue;
4960
4961 /* OK, make a DumpableObject for this relationship */
4962 pubrinfo[j].dobj.objType = DO_PUBLICATION_REL;
4963 pubrinfo[j].dobj.catId.tableoid =
4964 atooid(PQgetvalue(res, i, i_tableoid));
4965 pubrinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
4966 AssignDumpId(&pubrinfo[j].dobj);
4967 pubrinfo[j].dobj.namespace = tbinfo->dobj.namespace;
4968 pubrinfo[j].dobj.name = tbinfo->dobj.name;
4969 pubrinfo[j].publication = pubinfo;
4970 pubrinfo[j].pubtable = tbinfo;
4971 if (PQgetisnull(res, i, i_prrelqual))
4972 pubrinfo[j].pubrelqual = NULL;
4973 else
4974 pubrinfo[j].pubrelqual = pg_strdup(PQgetvalue(res, i, i_prrelqual));
4975
4976 if (!PQgetisnull(res, i, i_prattrs))
4977 {
4978 char **attnames;
4979 int nattnames;
4981
4982 if (!parsePGArray(PQgetvalue(res, i, i_prattrs),
4983 &attnames, &nattnames))
4984 pg_fatal("could not parse %s array", "prattrs");
4986 for (int k = 0; k < nattnames; k++)
4987 {
4988 if (k > 0)
4990
4991 appendPQExpBufferStr(attribs, fmtId(attnames[k]));
4992 }
4993 pubrinfo[j].pubrattrs = attribs->data;
4994 free(attribs); /* but not attribs->data */
4995 free(attnames);
4996 }
4997 else
4998 pubrinfo[j].pubrattrs = NULL;
4999
5000 /* Decide whether we want to dump it */
5002
5003 j++;
5004 }
5005
5006 PQclear(res);
5007 destroyPQExpBuffer(query);
5008}
#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 8682 of file pg_dump.c.

8683{
8684 PGresult *res;
8685 int ntups;
8686 int i;
8689 int i_tableoid;
8690 int i_oid;
8691 int i_rulename;
8692 int i_ruletable;
8693 int i_ev_type;
8694 int i_is_instead;
8695 int i_ev_enabled;
8696
8697 appendPQExpBufferStr(query, "SELECT "
8698 "tableoid, oid, rulename, "
8699 "ev_class AS ruletable, ev_type, is_instead, "
8700 "ev_enabled "
8701 "FROM pg_rewrite "
8702 "ORDER BY oid");
8703
8704 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8705
8706 ntups = PQntuples(res);
8707
8709
8710 i_tableoid = PQfnumber(res, "tableoid");
8711 i_oid = PQfnumber(res, "oid");
8712 i_rulename = PQfnumber(res, "rulename");
8713 i_ruletable = PQfnumber(res, "ruletable");
8714 i_ev_type = PQfnumber(res, "ev_type");
8715 i_is_instead = PQfnumber(res, "is_instead");
8716 i_ev_enabled = PQfnumber(res, "ev_enabled");
8717
8718 for (i = 0; i < ntups; i++)
8719 {
8721
8722 ruleinfo[i].dobj.objType = DO_RULE;
8723 ruleinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
8724 ruleinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
8725 AssignDumpId(&ruleinfo[i].dobj);
8726 ruleinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_rulename));
8728 ruleinfo[i].ruletable = findTableByOid(ruletableoid);
8729 if (ruleinfo[i].ruletable == NULL)
8730 pg_fatal("failed sanity check, parent table with OID %u of pg_rewrite entry with OID %u not found",
8731 ruletableoid, ruleinfo[i].dobj.catId.oid);
8732 ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
8733 ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
8734 ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
8735 ruleinfo[i].is_instead = *(PQgetvalue(res, i, i_is_instead)) == 't';
8736 ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled));
8737 if (ruleinfo[i].ruletable)
8738 {
8739 /*
8740 * If the table is a view or materialized view, force its ON
8741 * SELECT rule to be sorted before the view itself --- this
8742 * ensures that any dependencies for the rule affect the table's
8743 * positioning. Other rules are forced to appear after their
8744 * table.
8745 */
8746 if ((ruleinfo[i].ruletable->relkind == RELKIND_VIEW ||
8747 ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW) &&
8748 ruleinfo[i].ev_type == '1' && ruleinfo[i].is_instead)
8749 {
8750 addObjectDependency(&ruleinfo[i].ruletable->dobj,
8751 ruleinfo[i].dobj.dumpId);
8752 /* We'll merge the rule into CREATE VIEW, if possible */
8753 ruleinfo[i].separate = false;
8754 }
8755 else
8756 {
8758 ruleinfo[i].ruletable->dobj.dumpId);
8759 ruleinfo[i].separate = true;
8760 }
8761 }
8762 else
8763 ruleinfo[i].separate = true;
8764 }
8765
8766 PQclear(res);
8767
8768 destroyPQExpBuffer(query);
8769}

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:8388
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6215
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4804
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7877
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7821
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10519
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4226
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20195
void getTypes(Archive *fout)
Definition pg_dump.c:6290
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7756
void getOpclasses(Archive *fout)
Definition pg_dump.c:6736
void getForeignServers(Archive *fout)
Definition pg_dump.c:10613
void getFuncs(Archive *fout)
Definition pg_dump.c:7005
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10335
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4884
void getCasts(Archive *fout)
Definition pg_dump.c:9137
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7937
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10460
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6662
void getConversions(Archive *fout)
Definition pg_dump.c:6600
void getRules(Archive *fout)
Definition pg_dump.c:8682
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9331
void getCollations(Archive *fout)
Definition pg_dump.c:6534
void getAggregates(Archive *fout)
Definition pg_dump.c:6864
void getNamespaces(Archive *fout)
Definition pg_dump.c:6083
void getPublications(Archive *fout)
Definition pg_dump.c:4516
void getTSParsers(Archive *fout)
Definition pg_dump.c:10261
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7278
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8306
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20288
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10701
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5159
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8779
void getTransforms(Archive *fout)
Definition pg_dump.c:9247
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8975
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10401
void getProcLangs(Archive *fout)
Definition pg_dump.c:9053
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5408
void getOperators(Archive *fout)
Definition pg_dump.c:6458
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6799

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 5408 of file pg_dump.c.

5409{
5410 DumpOptions *dopt = fout->dopt;
5411 SubscriptionInfo *subinfo = NULL;
5413 PGresult *res;
5414 int i_srsubid;
5415 int i_srrelid;
5416 int i_srsubstate;
5417 int i_srsublsn;
5418 int ntups;
5420
5421 if (dopt->no_subscriptions || !dopt->binary_upgrade ||
5422 fout->remoteVersion < 170000)
5423 return;
5424
5425 res = ExecuteSqlQuery(fout,
5426 "SELECT srsubid, srrelid, srsubstate, srsublsn "
5427 "FROM pg_catalog.pg_subscription_rel "
5428 "ORDER BY srsubid",
5430 ntups = PQntuples(res);
5431 if (ntups == 0)
5432 goto cleanup;
5433
5434 /* Get pg_subscription_rel attributes */
5435 i_srsubid = PQfnumber(res, "srsubid");
5436 i_srrelid = PQfnumber(res, "srrelid");
5437 i_srsubstate = PQfnumber(res, "srsubstate");
5438 i_srsublsn = PQfnumber(res, "srsublsn");
5439
5441 for (int i = 0; i < ntups; i++)
5442 {
5444 Oid relid = atooid(PQgetvalue(res, i, i_srrelid));
5445 TableInfo *tblinfo;
5446
5447 /*
5448 * If we switched to a new subscription, check if the subscription
5449 * exists.
5450 */
5452 {
5454 if (subinfo == NULL)
5455 pg_fatal("subscription with OID %u does not exist", cur_srsubid);
5456
5458 }
5459
5460 tblinfo = findTableByOid(relid);
5461 if (tblinfo == NULL)
5462 pg_fatal("failed sanity check, relation with OID %u not found",
5463 relid);
5464
5465 /* OK, make a DumpableObject for this relationship */
5466 subrinfo[i].dobj.objType = DO_SUBSCRIPTION_REL;
5467 subrinfo[i].dobj.catId.tableoid = relid;
5468 subrinfo[i].dobj.catId.oid = cur_srsubid;
5469 AssignDumpId(&subrinfo[i].dobj);
5470 subrinfo[i].dobj.namespace = tblinfo->dobj.namespace;
5471 subrinfo[i].dobj.name = tblinfo->dobj.name;
5472 subrinfo[i].subinfo = subinfo;
5473 subrinfo[i].tblinfo = tblinfo;
5474 subrinfo[i].srsubstate = PQgetvalue(res, i, i_srsubstate)[0];
5475 if (PQgetisnull(res, i, i_srsublsn))
5476 subrinfo[i].srsublsn = NULL;
5477 else
5478 subrinfo[i].srsublsn = pg_strdup(PQgetvalue(res, i, i_srsublsn));
5479
5480 /* Decide whether we want to dump it */
5482 }
5483
5484cleanup:
5485 PQclear(res);
5486}
SubscriptionInfo * findSubscriptionByOid(Oid oid)
Definition common.c:1045
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 5159 of file pg_dump.c.

5160{
5161 DumpOptions *dopt = fout->dopt;
5162 PQExpBuffer query;
5163 PGresult *res;
5164 SubscriptionInfo *subinfo;
5165 int i_tableoid;
5166 int i_oid;
5167 int i_subname;
5168 int i_subowner;
5169 int i_subbinary;
5170 int i_substream;
5174 int i_subrunasowner;
5175 int i_subservername;
5176 int i_subconninfo;
5177 int i_subslotname;
5178 int i_subsynccommit;
5181 int i_suborigin;
5183 int i_subenabled;
5184 int i_subfailover;
5187 int i,
5188 ntups;
5189
5190 if (dopt->no_subscriptions || fout->remoteVersion < 100000)
5191 return;
5192
5193 if (!is_superuser(fout))
5194 {
5195 int n;
5196
5197 res = ExecuteSqlQuery(fout,
5198 "SELECT count(*) FROM pg_subscription "
5199 "WHERE subdbid = (SELECT oid FROM pg_database"
5200 " WHERE datname = current_database())",
5202 n = atoi(PQgetvalue(res, 0, 0));
5203 if (n > 0)
5204 pg_log_warning("subscriptions not dumped because current user is not a superuser");
5205 PQclear(res);
5206 return;
5207 }
5208
5209 query = createPQExpBuffer();
5210
5211 /* Get the subscriptions in current database. */
5213 "SELECT s.tableoid, s.oid, s.subname,\n"
5214 " s.subowner,\n"
5215 " s.subconninfo, s.subslotname, s.subsynccommit,\n"
5216 " s.subpublications,\n");
5217
5218 if (fout->remoteVersion >= 140000)
5219 appendPQExpBufferStr(query, " s.subbinary,\n");
5220 else
5221 appendPQExpBufferStr(query, " false AS subbinary,\n");
5222
5223 if (fout->remoteVersion >= 140000)
5224 appendPQExpBufferStr(query, " s.substream,\n");
5225 else
5226 appendPQExpBufferStr(query, " 'f' AS substream,\n");
5227
5228 if (fout->remoteVersion >= 150000)
5230 " s.subtwophasestate,\n"
5231 " s.subdisableonerr,\n");
5232 else
5233 appendPQExpBuffer(query,
5234 " '%c' AS subtwophasestate,\n"
5235 " false AS subdisableonerr,\n",
5237
5238 if (fout->remoteVersion >= 160000)
5240 " s.subpasswordrequired,\n"
5241 " s.subrunasowner,\n"
5242 " s.suborigin,\n");
5243 else
5244 appendPQExpBuffer(query,
5245 " 't' AS subpasswordrequired,\n"
5246 " 't' AS subrunasowner,\n"
5247 " '%s' AS suborigin,\n",
5249
5250 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5251 appendPQExpBufferStr(query, " o.remote_lsn AS suboriginremotelsn,\n"
5252 " s.subenabled,\n");
5253 else
5254 appendPQExpBufferStr(query, " NULL AS suboriginremotelsn,\n"
5255 " false AS subenabled,\n");
5256
5257 if (fout->remoteVersion >= 170000)
5259 " s.subfailover,\n");
5260 else
5262 " false AS subfailover,\n");
5263
5264 if (fout->remoteVersion >= 190000)
5266 " s.subretaindeadtuples,\n");
5267 else
5269 " false AS subretaindeadtuples,\n");
5270
5271 if (fout->remoteVersion >= 190000)
5273 " s.submaxretention,\n");
5274 else
5275 appendPQExpBufferStr(query, " 0 AS submaxretention,\n");
5276
5277 if (fout->remoteVersion >= 190000)
5279 " s.subwalrcvtimeout,\n");
5280 else
5282 " '-1' AS subwalrcvtimeout,\n");
5283
5284 if (fout->remoteVersion >= 190000)
5285 appendPQExpBufferStr(query, " fs.srvname AS subservername\n");
5286 else
5287 appendPQExpBufferStr(query, " NULL AS subservername\n");
5288
5290 "FROM pg_subscription s\n");
5291
5292 if (fout->remoteVersion >= 190000)
5294 "LEFT JOIN pg_catalog.pg_foreign_server fs \n"
5295 " ON fs.oid = s.subserver \n");
5296
5297 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5299 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
5300 " ON o.external_id = 'pg_' || s.oid::text \n");
5301
5303 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
5304 " WHERE datname = current_database())");
5305
5306 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5307
5308 ntups = PQntuples(res);
5309
5310 /*
5311 * Get subscription fields. We don't include subskiplsn in the dump as
5312 * after restoring the dump this value may no longer be relevant.
5313 */
5314 i_tableoid = PQfnumber(res, "tableoid");
5315 i_oid = PQfnumber(res, "oid");
5316 i_subname = PQfnumber(res, "subname");
5317 i_subowner = PQfnumber(res, "subowner");
5318 i_subenabled = PQfnumber(res, "subenabled");
5319 i_subbinary = PQfnumber(res, "subbinary");
5320 i_substream = PQfnumber(res, "substream");
5321 i_subtwophasestate = PQfnumber(res, "subtwophasestate");
5322 i_subdisableonerr = PQfnumber(res, "subdisableonerr");
5323 i_subpasswordrequired = PQfnumber(res, "subpasswordrequired");
5324 i_subrunasowner = PQfnumber(res, "subrunasowner");
5325 i_subfailover = PQfnumber(res, "subfailover");
5326 i_subretaindeadtuples = PQfnumber(res, "subretaindeadtuples");
5327 i_submaxretention = PQfnumber(res, "submaxretention");
5328 i_subservername = PQfnumber(res, "subservername");
5329 i_subconninfo = PQfnumber(res, "subconninfo");
5330 i_subslotname = PQfnumber(res, "subslotname");
5331 i_subsynccommit = PQfnumber(res, "subsynccommit");
5332 i_subwalrcvtimeout = PQfnumber(res, "subwalrcvtimeout");
5333 i_subpublications = PQfnumber(res, "subpublications");
5334 i_suborigin = PQfnumber(res, "suborigin");
5335 i_suboriginremotelsn = PQfnumber(res, "suboriginremotelsn");
5336
5337 subinfo = pg_malloc_array(SubscriptionInfo, ntups);
5338
5339 for (i = 0; i < ntups; i++)
5340 {
5341 subinfo[i].dobj.objType = DO_SUBSCRIPTION;
5342 subinfo[i].dobj.catId.tableoid =
5343 atooid(PQgetvalue(res, i, i_tableoid));
5344 subinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5345 AssignDumpId(&subinfo[i].dobj);
5346 subinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_subname));
5347 subinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_subowner));
5348
5349 subinfo[i].subenabled =
5350 (strcmp(PQgetvalue(res, i, i_subenabled), "t") == 0);
5351 if (PQgetisnull(res, i, i_subservername))
5352 subinfo[i].subservername = NULL;
5353 else
5355 subinfo[i].subbinary =
5356 (strcmp(PQgetvalue(res, i, i_subbinary), "t") == 0);
5357 subinfo[i].substream = *(PQgetvalue(res, i, i_substream));
5358 subinfo[i].subtwophasestate = *(PQgetvalue(res, i, i_subtwophasestate));
5359 subinfo[i].subdisableonerr =
5360 (strcmp(PQgetvalue(res, i, i_subdisableonerr), "t") == 0);
5361 subinfo[i].subpasswordrequired =
5362 (strcmp(PQgetvalue(res, i, i_subpasswordrequired), "t") == 0);
5363 subinfo[i].subrunasowner =
5364 (strcmp(PQgetvalue(res, i, i_subrunasowner), "t") == 0);
5365 subinfo[i].subfailover =
5366 (strcmp(PQgetvalue(res, i, i_subfailover), "t") == 0);
5367 subinfo[i].subretaindeadtuples =
5368 (strcmp(PQgetvalue(res, i, i_subretaindeadtuples), "t") == 0);
5369 subinfo[i].submaxretention =
5371 if (PQgetisnull(res, i, i_subconninfo))
5372 subinfo[i].subconninfo = NULL;
5373 else
5374 subinfo[i].subconninfo =
5376 if (PQgetisnull(res, i, i_subslotname))
5377 subinfo[i].subslotname = NULL;
5378 else
5379 subinfo[i].subslotname =
5381 subinfo[i].subsynccommit =
5383 subinfo[i].subwalrcvtimeout =
5385 subinfo[i].subpublications =
5387 subinfo[i].suborigin = pg_strdup(PQgetvalue(res, i, i_suborigin));
5389 subinfo[i].suboriginremotelsn = NULL;
5390 else
5391 subinfo[i].suboriginremotelsn =
5393
5394 /* Decide whether we want to dump it */
5395 selectDumpableObject(&(subinfo[i].dobj), fout);
5396 }
5397 PQclear(res);
5398
5399 destroyPQExpBuffer(query);
5400}
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::subservername, _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 9331 of file pg_dump.c.

9332{
9333 DumpOptions *dopt = fout->dopt;
9338 PGresult *res;
9339 int ntups;
9340 int curtblindx;
9341 int i_attrelid;
9342 int i_attnum;
9343 int i_attname;
9344 int i_atttypname;
9345 int i_attstattarget;
9346 int i_attstorage;
9347 int i_typstorage;
9348 int i_attidentity;
9349 int i_attgenerated;
9350 int i_attisdropped;
9351 int i_attlen;
9352 int i_attalign;
9353 int i_attislocal;
9354 int i_notnull_name;
9359 int i_attoptions;
9360 int i_attcollation;
9361 int i_attcompression;
9362 int i_attfdwoptions;
9363 int i_attmissingval;
9364 int i_atthasdef;
9365
9366 /*
9367 * We want to perform just one query against pg_attribute, and then just
9368 * one against pg_attrdef (for DEFAULTs) and two against pg_constraint
9369 * (for CHECK constraints and for NOT NULL constraints). However, we
9370 * mustn't try to select every row of those catalogs and then sort it out
9371 * on the client side, because some of the server-side functions we need
9372 * would be unsafe to apply to tables we don't have lock on. Hence, we
9373 * build an array of the OIDs of tables we care about (and now have lock
9374 * on!), and use a WHERE clause to constrain which rows are selected.
9375 */
9378 for (int i = 0; i < numTables; i++)
9379 {
9380 TableInfo *tbinfo = &tblinfo[i];
9381
9382 /* Don't bother to collect info for sequences */
9383 if (tbinfo->relkind == RELKIND_SEQUENCE)
9384 continue;
9385
9386 /*
9387 * Don't bother with uninteresting tables, either. For binary
9388 * upgrades, this is bypassed for pg_largeobject_metadata and
9389 * pg_shdepend so that the columns names are collected for the
9390 * corresponding COPY commands. Restoring the data for those catalogs
9391 * is faster than restoring the equivalent set of large object
9392 * commands.
9393 */
9394 if (!tbinfo->interesting &&
9395 !(fout->dopt->binary_upgrade &&
9396 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9397 tbinfo->dobj.catId.oid == SharedDependRelationId)))
9398 continue;
9399
9400 /* OK, we need info for this table */
9401 if (tbloids->len > 1) /* do we have more than the '{'? */
9403 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9404
9405 if (tbinfo->ncheck > 0)
9406 {
9407 /* Also make a list of the ones with check constraints */
9408 if (checkoids->len > 1) /* do we have more than the '{'? */
9410 appendPQExpBuffer(checkoids, "%u", tbinfo->dobj.catId.oid);
9411 }
9412 }
9415
9416 /*
9417 * Find all the user attributes and their types.
9418 *
9419 * Since we only want to dump COLLATE clauses for attributes whose
9420 * collation is different from their type's default, we use a CASE here to
9421 * suppress uninteresting attcollations cheaply.
9422 */
9424 "SELECT\n"
9425 "a.attrelid,\n"
9426 "a.attnum,\n"
9427 "a.attname,\n"
9428 "a.attstattarget,\n"
9429 "a.attstorage,\n"
9430 "t.typstorage,\n"
9431 "a.atthasdef,\n"
9432 "a.attisdropped,\n"
9433 "a.attlen,\n"
9434 "a.attalign,\n"
9435 "a.attislocal,\n"
9436 "pg_catalog.format_type(t.oid, a.atttypmod) AS atttypname,\n"
9437 "array_to_string(a.attoptions, ', ') AS attoptions,\n"
9438 "CASE WHEN a.attcollation <> t.typcollation "
9439 "THEN a.attcollation ELSE 0 END AS attcollation,\n"
9440 "pg_catalog.array_to_string(ARRAY("
9441 "SELECT pg_catalog.quote_ident(option_name) || "
9442 "' ' || pg_catalog.quote_literal(option_value) "
9443 "FROM pg_catalog.pg_options_to_table(attfdwoptions) "
9444 "ORDER BY option_name"
9445 "), E',\n ') AS attfdwoptions,\n");
9446
9447 /*
9448 * Find out any NOT NULL markings for each column. In 18 and up we read
9449 * pg_constraint to obtain the constraint name, and for valid constraints
9450 * also pg_description to obtain its comment. notnull_noinherit is set
9451 * according to the NO INHERIT property. For versions prior to 18, we
9452 * store an empty string as the name when a constraint is marked as
9453 * attnotnull (this cues dumpTableSchema to print the NOT NULL clause
9454 * without a name); also, such cases are never NO INHERIT.
9455 *
9456 * For invalid constraints, we need to store their OIDs for processing
9457 * elsewhere, so we bring the pg_constraint.oid value when the constraint
9458 * is invalid, and NULL otherwise. Their comments are handled not here
9459 * but by collectComments, because they're their own dumpable object.
9460 *
9461 * We track in notnull_islocal whether the constraint was defined directly
9462 * in this table or via an ancestor, for binary upgrade. flagInhAttrs
9463 * might modify this later.
9464 */
9465 if (fout->remoteVersion >= 180000)
9467 "co.conname AS notnull_name,\n"
9468 "CASE WHEN co.convalidated THEN pt.description"
9469 " ELSE NULL END AS notnull_comment,\n"
9470 "CASE WHEN NOT co.convalidated THEN co.oid "
9471 "ELSE NULL END AS notnull_invalidoid,\n"
9472 "co.connoinherit AS notnull_noinherit,\n"
9473 "co.conislocal AS notnull_islocal,\n");
9474 else
9476 "CASE WHEN a.attnotnull THEN '' ELSE NULL END AS notnull_name,\n"
9477 "NULL AS notnull_comment,\n"
9478 "NULL AS notnull_invalidoid,\n"
9479 "false AS notnull_noinherit,\n"
9480 "CASE WHEN a.attislocal THEN true\n"
9481 " WHEN a.attnotnull AND NOT a.attislocal THEN true\n"
9482 " ELSE false\n"
9483 "END AS notnull_islocal,\n");
9484
9485 if (fout->remoteVersion >= 140000)
9487 "a.attcompression AS attcompression,\n");
9488 else
9490 "'' AS attcompression,\n");
9491
9492 if (fout->remoteVersion >= 100000)
9494 "a.attidentity,\n");
9495 else
9497 "'' AS attidentity,\n");
9498
9499 if (fout->remoteVersion >= 110000)
9501 "CASE WHEN a.atthasmissing AND NOT a.attisdropped "
9502 "THEN a.attmissingval ELSE null END AS attmissingval,\n");
9503 else
9505 "NULL AS attmissingval,\n");
9506
9507 if (fout->remoteVersion >= 120000)
9509 "a.attgenerated\n");
9510 else
9512 "'' AS attgenerated\n");
9513
9514 /* need left join to pg_type to not fail on dropped columns ... */
9516 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9517 "JOIN pg_catalog.pg_attribute a ON (src.tbloid = a.attrelid) "
9518 "LEFT JOIN pg_catalog.pg_type t "
9519 "ON (a.atttypid = t.oid)\n",
9520 tbloids->data);
9521
9522 /*
9523 * In versions 18 and up, we need pg_constraint for explicit NOT NULL
9524 * entries and pg_description to get their comments.
9525 */
9526 if (fout->remoteVersion >= 180000)
9528 " LEFT JOIN pg_catalog.pg_constraint co ON "
9529 "(a.attrelid = co.conrelid\n"
9530 " AND co.contype = 'n' AND "
9531 "co.conkey = array[a.attnum])\n"
9532 " LEFT JOIN pg_catalog.pg_description pt ON "
9533 "(pt.classoid = co.tableoid AND pt.objoid = co.oid)\n");
9534
9536 "WHERE a.attnum > 0::pg_catalog.int2\n");
9537
9538 /*
9539 * For binary upgrades from <v12, be sure to pick up
9540 * pg_largeobject_metadata's oid column.
9541 */
9542 if (fout->dopt->binary_upgrade && fout->remoteVersion < 120000)
9544 "OR (a.attnum = -2::pg_catalog.int2 AND src.tbloid = "
9546
9548 "ORDER BY a.attrelid, a.attnum");
9549
9551
9552 ntups = PQntuples(res);
9553
9554 i_attrelid = PQfnumber(res, "attrelid");
9555 i_attnum = PQfnumber(res, "attnum");
9556 i_attname = PQfnumber(res, "attname");
9557 i_atttypname = PQfnumber(res, "atttypname");
9558 i_attstattarget = PQfnumber(res, "attstattarget");
9559 i_attstorage = PQfnumber(res, "attstorage");
9560 i_typstorage = PQfnumber(res, "typstorage");
9561 i_attidentity = PQfnumber(res, "attidentity");
9562 i_attgenerated = PQfnumber(res, "attgenerated");
9563 i_attisdropped = PQfnumber(res, "attisdropped");
9564 i_attlen = PQfnumber(res, "attlen");
9565 i_attalign = PQfnumber(res, "attalign");
9566 i_attislocal = PQfnumber(res, "attislocal");
9567 i_notnull_name = PQfnumber(res, "notnull_name");
9568 i_notnull_comment = PQfnumber(res, "notnull_comment");
9569 i_notnull_invalidoid = PQfnumber(res, "notnull_invalidoid");
9570 i_notnull_noinherit = PQfnumber(res, "notnull_noinherit");
9571 i_notnull_islocal = PQfnumber(res, "notnull_islocal");
9572 i_attoptions = PQfnumber(res, "attoptions");
9573 i_attcollation = PQfnumber(res, "attcollation");
9574 i_attcompression = PQfnumber(res, "attcompression");
9575 i_attfdwoptions = PQfnumber(res, "attfdwoptions");
9576 i_attmissingval = PQfnumber(res, "attmissingval");
9577 i_atthasdef = PQfnumber(res, "atthasdef");
9578
9579 /* Within the next loop, we'll accumulate OIDs of tables with defaults */
9582
9583 /*
9584 * Outer loop iterates once per table, not once per row. Incrementing of
9585 * r is handled by the inner loop.
9586 */
9587 curtblindx = -1;
9588 for (int r = 0; r < ntups;)
9589 {
9590 Oid attrelid = atooid(PQgetvalue(res, r, i_attrelid));
9592 int numatts;
9593 bool hasdefaults;
9594
9595 /* Count rows for this table */
9596 for (numatts = 1; numatts < ntups - r; numatts++)
9597 if (atooid(PQgetvalue(res, r + numatts, i_attrelid)) != attrelid)
9598 break;
9599
9600 /*
9601 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
9602 * order.
9603 */
9604 while (++curtblindx < numTables)
9605 {
9606 tbinfo = &tblinfo[curtblindx];
9607 if (tbinfo->dobj.catId.oid == attrelid)
9608 break;
9609 }
9610 if (curtblindx >= numTables)
9611 pg_fatal("unrecognized table OID %u", attrelid);
9612 /* cross-check that we only got requested tables */
9613 if (tbinfo->relkind == RELKIND_SEQUENCE ||
9614 (!tbinfo->interesting &&
9615 !(fout->dopt->binary_upgrade &&
9616 (tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId ||
9617 tbinfo->dobj.catId.oid == SharedDependRelationId))))
9618 pg_fatal("unexpected column data for table \"%s\"",
9619 tbinfo->dobj.name);
9620
9621 /* Save data for this table */
9622 tbinfo->numatts = numatts;
9623 tbinfo->attnames = pg_malloc_array(char *, numatts);
9624 tbinfo->atttypnames = pg_malloc_array(char *, numatts);
9625 tbinfo->attstattarget = pg_malloc_array(int, numatts);
9626 tbinfo->attstorage = pg_malloc_array(char, numatts);
9627 tbinfo->typstorage = pg_malloc_array(char, numatts);
9628 tbinfo->attidentity = pg_malloc_array(char, numatts);
9629 tbinfo->attgenerated = pg_malloc_array(char, numatts);
9630 tbinfo->attisdropped = pg_malloc_array(bool, numatts);
9631 tbinfo->attlen = pg_malloc_array(int, numatts);
9632 tbinfo->attalign = pg_malloc_array(char, numatts);
9633 tbinfo->attislocal = pg_malloc_array(bool, numatts);
9634 tbinfo->attoptions = pg_malloc_array(char *, numatts);
9635 tbinfo->attcollation = pg_malloc_array(Oid, numatts);
9636 tbinfo->attcompression = pg_malloc_array(char, numatts);
9637 tbinfo->attfdwoptions = pg_malloc_array(char *, numatts);
9638 tbinfo->attmissingval = pg_malloc_array(char *, numatts);
9639 tbinfo->notnull_constrs = pg_malloc_array(char *, numatts);
9640 tbinfo->notnull_comment = pg_malloc_array(char *, numatts);
9641 tbinfo->notnull_invalid = pg_malloc_array(bool, numatts);
9642 tbinfo->notnull_noinh = pg_malloc_array(bool, numatts);
9643 tbinfo->notnull_islocal = pg_malloc_array(bool, numatts);
9644 tbinfo->attrdefs = pg_malloc_array(AttrDefInfo *, numatts);
9645 hasdefaults = false;
9646
9647 for (int j = 0; j < numatts; j++, r++)
9648 {
9649 if (j + 1 != atoi(PQgetvalue(res, r, i_attnum)) &&
9650 !(fout->dopt->binary_upgrade && fout->remoteVersion < 120000 &&
9651 tbinfo->dobj.catId.oid == LargeObjectMetadataRelationId))
9652 pg_fatal("invalid column numbering in table \"%s\"",
9653 tbinfo->dobj.name);
9654 tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, r, i_attname));
9655 tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, r, i_atttypname));
9656 if (PQgetisnull(res, r, i_attstattarget))
9657 tbinfo->attstattarget[j] = -1;
9658 else
9659 tbinfo->attstattarget[j] = atoi(PQgetvalue(res, r, i_attstattarget));
9660 tbinfo->attstorage[j] = *(PQgetvalue(res, r, i_attstorage));
9661 tbinfo->typstorage[j] = *(PQgetvalue(res, r, i_typstorage));
9662 tbinfo->attidentity[j] = *(PQgetvalue(res, r, i_attidentity));
9663 tbinfo->attgenerated[j] = *(PQgetvalue(res, r, i_attgenerated));
9664 tbinfo->needs_override = tbinfo->needs_override || (tbinfo->attidentity[j] == ATTRIBUTE_IDENTITY_ALWAYS);
9665 tbinfo->attisdropped[j] = (PQgetvalue(res, r, i_attisdropped)[0] == 't');
9666 tbinfo->attlen[j] = atoi(PQgetvalue(res, r, i_attlen));
9667 tbinfo->attalign[j] = *(PQgetvalue(res, r, i_attalign));
9668 tbinfo->attislocal[j] = (PQgetvalue(res, r, i_attislocal)[0] == 't');
9669
9670 /* Handle not-null constraint name and flags */
9672 tbinfo, j,
9679
9680 tbinfo->notnull_comment[j] = PQgetisnull(res, r, i_notnull_comment) ?
9682 tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, r, i_attoptions));
9683 tbinfo->attcollation[j] = atooid(PQgetvalue(res, r, i_attcollation));
9684 tbinfo->attcompression[j] = *(PQgetvalue(res, r, i_attcompression));
9685 tbinfo->attfdwoptions[j] = pg_strdup(PQgetvalue(res, r, i_attfdwoptions));
9686 tbinfo->attmissingval[j] = pg_strdup(PQgetvalue(res, r, i_attmissingval));
9687 tbinfo->attrdefs[j] = NULL; /* fix below */
9688 if (PQgetvalue(res, r, i_atthasdef)[0] == 't')
9689 hasdefaults = true;
9690 }
9691
9692 if (hasdefaults)
9693 {
9694 /* Collect OIDs of interesting tables that have defaults */
9695 if (tbloids->len > 1) /* do we have more than the '{'? */
9697 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
9698 }
9699 }
9700
9701 /* If invalidnotnulloids has any data, finalize it */
9702 if (invalidnotnulloids != NULL)
9704
9705 PQclear(res);
9706
9707 /*
9708 * Now get info about column defaults. This is skipped for a data-only
9709 * dump, as it is only needed for table schemas.
9710 */
9711 if (dopt->dumpSchema && tbloids->len > 1)
9712 {
9713 AttrDefInfo *attrdefs;
9714 int numDefaults;
9716
9717 pg_log_info("finding table default expressions");
9718
9720
9721 printfPQExpBuffer(q, "SELECT a.tableoid, a.oid, adrelid, adnum, "
9722 "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc\n"
9723 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9724 "JOIN pg_catalog.pg_attrdef a ON (src.tbloid = a.adrelid)\n"
9725 "ORDER BY a.adrelid, a.adnum",
9726 tbloids->data);
9727
9729
9730 numDefaults = PQntuples(res);
9732
9733 curtblindx = -1;
9734 for (int j = 0; j < numDefaults; j++)
9735 {
9736 Oid adtableoid = atooid(PQgetvalue(res, j, 0));
9737 Oid adoid = atooid(PQgetvalue(res, j, 1));
9738 Oid adrelid = atooid(PQgetvalue(res, j, 2));
9739 int adnum = atoi(PQgetvalue(res, j, 3));
9740 char *adsrc = PQgetvalue(res, j, 4);
9741
9742 /*
9743 * Locate the associated TableInfo; we rely on tblinfo[] being in
9744 * OID order.
9745 */
9746 if (tbinfo == NULL || tbinfo->dobj.catId.oid != adrelid)
9747 {
9748 while (++curtblindx < numTables)
9749 {
9750 tbinfo = &tblinfo[curtblindx];
9751 if (tbinfo->dobj.catId.oid == adrelid)
9752 break;
9753 }
9754 if (curtblindx >= numTables)
9755 pg_fatal("unrecognized table OID %u", adrelid);
9756 }
9757
9758 if (adnum <= 0 || adnum > tbinfo->numatts)
9759 pg_fatal("invalid adnum value %d for table \"%s\"",
9760 adnum, tbinfo->dobj.name);
9761
9762 /*
9763 * dropped columns shouldn't have defaults, but just in case,
9764 * ignore 'em
9765 */
9766 if (tbinfo->attisdropped[adnum - 1])
9767 continue;
9768
9769 attrdefs[j].dobj.objType = DO_ATTRDEF;
9770 attrdefs[j].dobj.catId.tableoid = adtableoid;
9771 attrdefs[j].dobj.catId.oid = adoid;
9772 AssignDumpId(&attrdefs[j].dobj);
9773 attrdefs[j].adtable = tbinfo;
9774 attrdefs[j].adnum = adnum;
9775 attrdefs[j].adef_expr = pg_strdup(adsrc);
9776
9777 attrdefs[j].dobj.name = pg_strdup(tbinfo->dobj.name);
9778 attrdefs[j].dobj.namespace = tbinfo->dobj.namespace;
9779
9780 attrdefs[j].dobj.dump = tbinfo->dobj.dump;
9781
9782 /*
9783 * Figure out whether the default/generation expression should be
9784 * dumped as part of the main CREATE TABLE (or similar) command or
9785 * as a separate ALTER TABLE (or similar) command. The preference
9786 * is to put it into the CREATE command, but in some cases that's
9787 * not possible.
9788 */
9789 if (tbinfo->attgenerated[adnum - 1])
9790 {
9791 /*
9792 * Column generation expressions cannot be dumped separately,
9793 * because there is no syntax for it. By setting separate to
9794 * false here we prevent the "default" from being processed as
9795 * its own dumpable object. Later, flagInhAttrs() will mark
9796 * it as not to be dumped at all, if possible (that is, if it
9797 * can be inherited from a parent).
9798 */
9799 attrdefs[j].separate = false;
9800 }
9801 else if (tbinfo->relkind == RELKIND_VIEW)
9802 {
9803 /*
9804 * Defaults on a VIEW must always be dumped as separate ALTER
9805 * TABLE commands.
9806 */
9807 attrdefs[j].separate = true;
9808 }
9809 else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1))
9810 {
9811 /* column will be suppressed, print default separately */
9812 attrdefs[j].separate = true;
9813 }
9814 else
9815 {
9816 attrdefs[j].separate = false;
9817 }
9818
9819 if (!attrdefs[j].separate)
9820 {
9821 /*
9822 * Mark the default as needing to appear before the table, so
9823 * that any dependencies it has must be emitted before the
9824 * CREATE TABLE. If this is not possible, we'll change to
9825 * "separate" mode while sorting dependencies.
9826 */
9828 attrdefs[j].dobj.dumpId);
9829 }
9830
9831 tbinfo->attrdefs[adnum - 1] = &attrdefs[j];
9832 }
9833
9834 PQclear(res);
9835 }
9836
9837 /*
9838 * Get info about NOT NULL NOT VALID constraints. This is skipped for a
9839 * data-only dump, as it is only needed for table schemas.
9840 */
9841 if (dopt->dumpSchema && invalidnotnulloids)
9842 {
9844 int numConstrs;
9845 int i_tableoid;
9846 int i_oid;
9847 int i_conrelid;
9848 int i_conname;
9849 int i_consrc;
9850 int i_conislocal;
9851
9852 pg_log_info("finding invalid not-null constraints");
9853
9856 "SELECT c.tableoid, c.oid, conrelid, conname, "
9857 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9858 "conislocal, convalidated "
9859 "FROM unnest('%s'::pg_catalog.oid[]) AS src(conoid)\n"
9860 "JOIN pg_catalog.pg_constraint c ON (src.conoid = c.oid)\n"
9861 "ORDER BY c.conrelid, c.conname",
9862 invalidnotnulloids->data);
9863
9865
9866 numConstrs = PQntuples(res);
9868
9869 i_tableoid = PQfnumber(res, "tableoid");
9870 i_oid = PQfnumber(res, "oid");
9871 i_conrelid = PQfnumber(res, "conrelid");
9872 i_conname = PQfnumber(res, "conname");
9873 i_consrc = PQfnumber(res, "consrc");
9874 i_conislocal = PQfnumber(res, "conislocal");
9875
9876 /* As above, this loop iterates once per table, not once per row */
9877 curtblindx = -1;
9878 for (int j = 0; j < numConstrs;)
9879 {
9880 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9882 int numcons;
9883
9884 /* Count rows for this table */
9885 for (numcons = 1; numcons < numConstrs - j; numcons++)
9886 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9887 break;
9888
9889 /*
9890 * Locate the associated TableInfo; we rely on tblinfo[] being in
9891 * OID order.
9892 */
9893 while (++curtblindx < numTables)
9894 {
9895 tbinfo = &tblinfo[curtblindx];
9896 if (tbinfo->dobj.catId.oid == conrelid)
9897 break;
9898 }
9899 if (curtblindx >= numTables)
9900 pg_fatal("unrecognized table OID %u", conrelid);
9901
9902 for (int c = 0; c < numcons; c++, j++)
9903 {
9904 constrs[j].dobj.objType = DO_CONSTRAINT;
9905 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
9906 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
9907 AssignDumpId(&constrs[j].dobj);
9908 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
9909 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
9910 constrs[j].contable = tbinfo;
9911 constrs[j].condomain = NULL;
9912 constrs[j].contype = 'n';
9913 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
9914 constrs[j].confrelid = InvalidOid;
9915 constrs[j].conindex = 0;
9916 constrs[j].condeferrable = false;
9917 constrs[j].condeferred = false;
9918 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
9919
9920 /*
9921 * All invalid not-null constraints must be dumped separately,
9922 * because CREATE TABLE would not create them as invalid, and
9923 * also because they must be created after potentially
9924 * violating data has been loaded.
9925 */
9926 constrs[j].separate = true;
9927
9928 constrs[j].dobj.dump = tbinfo->dobj.dump;
9929 }
9930 }
9931 PQclear(res);
9932 }
9933
9934 /*
9935 * Get info about table CHECK constraints. This is skipped for a
9936 * data-only dump, as it is only needed for table schemas.
9937 */
9938 if (dopt->dumpSchema && checkoids->len > 2)
9939 {
9941 int numConstrs;
9942 int i_tableoid;
9943 int i_oid;
9944 int i_conrelid;
9945 int i_conname;
9946 int i_consrc;
9947 int i_conislocal;
9948 int i_convalidated;
9949
9950 pg_log_info("finding table check constraints");
9951
9954 "SELECT c.tableoid, c.oid, conrelid, conname, "
9955 "pg_catalog.pg_get_constraintdef(c.oid) AS consrc, "
9956 "conislocal, convalidated "
9957 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
9958 "JOIN pg_catalog.pg_constraint c ON (src.tbloid = c.conrelid)\n"
9959 "WHERE contype = 'c' "
9960 "ORDER BY c.conrelid, c.conname",
9961 checkoids->data);
9962
9964
9965 numConstrs = PQntuples(res);
9967
9968 i_tableoid = PQfnumber(res, "tableoid");
9969 i_oid = PQfnumber(res, "oid");
9970 i_conrelid = PQfnumber(res, "conrelid");
9971 i_conname = PQfnumber(res, "conname");
9972 i_consrc = PQfnumber(res, "consrc");
9973 i_conislocal = PQfnumber(res, "conislocal");
9974 i_convalidated = PQfnumber(res, "convalidated");
9975
9976 /* As above, this loop iterates once per table, not once per row */
9977 curtblindx = -1;
9978 for (int j = 0; j < numConstrs;)
9979 {
9980 Oid conrelid = atooid(PQgetvalue(res, j, i_conrelid));
9982 int numcons;
9983
9984 /* Count rows for this table */
9985 for (numcons = 1; numcons < numConstrs - j; numcons++)
9986 if (atooid(PQgetvalue(res, j + numcons, i_conrelid)) != conrelid)
9987 break;
9988
9989 /*
9990 * Locate the associated TableInfo; we rely on tblinfo[] being in
9991 * OID order.
9992 */
9993 while (++curtblindx < numTables)
9994 {
9995 tbinfo = &tblinfo[curtblindx];
9996 if (tbinfo->dobj.catId.oid == conrelid)
9997 break;
9998 }
9999 if (curtblindx >= numTables)
10000 pg_fatal("unrecognized table OID %u", conrelid);
10001
10002 if (numcons != tbinfo->ncheck)
10003 {
10004 pg_log_error(ngettext("expected %d check constraint on table \"%s\" but found %d",
10005 "expected %d check constraints on table \"%s\" but found %d",
10006 tbinfo->ncheck),
10007 tbinfo->ncheck, tbinfo->dobj.name, numcons);
10008 pg_log_error_hint("The system catalogs might be corrupted.");
10009 exit_nicely(1);
10010 }
10011
10012 tbinfo->checkexprs = constrs + j;
10013
10014 for (int c = 0; c < numcons; c++, j++)
10015 {
10016 bool validated = PQgetvalue(res, j, i_convalidated)[0] == 't';
10017
10018 constrs[j].dobj.objType = DO_CONSTRAINT;
10019 constrs[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
10020 constrs[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
10021 AssignDumpId(&constrs[j].dobj);
10022 constrs[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_conname));
10023 constrs[j].dobj.namespace = tbinfo->dobj.namespace;
10024 constrs[j].contable = tbinfo;
10025 constrs[j].condomain = NULL;
10026 constrs[j].contype = 'c';
10027 constrs[j].condef = pg_strdup(PQgetvalue(res, j, i_consrc));
10028 constrs[j].confrelid = InvalidOid;
10029 constrs[j].conindex = 0;
10030 constrs[j].condeferrable = false;
10031 constrs[j].condeferred = false;
10032 constrs[j].conislocal = (PQgetvalue(res, j, i_conislocal)[0] == 't');
10033
10034 /*
10035 * An unvalidated constraint needs to be dumped separately, so
10036 * that potentially-violating existing data is loaded before
10037 * the constraint.
10038 */
10039 constrs[j].separate = !validated;
10040
10041 constrs[j].dobj.dump = tbinfo->dobj.dump;
10042
10043 /*
10044 * Mark the constraint as needing to appear before the table
10045 * --- this is so that any other dependencies of the
10046 * constraint will be emitted before we try to create the
10047 * table. If the constraint is to be dumped separately, it
10048 * will be dumped after data is loaded anyway, so don't do it.
10049 * (There's an automatic dependency in the opposite direction
10050 * anyway, so don't need to add one manually here.)
10051 */
10052 if (!constrs[j].separate)
10054 constrs[j].dobj.dumpId);
10055
10056 /*
10057 * We will detect later whether the constraint must be split
10058 * out from the table definition.
10059 */
10060 }
10061 }
10062
10063 PQclear(res);
10064 }
10065
10069}
#define ngettext(s, p, n)
Definition c.h:1270
#define CppAsString2(x)
Definition c.h:506
#define pg_log_error(...)
Definition logging.h:108
#define pg_log_error_hint(...)
Definition logging.h:114
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:10119
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10246
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 7278 of file pg_dump.c.

7279{
7280 DumpOptions *dopt = fout->dopt;
7281 PGresult *res;
7282 int ntups;
7283 int i;
7285 TableInfo *tblinfo;
7286 int i_reltableoid;
7287 int i_reloid;
7288 int i_relname;
7289 int i_relnamespace;
7290 int i_relkind;
7291 int i_reltype;
7292 int i_relowner;
7293 int i_relchecks;
7294 int i_relhasindex;
7295 int i_relhasrules;
7296 int i_relpages;
7297 int i_reltuples;
7298 int i_relallvisible;
7299 int i_relallfrozen;
7300 int i_toastpages;
7301 int i_owning_tab;
7302 int i_owning_col;
7303 int i_reltablespace;
7304 int i_relhasoids;
7305 int i_relhastriggers;
7306 int i_relpersistence;
7307 int i_relispopulated;
7308 int i_relreplident;
7309 int i_relrowsec;
7310 int i_relforcerowsec;
7311 int i_relfrozenxid;
7312 int i_toastfrozenxid;
7313 int i_toastoid;
7314 int i_relminmxid;
7315 int i_toastminmxid;
7316 int i_reloptions;
7317 int i_checkoption;
7319 int i_reloftype;
7320 int i_foreignserver;
7321 int i_amname;
7323 int i_relacl;
7324 int i_acldefault;
7325 int i_ispartition;
7326
7327 /*
7328 * Find all the tables and table-like objects.
7329 *
7330 * We must fetch all tables in this phase because otherwise we cannot
7331 * correctly identify inherited columns, owned sequences, etc.
7332 *
7333 * We include system catalogs, so that we can work if a user table is
7334 * defined to inherit from a system catalog (pretty weird, but...)
7335 *
7336 * Note: in this phase we should collect only a minimal amount of
7337 * information about each table, basically just enough to decide if it is
7338 * interesting. In particular, since we do not yet have lock on any user
7339 * table, we MUST NOT invoke any server-side data collection functions
7340 * (for instance, pg_get_partkeydef()). Those are likely to fail or give
7341 * wrong answers if any concurrent DDL is happening.
7342 */
7343
7345 "SELECT c.tableoid, c.oid, c.relname, "
7346 "c.relnamespace, c.relkind, c.reltype, "
7347 "c.relowner, "
7348 "c.relchecks, "
7349 "c.relhasindex, c.relhasrules, c.relpages, "
7350 "c.reltuples, c.relallvisible, ");
7351
7352 if (fout->remoteVersion >= 180000)
7353 appendPQExpBufferStr(query, "c.relallfrozen, ");
7354 else
7355 appendPQExpBufferStr(query, "0 AS relallfrozen, ");
7356
7358 "c.relhastriggers, c.relpersistence, "
7359 "c.reloftype, "
7360 "c.relacl, "
7361 "acldefault(CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE)
7362 " THEN 's'::\"char\" ELSE 'r'::\"char\" END, c.relowner) AS acldefault, "
7363 "CASE WHEN c.relkind = " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN "
7364 "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) "
7365 "ELSE 0 END AS foreignserver, "
7366 "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, "
7367 "tc.oid AS toid, "
7368 "tc.relpages AS toastpages, "
7369 "tc.reloptions AS toast_reloptions, "
7370 "d.refobjid AS owning_tab, "
7371 "d.refobjsubid AS owning_col, "
7372 "tsp.spcname AS reltablespace, ");
7373
7374 if (fout->remoteVersion >= 120000)
7376 "false AS relhasoids, ");
7377 else
7379 "c.relhasoids, ");
7380
7381 if (fout->remoteVersion >= 90300)
7383 "c.relispopulated, ");
7384 else
7386 "'t' as relispopulated, ");
7387
7388 if (fout->remoteVersion >= 90400)
7390 "c.relreplident, ");
7391 else
7393 "'d' AS relreplident, ");
7394
7395 if (fout->remoteVersion >= 90500)
7397 "c.relrowsecurity, c.relforcerowsecurity, ");
7398 else
7400 "false AS relrowsecurity, "
7401 "false AS relforcerowsecurity, ");
7402
7403 if (fout->remoteVersion >= 90300)
7405 "c.relminmxid, tc.relminmxid AS tminmxid, ");
7406 else
7408 "0 AS relminmxid, 0 AS tminmxid, ");
7409
7410 if (fout->remoteVersion >= 90300)
7412 "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
7413 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
7414 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, ");
7415 else
7417 "c.reloptions, NULL AS checkoption, ");
7418
7419 if (fout->remoteVersion >= 90600)
7421 "am.amname, ");
7422 else
7424 "NULL AS amname, ");
7425
7426 if (fout->remoteVersion >= 90600)
7428 "(d.deptype = 'i') IS TRUE AS is_identity_sequence, ");
7429 else
7431 "false AS is_identity_sequence, ");
7432
7433 if (fout->remoteVersion >= 100000)
7435 "c.relispartition AS ispartition ");
7436 else
7438 "false AS ispartition ");
7439
7440 /*
7441 * Left join to pg_depend to pick up dependency info linking sequences to
7442 * their owning column, if any (note this dependency is AUTO except for
7443 * identity sequences, where it's INTERNAL). Also join to pg_tablespace to
7444 * collect the spcname.
7445 */
7447 "\nFROM pg_class c\n"
7448 "LEFT JOIN pg_depend d ON "
7449 "(c.relkind = " CppAsString2(RELKIND_SEQUENCE) " AND "
7450 "d.classid = 'pg_class'::regclass AND d.objid = c.oid AND "
7451 "d.objsubid = 0 AND "
7452 "d.refclassid = 'pg_class'::regclass AND d.deptype IN ('a', 'i'))\n"
7453 "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n");
7454
7455 /*
7456 * In 9.6 and up, left join to pg_am to pick up the amname.
7457 */
7458 if (fout->remoteVersion >= 90600)
7460 "LEFT JOIN pg_am am ON (c.relam = am.oid)\n");
7461
7462 /*
7463 * We purposefully ignore toast OIDs for partitioned tables; the reason is
7464 * that versions 10 and 11 have them, but later versions do not, so
7465 * emitting them causes the upgrade to fail.
7466 */
7468 "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid"
7469 " AND tc.relkind = " CppAsString2(RELKIND_TOASTVALUE)
7470 " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n");
7471
7472 /*
7473 * Restrict to interesting relkinds (in particular, not indexes). Not all
7474 * relkinds are possible in older servers, but it's not worth the trouble
7475 * to emit a version-dependent list.
7476 *
7477 * Composite-type table entries won't be dumped as such, but we have to
7478 * make a DumpableObject for them so that we can track dependencies of the
7479 * composite type (pg_depend entries for columns of the composite type
7480 * link to the pg_class entry not the pg_type entry).
7481 */
7483 "WHERE c.relkind IN ("
7492 "ORDER BY c.oid");
7493
7494 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
7495
7496 ntups = PQntuples(res);
7497
7498 *numTables = ntups;
7499
7500 /*
7501 * Extract data from result and lock dumpable tables. We do the locking
7502 * before anything else, to minimize the window wherein a table could
7503 * disappear under us.
7504 *
7505 * Note that we have to save info about all tables here, even when dumping
7506 * only one, because we don't yet know which tables might be inheritance
7507 * ancestors of the target table.
7508 */
7509 tblinfo = pg_malloc0_array(TableInfo, ntups);
7510
7511 i_reltableoid = PQfnumber(res, "tableoid");
7512 i_reloid = PQfnumber(res, "oid");
7513 i_relname = PQfnumber(res, "relname");
7514 i_relnamespace = PQfnumber(res, "relnamespace");
7515 i_relkind = PQfnumber(res, "relkind");
7516 i_reltype = PQfnumber(res, "reltype");
7517 i_relowner = PQfnumber(res, "relowner");
7518 i_relchecks = PQfnumber(res, "relchecks");
7519 i_relhasindex = PQfnumber(res, "relhasindex");
7520 i_relhasrules = PQfnumber(res, "relhasrules");
7521 i_relpages = PQfnumber(res, "relpages");
7522 i_reltuples = PQfnumber(res, "reltuples");
7523 i_relallvisible = PQfnumber(res, "relallvisible");
7524 i_relallfrozen = PQfnumber(res, "relallfrozen");
7525 i_toastpages = PQfnumber(res, "toastpages");
7526 i_owning_tab = PQfnumber(res, "owning_tab");
7527 i_owning_col = PQfnumber(res, "owning_col");
7528 i_reltablespace = PQfnumber(res, "reltablespace");
7529 i_relhasoids = PQfnumber(res, "relhasoids");
7530 i_relhastriggers = PQfnumber(res, "relhastriggers");
7531 i_relpersistence = PQfnumber(res, "relpersistence");
7532 i_relispopulated = PQfnumber(res, "relispopulated");
7533 i_relreplident = PQfnumber(res, "relreplident");
7534 i_relrowsec = PQfnumber(res, "relrowsecurity");
7535 i_relforcerowsec = PQfnumber(res, "relforcerowsecurity");
7536 i_relfrozenxid = PQfnumber(res, "relfrozenxid");
7537 i_toastfrozenxid = PQfnumber(res, "tfrozenxid");
7538 i_toastoid = PQfnumber(res, "toid");
7539 i_relminmxid = PQfnumber(res, "relminmxid");
7540 i_toastminmxid = PQfnumber(res, "tminmxid");
7541 i_reloptions = PQfnumber(res, "reloptions");
7542 i_checkoption = PQfnumber(res, "checkoption");
7543 i_toastreloptions = PQfnumber(res, "toast_reloptions");
7544 i_reloftype = PQfnumber(res, "reloftype");
7545 i_foreignserver = PQfnumber(res, "foreignserver");
7546 i_amname = PQfnumber(res, "amname");
7547 i_is_identity_sequence = PQfnumber(res, "is_identity_sequence");
7548 i_relacl = PQfnumber(res, "relacl");
7549 i_acldefault = PQfnumber(res, "acldefault");
7550 i_ispartition = PQfnumber(res, "ispartition");
7551
7552 if (dopt->lockWaitTimeout)
7553 {
7554 /*
7555 * Arrange to fail instead of waiting forever for a table lock.
7556 *
7557 * NB: this coding assumes that the only queries issued within the
7558 * following loop are LOCK TABLEs; else the timeout may be undesirably
7559 * applied to other things too.
7560 */
7561 resetPQExpBuffer(query);
7562 appendPQExpBufferStr(query, "SET statement_timeout = ");
7564 ExecuteSqlStatement(fout, query->data);
7565 }
7566
7567 resetPQExpBuffer(query);
7568
7569 for (i = 0; i < ntups; i++)
7570 {
7571 int32 relallvisible = atoi(PQgetvalue(res, i, i_relallvisible));
7572 int32 relallfrozen = atoi(PQgetvalue(res, i, i_relallfrozen));
7573
7574 tblinfo[i].dobj.objType = DO_TABLE;
7575 tblinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_reltableoid));
7576 tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid));
7577 AssignDumpId(&tblinfo[i].dobj);
7578 tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname));
7579 tblinfo[i].dobj.namespace =
7581 tblinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_relacl));
7582 tblinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
7583 tblinfo[i].dacl.privtype = 0;
7584 tblinfo[i].dacl.initprivs = NULL;
7585 tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind));
7586 tblinfo[i].reltype = atooid(PQgetvalue(res, i, i_reltype));
7587 tblinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_relowner));
7588 tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
7589 tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0);
7590 tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0);
7591 tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages));
7592 if (PQgetisnull(res, i, i_toastpages))
7593 tblinfo[i].toastpages = 0;
7594 else
7595 tblinfo[i].toastpages = atoi(PQgetvalue(res, i, i_toastpages));
7596 if (PQgetisnull(res, i, i_owning_tab))
7597 {
7598 tblinfo[i].owning_tab = InvalidOid;
7599 tblinfo[i].owning_col = 0;
7600 }
7601 else
7602 {
7603 tblinfo[i].owning_tab = atooid(PQgetvalue(res, i, i_owning_tab));
7604 tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col));
7605 }
7607 tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);
7608 tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);
7609 tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence));
7610 tblinfo[i].relispopulated = (strcmp(PQgetvalue(res, i, i_relispopulated), "t") == 0);
7611 tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident));
7612 tblinfo[i].rowsec = (strcmp(PQgetvalue(res, i, i_relrowsec), "t") == 0);
7613 tblinfo[i].forcerowsec = (strcmp(PQgetvalue(res, i, i_relforcerowsec), "t") == 0);
7614 tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid));
7616 tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid));
7617 tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid));
7618 tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid));
7619 tblinfo[i].reloptions = pg_strdup(PQgetvalue(res, i, i_reloptions));
7620 if (PQgetisnull(res, i, i_checkoption))
7621 tblinfo[i].checkoption = NULL;
7622 else
7623 tblinfo[i].checkoption = pg_strdup(PQgetvalue(res, i, i_checkoption));
7625 tblinfo[i].reloftype = atooid(PQgetvalue(res, i, i_reloftype));
7627 if (PQgetisnull(res, i, i_amname))
7628 tblinfo[i].amname = NULL;
7629 else
7630 tblinfo[i].amname = pg_strdup(PQgetvalue(res, i, i_amname));
7631 tblinfo[i].is_identity_sequence = (strcmp(PQgetvalue(res, i, i_is_identity_sequence), "t") == 0);
7632 tblinfo[i].ispartition = (strcmp(PQgetvalue(res, i, i_ispartition), "t") == 0);
7633
7634 /* other fields were zeroed above */
7635
7636 /*
7637 * Decide whether we want to dump this table.
7638 */
7639 if (tblinfo[i].relkind == RELKIND_COMPOSITE_TYPE)
7640 tblinfo[i].dobj.dump = DUMP_COMPONENT_NONE;
7641 else
7642 selectDumpableTable(&tblinfo[i], fout);
7643
7644 /*
7645 * Now, consider the table "interesting" if we need to dump its
7646 * definition, data or its statistics. Later on, we'll skip a lot of
7647 * data collection for uninteresting tables.
7648 *
7649 * Note: the "interesting" flag will also be set by flagInhTables for
7650 * parents of interesting tables, so that we collect necessary
7651 * inheritance info even when the parents are not themselves being
7652 * dumped. This is the main reason why we need an "interesting" flag
7653 * that's separate from the components-to-dump bitmask.
7654 */
7655 tblinfo[i].interesting = (tblinfo[i].dobj.dump &
7659
7660 tblinfo[i].dummy_view = false; /* might get set during sort */
7661 tblinfo[i].postponed_def = false; /* might get set during sort */
7662
7663 /* Tables have data */
7665
7666 /* Mark whether table has an ACL */
7667 if (!PQgetisnull(res, i, i_relacl))
7668 tblinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
7669 tblinfo[i].hascolumnACLs = false; /* may get set later */
7670
7671 /* Add statistics */
7672 if (tblinfo[i].interesting)
7673 {
7674 RelStatsInfo *stats;
7675
7676 stats = getRelationStatistics(fout, &tblinfo[i].dobj,
7677 tblinfo[i].relpages,
7678 PQgetvalue(res, i, i_reltuples),
7679 relallvisible, relallfrozen,
7680 tblinfo[i].relkind, NULL, 0);
7681 if (tblinfo[i].relkind == RELKIND_MATVIEW)
7682 tblinfo[i].stats = stats;
7683 }
7684
7685 /*
7686 * Read-lock target tables to make sure they aren't DROPPED or altered
7687 * in schema before we get around to dumping them.
7688 *
7689 * Note that we don't explicitly lock parents of the target tables; we
7690 * assume our lock on the child is enough to prevent schema
7691 * alterations to parent tables.
7692 *
7693 * NOTE: it'd be kinda nice to lock other relations too, not only
7694 * plain or partitioned tables, but the backend doesn't presently
7695 * allow that.
7696 *
7697 * We only need to lock the table for certain components; see
7698 * pg_dump.h
7699 */
7700 if ((tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK) &&
7701 (tblinfo[i].relkind == RELKIND_RELATION ||
7702 tblinfo[i].relkind == RELKIND_PARTITIONED_TABLE))
7703 {
7704 /*
7705 * Tables are locked in batches. When dumping from a remote
7706 * server this can save a significant amount of time by reducing
7707 * the number of round trips.
7708 */
7709 if (query->len == 0)
7710 appendPQExpBuffer(query, "LOCK TABLE %s",
7711 fmtQualifiedDumpable(&tblinfo[i]));
7712 else
7713 {
7714 appendPQExpBuffer(query, ", %s",
7715 fmtQualifiedDumpable(&tblinfo[i]));
7716
7717 /* Arbitrarily end a batch when query length reaches 100K. */
7718 if (query->len >= 100000)
7719 {
7720 /* Lock another batch of tables. */
7721 appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7722 ExecuteSqlStatement(fout, query->data);
7723 resetPQExpBuffer(query);
7724 }
7725 }
7726 }
7727 }
7728
7729 if (query->len != 0)
7730 {
7731 /* Lock the tables in the last batch. */
7732 appendPQExpBufferStr(query, " IN ACCESS SHARE MODE");
7733 ExecuteSqlStatement(fout, query->data);
7734 }
7735
7736 if (dopt->lockWaitTimeout)
7737 {
7738 ExecuteSqlStatement(fout, "SET statement_timeout = 0");
7739 }
7740
7741 PQclear(res);
7742
7743 destroyPQExpBuffer(query);
7744
7745 return tblinfo;
7746}
void ExecuteSqlStatement(Archive *AHX, const char *query)
static void selectDumpableTable(TableInfo *tbinfo, Archive *fout)
Definition pg_dump.c:2068
#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 9247 of file pg_dump.c.

9248{
9249 PGresult *res;
9250 int ntups;
9251 int i;
9252 PQExpBuffer query;
9254 int i_tableoid;
9255 int i_oid;
9256 int i_trftype;
9257 int i_trflang;
9258 int i_trffromsql;
9259 int i_trftosql;
9260
9261 /* Transforms didn't exist pre-9.5 */
9262 if (fout->remoteVersion < 90500)
9263 return;
9264
9265 query = createPQExpBuffer();
9266
9267 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9268 "trftype, trflang, trffromsql::oid, trftosql::oid "
9269 "FROM pg_transform "
9270 "ORDER BY 3,4");
9271
9272 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9273
9274 ntups = PQntuples(res);
9275
9277
9278 i_tableoid = PQfnumber(res, "tableoid");
9279 i_oid = PQfnumber(res, "oid");
9280 i_trftype = PQfnumber(res, "trftype");
9281 i_trflang = PQfnumber(res, "trflang");
9282 i_trffromsql = PQfnumber(res, "trffromsql");
9283 i_trftosql = PQfnumber(res, "trftosql");
9284
9285 for (i = 0; i < ntups; i++)
9286 {
9289 char *lanname;
9290
9292 transforminfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9293 transforminfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9295 transforminfo[i].trftype = atooid(PQgetvalue(res, i, i_trftype));
9296 transforminfo[i].trflang = atooid(PQgetvalue(res, i, i_trflang));
9297 transforminfo[i].trffromsql = atooid(PQgetvalue(res, i, i_trffromsql));
9298 transforminfo[i].trftosql = atooid(PQgetvalue(res, i, i_trftosql));
9299
9300 /*
9301 * Try to name transform as concatenation of type and language name.
9302 * This is only used for purposes of sorting. If we fail to find
9303 * either, the name will be an empty string.
9304 */
9308 if (typeInfo && lanname)
9309 appendPQExpBuffer(&namebuf, "%s %s",
9310 typeInfo->dobj.name, lanname);
9311 transforminfo[i].dobj.name = namebuf.data;
9312 free(lanname);
9313
9314 /* Decide whether we want to dump it */
9316 }
9317
9318 PQclear(res);
9319
9320 destroyPQExpBuffer(query);
9321}
static char * get_language_name(Archive *fout, Oid langid)
Definition pg_dump.c:9226

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 8779 of file pg_dump.c.

8780{
8783 PGresult *res;
8784 int ntups;
8785 int curtblindx;
8787 int i_tableoid,
8788 i_oid,
8789 i_tgrelid,
8790 i_tgname,
8793 i_tgdef;
8794
8795 /*
8796 * We want to perform just one query against pg_trigger. However, we
8797 * mustn't try to select every row of the catalog and then sort it out on
8798 * the client side, because some of the server-side functions we need
8799 * would be unsafe to apply to tables we don't have lock on. Hence, we
8800 * build an array of the OIDs of tables we care about (and now have lock
8801 * on!), and use a WHERE clause to constrain which rows are selected.
8802 */
8804 for (int i = 0; i < numTables; i++)
8805 {
8806 TableInfo *tbinfo = &tblinfo[i];
8807
8808 if (!tbinfo->hastriggers ||
8809 !(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
8810 continue;
8811
8812 /* OK, we need info for this table */
8813 if (tbloids->len > 1) /* do we have more than the '{'? */
8815 appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
8816 }
8818
8819 if (fout->remoteVersion >= 150000)
8820 {
8821 /*
8822 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8823 * result in non-forward-compatible dumps of WHEN clauses due to
8824 * under-parenthesization.
8825 *
8826 * NB: We need to see partition triggers in case the tgenabled flag
8827 * has been changed from the parent.
8828 */
8829 appendPQExpBuffer(query,
8830 "SELECT t.tgrelid, t.tgname, "
8831 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8832 "t.tgenabled, t.tableoid, t.oid, "
8833 "t.tgparentid <> 0 AS tgispartition\n"
8834 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8835 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8836 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8837 "WHERE ((NOT t.tgisinternal AND t.tgparentid = 0) "
8838 "OR t.tgenabled != u.tgenabled) "
8839 "ORDER BY t.tgrelid, t.tgname",
8840 tbloids->data);
8841 }
8842 else if (fout->remoteVersion >= 130000)
8843 {
8844 /*
8845 * NB: think not to use pretty=true in pg_get_triggerdef. It could
8846 * result in non-forward-compatible dumps of WHEN clauses due to
8847 * under-parenthesization.
8848 *
8849 * NB: We need to see tgisinternal triggers in partitions, in case the
8850 * tgenabled flag has been changed from the parent.
8851 */
8852 appendPQExpBuffer(query,
8853 "SELECT t.tgrelid, t.tgname, "
8854 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8855 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8856 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8857 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8858 "LEFT JOIN pg_catalog.pg_trigger u ON (u.oid = t.tgparentid) "
8859 "WHERE (NOT t.tgisinternal OR t.tgenabled != u.tgenabled) "
8860 "ORDER BY t.tgrelid, t.tgname",
8861 tbloids->data);
8862 }
8863 else if (fout->remoteVersion >= 110000)
8864 {
8865 /*
8866 * NB: We need to see tgisinternal triggers in partitions, in case the
8867 * tgenabled flag has been changed from the parent. No tgparentid in
8868 * version 11-12, so we have to match them via pg_depend.
8869 *
8870 * See above about pretty=true in pg_get_triggerdef.
8871 */
8872 appendPQExpBuffer(query,
8873 "SELECT t.tgrelid, t.tgname, "
8874 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8875 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8876 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8877 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8878 "LEFT JOIN pg_catalog.pg_depend AS d ON "
8879 " d.classid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8880 " d.refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass AND "
8881 " d.objid = t.oid "
8882 "LEFT JOIN pg_catalog.pg_trigger AS pt ON pt.oid = refobjid "
8883 "WHERE (NOT t.tgisinternal OR t.tgenabled != pt.tgenabled) "
8884 "ORDER BY t.tgrelid, t.tgname",
8885 tbloids->data);
8886 }
8887 else
8888 {
8889 /* See above about pretty=true in pg_get_triggerdef */
8890 appendPQExpBuffer(query,
8891 "SELECT t.tgrelid, t.tgname, "
8892 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8893 "t.tgenabled, false as tgispartition, "
8894 "t.tableoid, t.oid "
8895 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
8896 "JOIN pg_catalog.pg_trigger t ON (src.tbloid = t.tgrelid) "
8897 "WHERE NOT tgisinternal "
8898 "ORDER BY t.tgrelid, t.tgname",
8899 tbloids->data);
8900 }
8901
8902 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
8903
8904 ntups = PQntuples(res);
8905
8906 i_tableoid = PQfnumber(res, "tableoid");
8907 i_oid = PQfnumber(res, "oid");
8908 i_tgrelid = PQfnumber(res, "tgrelid");
8909 i_tgname = PQfnumber(res, "tgname");
8910 i_tgenabled = PQfnumber(res, "tgenabled");
8911 i_tgispartition = PQfnumber(res, "tgispartition");
8912 i_tgdef = PQfnumber(res, "tgdef");
8913
8915
8916 /*
8917 * Outer loop iterates once per table, not once per row. Incrementing of
8918 * j is handled by the inner loop.
8919 */
8920 curtblindx = -1;
8921 for (int j = 0; j < ntups;)
8922 {
8925 int numtrigs;
8926
8927 /* Count rows for this table */
8928 for (numtrigs = 1; numtrigs < ntups - j; numtrigs++)
8929 if (atooid(PQgetvalue(res, j + numtrigs, i_tgrelid)) != tgrelid)
8930 break;
8931
8932 /*
8933 * Locate the associated TableInfo; we rely on tblinfo[] being in OID
8934 * order.
8935 */
8936 while (++curtblindx < numTables)
8937 {
8938 tbinfo = &tblinfo[curtblindx];
8939 if (tbinfo->dobj.catId.oid == tgrelid)
8940 break;
8941 }
8942 if (curtblindx >= numTables)
8943 pg_fatal("unrecognized table OID %u", tgrelid);
8944
8945 /* Save data for this table */
8946 tbinfo->triggers = tginfo + j;
8947 tbinfo->numTriggers = numtrigs;
8948
8949 for (int c = 0; c < numtrigs; c++, j++)
8950 {
8951 tginfo[j].dobj.objType = DO_TRIGGER;
8952 tginfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
8953 tginfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
8954 AssignDumpId(&tginfo[j].dobj);
8955 tginfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_tgname));
8956 tginfo[j].dobj.namespace = tbinfo->dobj.namespace;
8957 tginfo[j].tgtable = tbinfo;
8958 tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
8959 tginfo[j].tgispartition = *(PQgetvalue(res, j, i_tgispartition)) == 't';
8960 tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
8961 }
8962 }
8963
8964 PQclear(res);
8965
8966 destroyPQExpBuffer(query);
8968}

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 10460 of file pg_dump.c.

10461{
10462 PGresult *res;
10463 int ntups;
10464 int i;
10465 PQExpBuffer query;
10467 int i_tableoid;
10468 int i_oid;
10469 int i_cfgname;
10470 int i_cfgnamespace;
10471 int i_cfgowner;
10472 int i_cfgparser;
10473
10474 query = createPQExpBuffer();
10475
10476 appendPQExpBufferStr(query, "SELECT tableoid, oid, cfgname, "
10477 "cfgnamespace, cfgowner, cfgparser "
10478 "FROM pg_ts_config");
10479
10480 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10481
10482 ntups = PQntuples(res);
10483
10485
10486 i_tableoid = PQfnumber(res, "tableoid");
10487 i_oid = PQfnumber(res, "oid");
10488 i_cfgname = PQfnumber(res, "cfgname");
10489 i_cfgnamespace = PQfnumber(res, "cfgnamespace");
10490 i_cfgowner = PQfnumber(res, "cfgowner");
10491 i_cfgparser = PQfnumber(res, "cfgparser");
10492
10493 for (i = 0; i < ntups; i++)
10494 {
10495 cfginfo[i].dobj.objType = DO_TSCONFIG;
10496 cfginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10497 cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10498 AssignDumpId(&cfginfo[i].dobj);
10499 cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
10500 cfginfo[i].dobj.namespace =
10502 cfginfo[i].rolname = getRoleName(PQgetvalue(res, i, i_cfgowner));
10503 cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
10504
10505 /* Decide whether we want to dump it */
10507 }
10508
10509 PQclear(res);
10510
10511 destroyPQExpBuffer(query);
10512}

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 10335 of file pg_dump.c.

10336{
10337 PGresult *res;
10338 int ntups;
10339 int i;
10340 PQExpBuffer query;
10342 int i_tableoid;
10343 int i_oid;
10344 int i_dictname;
10345 int i_dictnamespace;
10346 int i_dictowner;
10347 int i_dicttemplate;
10348 int i_dictinitoption;
10349
10350 query = createPQExpBuffer();
10351
10352 appendPQExpBufferStr(query, "SELECT tableoid, oid, dictname, "
10353 "dictnamespace, dictowner, "
10354 "dicttemplate, dictinitoption "
10355 "FROM pg_ts_dict");
10356
10357 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10358
10359 ntups = PQntuples(res);
10360
10362
10363 i_tableoid = PQfnumber(res, "tableoid");
10364 i_oid = PQfnumber(res, "oid");
10365 i_dictname = PQfnumber(res, "dictname");
10366 i_dictnamespace = PQfnumber(res, "dictnamespace");
10367 i_dictowner = PQfnumber(res, "dictowner");
10368 i_dictinitoption = PQfnumber(res, "dictinitoption");
10369 i_dicttemplate = PQfnumber(res, "dicttemplate");
10370
10371 for (i = 0; i < ntups; i++)
10372 {
10373 dictinfo[i].dobj.objType = DO_TSDICT;
10374 dictinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10375 dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10376 AssignDumpId(&dictinfo[i].dobj);
10377 dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
10378 dictinfo[i].dobj.namespace =
10380 dictinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_dictowner));
10381 dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
10382 if (PQgetisnull(res, i, i_dictinitoption))
10383 dictinfo[i].dictinitoption = NULL;
10384 else
10385 dictinfo[i].dictinitoption = pg_strdup(PQgetvalue(res, i, i_dictinitoption));
10386
10387 /* Decide whether we want to dump it */
10389 }
10390
10391 PQclear(res);
10392
10393 destroyPQExpBuffer(query);
10394}

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 10261 of file pg_dump.c.

10262{
10263 PGresult *res;
10264 int ntups;
10265 int i;
10266 PQExpBuffer query;
10268 int i_tableoid;
10269 int i_oid;
10270 int i_prsname;
10271 int i_prsnamespace;
10272 int i_prsstart;
10273 int i_prstoken;
10274 int i_prsend;
10275 int i_prsheadline;
10276 int i_prslextype;
10277
10278 query = createPQExpBuffer();
10279
10280 /*
10281 * find all text search objects, including builtin ones; we filter out
10282 * system-defined objects at dump-out time.
10283 */
10284
10285 appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, "
10286 "prsstart::oid, prstoken::oid, "
10287 "prsend::oid, prsheadline::oid, prslextype::oid "
10288 "FROM pg_ts_parser");
10289
10290 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10291
10292 ntups = PQntuples(res);
10293
10295
10296 i_tableoid = PQfnumber(res, "tableoid");
10297 i_oid = PQfnumber(res, "oid");
10298 i_prsname = PQfnumber(res, "prsname");
10299 i_prsnamespace = PQfnumber(res, "prsnamespace");
10300 i_prsstart = PQfnumber(res, "prsstart");
10301 i_prstoken = PQfnumber(res, "prstoken");
10302 i_prsend = PQfnumber(res, "prsend");
10303 i_prsheadline = PQfnumber(res, "prsheadline");
10304 i_prslextype = PQfnumber(res, "prslextype");
10305
10306 for (i = 0; i < ntups; i++)
10307 {
10308 prsinfo[i].dobj.objType = DO_TSPARSER;
10309 prsinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10310 prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10311 AssignDumpId(&prsinfo[i].dobj);
10312 prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
10313 prsinfo[i].dobj.namespace =
10315 prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
10316 prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
10317 prsinfo[i].prsend = atooid(PQgetvalue(res, i, i_prsend));
10318 prsinfo[i].prsheadline = atooid(PQgetvalue(res, i, i_prsheadline));
10319 prsinfo[i].prslextype = atooid(PQgetvalue(res, i, i_prslextype));
10320
10321 /* Decide whether we want to dump it */
10323 }
10324
10325 PQclear(res);
10326
10327 destroyPQExpBuffer(query);
10328}

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 10401 of file pg_dump.c.

10402{
10403 PGresult *res;
10404 int ntups;
10405 int i;
10406 PQExpBuffer query;
10408 int i_tableoid;
10409 int i_oid;
10410 int i_tmplname;
10411 int i_tmplnamespace;
10412 int i_tmplinit;
10413 int i_tmpllexize;
10414
10415 query = createPQExpBuffer();
10416
10417 appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
10418 "tmplnamespace, tmplinit::oid, tmpllexize::oid "
10419 "FROM pg_ts_template");
10420
10421 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10422
10423 ntups = PQntuples(res);
10424
10426
10427 i_tableoid = PQfnumber(res, "tableoid");
10428 i_oid = PQfnumber(res, "oid");
10429 i_tmplname = PQfnumber(res, "tmplname");
10430 i_tmplnamespace = PQfnumber(res, "tmplnamespace");
10431 i_tmplinit = PQfnumber(res, "tmplinit");
10432 i_tmpllexize = PQfnumber(res, "tmpllexize");
10433
10434 for (i = 0; i < ntups; i++)
10435 {
10436 tmplinfo[i].dobj.objType = DO_TSTEMPLATE;
10437 tmplinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
10438 tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
10439 AssignDumpId(&tmplinfo[i].dobj);
10440 tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
10441 tmplinfo[i].dobj.namespace =
10443 tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
10444 tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
10445
10446 /* Decide whether we want to dump it */
10448 }
10449
10450 PQclear(res);
10451
10452 destroyPQExpBuffer(query);
10453}

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 6290 of file pg_dump.c.

6291{
6292 PGresult *res;
6293 int ntups;
6294 int i;
6298 int i_tableoid;
6299 int i_oid;
6300 int i_typname;
6301 int i_typnamespace;
6302 int i_typacl;
6303 int i_acldefault;
6304 int i_typowner;
6305 int i_typelem;
6306 int i_typrelid;
6307 int i_typrelkind;
6308 int i_typtype;
6309 int i_typisdefined;
6310 int i_isarray;
6311 int i_typarray;
6312
6313 /*
6314 * we include even the built-in types because those may be used as array
6315 * elements by user-defined types
6316 *
6317 * we filter out the built-in types when we dump out the types
6318 *
6319 * same approach for undefined (shell) types and array types
6320 *
6321 * Note: as of 8.3 we can reliably detect whether a type is an
6322 * auto-generated array type by checking the element type's typarray.
6323 * (Before that the test is capable of generating false positives.) We
6324 * still check for name beginning with '_', though, so as to avoid the
6325 * cost of the subselect probe for all standard types. This would have to
6326 * be revisited if the backend ever allows renaming of array types.
6327 */
6328 appendPQExpBufferStr(query, "SELECT tableoid, oid, typname, "
6329 "typnamespace, typacl, "
6330 "acldefault('T', typowner) AS acldefault, "
6331 "typowner, "
6332 "typelem, typrelid, typarray, "
6333 "CASE WHEN typrelid = 0 THEN ' '::\"char\" "
6334 "ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
6335 "typtype, typisdefined, "
6336 "typname[0] = '_' AND typelem != 0 AND "
6337 "(SELECT typarray FROM pg_type te WHERE oid = pg_type.typelem) = oid AS isarray "
6338 "FROM pg_type");
6339
6340 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
6341
6342 ntups = PQntuples(res);
6343
6345
6346 i_tableoid = PQfnumber(res, "tableoid");
6347 i_oid = PQfnumber(res, "oid");
6348 i_typname = PQfnumber(res, "typname");
6349 i_typnamespace = PQfnumber(res, "typnamespace");
6350 i_typacl = PQfnumber(res, "typacl");
6351 i_acldefault = PQfnumber(res, "acldefault");
6352 i_typowner = PQfnumber(res, "typowner");
6353 i_typelem = PQfnumber(res, "typelem");
6354 i_typrelid = PQfnumber(res, "typrelid");
6355 i_typrelkind = PQfnumber(res, "typrelkind");
6356 i_typtype = PQfnumber(res, "typtype");
6357 i_typisdefined = PQfnumber(res, "typisdefined");
6358 i_isarray = PQfnumber(res, "isarray");
6359 i_typarray = PQfnumber(res, "typarray");
6360
6361 for (i = 0; i < ntups; i++)
6362 {
6363 tyinfo[i].dobj.objType = DO_TYPE;
6364 tyinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
6365 tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
6366 AssignDumpId(&tyinfo[i].dobj);
6367 tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
6368 tyinfo[i].dobj.namespace =
6370 tyinfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_typacl));
6371 tyinfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
6372 tyinfo[i].dacl.privtype = 0;
6373 tyinfo[i].dacl.initprivs = NULL;
6374 tyinfo[i].ftypname = NULL; /* may get filled later */
6375 tyinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_typowner));
6376 tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
6377 tyinfo[i].typrelid = atooid(PQgetvalue(res, i, i_typrelid));
6378 tyinfo[i].typrelkind = *PQgetvalue(res, i, i_typrelkind);
6379 tyinfo[i].typtype = *PQgetvalue(res, i, i_typtype);
6380 tyinfo[i].shellType = NULL;
6381
6382 if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0)
6383 tyinfo[i].isDefined = true;
6384 else
6385 tyinfo[i].isDefined = false;
6386
6387 if (strcmp(PQgetvalue(res, i, i_isarray), "t") == 0)
6388 tyinfo[i].isArray = true;
6389 else
6390 tyinfo[i].isArray = false;
6391
6392 tyinfo[i].typarray = atooid(PQgetvalue(res, i, i_typarray));
6393
6394 if (tyinfo[i].typtype == TYPTYPE_MULTIRANGE)
6395 tyinfo[i].isMultirange = true;
6396 else
6397 tyinfo[i].isMultirange = false;
6398
6399 /* Decide whether we want to dump it */
6401
6402 /* Mark whether type has an ACL */
6403 if (!PQgetisnull(res, i, i_typacl))
6404 tyinfo[i].dobj.components |= DUMP_COMPONENT_ACL;
6405
6406 /*
6407 * If it's a domain, fetch info about its constraints, if any
6408 */
6409 tyinfo[i].nDomChecks = 0;
6410 tyinfo[i].domChecks = NULL;
6411 tyinfo[i].notnull = NULL;
6412 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6413 tyinfo[i].typtype == TYPTYPE_DOMAIN)
6415
6416 /*
6417 * If it's a base type, make a DumpableObject representing a shell
6418 * definition of the type. We will need to dump that ahead of the I/O
6419 * functions for the type. Similarly, range types need a shell
6420 * definition in case they have a canonicalize function.
6421 *
6422 * Note: the shell type doesn't have a catId. You might think it
6423 * should copy the base type's catId, but then it might capture the
6424 * pg_depend entries for the type, which we don't want.
6425 */
6426 if ((tyinfo[i].dobj.dump & DUMP_COMPONENT_DEFINITION) &&
6427 (tyinfo[i].typtype == TYPTYPE_BASE ||
6428 tyinfo[i].typtype == TYPTYPE_RANGE))
6429 {
6431 stinfo->dobj.objType = DO_SHELL_TYPE;
6432 stinfo->dobj.catId = nilCatalogId;
6433 AssignDumpId(&stinfo->dobj);
6434 stinfo->dobj.name = pg_strdup(tyinfo[i].dobj.name);
6435 stinfo->dobj.namespace = tyinfo[i].dobj.namespace;
6436 stinfo->baseType = &(tyinfo[i]);
6437 tyinfo[i].shellType = stinfo;
6438
6439 /*
6440 * Initially mark the shell type as not to be dumped. We'll only
6441 * dump it if the I/O or canonicalize functions need to be dumped;
6442 * this is taken care of while sorting dependencies.
6443 */
6444 stinfo->dobj.dump = DUMP_COMPONENT_NONE;
6445 }
6446 }
6447
6448 PQclear(res);
6449
6450 destroyPQExpBuffer(query);
6451}
static const CatalogId nilCatalogId
Definition pg_dump.c:191
static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
Definition pg_dump.c:8570
static void selectDumpableType(TypeInfo *tyinfo, Archive *fout)
Definition pg_dump.c:2107

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 1112 of file common.c.

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

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 20288 of file pg_dump.c.

20290{
20291 DumpOptions *dopt = fout->dopt;
20292 PQExpBuffer query;
20293 PGresult *res;
20294 int ntups,
20295 i;
20296 int i_conrelid,
20298
20299 /* Nothing to do if no extensions */
20300 if (numExtensions == 0)
20301 return;
20302
20303 /*
20304 * Identify extension configuration tables and create TableDataInfo
20305 * objects for them, ensuring their data will be dumped even though the
20306 * tables themselves won't be.
20307 *
20308 * Note that we create TableDataInfo objects even in schema-only mode, ie,
20309 * user data in a configuration table is treated like schema data. This
20310 * seems appropriate since system data in a config table would get
20311 * reloaded by CREATE EXTENSION. If the extension is not listed in the
20312 * list of extensions to be included, none of its data is dumped.
20313 */
20314 for (i = 0; i < numExtensions; i++)
20315 {
20317 char *extconfig = curext->extconfig;
20318 char *extcondition = curext->extcondition;
20319 char **extconfigarray = NULL;
20320 char **extconditionarray = NULL;
20321 int nconfigitems = 0;
20322 int nconditionitems = 0;
20323
20324 /*
20325 * Check if this extension is listed as to include in the dump. If
20326 * not, any table data associated with it is discarded.
20327 */
20330 curext->dobj.catId.oid))
20331 continue;
20332
20333 /*
20334 * Check if this extension is listed as to exclude in the dump. If
20335 * yes, any table data associated with it is discarded.
20336 */
20339 curext->dobj.catId.oid))
20340 continue;
20341
20342 if (strlen(extconfig) != 0 || strlen(extcondition) != 0)
20343 {
20344 int j;
20345
20346 if (!parsePGArray(extconfig, &extconfigarray, &nconfigitems))
20347 pg_fatal("could not parse %s array", "extconfig");
20348 if (!parsePGArray(extcondition, &extconditionarray, &nconditionitems))
20349 pg_fatal("could not parse %s array", "extcondition");
20351 pg_fatal("mismatched number of configurations and conditions for extension");
20352
20353 for (j = 0; j < nconfigitems; j++)
20354 {
20357 bool dumpobj =
20358 curext->dobj.dump & DUMP_COMPONENT_DEFINITION;
20359
20361 if (configtbl == NULL)
20362 continue;
20363
20364 /*
20365 * Tables of not-to-be-dumped extensions shouldn't be dumped
20366 * unless the table or its schema is explicitly included
20367 */
20368 if (!(curext->dobj.dump & DUMP_COMPONENT_DEFINITION))
20369 {
20370 /* check table explicitly requested */
20371 if (table_include_oids.head != NULL &&
20373 configtbloid))
20374 dumpobj = true;
20375
20376 /* check table's schema explicitly requested */
20377 if (configtbl->dobj.namespace->dobj.dump &
20379 dumpobj = true;
20380 }
20381
20382 /* check table excluded by an exclusion switch */
20383 if (table_exclude_oids.head != NULL &&
20385 configtbloid))
20386 dumpobj = false;
20387
20388 /* check schema excluded by an exclusion switch */
20390 configtbl->dobj.namespace->dobj.catId.oid))
20391 dumpobj = false;
20392
20393 if (dumpobj)
20394 {
20396 if (configtbl->dataObj != NULL)
20397 {
20398 if (strlen(extconditionarray[j]) > 0)
20399 configtbl->dataObj->filtercond = pg_strdup(extconditionarray[j]);
20400 }
20401 }
20402 }
20403 }
20404 if (extconfigarray)
20408 }
20409
20410 /*
20411 * Now that all the TableDataInfo objects have been created for all the
20412 * extensions, check their FK dependencies and register them to try and
20413 * dump the data out in an order that they can be restored in.
20414 *
20415 * Note that this is not a problem for user tables as their FKs are
20416 * recreated after the data has been loaded.
20417 */
20418
20419 query = createPQExpBuffer();
20420
20421 printfPQExpBuffer(query,
20422 "SELECT conrelid, confrelid "
20423 "FROM pg_constraint "
20424 "JOIN pg_depend ON (objid = confrelid) "
20425 "WHERE contype = 'f' "
20426 "AND refclassid = 'pg_extension'::regclass "
20427 "AND classid = 'pg_class'::regclass;");
20428
20429 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
20430 ntups = PQntuples(res);
20431
20432 i_conrelid = PQfnumber(res, "conrelid");
20433 i_confrelid = PQfnumber(res, "confrelid");
20434
20435 /* Now get the dependencies and register them */
20436 for (i = 0; i < ntups; i++)
20437 {
20438 Oid conrelid,
20439 confrelid;
20441 *contable;
20442
20443 conrelid = atooid(PQgetvalue(res, i, i_conrelid));
20444 confrelid = atooid(PQgetvalue(res, i, i_confrelid));
20445 contable = findTableByOid(conrelid);
20446 reftable = findTableByOid(confrelid);
20447
20448 if (reftable == NULL ||
20449 reftable->dataObj == NULL ||
20450 contable == NULL ||
20451 contable->dataObj == NULL)
20452 continue;
20453
20454 /*
20455 * Make referencing TABLE_DATA object depend on the referenced table's
20456 * TABLE_DATA object.
20457 */
20458 addObjectDependency(&contable->dataObj->dobj,
20459 reftable->dataObj->dobj.dumpId);
20460 }
20461 PQclear(res);
20462 destroyPQExpBuffer(query);
20463}
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:3026
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 720 of file common.c.

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

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

Referenced by getLOs().

◆ recordExtensionMembership()

void recordExtensionMembership ( CatalogId  catId,
ExtensionInfo ext 
)
extern

Definition at line 1064 of file common.c.

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

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 10246 of file pg_dump.c.

10247{
10248 if (dopt->binary_upgrade)
10249 return true;
10250 if (tbinfo->attisdropped[colno])
10251 return false;
10252 return (tbinfo->attislocal[colno] || tbinfo->ispartition);
10253}

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}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
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, memcpy(), 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().