Re: [PATCHES] Include tablespace information in psql \d footers
On Mon, 12 Jul 2004, Bruce Momjian wrote: > Bruce Momjian wrote: > > > > Patch applied. Thanks. > > > > I removed the display of tablespaces for sequences and toast tables: > > > > test=> \d test > > Table "public.test" > > Column | Type | Modifiers > > +-+--- > > x | integer | > > > > test=> \d test2 > > Table "public.test2" > > Column | Type | Modifiers > > +-+--- > > x | integer | > > Tablespace: > > "tmp" > > > > Why is the tablespace name printed on a separate line? > > OK, I moved the tablespace name up on to the same line just like Has > oids: Works for me. Thanks, Gavin ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PATCHES] Include tablespace information in psql \d footers
Bruce Momjian wrote: > > Patch applied. Thanks. > > I removed the display of tablespaces for sequences and toast tables: > > test=> \d test >Table "public.test" >Column | Type | Modifiers > +-+--- >x | integer | > > test=> \d test2 >Table "public.test2" >Column | Type | Modifiers > +-+--- >x | integer | > Tablespace: > "tmp" > > Why is the tablespace name printed on a separate line? OK, I moved the tablespace name up on to the same line just like Has oids: test=> \d+ test3 Table "public.test3" Column | Type | Modifiers | Description +-+---+- x | integer | not null | Indexes: "test3_pkey" PRIMARY KEY, btree (x) Contains OIDs: yes Tablespace: "tmp" -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster
Re: [PATCHES] Include tablespace information in psql \d footers
Patch applied. Thanks. I removed the display of tablespaces for sequences and toast tables: test=> \d test Table "public.test" Column | Type | Modifiers +-+--- x | integer | test=> \d test2 Table "public.test2" Column | Type | Modifiers +-+--- x | integer | Tablespace: "tmp" Why is the tablespace name printed on a separate line? --- Gavin Sherry wrote: > On Fri, 25 Jun 2004, Tom Lane wrote: > > > Gavin Sherry <[EMAIL PROTECTED]> writes: > > > Attached. > > > > Couple of problems with this: > > > > 1. Don't #ifndef WIN32 it. In the first place, we might have tablespace > > support on Windows later, and in the second place, even if psql is > > running on Windows that doesn't mean the server it's talking to is. > > Oops. > > > > > 2. Printing "pg_default" when reltblspace is zero is wrong. Get the > > database's default tablespace and print that. Or perhaps better, > > don't print anything at all; that would avoid cluttering the display > > for people who don't use tablespaces. > > Ahhh yes of course. Attached is a patch with docs which excludes reporting > of the default tablespace. > > Gavin Content-Description: [ Attachment, skipping... ] > > ---(end of broadcast)--- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup.| Newtown Square, Pennsylvania 19073 ---(end of broadcast)--- TIP 8: explain analyze is your friend
Re: [PATCHES] Include tablespace information in psql \d footers
On Fri, 25 Jun 2004, Tom Lane wrote: > Gavin Sherry <[EMAIL PROTECTED]> writes: > > Attached. > > Couple of problems with this: > > 1. Don't #ifndef WIN32 it. In the first place, we might have tablespace > support on Windows later, and in the second place, even if psql is > running on Windows that doesn't mean the server it's talking to is. Oops. > > 2. Printing "pg_default" when reltblspace is zero is wrong. Get the > database's default tablespace and print that. Or perhaps better, > don't print anything at all; that would avoid cluttering the display > for people who don't use tablespaces. Ahhh yes of course. Attached is a patch with docs which excludes reporting of the default tablespace. GavinIndex: doc/src/sgml/ref/psql-ref.sgml === RCS file: /usr/local/cvsroot/pgsql-server/doc/src/sgml/ref/psql-ref.sgml,v retrieving revision 1.116 diff -2 -c -r1.116 psql-ref.sgml *** doc/src/sgml/ref/psql-ref.sgml 18 Jun 2004 06:13:05 - 1.116 --- doc/src/sgml/ref/psql-ref.sgml 28 Jun 2004 17:59:31 - *** *** 785,789 For each relation (table, view, index, or sequence) matching the pattern, show all ! columns, their types, and any special attributes such as NOT NULL or defaults, if any. Associated indexes, constraints, rules, and triggers are --- 785,790 For each relation (table, view, index, or sequence) matching the pattern, show all ! columns, their types, the tablespace they reside in (if this differs ! from the database default) and any special attributes such as NOT NULL or defaults, if any. Associated indexes, constraints, rules, and triggers are Index: src/bin/psql/common.h === RCS file: /usr/local/cvsroot/pgsql-server/src/bin/psql/common.h,v retrieving revision 1.35 diff -2 -c -r1.35 common.h *** src/bin/psql/common.h 19 Apr 2004 17:42:58 - 1.35 --- src/bin/psql/common.h 24 Jun 2004 03:16:02 - *** *** 21,24 --- 21,27 #endif + #define atooid(x) ((Oid) strtoul((x), NULL, 10)) + + /* * Safer versions of some standard C library functions. If an Index: src/bin/psql/describe.c === RCS file: /usr/local/cvsroot/pgsql-server/src/bin/psql/describe.c,v retrieving revision 1.99 diff -2 -c -r1.99 describe.c *** src/bin/psql/describe.c 18 Jun 2004 06:14:04 - 1.99 --- src/bin/psql/describe.c 28 Jun 2004 18:02:08 - *** *** 40,43 --- 40,46 const char *altnamevar, const char *visibilityrule); + static void add_tablespace_footer(char relkind, Oid tablespace, + char **footers, int *count, PQExpBufferData buf); + /* * Handlers for various slash commands displaying some sort of list *** *** 683,686 --- 686,690 boolhasrules; boolhasoids; + Oid tablespace; } tableinfo; boolshow_modifiers = false; *** *** 695,699 /* Get general table info */ printfPQExpBuffer(&buf, !"SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, relhasoids\n" "FROM pg_catalog.pg_class WHERE oid = '%s'", oid); --- 699,704 /* Get general table info */ printfPQExpBuffer(&buf, !"SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n" ! "relhasoids, reltablespace \n" "FROM pg_catalog.pg_class WHERE oid = '%s'", oid); *** *** 718,721 --- 723,727 tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 4), "t") == 0; tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0; + tableinfo.tablespace = atooid(PQgetvalue(res, 0, 6)); PQclear(res); *** *** 869,873 /* Make footers */ ! if (tableinfo.relkind == 'i') { /* Footer information about an index */ --- 875,893 /* Make footers */ ! if(tableinfo.relkind == 'S' || tableinfo.relkind == 't') ! { ! /* !* We can handle TOAST and sequences together, as the only !* footer is tablespace !*/ ! int count_footers = 0; ! ! footers = pg_malloc_zero(3 * sizeof(*footers)); ! ! add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace, ! &footers[0], &count_footers, buf); ! foot
Re: [PATCHES] Include tablespace information in psql \d footers
Gavin Sherry <[EMAIL PROTECTED]> writes: > Attached. Couple of problems with this: 1. Don't #ifndef WIN32 it. In the first place, we might have tablespace support on Windows later, and in the second place, even if psql is running on Windows that doesn't mean the server it's talking to is. 2. Printing "pg_default" when reltblspace is zero is wrong. Get the database's default tablespace and print that. Or perhaps better, don't print anything at all; that would avoid cluttering the display for people who don't use tablespaces. regards, tom lane ---(end of broadcast)--- TIP 8: explain analyze is your friend
[PATCHES] Include tablespace information in psql \d footers
Attached. There is no other way at the moment to get the tablespace name of an object in psql. We get information for tables, index, sequences and toast tables. We should probably do this for schemas too... GavinIndex: src/bin/psql/common.h === RCS file: /usr/local/cvsroot/pgsql-server/src/bin/psql/common.h,v retrieving revision 1.35 diff -2 -c -r1.35 common.h *** src/bin/psql/common.h 19 Apr 2004 17:42:58 - 1.35 --- src/bin/psql/common.h 24 Jun 2004 03:16:02 - *** *** 21,24 --- 21,27 #endif + #define atooid(x) ((Oid) strtoul((x), NULL, 10)) + + /* * Safer versions of some standard C library functions. If an Index: src/bin/psql/describe.c === RCS file: /usr/local/cvsroot/pgsql-server/src/bin/psql/describe.c,v retrieving revision 1.99 diff -2 -c -r1.99 describe.c *** src/bin/psql/describe.c 18 Jun 2004 06:14:04 - 1.99 --- src/bin/psql/describe.c 24 Jun 2004 10:59:32 - *** *** 40,43 --- 40,46 const char *altnamevar, const char *visibilityrule); + static void add_tablespace_footer(char relkind, Oid tablespace, + char **footers, int *count, PQExpBufferData buf); + /* * Handlers for various slash commands displaying some sort of list *** *** 683,686 --- 686,690 boolhasrules; boolhasoids; + Oid tablespace; } tableinfo; boolshow_modifiers = false; *** *** 695,699 /* Get general table info */ printfPQExpBuffer(&buf, !"SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, relhasoids\n" "FROM pg_catalog.pg_class WHERE oid = '%s'", oid); --- 699,704 /* Get general table info */ printfPQExpBuffer(&buf, !"SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n" ! "relhasoids, reltablespace \n" "FROM pg_catalog.pg_class WHERE oid = '%s'", oid); *** *** 718,721 --- 723,727 tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 4), "t") == 0; tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0; + tableinfo.tablespace = atooid(PQgetvalue(res, 0, 6)); PQclear(res); *** *** 869,873 /* Make footers */ ! if (tableinfo.relkind == 'i') { /* Footer information about an index */ --- 875,895 /* Make footers */ ! if(tableinfo.relkind == 'S' || tableinfo.relkind == 't') ! { ! /* !* We can handle TOAST and sequences together, as the only !* footer is tablespace !*/ ! int count_footers = 0; ! ! footers = pg_malloc_zero(3 * sizeof(*footers)); ! ! #ifndef WIN32 ! add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace, ! &footers[0], &count_footers, buf); ! #endif ! footers[count_footers] = NULL; ! } ! else if (tableinfo.relkind == 'i') { /* Footer information about an index */ *** *** 898,901 --- 920,924 char *indtable = PQgetvalue(result, 0, 4); char *indpred = PQgetvalue(result, 0, 5); + int count_footers = 0; if (strcmp(indisprimary, "t") == 0) *** *** 917,923 appendPQExpBuffer(&tmpbuf, _(", CLUSTER")); ! footers = pg_malloc_zero(2 * sizeof(*footers)); ! footers[0] = pg_strdup(tmpbuf.data); ! footers[1] = NULL; } --- 940,951 appendPQExpBuffer(&tmpbuf, _(", CLUSTER")); ! footers = pg_malloc_zero(4 * sizeof(*footers)); ! footers[count_footers++] = pg_strdup(tmpbuf.data); ! #ifndef WIN32 ! add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace, ! footers, &count_footers, tmpbuf); ! #endif ! footers[count_footers] = NULL; ! } *** *** 1104,1108 inherits_count = PQntuples(result6); ! footers = pg_malloc_zero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inherits_count + 6)