Re: [pgsql-hackers-win32] PITR on Win32 - Archive and Restore - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [pgsql-hackers-win32] PITR on Win32 - Archive and Restore
Date
Msg-id 200408121830.i7CIUJC26439@candle.pha.pa.us
Whole thread Raw
List pgsql-patches
Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.net> writes:
> > Actually, it appears to me that we have a 100% solution.
>
> Yeah --- "friends don't let friends use Windows" ...
>
> Is there any part of this discussion that does not amount to documenting
> Redmond's bugs?
>
> I'm perfectly happy to back out the slash-to-backslash conversion I
> committed a bit ago, but I'm worried about what else is coming down
> the pike.

I did enough tests to realize that we have done the best we can with
Win32 COPY.  It is OK with forward slashes in the second argument but
not the first.

The attached applied patch cleans up our implementation and documents
its purpose. I also added some examples for 'archive_command'.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/backend/access/transam/xlog.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/access/transam/xlog.c,v
retrieving revision 1.159
diff -c -c -r1.159 xlog.c
*** src/backend/access/transam/xlog.c    11 Aug 2004 04:07:15 -0000    1.159
--- src/backend/access/transam/xlog.c    12 Aug 2004 18:23:58 -0000
***************
*** 1962,1978 ****
                      /* %p: full path of target file */
                      sp++;
                      StrNCpy(dp, xlogpath, endp-dp);
! #ifndef WIN32
                      dp += strlen(dp);
- #else
-                     /* On Windows, change / to \ in the substituted path */
-                     while (*dp)
-                     {
-                         if (*dp == '/')
-                             *dp = '\\';
-                         dp++;
-                     }
- #endif
                      break;
                  case 'f':
                      /* %f: filename of desired file */
--- 1962,1981 ----
                      /* %p: full path of target file */
                      sp++;
                      StrNCpy(dp, xlogpath, endp-dp);
!                     /*
!                      *    make_native_path() is required because COPY is an internal
!                      *    CMD.EXE command and doesn't process forward slashes in the
!                      *    same way as external commands.  Quoting the first argument
!                      *    to COPY does not convert forward to backward slashes, but
!                      *    COPY does properly process quoted forward slashes in the
!                      *    second argument.
!                      *
!                      *    COPY works with quoted forward slashes in the first argument
!                      *    only if the current directory is the same as the directory
!                      *    of the first argument.
!                      */
!                     make_native_path(dp);
                      dp += strlen(dp);
                      break;
                  case 'f':
                      /* %f: filename of desired file */
Index: src/backend/utils/misc/postgresql.conf.sample
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/utils/misc/postgresql.conf.sample,v
retrieving revision 1.124
diff -c -c -r1.124 postgresql.conf.sample
*** src/backend/utils/misc/postgresql.conf.sample    8 Aug 2004 19:42:57 -0000    1.124
--- src/backend/utils/misc/postgresql.conf.sample    12 Aug 2004 18:24:02 -0000
***************
*** 117,129 ****
  # - Archiving -

  #archive_command = ''        # command to use to archive a logfile segment
!
  # If archive_command is '' then archiving is disabled.  Otherwise, set it
! # to a command to copy a file to the proper place.  A simplistic example
! # is 'cp %p /mnt/server/archivedir/%f'.  Any %p in the string is replaced
! # by the absolute path of the file to archive, while any %f is replaced by
! # the file name only.  NOTE: it is important for the command to return
! # zero exit status if and only if it succeeded.

  #---------------------------------------------------------------------------
  # QUERY TUNING
--- 117,133 ----
  # - Archiving -

  #archive_command = ''        # command to use to archive a logfile segment
! #
  # If archive_command is '' then archiving is disabled.  Otherwise, set it
! # to a command to copy a file to the proper place.  Any %p in the string
! # is replaced by the absolute path of the file to archive, while any %f is
! # replaced by the file name only.  NOTE: it is important for the command to
! # return zero exit status only if it succeeds.
! #
! # Examples:
! #     archive_command = 'cp "%p" /mnt/server/archivedir/"%f"'
! #     archive_command = 'copy "%p" /mnt/server/archivedir/"%f"'  # Win32
!

  #---------------------------------------------------------------------------
  # QUERY TUNING
Index: src/include/port.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/port.h,v
retrieving revision 1.51
diff -c -c -r1.51 port.h
*** src/include/port.h    9 Aug 2004 02:12:51 -0000    1.51
--- src/include/port.h    12 Aug 2004 18:24:03 -0000
***************
*** 39,44 ****
--- 39,45 ----
  extern char *first_path_separator(const char *filename);

  extern void canonicalize_path(char *path);
+ extern void make_native_path(char *path);
  extern const char *get_progname(const char *argv0);
  extern void get_share_path(const char *my_exec_path, char *ret_path);
  extern void get_etc_path(const char *my_exec_path, char *ret_path);
Index: src/port/path.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/port/path.c,v
retrieving revision 1.27
diff -c -c -r1.27 path.c
*** src/port/path.c    9 Aug 2004 20:20:46 -0000    1.27
--- src/port/path.c    12 Aug 2004 18:24:08 -0000
***************
*** 88,93 ****
--- 88,110 ----


  /*
+  *    make_native_path
+  *    On WIN32, change / to \ in the path.
+  */
+ void
+ make_native_path(char *filename)
+ {
+ #ifdef WIN32
+     char *p;
+
+     for (p = filename; *p; p++)
+         if (*p == '/')
+             *p = '\\';
+ #endif
+ }
+
+
+ /*
   * Make all paths look like Unix
   */
  void

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: [pgsql-hackers-win32] PITR on Win32 - Archive and Restore
Next
From: Bruce Momjian
Date:
Subject: Re: dbsize modification to support tablespaces