Re: [PATCHES] [BUGS] Incomplete docs for restore_command for hot standby

2008-03-28 Thread Simon Riggs
On Mon, 2008-02-25 at 17:56 +0600, Markus Bertheau wrote:
 2008/2/22, Simon Riggs [EMAIL PROTECTED]:

  If you have some suggested changes, I'd be happy to hear them.
 
   Probably additions are better than just changes though.
 
 What about this:
 
 *** a/doc/src/sgml/backup.sgml
 --- b/doc/src/sgml/backup.sgml
 ***

...

 The FIXME of course needs replacement by someone in the know.

Doc patch edited to include all of Markus' points, tidy up some related
text and fix typos.

Good to apply to HEAD.

-- 
  Simon Riggs
  2ndQuadrant  http://www.2ndQuadrant.com 

  PostgreSQL UK 2008 Conference: http://www.postgresql.org.uk
Index: doc/src/sgml/backup.sgml
===
RCS file: /home/sriggs/pg/REPOSITORY/pgsql/doc/src/sgml/backup.sgml,v
retrieving revision 2.115
diff -c -r2.115 backup.sgml
*** doc/src/sgml/backup.sgml	7 Mar 2008 01:46:41 -	2.115
--- doc/src/sgml/backup.sgml	28 Mar 2008 13:08:38 -
***
*** 577,587 
 para
  It is important that the archive command return zero exit status if and
  only if it succeeded.  Upon getting a zero result,
! productnamePostgreSQL/ will assume that the WAL segment file has been
! successfully archived, and will remove or recycle it.
! However, a nonzero status tells
! productnamePostgreSQL/ that the file was not archived; it will try
! again periodically until it succeeds.
 /para
  
 para
--- 577,586 
 para
  It is important that the archive command return zero exit status if and
  only if it succeeded.  Upon getting a zero result,
! productnamePostgreSQL/ will assume that the file has been
! successfully archived, and will remove or recycle it.  However, a nonzero 
! status tells productnamePostgreSQL/ that the file was not archived; 
! it will try again periodically until it succeeds.
 /para
  
 para
***
*** 1001,1011 
  
 para
  It is important that the command return nonzero exit status on failure.
! The command emphasiswill/ be asked for log files that are not present
  in the archive; it must return nonzero when so asked.  This is not an
! error condition.  Be aware also that the base name of the literal%p/
! path will be different from literal%f/; do not expect them to be
! interchangeable.
 /para
  
 para
--- 1000,1012 
  
 para
  It is important that the command return nonzero exit status on failure.
! The command emphasiswill/ be asked for files that are not present
  in the archive; it must return nonzero when so asked.  This is not an
! error condition.  Not all of the requested files will be WAL segment
! files. You should also expect requests for files with a suffix of 
! literal.backup/ or literal.history/. Also be aware also that
! the base name of the literal%p/ path will be different from 
! literal%f/; do not expect them to be interchangeable.
 /para
  
 para
***
*** 1576,1594 
  
 para
  The magic that makes the two loosely coupled servers work together is
! simply a varnamerestore_command/ used on the standby that waits
! for the next WAL file to become available from the primary. The
! varnamerestore_command/ is specified in the
  filenamerecovery.conf/ file on the standby server. Normal recovery
  processing would request a file from the WAL archive, reporting failure
  if the file was unavailable.  For standby processing it is normal for
! the next file to be unavailable, so we must be patient and wait for
! it to appear. A waiting varnamerestore_command/ can be written as
! a custom script that loops after polling for the existence of the next
! WAL file. There must also be some way to trigger failover, which should
! interrupt the varnamerestore_command/, break the loop and return
! a file-not-found error to the standby server. This ends recovery and
! the standby will then come up as a normal server.
 /para
  
 para
--- 1577,1598 
  
 para
  The magic that makes the two loosely coupled servers work together is
! simply a varnamerestore_command/ used on the standby that,
! when asked for the next WAL file, waits for it to become available from
! the primary. The varnamerestore_command/ is specified in the
  filenamerecovery.conf/ file on the standby server. Normal recovery
  processing would request a file from the WAL archive, reporting failure
  if the file was unavailable.  For standby processing it is normal for
