REmove pg4_dump...its old stuff that is sooo out of date as to be useless...

This commit is contained in:
Marc G. Fournier 1997-01-06 03:25:40 +00:00
parent 5b104c30e9
commit 046873ac90
5 changed files with 0 additions and 2299 deletions

View File

@ -1,13 +0,0 @@
#
# /usr/local/devel/pglite/cvs/src/bin/pg_dump/Makefile.v4r2,v 1.1 1995/05/17 18:57:10 jolly Exp
#
.include <postgres.global.mk>
CFLAGS+= -I${.CURDIR}/../../backend/tmp -I${.CURDIR}/../../backend/port/${PORTNAME}
PROG= pg4_dump
SRCS= pg4_dump.c common.c
.include <postgres.prog.mk>

View File

@ -1,87 +0,0 @@
pg4_dump is a utility for dumping out a postgres (version 4, release 2)
database into a script file containing query commands. The script
files are in a ASCII format and can be used to reconstruct the
database, even on other machines and other architectures. pg_dump
will produce the queries necessary to re-generate all user-defined
types, functions, tables, indices, aggregates, and operators. In
addition, all the data is copied out in ASCII format so that it can be
readily copied in again.
The sources in this directory can be used to build two different
versions of the program. The two versions require different
versions of libpq, and the same binary cannot serve both purposes.
To build:
% bmake clean install
This version of the program will read in your postgres v4r2
database and output the schema and the data tuples in one of two
formats: POSTQUEL or SQL. The POSTQUEL->POSTQUEL dumps are useful
for moving from one v4r2 installation to another. The POSTQUEL->SQL
dumps are useful for migrating from v4r2 to postgres95.
Use the -o [SQL|POSTQUEL] option to specify output query language.
How to use pg4_dump:
-------------------
The command line options are fairly self explanatory. Use -help to
see the command line options. I recommend using -v to get more
verbose descriptions of what pg_dump is doing.
After running pg4_dump, one should examine the output script file for any
warnings, especially in light of the limitations listed below.
A typical use of pg4_dump:
% pg4_dump -v -f oldDB.dump oldDB
% createdb newDB
% monitor newDB < oldDB.dump
Caveats and limitations:
------------------------
pg4_dump has a few limitations. The limitations mostly stem from
difficulty in extracting certain meta-information from the system
catalogs.
rules and views:
pg4_dump does not understand user-defined rules and views and
will fail to dump them properly. (This is due to the fact that
rules are stored as plans in the catalogs and not textually)
partial indices:
pg4_dump does not understand partial indices. (The reason is
the same as above. Partial index predicates are stored as plans)
source text of POSTQUEL functions:
pg4_dump does not convert the source text of a user-defined
POSTQUEL function into SQL. Manual intervention is required.
large objects:
pg4_dump does not handle large objects. Inversion large
objects are ignored and must be dealt with manually.
oid preservation:
pg4_dump does not preserve oid's while dumping. If you have
stored oid's explicitly in tables in user-defined attributes,
and are using them as keys, then the output scripts will not
regenerate your database correctly.
pg4_dump has not been tested and will probably not work properly for
versions of postgres prior to 4.2.
Bug-reporting
--------------
If you should find a problem with pg4_dump, it is very important that
you provide a (small) sample database which illustrates the problem.
Please send bugs, questions, and feedback to the
postgres95@postgres.berkeley.edu

View File

