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:552
int32_t int32
Definition c.h:614
uint32_t uint32
Definition c.h:618
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:8389
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:6216
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:7878
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:7822
TableInfo * findTableByOid(Oid oid)
Definition common.c:864
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10520
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:20196
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:6291
struct _dumpableObject DumpableObject
struct _accessMethodInfo AccessMethodInfo
struct _attrDefInfo AttrDefInfo
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7757
void getOpclasses(Archive *fout)
Definition pg_dump.c:6737
void getForeignServers(Archive *fout)
Definition pg_dump.c:10614
void getFuncs(Archive *fout)
Definition pg_dump.c:7006
OprInfo * findOprByOid(Oid oid)
Definition common.c:937
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10336
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:9138
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7938
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:10461
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:6663
void getConversions(Archive *fout)
Definition pg_dump.c:6601
void getRules(Archive *fout)
Definition pg_dump.c:8683
ExtensionInfo * findOwningExtension(CatalogId catalogId)
Definition common.c:1088
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9332
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:6535
struct _namespaceInfo NamespaceInfo
void getAggregates(Archive *fout)
Definition pg_dump.c:6865
struct _shellTypeInfo ShellTypeInfo
void getNamespaces(Archive *fout)
Definition pg_dump.c:6084
void getPublications(Archive *fout)
Definition pg_dump.c:4516
void getTSParsers(Archive *fout)
Definition pg_dump.c:10262
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:7279
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:8307
struct _dumpableAcl DumpableAcl
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20289
DumpId getMaxDumpId(void)
Definition common.c:755
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10702
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:8780
void getTransforms(Archive *fout)
Definition pg_dump.c:9248
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8976
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:10402
void getProcLangs(Archive *fout)
Definition pg_dump.c:9054
bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
Definition pg_dump.c:10247
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5409
struct _tableAttachInfo TableAttachInfo
void removeObjectDependency(DumpableObject *dobj, DumpId refId)
Definition common.c:844
void getOperators(Archive *fout)
Definition pg_dump.c:6459
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6800
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:945
#define OidIsValid(objectId)
Definition c.h:860
#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 6663 of file pg_dump.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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:124
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)

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

Referenced by getSchemaData().

◆ getProcLangs()

void getProcLangs ( Archive fout)
extern

Definition at line 9054 of file pg_dump.c.