! the next WAL file to be unavailable, so we must be patient and wait for
! it to appear. For files ending in literal.backup/ or 
! literal.history/ there is no need to wait, though a non-zero return
! code should also be returned in this case. A waiting 
! varnamerestore_command/ can be written as a custom script that loops
! 

Re: [PATCHES] [BUGS] Incomplete docs for restore_command for hotstandby

2008-03-28 Thread Heikki Linnakangas

Simon Riggs wrote:

On Mon, 2008-02-25 at 17:56 +0600, Markus Bertheau wrote:

The FIXME of course needs replacement by someone in the know.


Doc patch edited to include all of Markus' points, tidy up some related
text and fix typos.

Good to apply to HEAD.


Committed to HEAD with minor fixes.

What's our policy wrt. back-patching doc changes? This seems applicable 
to older versions as well, but do we do that?


--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] [WIP] Keeping track of snapshots

2008-03-28 Thread Alvaro Herrera
Gregory Stark wrote:
 Alvaro Herrera [EMAIL PROTECTED] writes:
 
  The other question is about CommitTransactionCommand.  Currently my
  EOXact routine barfs for every snapshot not unregistered on main
  transaction commit -- a leak.  I see this as a good thing, however it
  forced me to be more meticulous about not having ActiveSnapshot be set
  in commands that have multiple transactions like VACUUM, multitable
  CLUSTER and CREATE INDEX CONCURRENTLY.
 
 I believe ActiveSnapshot has to be set during CREATE INDEX CONCURRENTLY if
 it's an expression index which calls a function which needs a snapshot...

Yeah, it is set at that point -- it is unset just before
CommitTransactionCommand is called.  Same for multitable CLUSTER -- it
certainly does need a snapshot, but it needs to unregister it just
before committing at the end of processing each table.

 AFAICT VACUUM had better not ever need a snapshot because its xmin isn't
 included in other vacuum commands' globalxmin so there's no guarantee that if
 it had a snapshot that the tuples visible in that snapshot wouldn't disappear
 out from under it.

Yeah, I neglected to mention that this is just for VACUUM FULL (which
does have its xmin included in snapshots).

-- 
Alvaro Herrerahttp://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] [BUGS] Incomplete docs for restore_command for hotstandby

2008-03-28 Thread Bruce Momjian
Heikki Linnakangas wrote:
 Simon Riggs wrote:
  On Mon, 2008-02-25 at 17:56 +0600, Markus Bertheau wrote:
  The FIXME of course needs replacement by someone in the know.
  
  Doc patch edited to include all of Markus' points, tidy up some related
  text and fix typos.
  
  Good to apply to HEAD.
 
 Committed to HEAD with minor fixes.
 
 What's our policy wrt. back-patching doc changes? This seems applicable 
 to older versions as well, but do we do that?

I do backpatch of doc changes if the change is serious.

-- 
  Bruce Momjian  [EMAIL PROTECTED]http://momjian.us
  EnterpriseDB http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] [HACKERS] Text - C string

2008-03-28 Thread Brendan Jurd
On 26/03/2008, Tom Lane [EMAIL PROTECTED] wrote:
  There are no textout/textin calls left, but I may have missed some
  places that were doing it the hard way with direct palloc/memcpy
  manipulations.  It might be worth trolling all the VARDATA() references
  to see if any more are easily replaceable.


I think there are perhaps a dozen such sites, and I hope to submit a
cleanup patch that gets rid of these soon.

I did come across one site I'm not sure about in utils/adt/xml.c:291

/*
 * We need a null-terminated string to pass to parse_xml_decl().  Rather
 * than make a separate copy, make the temporary result one byte bigger
 * than it needs to be.
 */
result = palloc(nbytes + 1 + VARHDRSZ);
SET_VARSIZE(result, nbytes + VARHDRSZ);
memcpy(VARDATA(result), str, nbytes);
str = VARDATA(result);
str[nbytes] = '\0';

