From dd2c410616bde7db2d62e4238c4b748aa9e1be46 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 20 Jun 1997 02:20:26 +0000 Subject: [PATCH] Allow pg_dump to preserve owners of all objects. --- src/bin/pg_dump/pg_dump.c | 80 ++++++++++++++++++++++++++++----------- src/bin/psql/psql.c | 51 +++++++++++++++---------- 2 files changed, 87 insertions(+), 44 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 2ebabed51e..7163391a4f 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -21,7 +21,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.32 1997/06/07 05:29:22 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.33 1997/06/20 02:20:17 momjian Exp $ * * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * @@ -263,7 +263,7 @@ dumpClasses_dumpData(FILE *fout, const char *classname, int tuple; int field; - sprintf(query, "select * from %s;\n", classname); + sprintf(query, "select * from %s", classname); res = PQexec(g_conn, query); if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) { @@ -546,6 +546,7 @@ getTypes(int *numTypes) int i_typdefault; int i_typrelid; int i_typbyval; + int i_usename; res = PQexec(g_conn, "begin"); if (!res || @@ -561,9 +562,10 @@ getTypes(int *numTypes) /* we filter out the built-in types when we dump out the types */ - sprintf(query, "SELECT oid, typowner,typname, typlen, typprtlen, " + sprintf(query, "SELECT pg_type.oid, typowner,typname, typlen, typprtlen, " "typinput, typoutput, typreceive, typsend, typelem, typdelim, " - "typdefault, typrelid,typbyval from pg_type"); + "typdefault, typrelid,typbyval, usename from pg_type, pg_user " + "where typowner = usesysid"); res = PQexec(g_conn,query); if (!res || @@ -590,6 +592,7 @@ getTypes(int *numTypes) i_typdefault = PQfnumber(res,"typdefault"); i_typrelid = PQfnumber(res,"typrelid"); i_typbyval = PQfnumber(res,"typbyval"); + i_usename = PQfnumber(res,"usename"); for (i=0;i '%d'::oid", + "SELECT pg_proc.oid, proname, prolang, pronargs, prorettype, " + "proretset, proargtypes, prosrc, probin, usename " + "from pg_proc, pg_user " + "where pg_proc.oid > '%d'::oid and proowner = usesysid", g_last_builtin_oid); res = PQexec(g_conn, query); @@ -1005,7 +1023,6 @@ getFuncs(int *numFuncs) i_oid = PQfnumber(res,"oid"); i_proname = PQfnumber(res,"proname"); - i_proowner = PQfnumber(res,"proowner"); i_prolang = PQfnumber(res,"prolang"); i_pronargs = PQfnumber(res,"pronargs"); i_proargtypes = PQfnumber(res,"proargtypes"); @@ -1013,11 +1030,11 @@ getFuncs(int *numFuncs) i_proretset = PQfnumber(res,"proretset"); i_prosrc = PQfnumber(res,"prosrc"); i_probin = PQfnumber(res,"probin"); + i_usename = PQfnumber(res,"usename"); for (i=0;i '%d'::oid " - "and t2.relname !~ '^pg_' and t1.relname !~ '^Xinx' ;", + "and t2.relname !~ '^pg_' and t1.relname !~ '^Xinx'", g_last_builtin_oid); res = PQexec(g_conn, query); @@ -1384,6 +1408,8 @@ dumpTypes(FILE* fout, FuncInfo* finfo, int numFuncs, if (funcInd != -1) dumpOneFunc(fout,finfo,funcInd,tinfo,numTypes); + fprintf(fout,"\\connect - %s\n",tinfo[i].usename); + sprintf(q, "CREATE TYPE %s " "( internallength = %s, externallength = %s, input = %s, " @@ -1448,6 +1474,8 @@ dumpOneFunc(FILE* fout, FuncInfo* finfo, int i, else finfo[i].dumped = 1; + fprintf(fout,"\\connect - %s\n",finfo[i].usename); + sprintf(q,"CREATE FUNCTION %s (",finfo[i].proname); for (j=0;jopt.align)); fprintf(stderr, " \\C [] -- set html3 caption (currently '%s')\n", ps->opt.caption ? ps->opt.caption : ""); - fprintf(stderr, " \\connect -- connect to new database (currently '%s')\n", PQdb(ps->db)); + fprintf(stderr, " \\connect -- connect to new database (currently '%s')\n", PQdb(ps->db)); fprintf(stderr, " \\copy table {from | to} \n"); fprintf(stderr, " \\d [] -- list tables and indicies in database or columns in
, * for all\n"); fprintf(stderr, " \\di -- list only indicies in database\n"); @@ -172,6 +174,11 @@ slashUsage(PsqlSettings * ps) fprintf(stderr, " \\m -- toggle monitor-like table display (currently %s)\n", on(ps->opt.standard)); fprintf(stderr, " \\o [] [|] -- send all query results to stdout, , or pipe\n"); fprintf(stderr, " \\p -- print the current query buffer\n"); + + fprintf(stderr, "Press ENTER to continue"); + /* eat up any extra characters typed before ENTER */ + while ((ch = fgetc(stdin)) != '\r' && ch != '\n') + ; fprintf(stderr, " \\q -- quit\n"); fprintf(stderr, " \\r -- reset(clear) the query buffer\n"); fprintf(stderr, " \\s [] -- print history or save it in \n"); @@ -858,18 +865,16 @@ do_copy(const char *args, PsqlSettings * settings) static void do_connect(const char *new_dbname, const char *new_user, - PsqlSettings * settings) + PsqlSettings *settings) { - - char *dbname = PQdb(settings->db); if (!new_dbname) fprintf(stderr, "\\connect must be followed by a database name\n"); else { - PGconn *olddb = settings->db; + PGconn *olddb = settings->db; static char *userenv = NULL; char *old_userenv = NULL; + const char *dbparam; - printf("closing connection to database: %s\n", dbname); if (new_user != NULL) { /* PQsetdb() does not allow us to specify the user, @@ -885,23 +890,27 @@ do_connect(const char *new_dbname, if (old_userenv != NULL) free(old_userenv); } + + if (strcmp(new_dbname,"-") != 0) + dbparam = new_dbname; + else dbparam = PQdb(olddb); + settings->db = PQsetdb(PQhost(olddb), PQport(olddb), - NULL, NULL, new_dbname); - if (!new_user) - printf("connecting to new database: %s\n", new_dbname); - else - printf("connecting to new database: %s as user: %s\n", - new_dbname,new_user); + NULL, NULL, dbparam); + if (!settings->quiet) { + if (!new_user) + printf("connecting to new database: %s\n", dbparam); + else if (dbparam != new_dbname) + printf("connecting as new user: %s\n", new_user); + else + printf("connecting to new database: %s as user: %s\n", + dbparam,new_user); + } + if (PQstatus(settings->db) == CONNECTION_BAD) { fprintf(stderr, "%s\n", PQerrorMessage(settings->db)); - printf("reconnecting to %s\n", dbname); - settings->db = PQsetdb(PQhost(olddb), PQport(olddb), - NULL, NULL, dbname); - if (PQstatus(settings->db) == CONNECTION_BAD) { - fprintf(stderr, - "could not reconnect to %s. exiting\n", dbname); - exit(2); - } + fprintf(stderr,"Could not connect to new database. exiting\n"); + exit(2); } else { PQfinish(olddb); free(settings->prompt);