[PATCHES] Include tablespace information in psql \d footers

2004-06-24 Thread Gavin Sherry
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)
 * 

[PATCHES] pg_dump --clean w/ = 7.2 server

2004-06-24 Thread Kris Jurka

When running pg_dump --clean against a server that doesn't have schemas 
the namespace is blank and ends up producing a dump full off things like:

DROP TABLE .tab;

The attached patch only includes a schema if one exists.  There are
numerous comments about the DROPs needing to be fully qualified to avoid
conflicting with pg_catalog, but this should be mostly safe because it
would require a user defined object to be present in a later server
version with the same name, and it is difficult to impossible to drop
system objects anyway.

Kris JurkaIndex: src/bin/pg_dump/pg_dump.c
===
RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.376
diff -c -r1.376 pg_dump.c
*** src/bin/pg_dump/pg_dump.c   21 Jun 2004 13:36:41 -  1.376
--- src/bin/pg_dump/pg_dump.c   24 Jun 2004 12:21:45 -
***
*** 4616,4625 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delq, DROP TYPE %s.,
! fmtId(tinfo-dobj.namespace-dobj.name));
!   appendPQExpBuffer(delq, %s CASCADE;\n,
! fmtId(tinfo-dobj.name));
  
appendPQExpBuffer(q,
  CREATE TYPE %s (\n
--- 4616,4624 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delq, DROP TYPE %s CASCADE;\n,
! 
fmtQualifiedId(tinfo-dobj.namespace-dobj.name,
! tinfo-dobj.name));
  
appendPQExpBuffer(q,
  CREATE TYPE %s (\n
***
*** 4795,4804 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delq, DROP DOMAIN %s.,
! fmtId(tinfo-dobj.namespace-dobj.name));
!   appendPQExpBuffer(delq, %s;\n,
! fmtId(tinfo-dobj.name));
  
ArchiveEntry(fout, tinfo-dobj.catId, tinfo-dobj.dumpId,
 tinfo-dobj.name,
--- 4794,4802 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delq, DROP DOMAIN %s;\n,
! 
fmtQualifiedId(tinfo-dobj.namespace-dobj.name,
! tinfo-dobj.name));
  
ArchiveEntry(fout, tinfo-dobj.catId, tinfo-dobj.dumpId,
 tinfo-dobj.name,
***
*** 4888,4897 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delq, DROP TYPE %s.,
! fmtId(tinfo-dobj.namespace-dobj.name));
!   appendPQExpBuffer(delq, %s;\n,
! fmtId(tinfo-dobj.name));
  
ArchiveEntry(fout, tinfo-dobj.catId, tinfo-dobj.dumpId,
 tinfo-dobj.name,
--- 4886,4894 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delq, DROP TYPE %s;\n,
! 
fmtQualifiedId(tinfo-dobj.namespace-dobj.name,
! tinfo-dobj.name));
  
ArchiveEntry(fout, tinfo-dobj.catId, tinfo-dobj.dumpId,
 tinfo-dobj.name,
***
*** 5221,5228 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delqry, DROP FUNCTION %s.%s;\n,
! fmtId(finfo-dobj.namespace-dobj.name),
  funcsig);
  
rettypename = getFormattedTypeName(finfo-prorettype, zeroAsOpaque);
--- 5218,5228 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delqry, DROP FUNCTION );
!   if (strlen(finfo-dobj.namespace-dobj.name) != 0)
!   appendPQExpBuffer(delqry, %s.,
! fmtId(finfo-dobj.namespace-dobj.name));
!   appendPQExpBuffer(delqry, %s;\n,
  funcsig);
  
rettypename = getFormattedTypeName(finfo-prorettype, zeroAsOpaque);
***
*** 5644,5651 
 * DROP must be fully qualified in case same name appears in
 * pg_catalog
 */
!   appendPQExpBuffer(delq, DROP OPERATOR %s.%s;\n,
! fmtId(oprinfo-dobj.namespace-dobj.name),
  oprid-data);
  
appendPQExpBuffer(q, CREATE 

Re: [PATCHES] pg_dump --clean w/ = 7.2 server

2004-06-24 Thread Christopher Kings-Lynne
When running pg_dump --clean against a server that doesn't have schemas 
the namespace is blank and ends up producing a dump full off things like:

DROP TABLE .tab;
Since the person is dumping using 7.5 pg_dump, presumably they will be 
restoring to 7.5, and it should be:

DROP TABLE public.tab;
Chris
---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [PATCHES] pg_dump --clean w/ = 7.2 server

2004-06-24 Thread Tom Lane
Christopher Kings-Lynne [EMAIL PROTECTED] writes:
 When running pg_dump --clean against a server that doesn't have schemas 
 the namespace is blank and ends up producing a dump full off things like:
 
 DROP TABLE .tab;

 Since the person is dumping using 7.5 pg_dump, presumably they will be 
 restoring to 7.5, and it should be:

 DROP TABLE public.tab;

Possibly the most correct solution is to assign the name public to the
dummy schema that pg_dump creates internally when talking to a pre-7.3
server.

I seem to recall that there was some reason for using , but I don't
recall what exactly.

regards, tom lane

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [PATCHES] pg_ctl service integration for WIN32

2004-06-24 Thread Tom Lane
Magnus Hagander [EMAIL PROTECTED] writes:
 Amended patch attached.
 Claudio

 Been testing this, and found a couple of small issues. Attached is a
 patch that fixes these. (Note - Claudios patch is included in this one,
 since it hasn't been applied yet..)

Applied, but where's the documentation update?

regards, tom lane

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [PATCHES] Compiling libpq with VisualC

2004-06-24 Thread Tom Lane
Andreas Pflug [EMAIL PROTECTED] writes:
 elog.h is included in postgres.h, which is included in many 
 src/port/*.c. Many of them are pretty straight, not requiring any 
 backend specific stuff, so the attached patch will change postgres.h to 
 c.h for most of them.

Applied.  I did the sys/time.h stuff the standard Autoconf way, however.

regards, tom lane

---(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] initdb initial password from file

2004-06-24 Thread Tom Lane
Magnus Hagander [EMAIL PROTECTED] writes:
 Attached is a patch that adds the option --pwfile=3Dfilename to initdb.

Applied with minor editorialization (printing the numeric errno isn't
my idea of friendly...)

regards, tom lane

---(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] Cancel/Kill backend functions -- docs

2004-06-24 Thread Tom Lane
Magnus Hagander [EMAIL PROTECTED] writes:
 Here's at least some documentation about these.

Applied.

regards, tom lane

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [PATCHES] nested xacts and phantom Xids

2004-06-24 Thread Simon Riggs
On Wed, 2004-06-23 at 13:57, Bruce Momjian wrote:
 I am sorry to have given Alvaro another idea that didn't work. 

No way! Keep having the ideas, please.

I've done some more digging in dead time on all of this and I think
we're on the right course in general by implementing all of this.

...well done to Alvaro for being able to make the ideas reality.

Best regards, Simon Riggs


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send unregister YourEmailAddressHere to [EMAIL PROTECTED])


Re: [PATCHES] stderr win32 admin check

2004-06-24 Thread Tom Lane
Magnus Hagander [EMAIL PROTECTED] writes:
 Attached is the updated version of this patch, which now includes proper
 testing for win32 service running. This is tested and verified with
 Claudios service wrapper pg_ctl patch (including the parts I added and
 sent in a short while ago).

Applied.

regards, tom lane

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [PATCHES] pg_dump --clean w/ = 7.2 server

2004-06-24 Thread Kris Jurka


On Thu, 24 Jun 2004, Tom Lane wrote:

 Christopher Kings-Lynne [EMAIL PROTECTED] writes:
  When running pg_dump --clean against a server that doesn't have schemas 
  the namespace is blank and ends up producing a dump full off things like:
  
  DROP TABLE .tab;
 
  Since the person is dumping using 7.5 pg_dump, presumably they will be 
  restoring to 7.5, and it should be:
 
  DROP TABLE public.tab;
 
 Possibly the most correct solution is to assign the name public to the
 dummy schema that pg_dump creates internally when talking to a pre-7.3
 server.

I was considering that they might want to restore the dump into another 
schema and that would be easier with an unqualified name.  I don't really 
understand why the name needs to be fully qualified in the first place.

 I seem to recall that there was some reason for using , but I don't
 recall what exactly.
 

It seems like the only possible reasons are deliberately making it fail or 
just a lack of testing.  There's no way it does anything useful.

Kris Jurka

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [PATCHES] pg_dump --clean w/ = 7.2 server

2004-06-24 Thread Tom Lane
Kris Jurka [EMAIL PROTECTED] writes:
 Possibly the most correct solution is to assign the name public to the
 dummy schema that pg_dump creates internally when talking to a pre-7.3
 server.

 I was considering that they might want to restore the dump into another 
 schema and that would be easier with an unqualified name.  I don't really 
 understand why the name needs to be fully qualified in the first place.

Because it's entirely too likely that you'll drop the wrong thing if you
issue an unqualified DROP.

regards, tom lane

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


[PATCHES] Add argument name to CREATE FUNCTION documentation

2004-06-24 Thread Dennis Bjorklund
It's not much text, but someone who speaks english might want to look at 
it.

If it's okay I can commit.

-- 
/Dennis Björklund
Index: doc/src/sgml/ref/create_function.sgml
===
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/create_function.sgml,v
retrieving revision 1.56
diff -u -c -r1.56 create_function.sgml
*** doc/src/sgml/ref/create_function.sgml   16 May 2004 23:22:07 -  1.56
--- doc/src/sgml/ref/create_function.sgml   24 Jun 2004 22:02:35 -
***
*** 19,25 
  
   refsynopsisdiv
  synopsis
! CREATE [ OR REPLACE ] FUNCTION replaceable class=parametername/replaceable ( [ 
replaceable class=parameterargtype/replaceable [, ...] ] )
  RETURNS replaceable class=parameterrettype/replaceable
{ LANGUAGE replaceable class=parameterlangname/replaceable
  | IMMUTABLE | STABLE | VOLATILE
--- 19,25 
  
   refsynopsisdiv
  synopsis
! CREATE [ OR REPLACE ] FUNCTION replaceable class=parametername/replaceable ( [ 
[replaceable class=parameterargname/replaceable] replaceable 
class=parameterargtype/replaceable [, ...] ] )
  RETURNS replaceable class=parameterrettype/replaceable
{ LANGUAGE replaceable class=parameterlangname/replaceable
  | IMMUTABLE | STABLE | VOLATILE
***
*** 84,89 
--- 84,101 
   listitem
para
 The name of a function to create.
+   /para
+  /listitem
+ /varlistentry
+ 
+ varlistentry
+  termreplaceable class=parameterargname/replaceable/term
+ 
+  listitem
+   para
+The name of an argument. Some languages (currently only PL/pgSQL) lets
+you use the name in the function body, for other languages the
+argument name is just extra documentation.
/para
   /listitem
  /varlistentry

---(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] nested xacts and phantom Xids

2004-06-24 Thread Alvaro Herrera
On Sun, Jun 20, 2004 at 08:49:22PM -0400, Tom Lane wrote:

Regarding GUC, a WIP report:

 Given patches for inval.c and guc.c, I would say that the patch is
 functionally close enough to done that we could commit to including
 it in 7.5 --- the other stuff could be wrapped up post-feature-freeze.

I figured I could save the values whenever they are going to change, and
restore them if the subtransaction aborts.  This seems to work fine
(lightly tested).

I still have to figure out how to handle allocation for string vars, but
I thought I'd post the patch for others to see.  Please let me know if
it's too ugly.  (This patch misses the pieces in xact.c and xact.h but
I'm sure the concept is clear.)

I'll post a full patch once the missing deferred trigger stuff works.
With the patches I posted to inval.c I think this fulfills the
requirements, barring the performance issues raised.

Comments?

-- 
Alvaro Herrera (alvherre[a]dcc.uchile.cl)
No single strategy is always right (Unless the boss says so)
(Larry Wall)
Index: guc.c
===
RCS file: /home/alvherre/cvs/pgsql-server/src/backend/utils/misc/guc.c,v
retrieving revision 1.211
diff -c -w -b -B -c -r1.211 guc.c
*** guc.c   11 Jun 2004 03:54:54 -  1.211
--- guc.c   24 Jun 2004 23:41:42 -
***
*** 25,30 
--- 25,31 
  #include utils/guc.h
  #include utils/guc_tables.h
  
+ #include access/xact.h
  #include catalog/namespace.h
  #include catalog/pg_type.h
  #include commands/async.h
***
*** 54,59 
--- 55,61 
  #include tcop/tcopprot.h
  #include utils/array.h
  #include utils/builtins.h
+ #include utils/memutils.h
  #include utils/pg_locale.h
  #include pgstat.h
  
***
*** 76,81 
--- 78,85 
  static const char *assign_log_destination(const char *value,
bool doit, GucSource source);
  
+ static void SaveGucVariable(struct config_generic *conf);
+ 
  #ifdef HAVE_SYSLOG
  extern char *Syslog_facility;
  extern char *Syslog_ident;
***
*** 105,110 
--- 109,115 
   GucSource source);
  static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
  static bool assign_log_stats(bool newval, bool doit, GucSource source);
+ static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
  
  
  /*
***
*** 172,177 
--- 177,183 
  static intmax_index_keys;
  static intmax_identifier_length;
  static intblock_size;
+ static intnesting_level;
  static bool integer_datetimes;
  
  /* Macros for freeing malloc'd pointers only if appropriate to do so */
***
*** 801,807 
GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
},
XactReadOnly,
!   false, NULL, NULL
},
{
{add_missing_from, PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
--- 807,813 
GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
},
XactReadOnly,
!   false, assign_transaction_read_only, NULL
},
{
{add_missing_from, PGC_USERSET, COMPAT_OPTIONS_PREVIOUS,
***
*** 1311,1316 
--- 1317,1333 
BLCKSZ, BLCKSZ, BLCKSZ, NULL, NULL
},
  
+   {
+   /* XXX probably it's a bad idea for this to be GUC_REPORT. */
+   {nesting_level, PGC_INTERNAL, UNGROUPED,
+   gettext_noop(Shows the current transaction nesting level),
+   NULL,
+   GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_REPORT
+   },
+   nesting_level,
+   0, 0, INT_MAX, NULL, NULL
+   },
+ 
/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
***
*** 2001,2014 
return find_option(map_old_guc_names[i+1]);
}
  
!   /* Check if the name is qualified, and if so, check if the qualifier
 * maps to a custom variable class.
 */
dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
if(dot != NULL  is_custom_class(name, dot - name))
!   /*
!* Add a placeholder variable for this name
!*/
return (struct config_generic*)add_placeholder_variable(name);
  
/* Unknown name */
--- 2018,2030 
return find_option(map_old_guc_names[i+1]);
}
  