The author seemed pretty sure he didn't want to make a separate copy
of the string, so I'm thinking there's not a whole lot I can do to
improve this site.

  I notice in particular that xfunc.sgml contains sample C functions to
  copy and concatenate text.  While these aren't directly replaceable
  with the new functions, I wonder whether we ought to change the examples
  to make them less certain to break if we ever change text's
  representation.


Yes, these sample C functions are shown in tutorial/funcs.c and
funcs_new.c as well.  I agree that the examples could do with
changing, but don't have any keen insight on what to change them to.

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] [HACKERS] Text - C string

2008-03-28 Thread Tom Lane
Brendan Jurd [EMAIL PROTECTED] writes:
 On 26/03/2008, Tom Lane [EMAIL PROTECTED] wrote:
 There are no textout/textin calls left, but I may have missed some
 places that were doing it the hard way with direct palloc/memcpy
 manipulations.  It might be worth trolling all the VARDATA() references
 to see if any more are easily replaceable.

 I think there are perhaps a dozen such sites, and I hope to submit a
 cleanup patch that gets rid of these soon.
 I did come across one site I'm not sure about in utils/adt/xml.c:291

I intentionally didn't touch xml.c, nor anyplace that is not dealing
in text, even if it happens to be binary-compatible with text.

regards, tom lane

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


Re: [PATCHES] [HACKERS] Text - C string

2008-03-28 Thread Brendan Jurd
On 29/03/2008, Tom Lane [EMAIL PROTECTED] wrote:
 I intentionally didn't touch xml.c, nor anyplace that is not dealing
  in text, even if it happens to be binary-compatible with text.


Hmm, okay.  My original submission did include a few such changes; for
example, in xml_in and xml_out_internal I saw that the conversion
between xmltype and cstring was identical to the text conversion, so I
went ahead and used the text functions.  Feedback upthread suggested
that it was okay to go ahead with casting in identical cases. [1]

I saw that these changes made it into the commit, so I assumed that it
was the right call.

If we don't want to meddle with xmltype/bytea/VarChar at all, we'll
have to revert those changes, and I'll have to seriously scale back
the cleanup patch I was about to post.

Regards,
BJ

[1] http://archives.postgresql.org/pgsql-hackers/2007-09/msg01094.php

-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches


[PATCHES] create language ... if not exists

2008-03-28 Thread Andreas 'ads' Scherbaum

Hello all,

yesterday i ran into a small problem:
http://andreas.scherbaum.la/blog/archives/346-create-language-if-not-exist.html
and was bugged to create a patch for PostgreSQL. So here is a first
version, still missing some things like documentation.

The attached patch for HEAD extends the CREATE LANGUAGE statement by an
IF NOT EXISTS option which in effect changes the raised error into a
notice.

Before i continue working on this patch i would like to know if this
extension has a chance to go into PG and what other changes i should
apply (beside the missing documentation).


Thank you

