On Sat, 2006-11-04 at 13:29 -0500, Tom Lane wrote:
> "Simon Riggs" <[EMAIL PROTECTED]> writes:
> >> On Fri, Nov 03, 2006 at 11:25:09AM -0500, Tom Lane wrote:
> >>> Since 8.1 has done this all along and no one's actually complained about
> >>> it, I guess no one is using scripts that do "cd".  I'm inclined to go
> >>> with Bernd's suggestion to change the docs to match the code, but does
> >>> anyone have a contrary opinion?
> 
> > +1 Doc bug for 8.2, feature request for 8.3, unless Windows bites.
> 
> Looking back in the archives, I note that one of the arguments for
> making the server use relative paths everywhere was so that it'd be
> robust against things like DBAs moving directories that contain live
> postmasters.  If we provide a %P option, or otherwise encourage people
> to write scripts that depend on the absolute path of $PGDATA, we'd lose
> some of this robustness.  So that might be an argument for leaving the
> code as-is indefinitely ... not a very strong argument maybe, but it's
> more than just we're-too-lazy-to-add-%P.
> 
> Anyway, I've corrected the documentation in HEAD and 8.1.

I think I can fulfil Bernd, Florian and Martijn's wishes by supplying an
additional substitutable parameter %d which is replaced by the DataDir.
This allows people to use an absolute directory if they wish, allows us
to continue with the functionality of %p as-is and all without a
possible confusion between %p and %P. It also allows %d to be used as an
identifier which might be used to locate the appropriate archive for
those with multiple servers without editing the archive_command for each
of those servers.

So using %d/%p will give you the absolute path for forward-slashers.
Works for archive and recovery.

Patch included, code and docs. 
Code comments now discuss relative paths also.

Comments?

-- 
  Simon Riggs             
  EnterpriseDB   http://www.enterprisedb.com