!   /*
!* Check if the name is qualified, and if so, check if the qualifier
 * maps to a custom variable class.
 */
dot = strchr(name, GUC_QUALIFIER_SEPARATOR);
if(dot != NULL  is_custom_class(name, dot - name))
!   /* Add a placeholder variable for this name */
  

Re: [PATCHES] Add argument name to CREATE FUNCTION documentation

2004-06-24 Thread Tom Lane
Dennis Bjorklund [EMAIL PROTECTED] writes:
 It's not much text, but someone who speaks english might want to look at 
 it.

Two trivial comments:

1. We usually leave spaces around brackets in syntax definitions, so
I'd go for ... [ argname ] ... not  ... [argname] ...
Also, check that the resulting format looks good in psql's \h output.
You might need to fool with spacing/line breaks to make it look good.

2. The grammar in your description is a bit off; it would read better as

   The name of an argument. Some languages (currently only PL/pgSQL) let
   you use the name in the function body.  For other languages the
   argument name is just extra documentation.

Otherwise, apply away.

regards, tom lane

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [PATCHES] Add argument name to CREATE FUNCTION documentation

2004-06-24 Thread Dennis Bjorklund
On Thu, 24 Jun 2004, Tom Lane wrote:

 1. We usually leave spaces around brackets in syntax definitions, so
 I'd go for ... [ argname ] ... not  ... [argname] ...

I saw both in that very rule (later there is an [EXTERNAL]) so I guessed
that one use what looks best at different places. But consistency is good.

-- 
/Dennis Björklund


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [PATCHES] Add argument name to CREATE FUNCTION documentation

2004-06-24 Thread Tom Lane
Dennis Bjorklund [EMAIL PROTECTED] writes:
 On Thu, 24 Jun 2004, Tom Lane wrote:
 1. We usually leave spaces around brackets in syntax definitions, so
 I'd go for ... [ argname ] ... not  ... [argname] ...

 I saw both in that very rule (later there is an [EXTERNAL]) so I guessed
 that one use what looks best at different places. But consistency is good.

Feel free to fix that one while you're at it ... but yes, this is mostly
a visual thing.  Do what looks good.

regards, tom lane

---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org