9055{
9056 PGresult *res;
9057 int ntups;
9058 int i;
9061 int i_tableoid;
9062 int i_oid;
9063 int i_lanname;
9064 int i_lanpltrusted;
9065 int i_lanplcallfoid;
9066 int i_laninline;
9067 int i_lanvalidator;
9068 int i_lanacl;
9069 int i_acldefault;
9070 int i_lanowner;
9071
9072 appendPQExpBufferStr(query, "SELECT tableoid, oid, "
9073 "lanname, lanpltrusted, lanplcallfoid, "
9074 "laninline, lanvalidator, "
9075 "lanacl, "
9076 "acldefault('l', lanowner) AS acldefault, "
9077 "lanowner "
9078 "FROM pg_language "
9079 "WHERE lanispl "
9080 "ORDER BY oid");
9081
9082 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
9083
9084 ntups = PQntuples(res);
9085
9087
9088 i_tableoid = PQfnumber(res, "tableoid");
9089 i_oid = PQfnumber(res, "oid");
9090 i_lanname = PQfnumber(res, "lanname");
9091 i_lanpltrusted = PQfnumber(res, "lanpltrusted");
9092 i_lanplcallfoid = PQfnumber(res, "lanplcallfoid");
9093 i_laninline = PQfnumber(res, "laninline");
9094 i_lanvalidator = PQfnumber(res, "lanvalidator");
9095 i_lanacl = PQfnumber(res, "lanacl");
9096 i_acldefault = PQfnumber(res, "acldefault");
9097 i_lanowner = PQfnumber(res, "lanowner");
9098
9099 for (i = 0; i < ntups; i++)
9100 {
9101 planginfo[i].dobj.objType = DO_PROCLANG;
9102 planginfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
9103 planginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
9104 AssignDumpId(&planginfo[i].dobj);
9105
9106 planginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_lanname));
9107 planginfo[i].dacl.acl = pg_strdup(PQgetvalue(res, i, i_lanacl));
9108 planginfo[i].dacl.acldefault = pg_strdup(PQgetvalue(res, i, i_acldefault));
9109 planginfo[i].dacl.privtype = 0;
9110 planginfo[i].dacl.initprivs = NULL;
9111 planginfo[i].lanpltrusted = *(PQgetvalue(res, i, i_lanpltrusted)) == 't';
9112 planginfo[i].lanplcallfoid = atooid(PQgetvalue(res, i, i_lanplcallfoid));
9113 planginfo[i].laninline = atooid(PQgetvalue(res, i, i_laninline));
9114 planginfo[i].lanvalidator = atooid(PQgetvalue(res, i, i_lanvalidator));
9115 planginfo[i].lanowner = getRoleName(PQgetvalue(res, i, i_lanowner));
9116
9117 /* Decide whether we want to dump it */
9119
9120 /* Mark whether language has an ACL */
9121 if (!PQgetisnull(res, i, i_lanacl))
9122 planginfo[i].dobj.components |= DUMP_COMPONENT_ACL;
9123 }
9124
9125 PQclear(res);
9126
9127 destroyPQExpBuffer(query);
9128}
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 EXCEPT TABLE entries 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 TABLE list.
4632 *
4633 * Therefore, the approach is to dump the complete EXCEPT TABLE list
4634 * in a single CREATE PUBLICATION statement. PublicationInfo is used
4635 * to 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 8683 of file pg_dump.c.

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

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:8389
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition pg_dump.c:6216
void getPublicationNamespaces(Archive *fout)
Definition pg_dump.c:4804
void getPartitioningInfo(Archive *fout)
Definition pg_dump.c:7878
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition pg_dump.c:7822
void getForeignDataWrappers(Archive *fout)
Definition pg_dump.c:10520
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:20196
void getTypes(Archive *fout)
Definition pg_dump.c:6291
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7757
void getOpclasses(Archive *fout)
Definition pg_dump.c:6737
void getForeignServers(Archive *fout)
Definition pg_dump.c:10614
void getFuncs(Archive *fout)
Definition pg_dump.c:7006
void getTSDictionaries(Archive *fout)
Definition pg_dump.c:10336
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:4884
void getCasts(Archive *fout)
Definition pg_dump.c:9138
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:7938
void getTSConfigurations(Archive *fout)
Definition pg_dump.c:10461
void getAccessMethods(Archive *fout)
Definition pg_dump.c:6663
void getConversions(Archive *fout)
Definition pg_dump.c:6601
void getRules(Archive *fout)
Definition pg_dump.c:8683
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition pg_dump.c:9332
void getCollations(Archive *fout)
Definition pg_dump.c:6535
void getAggregates(Archive *fout)
Definition pg_dump.c:6865
void getNamespaces(Archive *fout)
Definition pg_dump.c:6084
void getPublications(Archive *fout)
Definition pg_dump.c:4516
void getTSParsers(Archive *fout)
Definition pg_dump.c:10262
TableInfo * getTables(Archive *fout, int *numTables)
Definition pg_dump.c:7279
void getExtendedStatistics(Archive *fout)
Definition pg_dump.c:8307
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition pg_dump.c:20289
void getDefaultACLs(Archive *fout)
Definition pg_dump.c:10702
void getSubscriptions(Archive *fout)
Definition pg_dump.c:5159
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition pg_dump.c:8780
void getTransforms(Archive *fout)
Definition pg_dump.c:9248
void getEventTriggers(Archive *fout)
Definition pg_dump.c:8976
void getTSTemplates(Archive *fout)
Definition pg_dump.c:10402
void getProcLangs(Archive *fout)
Definition pg_dump.c:9054
void getSubscriptionRelations(Archive *fout)
Definition pg_dump.c:5409
void getOperators(Archive *fout)
Definition pg_dump.c:6459
void getOpfamilies(Archive *fout)
Definition pg_dump.c:6800

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