Index: doc/src/sgml/backup.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/backup.sgml,v
retrieving revision 2.93
diff -c -r2.93 backup.sgml
*** doc/src/sgml/backup.sgml	4 Nov 2006 18:20:27 -0000	2.93
--- doc/src/sgml/backup.sgml	5 Nov 2006 14:44:34 -0000
***************
*** 521,527 ****
      any <literal>%p</> is replaced by the path name of the file to
      archive, while any <literal>%f</> is replaced by the file name only.
      (The path name is relative to the working directory of the server,
!     i.e., the cluster's data directory.)
      Write <literal>%%</> if you need to embed an actual <literal>%</>
      character in the command.  The simplest useful command is something
      like
--- 521,528 ----
      any <literal>%p</> is replaced by the path name of the file to
      archive, while any <literal>%f</> is replaced by the file name only.
      (The path name is relative to the working directory of the server,
!     i.e., the cluster's data directory, which can also be specified
!     using %d, if required)
      Write <literal>%%</> if you need to embed an actual <literal>%</>
      character in the command.  The simplest useful command is something
      like
***************
*** 599,605 ****
      In writing your archive command, you should assume that the file names to
      be archived may be up to 64 characters long and may contain any
      combination of ASCII letters, digits, and dots.  It is not necessary to
!     remember the original full path (<literal>%p</>) but it is necessary to
      remember the file name (<literal>%f</>).
     </para>
  
--- 600,606 ----
      In writing your archive command, you should assume that the file names to
      be archived may be up to 64 characters long and may contain any
      combination of ASCII letters, digits, and dots.  It is not necessary to
!     remember the original relative path (<literal>%p</>) but it is necessary to
      remember the file name (<literal>%f</>).
     </para>
  
***************
*** 919,925 ****
      replaced by the name of the desired log file, and <literal>%p</>,
      which is replaced by the path name to copy the log file to.
      (The path name is relative to the working directory of the server,
!     i.e., the cluster's data directory.)
      Write <literal>%%</> if you need to embed an actual <literal>%</>
      character in the command.  The simplest useful command is
      something like
--- 920,927 ----
      replaced by the name of the desired log file, and <literal>%p</>,
      which is replaced by the path name to copy the log file to.
      (The path name is relative to the working directory of the server,
!     i.e., the cluster's data directory, which can also be specified
!     using %d, if required.)
      Write <literal>%%</> if you need to embed an actual <literal>%</>
      character in the command.  The simplest useful command is
      something like
***************
*** 1010,1016 ****
          and any <literal>%p</> is replaced by the path name to copy
          it to on the server.
          (The path name is relative to the working directory of the server,
!         i.e., the cluster's data directory.)
          Write <literal>%%</> to embed an actual <literal>%</> character
          in the command. 
         </para>
--- 1012,1019 ----
          and any <literal>%p</> is replaced by the path name to copy
          it to on the server.
          (The path name is relative to the working directory of the server,
!         i.e., the cluster's data directory, which can also be specified
!         using %d, if required)
          Write <literal>%%</> to embed an actual <literal>%</> character
          in the command. 
         </para>
Index: doc/src/sgml/config.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/config.sgml,v
retrieving revision 1.93
diff -c -r1.93 config.sgml
*** doc/src/sgml/config.sgml	4 Nov 2006 18:20:27 -0000	1.93
--- doc/src/sgml/config.sgml	5 Nov 2006 14:44:41 -0000
***************
*** 1576,1582 ****
          replaced by the path name of the file to archive, and any
          <literal>%f</> is replaced by the file name only.
          (The path name is relative to the working directory of the server,
!         i.e., the cluster's data directory.)
          Use <literal>%%</> to embed an actual <literal>%</> character in the
          command. For more information see <xref
          linkend="backup-archiving-wal">.
--- 1576,1583 ----
          replaced by the path name of the file to archive, and any
          <literal>%f</> is replaced by the file name only.
          (The path name is relative to the working directory of the server,
!         i.e., the cluster's data directory, which can also be specified
!         using %d, if required)
          Use <literal>%%</> to embed an actual <literal>%</> character in the
          command. For more information see <xref
          linkend="backup-archiving-wal">.
Index: src/backend/access/transam/xlog.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xlog.c,v
retrieving revision 1.252
diff -c -r1.252 xlog.c
*** src/backend/access/transam/xlog.c	18 Oct 2006 22:44:11 -0000	1.252
--- src/backend/access/transam/xlog.c	5 Nov 2006 14:44:48 -0000
***************
*** 2416,2423 ****
  		{
  			switch (sp[1])
  			{
  				case 'p':
! 					/* %p: full path of target file */
  					sp++;
  					StrNCpy(dp, xlogpath, endp - dp);
  					make_native_path(dp);
--- 2416,2430 ----
  		{
  			switch (sp[1])
  			{
+ 				case 'd':
+ 					/* %d: DataDirectory of server */
+ 					sp++;
+ 					StrNCpy(dp, DataDir, endp - dp);
+ 					make_native_path(dp);
+ 					dp += strlen(dp);
+ 					break;
  				case 'p':
! 					/* %p: relative path of target file */
  					sp++;
  					StrNCpy(dp, xlogpath, endp - dp);
  					make_native_path(dp);
Index: src/backend/postmaster/pgarch.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/postmaster/pgarch.c,v
retrieving revision 1.25
diff -c -r1.25 pgarch.c
*** src/backend/postmaster/pgarch.c	7 Aug 2006 17:41:42 -0000	1.25
--- src/backend/postmaster/pgarch.c	5 Nov 2006 14:44:49 -0000
***************
*** 416,423 ****
  		{
  			switch (sp[1])
  			{
  				case 'p':
! 					/* %p: full path of source file */
  					sp++;
  					StrNCpy(dp, pathname, endp - dp);
  					make_native_path(dp);
--- 416,430 ----
  		{
  			switch (sp[1])
  			{
+ 				case 'd':
+ 					/* %d: DataDirectory of server */
+ 					sp++;
+ 					StrNCpy(dp, DataDir, endp - dp);
+ 					make_native_path(dp);
+ 					dp += strlen(dp);
+ 					break;
  				case 'p':
! 					/* %p: relative path of source file */
  					sp++;
  					StrNCpy(dp, pathname, endp - dp);
  					make_native_path(dp);
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to