diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-05-10 22:36:27 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-05-10 22:36:27 +0000 |
| commit | 9f0ae0c82060e3dcd1fa7ac8bbe35a3f9a44dbba (patch) | |
| tree | 1949d052323eef0a1b071f65cf20f0762ae19367 /src/bin/pg_dump/pg_dump.h | |
| parent | 1011fb651d83932805bfbbad35c2b49490e5b739 (diff) | |
| download | postgresql-9f0ae0c82060e3dcd1fa7ac8bbe35a3f9a44dbba.tar.gz | |
First pass at schema-fying pg_dump/pg_restore. Much to do still,
but the basic capability seems to work.
Diffstat (limited to 'src/bin/pg_dump/pg_dump.h')
| -rw-r--r-- | src/bin/pg_dump/pg_dump.h | 293 |
1 files changed, 111 insertions, 182 deletions
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index 580dacf66d..1cf7a02e30 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -1,27 +1,12 @@ /*------------------------------------------------------------------------- * * pg_dump.h - * header file for the pg_dump utility + * Common header file for the pg_dump utility * * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pg_dump.h,v 1.84 2002/04/24 22:39:49 petere Exp $ - * - * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 - * - * - Fixed dumpTable output to output lengths for char and varchar types! - * - Added single. quote to twin single quote expansion for 'insert' string - * mode. - * - * Modifications - 6/1/97 - igor@sba.miami.edu - * - Added extern's for the functions that clear allocated memory - * in pg_dump.c - * - * Modifications - 14-Sep-2000 - pjw@rhyme.com.au - * - Added typedefn fields to typeinfo and relinfo - * - Added enum for findTypeByOid to allow special handling of - * '0' OID. + * $Id: pg_dump.h,v 1.85 2002/05/10 22:36:27 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -32,171 +17,133 @@ #include "pg_backup.h" #include "pqexpbuffer.h" -/* The data structures used to store system catalog information */ +/* + * The data structures used to store system catalog information + * + * NOTE: the structures described here live for the entire pg_dump run; + * and in most cases we make a struct for every object we can find in the + * catalogs, not only those we are actually going to dump. Hence, it's + * best to store a minimal amount of per-object info in these structs, + * and retrieve additional per-object info when and if we dump a specific + * object. In particular, try to avoid retrieving expensive-to-compute + * information until it's known to be needed. + */ + +typedef struct _namespaceInfo +{ + char *oid; + char *nspname; + char *usename; /* name of owner, or empty string */ + char *nspacl; + bool dump; /* true if need to dump definition */ +} NamespaceInfo; typedef struct _typeInfo { char *oid; - char *typowner; - char *typname; - char *typlen; - char *typprtlen; - char *typinput; - char *typoutput; - char *typreceive; - char *typsend; - char *typelem; - char *typdelim; - char *typdefault; - char *typrelid; - char *typalign; - char *typstorage; - char *usename; - char *typedefn; - char *typtype; - int passedbyvalue; - int isArray; - int isDefined; + char *typname; /* name as seen in catalog */ + /* Note: format_type might produce something different than typname */ + NamespaceInfo *typnamespace; /* link to containing namespace */ + char *usename; /* name of owner, or empty string */ + char *typelem; /* OID */ + char *typrelid; /* OID */ + char typtype; /* 'b', 'c', etc */ + bool isArray; /* true if user-defined array type */ + bool isDefined; /* true if typisdefined */ } TypeInfo; typedef struct _funcInfo { char *oid; char *proname; - char *proowner; + NamespaceInfo *pronamespace; /* link to containing namespace */ + char *usename; /* name of owner, or empty string */ Oid lang; int nargs; - char **argtypes; - char *prorettype; - int retset; /* 1 if the function returns a set, else 0 */ - char *prosrc; - char *probin; - char *usename; - char provolatile; /* Attr */ - bool isimplicit; /* Attr */ - bool isstrict; /* Attr */ - int dumped; /* 1 if already dumped */ + char **argtypes; /* OIDs */ + char *prorettype; /* OID */ + bool dumped; /* true if already dumped */ } FuncInfo; -typedef struct _trigInfo +typedef struct _aggInfo { char *oid; - char *tgname; - char *tgsrc; - char *tgdel; - char *tgcomment; -} TrigInfo; + char *aggname; + NamespaceInfo *aggnamespace; /* link to containing namespace */ + char *usename; +} AggInfo; + +typedef struct _oprInfo +{ + char *oid; + char *oprname; + NamespaceInfo *oprnamespace; /* link to containing namespace */ + char *usename; + char *oprcode; /* as OID, not regproc name */ +} OprInfo; typedef struct _tableInfo { + /* + * These fields are collected for every table in the database. + */ char *oid; char *relname; + NamespaceInfo *relnamespace; /* link to containing namespace */ + char *usename; /* name of owner, or empty string */ char *relacl; - char *viewdef; - char *viewoid; /* OID of view - should be >= oid of table - * important because views may be - * constructed manually from rules, and - * rule may ref things created after the - * base table was created. */ char relkind; bool hasindex; /* does it have any indexes? */ + bool hasrules; /* does it have any rules? */ bool hasoids; /* does it have OIDs? */ + int ncheck; /* # of CHECK expressions */ + int ntrig; /* # of triggers */ + + bool interesting; /* true if need to collect more data */ + bool dump; /* true if we want to dump it */ + + /* + * These fields are computed only if we decide the table is interesting + * (it's either a table to dump, or a direct parent of a dumpable table). + */ int numatts; /* number of attributes */ - int *inhAttrs; /* an array of flags, one for each - * attribute if the value is 1, then this - * attribute is an inherited attribute */ - int *inhAttrDef; /* Flags indicating if attrdef is - * inherited */ - int *inhNotNull; /* Flags indicating if NOT NULL in - * inherited */ char **attnames; /* the attribute names */ - char **atttypedefns; /* formatted column type definitions */ - char **typnames; /* fill out attributes */ - bool *notnull; /* Not null constraints of an attribute */ + char **atttypnames; /* attribute type names */ + int *atttypmod; /* type-specific type modifiers */ + /* + * Note: we need to store per-attribute notnull and default stuff for + * all interesting tables so that we can tell which constraints were + * inherited. + */ + bool *notnull; /* Not null constraints on attributes */ char **adef_expr; /* DEFAULT expressions */ - int numParents; /* number of (immediate) parent - * supertables */ - char **parentRels; /* names of parent relations, NULL if - * numParents == 0 */ - char **out_attnames; /* the attribute names, in the order they - * would be in, when the table is created - * in the target query language. this is - * needed because the SQL tables will not - * have the same order of attributes as - * the POSTQUEL tables */ - int *atttypmod; /* type-specific type modifier */ - char *usename; - int ncheck; /* # of CHECK expressions */ - char **check_expr; /* [CONSTRAINT name] CHECK expressions */ - int ntrig; /* # of triggers */ - TrigInfo *triggers; /* Triggers on the table */ - char *pkIndexOid; /* Primary Key index OID */ - char *primary_key_name; /* PRIMARY KEY name, if any */ + bool *inhAttrs; /* true if each attribute is inherited */ + bool *inhAttrDef; /* true if attr's default is inherited */ + bool *inhNotNull; /* true if NOT NULL is inherited */ + + /* + * Stuff computed only for dumpable tables. + */ + int numParents; /* number of (immediate) parent tables */ + int *parentIndexes; /* TableInfo indexes of immediate parents */ + + char *viewoid; /* OID of view - should be >= oid of table + * important because views may be + * constructed manually from rules, and + * rule may ref things created after the + * base table was created. */ } TableInfo; typedef struct _inhInfo { - char *inhrelid; - char *inhparent; + char *inhrelid; /* OID of a child table */ + char *inhparent; /* OID of its parent */ } InhInfo; -typedef struct _indInfo -{ - char *indexreloid; /* oid of the index itself */ - char *indreloid; /* oid of the table the index is on */ - char *indexrelname; /* name of the index itself */ - char *indrelname; /* name of the indexed table */ - char *indexdef; /* index definitional command */ - char *indisprimary; /* is this a PK index? */ - int indnkeys; /* number of keys in index */ - char **indkey; /* attribute numbers of the key - * attributes */ -} IndInfo; - -typedef struct _aggInfo -{ - char *oid; - char *aggname; - char *aggtransfn; - char *aggfinalfn; - char *aggtranstype; - char *aggbasetype; - char *agginitval; - char *usename; - int convertok; /* Flag to indicate of version convertsion - * is OK */ -} AggInfo; - -typedef struct _oprInfo -{ - char *oid; - char *oprname; - char *oprkind; /*---------- - * b = binary, - * l = left unary - * r = right unary - *---------- - */ - char *oprcode; /* operator function name */ - char *oprleft; /* left operand type */ - char *oprright; /* right operand type */ - char *oprcom; /* oid of the commutator operator */ - char *oprnegate; /* oid of the negator operator */ - char *oprrest; /* name of the function to calculate - * operator restriction selectivity */ - char *oprjoin; /* name of the function to calculate - * operator join selectivity */ - char *oprcanhash; /* can we use hash join strategy ? */ - char *oprlsortop; /* oid's of the left and right sort - * operators */ - char *oprrsortop; - char *usename; -} OprInfo; /* global decls */ extern bool force_quotes; /* double-quotes for identifiers flag */ extern bool g_verbose; /* verbose flag */ -extern Oid g_last_builtin_oid; /* value of the last builtin oid */ extern Archive *g_fout; /* the script file */ /* placeholders for comment starting and ending delimiters */ @@ -212,73 +159,55 @@ extern char g_opaque_type[10]; /* name for the opaque type */ */ /* * common utility functions -*/ + */ extern TableInfo *dumpSchema(Archive *fout, int *numTablesPtr, - const char *tablename, - const bool acls, - const bool oids, + const bool aclsSkip, const bool schemaOnly, const bool dataOnly); -extern void dumpSchemaIdx(Archive *fout, - const char *tablename, - TableInfo *tblinfo, - int numTables); typedef enum _OidOptions { zeroAsOpaque = 1, zeroAsAny = 2, zeroAsStar = 4, - zeroAsNone = 8, - useBaseTypeName = 1024 + zeroAsNone = 8 } OidOptions; -extern char *findTypeByOid(TypeInfo *tinfo, int numTypes, const char *oid, OidOptions opts); +extern int findTableByOid(TableInfo *tbinfo, int numTables, const char *oid); extern char *findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid); -extern int findFuncByName(FuncInfo *finfo, int numFuncs, const char *name); -extern int findTableByName(TableInfo *tbinfo, int numTables, const char *relname); +extern int findFuncByOid(FuncInfo *finfo, int numFuncs, const char *oid); extern void check_conn_and_db(void); +extern void exit_nicely(void); + extern void parseNumericArray(const char *str, char **array, int arraysize); /* * version specific routines */ +extern NamespaceInfo *getNamespaces(int *numNamespaces); extern TypeInfo *getTypes(int *numTypes); extern FuncInfo *getFuncs(int *numFuncs); extern AggInfo *getAggregates(int *numAggregates); - -extern void clearAggInfo(AggInfo *, int); -extern void clearFuncInfo(FuncInfo *, int); -extern void clearInhInfo(InhInfo *, int); -extern void clearIndInfo(IndInfo *, int); -extern void clearOprInfo(OprInfo *, int); -extern void clearTypeInfo(TypeInfo *, int); - extern OprInfo *getOperators(int *numOperators); -extern TableInfo *getTables(int *numTables, FuncInfo *finfo, int numFuncs, - const char* tablename); +extern TableInfo *getTables(int *numTables); extern InhInfo *getInherits(int *numInherits); + extern void getTableAttrs(TableInfo *tbinfo, int numTables); -extern IndInfo *getIndexes(int *numIndexes); extern void dumpDBComment(Archive *outfile); +extern void dumpNamespaces(Archive *fout, + NamespaceInfo *nsinfo, int numNamespaces); extern void dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs, TypeInfo *tinfo, int numTypes); -extern void dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs, - TypeInfo *tinfo, int numTypes); -extern void dumpFuncs(Archive *fout, FuncInfo *finfo, int numFuncs, - TypeInfo *tinfo, int numTypes); -extern void dumpAggs(Archive *fout, AggInfo *agginfo, int numAggregates, - TypeInfo *tinfo, int numTypes); -extern void dumpOprs(Archive *fout, OprInfo *agginfo, int numOperators, - TypeInfo *tinfo, int numTypes); -extern void dumpTables(Archive *fout, TableInfo *tbinfo, int numTables, - const char *tablename, const bool acls, - const bool schemaOnly, const bool dataOnly); -extern void dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes, - TableInfo *tbinfo, int numTables, const char *tablename); -extern void exit_nicely(void); +extern void dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs); +extern void dumpFuncs(Archive *fout, FuncInfo *finfo, int numFuncs); +extern void dumpAggs(Archive *fout, AggInfo *agginfo, int numAggregates); +extern void dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators); +extern void dumpTables(Archive *fout, TableInfo *tblinfo, int numTables, + const bool aclsSkip, + const bool schemaOnly, const bool dataOnly); +extern void dumpIndexes(Archive *fout, TableInfo *tbinfo, int numTables); #endif /* PG_DUMP_H */ |
