diff options
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/initdb/initdb.c | 51 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_dump.c | 41 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_dumpall.c | 46 | ||||
| -rw-r--r-- | src/bin/psql/command.c | 6 | ||||
| -rw-r--r-- | src/bin/psql/describe.c | 20 | ||||
| -rw-r--r-- | src/bin/psql/describe.h | 4 | ||||
| -rw-r--r-- | src/bin/psql/tab-complete.c | 5 |
7 files changed, 145 insertions, 28 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 4a85dfb24d..e1c7ad30ce 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -42,7 +42,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.108 2006/02/10 22:05:42 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.109 2006/02/12 03:22:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -105,6 +105,7 @@ static const char *progname; static char *encodingid = "0"; static char *bki_file; static char *desc_file; +static char *shdesc_file; static char *hba_file; static char *ident_file; static char *conf_file; @@ -181,6 +182,7 @@ static void unlimit_systables(void); static void setup_depend(void); static void setup_sysviews(void); static void setup_description(void); +static void setup_shared_description(void); static void setup_conversion(void); static void setup_privileges(void); static void set_info_version(void); @@ -1574,6 +1576,7 @@ unlimit_systables(void) "ALTER TABLE pg_description CREATE TOAST TABLE;\n", "ALTER TABLE pg_proc CREATE TOAST TABLE;\n", "ALTER TABLE pg_rewrite CREATE TOAST TABLE;\n", + "ALTER TABLE pg_shdescription CREATE TOAST TABLE;\n", "ALTER TABLE pg_statistic CREATE TOAST TABLE;\n", NULL }; @@ -1752,6 +1755,42 @@ setup_description(void) } /* + * load shared description data + */ +static void +setup_shared_description(void) +{ + PG_CMD_DECL; + + fputs(_("loading pg_shdescription ... "), stdout); + fflush(stdout); + + snprintf(cmd, sizeof(cmd), + "\"%s\" %s template1 >%s", + backend_exec, backend_options, + DEVNULL); + + PG_CMD_OPEN; + + PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_shdescription ( " + " objoid oid, " + " classname name, " + " description text) WITHOUT OIDS;\n"); + + PG_CMD_PRINTF1("COPY tmp_pg_shdescription FROM '%s';\n", + shdesc_file); + + PG_CMD_PUTS("INSERT INTO pg_shdescription " + " SELECT t.objoid, c.oid, t.description " + " FROM tmp_pg_shdescription t, pg_class c " + " WHERE c.relname = t.classname;\n"); + + PG_CMD_CLOSE; + + check_ok(); +} + +/* * load conversion functions */ static void @@ -2702,6 +2741,7 @@ main(int argc, char *argv[]) set_input(&bki_file, "postgres.bki"); set_input(&desc_file, "postgres.description"); + set_input(&shdesc_file, "postgres.shdescription"); set_input(&hba_file, "pg_hba.conf.sample"); set_input(&ident_file, "pg_ident.conf.sample"); set_input(&conf_file, "postgresql.conf.sample"); @@ -2718,12 +2758,14 @@ main(int argc, char *argv[]) "VERSION=%s\n" "PGDATA=%s\nshare_path=%s\nPGPATH=%s\n" "POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n" - "POSTGRES_DESCR=%s\nPOSTGRESQL_CONF_SAMPLE=%s\n" + "POSTGRES_DESCR=%s\nPOSTGRES_SHDESCR=%s\n" + "POSTGRESQL_CONF_SAMPLE=%s\n" "PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n", PG_VERSION, pg_data, share_path, bin_path, effective_user, bki_file, - desc_file, conf_file, + desc_file, shdesc_file, + conf_file, hba_file, ident_file); if (show_setting) exit(0); @@ -2731,6 +2773,7 @@ main(int argc, char *argv[]) check_input(bki_file); check_input(desc_file); + check_input(shdesc_file); check_input(hba_file); check_input(ident_file); check_input(conf_file); @@ -2918,6 +2961,8 @@ main(int argc, char *argv[]) setup_description(); + setup_shared_description(); + setup_conversion(); setup_privileges(); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 3dffc9b3f4..fb0be000d5 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.427 2006/01/21 02:16:20 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.428 2006/02/12 03:22:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1185,7 +1185,20 @@ dumpDatabase(Archive *AH) selectSourceSchema("pg_catalog"); /* Get the database owner and parameters from pg_database */ - if (g_fout->remoteVersion >= 80000) + if (g_fout->remoteVersion >= 80200) + { + appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " + "(%s datdba) as dba, " + "pg_encoding_to_char(encoding) as encoding, " + "(SELECT spcname FROM pg_tablespace t WHERE t.oid = dattablespace) as tablespace, " + "shobj_description(oid, 'pg_database') as description " + + "FROM pg_database " + "WHERE datname = ", + username_subquery); + appendStringLiteral(dbQry, datname, true); + } + else if (g_fout->remoteVersion >= 80000) { appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " "(%s datdba) as dba, " @@ -1287,10 +1300,28 @@ dumpDatabase(Archive *AH) NULL); /* Dumper Arg */ /* Dump DB comment if any */ - resetPQExpBuffer(dbQry); - appendPQExpBuffer(dbQry, "DATABASE %s", fmtId(datname)); - dumpComment(AH, dbQry->data, NULL, "", + if (g_fout->remoteVersion >= 80200) + { + /* 8.2 keeps comments on shared objects in a shared table, so + * we cannot use the dumpComment used for other database objects. + */ + char *comment = PQgetvalue(res, 0, PQfnumber(res, "description")); + if (comment && strlen(comment)) { + resetPQExpBuffer(dbQry); + appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname)); + appendStringLiteral(dbQry, comment, false); + appendPQExpBuffer(dbQry, ";\n"); + + ArchiveEntry(AH, dbCatId, createDumpId(), datname, NULL, NULL, + dba, false, "COMMENT", dbQry->data, "", NULL, + &dbDumpId, 1, NULL, NULL); + } + } else { + resetPQExpBuffer(dbQry); + appendPQExpBuffer(dbQry, "DATABASE %s", fmtId(datname)); + dumpComment(AH, dbQry->data, NULL, "", dbCatId, 0, dbDumpId); + } PQclear(res); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index d74e42fba5..a811b6353e 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.69 2005/10/15 02:49:39 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.70 2006/02/12 03:22:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -409,16 +409,25 @@ dumpRoles(PGconn *conn) i_rolcanlogin, i_rolconnlimit, i_rolpassword, - i_rolvaliduntil; + i_rolvaliduntil, + i_rolcomment; int i; /* note: rolconfig is dumped later */ - if (server_version >= 80100) + if (server_version >= 80200) + printfPQExpBuffer(buf, + "SELECT rolname, rolsuper, rolinherit, " + "rolcreaterole, rolcreatedb, rolcatupdate, " + "rolcanlogin, rolconnlimit, rolpassword, " + "rolvaliduntil, " + "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment " + "FROM pg_authid"); + else if (server_version >= 80100) printfPQExpBuffer(buf, "SELECT rolname, rolsuper, rolinherit, " "rolcreaterole, rolcreatedb, rolcatupdate, " "rolcanlogin, rolconnlimit, rolpassword, " - "rolvaliduntil " + "rolvaliduntil, null as rolcomment " "FROM pg_authid"); else printfPQExpBuffer(buf, @@ -432,6 +441,7 @@ dumpRoles(PGconn *conn) "-1 as rolconnlimit, " "passwd as rolpassword, " "valuntil as rolvaliduntil " + "null as rolcomment " "FROM pg_shadow " "UNION ALL " "SELECT groname as rolname, " @@ -444,6 +454,7 @@ dumpRoles(PGconn *conn) "-1 as rolconnlimit, " "null::text as rolpassword, " "null::abstime as rolvaliduntil " + "null " "FROM pg_group"); res = executeQuery(conn, buf->data); @@ -458,6 +469,7 @@ dumpRoles(PGconn *conn) i_rolconnlimit = PQfnumber(res, "rolconnlimit"); i_rolpassword = PQfnumber(res, "rolpassword"); i_rolvaliduntil = PQfnumber(res, "rolvaliduntil"); + i_rolcomment = PQfnumber(res, "rolcomment"); if (PQntuples(res) > 0) printf("--\n-- Roles\n--\n\n"); @@ -523,6 +535,12 @@ dumpRoles(PGconn *conn) appendPQExpBuffer(buf, ";\n"); + if (!PQgetisnull(res, i, i_rolcomment)) { + appendPQExpBuffer(buf, "COMMENT ON ROLE %s IS ", fmtId(rolename)); + appendStringLiteral(buf, PQgetvalue(res, i, i_rolcomment), true); + appendPQExpBuffer(buf, ";\n"); + } + printf("%s", buf->data); if (server_version >= 70300) @@ -652,9 +670,18 @@ dumpTablespaces(PGconn *conn) * Get all tablespaces except built-in ones (which we assume are named * pg_xxx) */ - res = executeQuery(conn, "SELECT spcname, " + if (server_version >= 80200) + res = executeQuery(conn, "SELECT spcname, " + "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, " + "spclocation, spcacl, " + "pg_catalog.shobj_description(oid, 'pg_tablespace') " + "FROM pg_catalog.pg_tablespace " + "WHERE spcname NOT LIKE 'pg!_%' ESCAPE '!'"); + else + res = executeQuery(conn, "SELECT spcname, " "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, " - "spclocation, spcacl " + "spclocation, spcacl, " + "null " "FROM pg_catalog.pg_tablespace " "WHERE spcname NOT LIKE 'pg!_%' ESCAPE '!'"); @@ -668,6 +695,7 @@ dumpTablespaces(PGconn *conn) char *spcowner = PQgetvalue(res, i, 1); char *spclocation = PQgetvalue(res, i, 2); char *spcacl = PQgetvalue(res, i, 3); + char *spccomment = PQgetvalue(res, i, 4); char *fspcname; /* needed for buildACLCommands() */ @@ -693,6 +721,12 @@ dumpTablespaces(PGconn *conn) exit(1); } + if (spccomment && strlen(spccomment)) { + appendPQExpBuffer(buf, "COMMENT ON TABLESPACE %s IS ", fspcname); + appendStringLiteral(buf, spccomment, true); + appendPQExpBuffer(buf, ";\n"); + } + printf("%s", buf->data); free(fspcname); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index a095e0321b..8bd2e14f56 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.159 2006/02/12 02:54:30 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.160 2006/02/12 03:22:19 momjian Exp $ */ #include "postgres_fe.h" #include "command.h" @@ -379,7 +379,7 @@ exec_command(const char *cmd, break; case 'g': /* no longer distinct from \du */ - success = describeRoles(pattern); + success = describeRoles(pattern, show_verbose); break; case 'l': success = do_lo_list(); @@ -404,7 +404,7 @@ exec_command(const char *cmd, success = listTables(&cmd[1], pattern, show_verbose); break; case 'u': - success = describeRoles(pattern); + success = describeRoles(pattern, show_verbose); break; default: diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 5caf16df8c..17ca722f30 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.130 2005/11/22 18:17:29 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.131 2006/02/12 03:22:19 momjian Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -127,8 +127,9 @@ describeTablespaces(const char *pattern, bool verbose) if (verbose) appendPQExpBuffer(&buf, - ",\n spcacl as \"%s\"", - _("Access privileges")); + ",\n spcacl as \"%s\"" + ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"", + _("Access privileges"), _("Description")); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_tablespace\n"); @@ -362,7 +363,7 @@ listAllDbs(bool verbose) _("Encoding")); if (verbose) appendPQExpBuffer(&buf, - ",\n pg_catalog.obj_description(d.oid, 'pg_database') as \"%s\"", + ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"", _("Description")); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_database d" @@ -1382,7 +1383,7 @@ add_tablespace_footer(char relkind, Oid tablespace, char **footers, * Describes roles. Any schema portion of the pattern is ignored. */ bool -describeRoles(const char *pattern) +describeRoles(const char *pattern, bool verbose) { PQExpBufferData buf; PGresult *res; @@ -1398,8 +1399,7 @@ describeRoles(const char *pattern) " CASE WHEN r.rolconnlimit < 0 THEN CAST('%s' AS pg_catalog.text)\n" " ELSE CAST(r.rolconnlimit AS pg_catalog.text)\n" " END AS \"%s\", \n" - " ARRAY(SELECT b.rolname FROM pg_catalog.pg_auth_members m JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid) WHERE m.member = r.oid) as \"%s\"\n" - "FROM pg_catalog.pg_roles r\n", + " ARRAY(SELECT b.rolname FROM pg_catalog.pg_auth_members m JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid) WHERE m.member = r.oid) as \"%s\"", _("Role name"), _("yes"), _("no"), _("Superuser"), _("yes"), _("no"), _("Create role"), @@ -1407,6 +1407,12 @@ describeRoles(const char *pattern) _("no limit"), _("Connections"), _("Member of")); + if (verbose) + appendPQExpBuffer(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS \"%s\"", + _("Description")); + + appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_roles r\n"); + processNamePattern(&buf, pattern, false, false, NULL, "r.rolname", NULL, NULL); diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h index 22528f95a3..6289238736 100644 --- a/src/bin/psql/describe.h +++ b/src/bin/psql/describe.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.29 2005/08/14 18:49:30 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.30 2006/02/12 03:22:19 momjian Exp $ */ #ifndef DESCRIBE_H #define DESCRIBE_H @@ -26,7 +26,7 @@ extern bool describeTypes(const char *pattern, bool verbose); extern bool describeOperators(const char *pattern); /* \du, \dg */ -extern bool describeRoles(const char *pattern); +extern bool describeRoles(const char *pattern, bool verbose); /* \z (or \dp) */ extern bool permissionsList(const char *pattern); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index fd32a520fd..f77b3a8f43 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.145 2006/02/11 21:55:35 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.146 2006/02/12 03:22:19 momjian Exp $ */ /*---------------------------------------------------------------------- @@ -925,7 +925,8 @@ psql_completion(char *text, int start, int end) static const char *const list_COMMENT[] = {"CAST", "CONVERSION", "DATABASE", "INDEX", "LANGUAGE", "RULE", "SCHEMA", "SEQUENCE", "TABLE", "TYPE", "VIEW", "COLUMN", "AGGREGATE", "FUNCTION", - "OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT", NULL}; + "OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT", + "TABLESPACE", "ROLE", NULL}; COMPLETE_WITH_LIST(list_COMMENT); } |