@ -1,401 +0,0 @@
/*-------------------------------------------------------------------------
*
* common.c--
* common routines between pg_dump and pg4_dump
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* /usr/local/devel/pglite/cvs/src/bin/pg_dump/common.c,v 1.5 1995/06/28 22:32:35 jolly Exp
*
*-------------------------------------------------------------------------
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/param.h> /* for MAXHOSTNAMELEN on most */
#if defined(sparc_solaris) || defined(i386_solaris)
#include <netdb.h> /* for MAXHOSTNAMELEN on some */
#endif
#include "postgres.h"
#include "libpq-fe.h"
#include "libpq/auth.h"
#include <port-protos.h> /* for strdup () *(
#include "pg_dump.h"
/*
* check_conn_and_db checks the connection and the database
*/
void
check_conn_and_db()
{
char *string= PQexec(" ");
switch(*string) {
case 'E':
case 'R':
PQfinish();
exit(2);
break;
}
}
/*
* findTypeByOid
* given an oid of a type, return its typename
*
* if oid is "0", return "opaque" -- this is a special case
*
* NOTE: should hash this, but just do linear search for now
*/
char*
findTypeByOid(TypeInfo* tinfo, int numTypes, char* oid)
{
int i;
if (strcmp(oid, "0") == 0) return g_opaque_type;
for (i=0;i<numTypes;i++) {
if (strcmp(tinfo[i].oid, oid) == 0)
return tinfo[i].typname;
}
/* should never get here */
fprintf(stderr,"failed sanity check, type with oid %s was not found\n",
oid);
exit(2);
}
/*
* findOprByOid
* given the oid of an operator, return the name of the operator
*
*
* NOTE: should hash this, but just do linear search for now
*
*/
char*
findOprByOid(OprInfo *oprinfo, int numOprs, char *oid)
{
int i;
for (i=0;i<numOprs;i++) {
if (strcmp(oprinfo[i].oid, oid) == 0)
return oprinfo[i].oprname;
}
/* should never get here */
fprintf(stderr,"failed sanity check, opr with oid %s was not found\n",
oid);
exit(2);
}
/*
* findParentsByOid --
* given the oid of a class, return the names of its parent classes
* and assign the number of parents to the last argument.
*
*
* returns NULL if none
*/
char**
findParentsByOid(TableInfo* tblinfo, int numTables,
InhInfo* inhinfo, int numInherits, char *oid,
int *numParentsPtr)
{
int i,j;
int parentInd;
char** result;
int numParents;
numParents = 0;
for (i=0;i<numInherits;i++) {
if ( strcmp(inhinfo[i].inhrel, oid) == 0) {
numParents++;
}
}
*numParentsPtr = numParents;
if (numParents > 0) {
result = (char**)malloc(sizeof(char*) * numParents);
j = 0;
for (i=0;i<numInherits;i++) {
if ( strcmp(inhinfo[i].inhrel, oid) == 0) {
parentInd = findTableByOid(tblinfo, numTables,
inhinfo[i].inhparent);
result[j++] = tblinfo[parentInd].relname;
}
}
return result;
}
else
return NULL;
}
/*
* parseArgTypes
* parse a string of eight numbers delimited by spaces
* into a character array
*/
void
parseArgTypes(char **argtypes, char* str)
{
int i, j, argNum;
char temp[100];
char s;
argNum = 0;
j = 0;
while ( (s = *str) != '\0') {
if (s == ' ') {
temp[j] = '\0';
argtypes[argNum] = strdup(temp);
argNum++;
j = 0;
} else {
temp[j] = s;
j++;
}
str++;
}
if (j != 0) {
temp[j] = '\0';
argtypes[argNum] = strdup(temp);
}
}
/*
* strInArray:
* takes in a string and a string array and the number of elements in the
* string array.
* returns the index if the string is somewhere in the array, -1 otherwise
*
*/
int
strInArray(char* pattern, char** arr, int arr_size)
{
int i;
for (i=0;i<arr_size;i++) {
if (strcmp(pattern, arr[i]) == 0)
return i;
}
return -1;
}
/*
* dumpSchema:
* we have a valid connection, we are now going to dump the schema
* into the file
*
*/
TableInfo *
dumpSchema(FILE* fout, int *numTablesPtr)
{
int numTypes;
int numFuncs;
int numTables;
int numInherits;
int numIndices;
int numAggregates;
int numOperators;
TypeInfo *tinfo;
FuncInfo *finfo;
AggInfo *agginfo;
TableInfo *tblinfo;
InhInfo *inhinfo;
IndInfo *indinfo;
OprInfo *oprinfo;
if (g_verbose) fprintf(stderr,"%s reading user-defined types %s\n",
g_comment_start, g_comment_end);
tinfo = getTypes(&numTypes);
if (g_verbose) fprintf(stderr,"%s reading user-defined functions %s\n",
g_comment_start, g_comment_end);
finfo = getFuncs(&numFuncs);
if (g_verbose) fprintf(stderr,"%s reading user-defined aggregates %s\n",
g_comment_start, g_comment_end);
agginfo = getAggregates(&numAggregates);
if (g_verbose) fprintf(stderr,"%s reading user-defined operators %s\n",
g_comment_start, g_comment_end);
oprinfo = getOperators(&numOperators);
if (g_verbose) fprintf(stderr,"%s reading user-defined tables %s\n",
g_comment_start, g_comment_end);
tblinfo = getTables(&numTables);
if (g_verbose) fprintf(stderr,"%s reading table inheritance information %s\n",
g_comment_start, g_comment_end);
inhinfo = getInherits(&numInherits);
if (g_verbose) fprintf(stderr, "%s finding the attribute names and types for each table %s\n",
g_comment_start, g_comment_end);
getTableAttrs(tblinfo, numTables);
if (g_verbose) fprintf(stderr, "%s flagging inherited attributes in subtables %s\n",
g_comment_start, g_comment_end);
flagInhAttrs(tblinfo, numTables, inhinfo, numInherits);
if (g_verbose) fprintf(stderr,"%s reading indices information %s\n",
g_comment_start, g_comment_end);
indinfo = getIndices(&numIndices);
if (g_verbose) fprintf(stderr,"%s dumping out user-defined types %s\n",
g_comment_start, g_comment_end);
dumpTypes(fout, finfo, numFuncs, tinfo, numTypes);
if (g_verbose) fprintf(stderr,"%s dumping out tables %s\n",
g_comment_start, g_comment_end);
dumpTables(fout, tblinfo, numTables, inhinfo, numInherits,
tinfo, numTypes);
if (g_verbose) fprintf(stderr,"%s dumping out user-defined functions %s\n",
g_comment_start, g_comment_end);
dumpFuncs(fout, finfo, numFuncs, tinfo, numTypes);
if (g_verbose) fprintf(stderr,"%s dumping out user-defined functions %s\n",
g_comment_start, g_comment_end);
dumpAggs(fout, agginfo, numAggregates, tinfo, numTypes);
if (g_verbose) fprintf(stderr,"%s dumping out user-defined operators %s\n",
g_comment_start, g_comment_end);
dumpOprs(fout, oprinfo, numOperators, tinfo, numTypes);
if (g_verbose) fprintf(stderr,"%s dumping out indices %s\n",
g_comment_start, g_comment_end);
dumpIndices(fout, indinfo, numIndices, tblinfo, numTables);
*numTablesPtr = numTables;
return tblinfo;
}
/* flagInhAttrs -
* for each table in tblinfo, flag its inherited attributes
* so when we dump the table out, we don't dump out the inherited attributes
*
* initializes the parentRels field of each table
*
* modifies tblinfo
*
*/
void
flagInhAttrs(TableInfo* tblinfo, int numTables,
InhInfo* inhinfo, int numInherits)
{
int i,j,k;
int parentInd;
char *parentRels;
int numParents;
/* we go backwards because the tables in tblinfo are in OID
order, meaning the subtables are after the parent tables
we flag inherited attributes from child tables first */
for (i = numTables-1; i >= 0; i--) {
tblinfo[i].parentRels = findParentsByOid(tblinfo, numTables,
inhinfo, numInherits,
tblinfo[i].oid,
&tblinfo[i].numParents);
for (k=0;k<tblinfo[i].numParents;k++) {
parentInd = findTableByName(tblinfo, numTables,
tblinfo[i].parentRels[k]);
for (j=0;j<tblinfo[i].numatts;j++) {
if (strInArray(tblinfo[i].attnames[j],
tblinfo[parentInd].attnames,
tblinfo[parentInd].numatts) != -1) {
tblinfo[i].inhAttrs[j] = 1;
}
}
}
}
}
/*
* findTableByName
* finds the index (in tblinfo) of the table with the given relname
* returns -1 if not found
*
* NOTE: should hash this, but just do linear search for now
*/
int
findTableByName(TableInfo* tblinfo, int numTables, char* relname)
{
int i;
for (i=0;i<numTables;i++) {
if (strcmp(tblinfo[i].relname, relname) == 0)
return i;
}
return -1;
}
/*
* findTableByOid
* finds the index (in tblinfo) of the table with the given oid
* returns -1 if not found
*
* NOTE: should hash this, but just do linear search for now
*/
int
findTableByOid(TableInfo* tblinfo, int numTables, char* oid)
{
int i;
for (i=0;i<numTables;i++) {
if (strcmp(tblinfo[i].oid, oid) == 0)
return i;
}
return -1;
}
/*
* findFuncByName
* finds the index (in finfo) of the function with the given name
* returns -1 if not found
*
* NOTE: should hash this, but just do linear search for now
*/
int
findFuncByName(FuncInfo* finfo, int numFuncs, char* name)
{
int i;
for (i=0;i<numFuncs;i++) {
if (strcmp(finfo[i].proname, name) == 0)
return i;
}
return -1;
}
/*
* isArchiveName
*
* returns true if the relation name is an archive name, false otherwise
*/
int
isArchiveName(char* relname)
{
return (strlen(relname) > 1 && relname[1] == ',');
}