5410{
5411 DumpOptions *dopt = fout->dopt;
5412 SubscriptionInfo *subinfo = NULL;
5414 PGresult *res;
5415 int i_srsubid;
5416 int i_srrelid;
5417 int i_srsubstate;
5418 int i_srsublsn;
5419 int ntups;
5421
5422 if (dopt->no_subscriptions || !dopt->binary_upgrade ||
5423 fout->remoteVersion < 170000)
5424 return;
5425
5426 res = ExecuteSqlQuery(fout,
5427 "SELECT srsubid, srrelid, srsubstate, srsublsn "
5428 "FROM pg_catalog.pg_subscription_rel "
5429 "ORDER BY srsubid",
5431 ntups = PQntuples(res);
5432 if (ntups == 0)
5433 goto cleanup;
5434
5435 /* Get pg_subscription_rel attributes */
5436 i_srsubid = PQfnumber(res, "srsubid");
5437 i_srrelid = PQfnumber(res, "srrelid");
5438 i_srsubstate = PQfnumber(res, "srsubstate");
5439 i_srsublsn = PQfnumber(res, "srsublsn");
5440
5442 for (int i = 0; i < ntups; i++)
5443 {
5445 Oid relid = atooid(PQgetvalue(res, i, i_srrelid));
5446 TableInfo *tblinfo;
5447
5448 /*
5449 * If we switched to a new subscription, check if the subscription
5450 * exists.
5451 */
5453 {
5455 if (subinfo == NULL)
5456 pg_fatal("subscription with OID %u does not exist", cur_srsubid);
5457
5459 }
5460
5461 tblinfo = findTableByOid(relid);
5462 if (tblinfo == NULL)
5463 pg_fatal("failed sanity check, relation with OID %u not found",
5464 relid);
5465
5466 /* OK, make a DumpableObject for this relationship */
5467 subrinfo[i].dobj.objType = DO_SUBSCRIPTION_REL;
5468 subrinfo[i].dobj.catId.tableoid = relid;
5469 subrinfo[i].dobj.catId.oid = cur_srsubid;
5470 AssignDumpId(&subrinfo[i].dobj);
5471 subrinfo[i].dobj.namespace = tblinfo->dobj.namespace;
5472 subrinfo[i].dobj.name = tblinfo->dobj.name;
5473 subrinfo[i].subinfo = subinfo;
5474 subrinfo[i].tblinfo = tblinfo;
5475 subrinfo[i].srsubstate = PQgetvalue(res, i, i_srsubstate)[0];
5476 if (PQgetisnull(res, i, i_srsublsn))
5477 subrinfo[i].srsublsn = NULL;
5478 else
5479 subrinfo[i].srsublsn = pg_strdup(PQgetvalue(res, i, i_srsublsn));
5480
5481 /* Decide whether we want to dump it */
5483 }
5484
5485cleanup:
5486 PQclear(res);
5487}
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 appendPQExpBuffer(query,
5276 " 0 AS submaxretention,\n");
5277
5278 if (fout->remoteVersion >= 190000)
5280 " s.subwalrcvtimeout,\n");
5281 else
5283 " '-1' AS subwalrcvtimeout,\n");
5284
5285 if (fout->remoteVersion >= 190000)
5286 appendPQExpBufferStr(query, " fs.srvname AS subservername\n");
5287 else
5288 appendPQExpBufferStr(query, " NULL AS subservername\n");
5289
5291 "FROM pg_subscription s\n");
5292
5293 if (fout->remoteVersion >= 190000)
5295 "LEFT JOIN pg_catalog.pg_foreign_server fs \n"
5296 " ON fs.oid = s.subserver \n");
5297
5298 if (dopt->binary_upgrade && fout->remoteVersion >= 170000)
5300 "LEFT JOIN pg_catalog.pg_replication_origin_status o \n"
5301 " ON o.external_id = 'pg_' || s.oid::text \n");
5302
5304 "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
5305 " WHERE datname = current_database())");
5306
5307 res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
5308
5309 ntups = PQntuples(res);
5310
5311 /*
5312 * Get subscription fields. We don't include subskiplsn in the dump as
5313 * after restoring the dump this value may no longer be relevant.
5314 */
5315 i_tableoid = PQfnumber(res, "tableoid");
5316 i_oid = PQfnumber(res, "oid");
5317 i_subname = PQfnumber(res, "subname");
5318 i_subowner = PQfnumber(res, "subowner");
5319 i_subenabled = PQfnumber(res, "subenabled");
5320 i_subbinary = PQfnumber(res, "subbinary");
5321 i_substream = PQfnumber(res, "substream");
5322 i_subtwophasestate = PQfnumber(res, "subtwophasestate");
5323 i_subdisableonerr = PQfnumber(res, "subdisableonerr");
5324 i_subpasswordrequired = PQfnumber(res, "subpasswordrequired");
5325 i_subrunasowner = PQfnumber(res, "subrunasowner");
5326 i_subfailover = PQfnumber(res, "subfailover");
5327 i_subretaindeadtuples = PQfnumber(res, "subretaindeadtuples");
5328 i_submaxretention = PQfnumber(res, "submaxretention");
5329 i_subservername = PQfnumber(res, "subservername");
5330 i_subconninfo = PQfnumber(res, "subconninfo");
5331 i_subslotname = PQfnumber(res, "subslotname");
5332 i_subsynccommit = PQfnumber(res, "subsynccommit");
5333 i_subwalrcvtimeout = PQfnumber(res, "subwalrcvtimeout");
5334 i_subpublications = PQfnumber(res, "subpublications");
5335 i_suborigin = PQfnumber(res, "suborigin");
5336 i_suboriginremotelsn = PQfnumber(res, "suboriginremotelsn");
5337
5338 subinfo = pg_malloc_array(SubscriptionInfo, ntups);
5339
5340 for (i = 0; i < ntups; i++)
5341 {
5342 subinfo[i].dobj.objType = DO_SUBSCRIPTION;
5343 subinfo[i].dobj.catId.tableoid =
5344 atooid(PQgetvalue(res, i, i_tableoid));
5345 subinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
5346 AssignDumpId(&subinfo[i].dobj);
5347 subinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_subname));
5348 subinfo[i].rolname = getRoleName(PQgetvalue(res, i, i_subowner));
5349
5350 subinfo[i].subenabled =
5351 (strcmp(PQgetvalue(res, i, i_subenabled), "t") == 0);
5352 if (PQgetisnull(res, i, i_subservername))
5353 subinfo[i].subservername = NULL;
5354 else
5356 subinfo[i].subbinary =
5357 (strcmp(PQgetvalue(res, i, i_subbinary), "t") == 0);
5358 subinfo[i].substream = *(PQgetvalue(res, i, i_substream));
5359 subinfo[i].subtwophasestate = *(PQgetvalue(res, i, i_subtwophasestate));
5360 subinfo[i].subdisableonerr =
5361 (strcmp(PQgetvalue(res, i, i_subdisableonerr), "t") == 0);
5362 subinfo[i].subpasswordrequired =
5363 (strcmp(PQgetvalue(res, i, i_subpasswordrequired), "t") == 0);
5364 subinfo[i].subrunasowner =
5365 (strcmp(PQgetvalue(res, i, i_subrunasowner), "t") == 0);
5366 subinfo[i].subfailover =
5367 (strcmp(PQgetvalue(res, i, i_subfailover), "t") == 0);
5368 subinfo[i].subretaindeadtuples =
5369 (strcmp(PQgetvalue(res, i, i_subretaindeadtuples), "t") == 0);
5370 subinfo[i].submaxretention =
5372 if (PQgetisnull(res, i, i_subconninfo))
5373 subinfo[i].subconninfo = NULL;
5374 else
5375 subinfo[i].subconninfo =
5377 if (PQgetisnull(res, i, i_subslotname))
5378 subinfo[i].subslotname = NULL;
5379 else
5380 subinfo[i].subslotname =
5382 subinfo[i].subsynccommit =
5384 subinfo[i].subwalrcvtimeout =
5386 subinfo[i].subpublications =
5388 subinfo[i].suborigin = pg_strdup(PQgetvalue(res, i, i_suborigin));
5390 subinfo[i].suboriginremotelsn = NULL;
5391 else
5392 subinfo[i].suboriginremotelsn =
5394
5395 /* Decide whether we want to dump it */
5396 selectDumpableObject(&(subinfo[i].dobj), fout);
5397 }
5398 PQclear(res);
5399
5400 destroyPQExpBuffer(query);
5401}
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 9332 of file pg_dump.c.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

References _dumpOptions::binary_upgrade, and fb().

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

◆ sortDumpableObjects()

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

Definition at line 559 of file pg_dump_sort.c.

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

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

Referenced by main().

◆ sortDumpableObjectsByTypeName()

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

Definition at line 192 of file pg_dump_sort.c.

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

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

Referenced by main().