-- 
Andreas 'ads' Scherbaum
German PostgreSQL User Group
Index: src/backend/commands/proclang.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/commands/proclang.c,v
retrieving revision 1.77
diff -u -3 -p -r1.77 proclang.c
--- src/backend/commands/proclang.c	27 Mar 2008 03:57:33 -	1.77
+++ src/backend/commands/proclang.c	29 Mar 2008 01:18:59 -
@@ -75,9 +75,20 @@ CreateProceduralLanguage(CreatePLangStmt
 	if (SearchSysCacheExists(LANGNAME,
 			 PointerGetDatum(languageName),
 			 0, 0, 0))
-		ereport(ERROR,
-(errcode(ERRCODE_DUPLICATE_OBJECT),
- errmsg(language \%s\ already exists, languageName)));
+	{
+		if (!stmt-existing_ok)
+		{
+			ereport(ERROR,
+	(errcode(ERRCODE_DUPLICATE_OBJECT),
+	 errmsg(language \%s\ already exists, languageName)));
+		}
+		else
+		{
+			ereport(NOTICE,
+	(errmsg(language \%s\ already exists, skipping, languageName)));
+			return;
+		}
+	}
 
 	/*
 	 * If we have template information for the language, ignore the supplied
Index: src/backend/parser/gram.y
===
RCS file: /projects/cvsroot/pgsql/src/backend/parser/gram.y,v
retrieving revision 2.611
diff -u -3 -p -r2.611 gram.y
--- src/backend/parser/gram.y	28 Mar 2008 00:21:55 -	2.611
+++ src/backend/parser/gram.y	29 Mar 2008 01:19:03 -
@@ -195,7 +195,7 @@ static Node *makeXmlExpr(XmlExprOp op, c
 %type ival	opt_lock lock_type cast_context
 %type boolean	opt_force opt_or_replace
 opt_grant_grant_option opt_grant_admin_option
-opt_nowait opt_if_exists
+opt_nowait opt_if_exists opt_if_not_exists
 
 %type list	OptRoleList
 %type defelt	OptRoleElem
@@ -2529,6 +2529,7 @@ CreatePLangStmt:
 n-plhandler = NIL;
 n-plvalidator = NIL;
 n-pltrusted = false;
+n-existing_ok = false;
 $$ = (Node *)n;
 			}
 			| CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
@@ -2540,6 +2541,30 @@ CreatePLangStmt:
 n-plvalidator = $8;
 n-pltrusted = $2;
 /* LANCOMPILER is now ignored entirely */
+n-existing_ok = false;
+$$ = (Node *)n;
+			}
+			| CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst IF_P NOT EXISTS
+			{
+CreatePLangStmt *n = makeNode(CreatePLangStmt);
+n-plname = $5;
+/* parameters are all to be supplied by system */
+n-plhandler = NIL;
+n-plvalidator = NIL;
+n-pltrusted = false;
+n-existing_ok = true;
+$$ = (Node *)n;
+			}
+			| CREATE opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
+			  HANDLER handler_name opt_validator opt_lancompiler
+			{
+CreatePLangStmt *n = makeNode(CreatePLangStmt);
+n-plname = $5;
+n-plhandler = $7;
+n-plvalidator = $8;
+n-pltrusted = $2;
+/* LANCOMPILER is now ignored entirely */
+n-existing_ok = true;
 $$ = (Node *)n;
 			}
 		;
@@ -4493,6 +4518,10 @@ opt_if_exists: IF_P EXISTS		{ $$ = T
 		| /*EMPTY*/{ $$ = FALSE; }
 		;
 
+opt_if_not_exists: IF_P NOT EXISTS		{ $$ = TRUE; }
+		| /*EMPTY*/{ $$ = FALSE; }
+		;
+
 
 /*
  *
Index: src/include/nodes/parsenodes.h
===
RCS file: /projects/cvsroot/pgsql/src/include/nodes/parsenodes.h,v
retrieving revision 1.361
diff -u -3 -p -r1.361 parsenodes.h
--- src/include/nodes/parsenodes.h	21 Mar 2008 22:41:48 -	1.361
+++ src/include/nodes/parsenodes.h	29 Mar 2008 01:19:05 -
@@ -1262,6 +1262,7 @@ typedef struct CreatePLangStmt
 	List	   *plhandler;		/* PL call handler function (qual. name) */
 	List	   *plvalidator;	/* optional validator function (qual. name) */
 	bool		pltrusted;		/* PL is trusted */
+	bool		existing_ok;		/* skip error if already there? */
 } CreatePLangStmt;
 
 typedef struct DropPLangStmt
Index: src/interfaces/ecpg/preproc/preproc.y
===
RCS file: /projects/cvsroot/pgsql/src/interfaces/ecpg/preproc/preproc.y,v
retrieving revision 1.363
diff -u -3 -p -r1.363 preproc.y
--- src/interfaces/ecpg/preproc/preproc.y	27 Mar 2008 07:56:00 -	1.363
+++ src/interfaces/ecpg/preproc/preproc.y	29 Mar 2008 01:19:09 -
@@ -593,7 +593,7 @@ add_typedef(char *name, char * dimension
 %type  str	CreatePLangStmt