File diff suppressed because it is too large Load Diff

View File

@ -1,194 +0,0 @@
/*-------------------------------------------------------------------------
*
* pg_dump.h
* header file for the pg_dump utility
*
* Copyright (c) 1994, Regents of the University of California
*
* pg_dump.h,v 1.5 1995/06/28 22:32:36 jolly Exp
*
*-------------------------------------------------------------------------
*/
/* The *Info data structures run-time C structures used to store
system catalog information */
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;
int passedbyvalue;
int isArray;
} TypeInfo;
typedef struct _funcInfo {
char* oid;
char* proname;
char* proowner;
int lang; /* 1 if C, else SQL */
int nargs;
char* argtypes[8]; /* should be derived from obj/fmgr.h instead of hardwired*/
char* prorettype;
int retset; /* 1 if the function returns a set, 0 otherwise */
char* prosrc;
char* probin;
int dumped; /* 1 if already dumped */
} FuncInfo;
typedef struct _tableInfo {
char *oid;
char *relname;
char *relarch;
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 */
char **attnames; /* the attribute names */
char **typnames; /* fill out attributes */
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 */
} TableInfo;
typedef struct _inhInfo {
char *oid;
char *inhrel;
char *inhparent;
} InhInfo;
typedef struct _indInfo {
char *indexrelname; /* name of the secondary index class */
char *indrelname; /* name of the indexed heap class */
char *indamname; /* name of the access method (e.g. btree, rtree, etc.) */
char *indproc; /* oid of the function to compute the index, 0 if none*/
char *indkey; /* attribute number of the key attribute */
char *indclassname; /* name of the opclass of the key */
} IndInfo;
typedef struct _aggInfo {
char *oid;
char *aggname;
char *aggtransfn1;
char *aggtransfn2;
char *aggfinalfn;
char *aggtranstype1;
char *aggbasetype;
char *aggtranstype2;
char *agginitval1;
char *agginitval2;
} 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;
} OprInfo;
/* global decls */
extern int g_verbose; /* verbose flag */
extern int g_last_builtin_oid; /* value of the last builtin oid */
extern FILE *g_fout; /* the script file */
/* placeholders for comment starting and ending delimiters */
extern char g_comment_start[10];
extern char g_comment_end[10];
extern char g_opaque_type[10]; /* name for the opaque type */
/* pg_dump is really two programs in one
one version works with postgres v4r2
and the other works with postgres95
the common routines are declared here
/*
* common utility functions
*/
extern TableInfo* dumpSchema(FILE* fout, int *numTablesPtr);
extern char* findTypeByOid(TypeInfo* tinfo, int numTypes, char* oid);
extern char* findOprByOid(OprInfo *oprinfo, int numOprs, char *oid);
extern int findFuncByName(FuncInfo* finfo, int numFuncs, char* name);
extern char** findParentsByOid(TableInfo* tbinfo, int numTables,
InhInfo* inhinfo, int numInherits,
char *oid,
int *numParents);
extern int findTableByName(TableInfo *tbinfo, int numTables, char *relname);
extern int findTableByOid(TableInfo *tbinfo, int numTables, char *oid);
extern void flagInhAttrs(TableInfo* tbinfo, int numTables,
InhInfo* inhinfo, int numInherits);
extern void check_conn_and_db();
extern int strInArray(char* pattern, char** arr, int arr_size);
extern void parseArgTypes(char **argtypes, char* str);
extern int isArchiveName(char*);
/*
* version specific routines
*/
extern TypeInfo* getTypes(int *numTypes);
extern FuncInfo* getFuncs(int *numFuncs);
extern AggInfo* getAggregates(int *numAggregates);
extern OprInfo* getOperators(int *numOperators);
extern TableInfo* getTables(int *numTables);
extern InhInfo* getInherits(int *numInherits);
extern void getTableAttrs(TableInfo* tbinfo, int numTables);
extern IndInfo* getIndices(int *numIndices);
extern void dumpTypes(FILE* fout, FuncInfo* finfo, int numFuncs,
TypeInfo* tinfo, int numTypes);
extern void dumpFuncs(FILE* fout, FuncInfo* finfo, int numFuncs,
TypeInfo *tinfo, int numTypes);
extern void dumpAggs(FILE* fout, AggInfo* agginfo, int numAggregates,
TypeInfo *tinfo, int numTypes);
extern void dumpOprs(FILE* fout, OprInfo* agginfo, int numOperators,
TypeInfo *tinfo, int numTypes);
extern void dumpOneFunc(FILE* fout, FuncInfo* finfo, int i,
TypeInfo *tinfo, int numTypes);
extern void dumpTables(FILE* fout, TableInfo* tbinfo, int numTables,
InhInfo *inhinfo, int numInherits,
TypeInfo *tinfo, int numTypes);
extern void dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices,
TableInfo* tbinfo, int numTables);
extern void dumpClasses(TableInfo *tbinfo, int numTables, FILE *fout);
extern void dumpTuples(char *portalname, FILE *fout, int *attrmap);
extern char* checkForQuote(char* s);
extern int findLastBuiltinOid();
/* largest query string size */
#define MAXQUERYLEN 5000
/* these voodoo constants are from the backend */
#define C_PROLANG_OID 13