Re: [HACKERS] Cannot initdb in cvs tip

Lists: pgsql-hackerspgsql-hackers-win32pgsql-patches
From: "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>, <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Cannot initdb in cvs tip
Date: 2004-06-19 22:04:38
Message-ID: E7F85A1B5FF8D44C8A1AF6885BC9A0E40C3629@ratbert.vale-housing.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches

> -----Original Message-----
> From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
> Sent: 19 June 2004 00:22
> To: Dave Page
> Cc: PostgreSQL-development
> Subject: Re: [HACKERS] Cannot initdb in cvs tip
>
> "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk> writes:
> > I'm getting the following error when trying to initdb with CVS tip.
>
> > creating template1 database in
> C:/msys/1.0/local/pgsql/data/base/1 ...
> > ERROR: could not open segment 1 of relation 1663/1/1255
> (target block
> > 26189776): No such file or directory
>
> The target block number is obviously broken :-(. But maybe
> you have a build consistency problem --- did you try a make
> distclean and full rebuild?

OK, that cured that one - thanks.

> > although it says it's clearing the contents of the directory, in
> > actual fact it leaves the directory structure in place, thus a
> > subsequent initdb will not run without a manual clearup.
>
> Hm. The rmtree() function in initdb.c is responsible for
> this, and I see it has WIN32-specific behavior, which is
> evidently wrong.
> Can you recommend a fix?

The current solution does an "rmdir /q /s $PGDATA" if the datadir was
created, and "del /q /s $PGDATA" if the directory already existed. The
second case will not work, as del will not remove directories. AFAICS,
there is no easy way to do this using system() as rmdir won't accept
wildcards, so we can't do "del $PGDATA/* && rmdir $PGDATA/*".

It seems to me that the simple answer is to put Andrew's recursive
unlink code back in (as he suggested), which Bruce removed as rm etc.
were being used in commands/dbcommands.c (which should work fine under
Windows). Patch below....

Regards, Dave

*** initdb.c.orig Sat Jun 19 22:15:28 2004
--- initdb.c Sat Jun 19 23:02:10 2004
***************
*** 132,137 ****
--- 132,144 ----
static void *xmalloc(size_t size);
static char *xstrdup(const char *s);
static bool rmtree(char *path, bool rmtopdir);
+
+ #ifdef WIN32
+ static int init_unlink(const char *);
+ #else
+ #define init_unlink(x) unlink( (x) )
+ #endif /* WIN32 */
+
static char **replace_token(char **lines, char *token, char
*replacement);
static char **readfile(char *path);
static void writefile(char *path, char **lines);
***************
*** 245,264 ****
static bool
rmtree(char *path, bool rmtopdir)
{
! char buf[MAXPGPATH + 64];

! #ifndef WIN32
! /* doesn't handle .* files, but we don't make any... */
! snprintf(buf, sizeof(buf), "rm -rf \"%s\"%s", path,
! rmtopdir ? "" : "/*");
! #else
! snprintf(buf, sizeof(buf), "%s /s /q \"%s\"",
! rmtopdir ? "rmdir" : "del", path);
! #endif

! return !system(buf);
}


/*
* make a copy of the array of lines, with token replaced by
replacement
--- 252,349 ----
static bool
rmtree(char *path, bool rmtopdir)
{
! char filepath[MAXPGPATH];
! DIR *dir;
! struct dirent *file;
! char **filenames;
! char **filename;
! int numnames = 0;
! struct stat statbuf;

! /*
! * we copy all the names out of the directory before we start
modifying
! * it.
! *
! */
!
! dir = opendir(path);
! if (dir == NULL)
! return false;

! while ((file = readdir(dir)) != NULL)
! {
! if (strcmp(file->d_name, ".") != 0 &&
strcmp(file->d_name, "..") != 0)
! numnames++;
! }
!
! rewinddir(dir);
!
! filenames = xmalloc((numnames + 2) * sizeof(char *));
! numnames = 0;
!
! while ((file = readdir(dir)) != NULL)
! {
! if (strcmp(file->d_name, ".") != 0 &&
strcmp(file->d_name, "..") != 0)
! filenames[numnames++] = xstrdup(file->d_name);
! }
!
! filenames[numnames] = NULL;
!
! closedir(dir);
!
! /* now we have the names we can start removing things */
!
! for (filename = filenames; *filename; filename++)
! {
! snprintf(filepath, MAXPGPATH, "%s/%s", path, *filename);
!
! if (stat(filepath, &statbuf) != 0)
! return false;
!
! if (S_ISDIR(statbuf.st_mode))
! {
! /* call ourselves recursively for a directory */
! if (!rmtree(filepath, true))
! return false;
! }
! else
! {
! if (init_unlink(filepath) != 0)
! return false;
! }
! }
!
! if (rmtopdir)
! {
! if (rmdir(path) != 0)
! return false;
! }
!
! return true;
}

+ #ifdef WIN32
+
+ /* workaround for win32 unlink bug, not using logging like in
port/dirmod.c */
+
+ /* make sure we call the real unlink from MSVCRT */
+
+ #ifdef unlink
+ #undef unlink
+ #endif
+
+ static int
+ init_unlink(const char *path)
+ {
+ while (unlink(path))
+ {
+ if (errno != EACCES)
+ return -1;
+ Sleep(100); /* ms */
+ }
+ return 0;
+ }
+ #endif /* WIN32 */

/*
* make a copy of the array of lines, with token replaced by
replacement


From: John Hansen <john(at)geeknet(dot)com(dot)au>
To: Dave Page <dpage(at)vale-housing(dot)co(dot)uk>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, pgsql-patches(at)postgresql(dot)org
Subject: Re: Cannot initdb in cvs tip
Date: 2004-06-20 01:27:36
Message-ID: 1087694856.3356.3.camel@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches

On Sun, 2004-06-20 at 08:04, Dave Page wrote:
>
> > -----Original Message-----
> > From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
> > Sent: 19 June 2004 00:22
> > To: Dave Page
> > Cc: PostgreSQL-development
> > Subject: Re: [HACKERS] Cannot initdb in cvs tip
> >
> > "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk> writes:
> > > I'm getting the following error when trying to initdb with CVS tip.
> >
> > > creating template1 database in
> > C:/msys/1.0/local/pgsql/data/base/1 ...
> > > ERROR: could not open segment 1 of relation 1663/1/1255
> > (target block
> > > 26189776): No such file or directory
> >
> > The target block number is obviously broken :-(. But maybe
> > you have a build consistency problem --- did you try a make
> > distclean and full rebuild?
>
> OK, that cured that one - thanks.
>
> > > although it says it's clearing the contents of the directory, in
> > > actual fact it leaves the directory structure in place, thus a
> > > subsequent initdb will not run without a manual clearup.
> >
> > Hm. The rmtree() function in initdb.c is responsible for
> > this, and I see it has WIN32-specific behavior, which is
> > evidently wrong.
> > Can you recommend a fix?
>
> The current solution does an "rmdir /q /s $PGDATA" if the datadir was
> created, and "del /q /s $PGDATA" if the directory already existed. The
> second case will not work, as del will not remove directories. AFAICS,
> there is no easy way to do this using system() as rmdir won't accept
> wildcards, so we can't do "del $PGDATA/* && rmdir $PGDATA/*".
>
> It seems to me that the simple answer is to put Andrew's recursive
> unlink code back in (as he suggested), which Bruce removed as rm etc.
> were being used in commands/dbcommands.c (which should work fine under
> Windows). Patch below....
>

you could of course rmdir /s /q $PGDATA && mkdir $PGDATA if the purpose
is to leave the directory intact if it already existed prior to install.

Regards,

John
> Regards, Dave
>
> *** initdb.c.orig Sat Jun 19 22:15:28 2004
> --- initdb.c Sat Jun 19 23:02:10 2004
> ***************
> *** 132,137 ****
> --- 132,144 ----
> static void *xmalloc(size_t size);
> static char *xstrdup(const char *s);
> static bool rmtree(char *path, bool rmtopdir);
> +
> + #ifdef WIN32
> + static int init_unlink(const char *);
> + #else
> + #define init_unlink(x) unlink( (x) )
> + #endif /* WIN32 */
> +
> static char **replace_token(char **lines, char *token, char
> *replacement);
> static char **readfile(char *path);
> static void writefile(char *path, char **lines);
> ***************
> *** 245,264 ****
> static bool
> rmtree(char *path, bool rmtopdir)
> {
> ! char buf[MAXPGPATH + 64];
>
> ! #ifndef WIN32
> ! /* doesn't handle .* files, but we don't make any... */
> ! snprintf(buf, sizeof(buf), "rm -rf \"%s\"%s", path,
> ! rmtopdir ? "" : "/*");
> ! #else
> ! snprintf(buf, sizeof(buf), "%s /s /q \"%s\"",
> ! rmtopdir ? "rmdir" : "del", path);
> ! #endif
>
> ! return !system(buf);
> }
>
>
> /*
> * make a copy of the array of lines, with token replaced by
> replacement
> --- 252,349 ----
> static bool
> rmtree(char *path, bool rmtopdir)
> {
> ! char filepath[MAXPGPATH];
> ! DIR *dir;
> ! struct dirent *file;
> ! char **filenames;
> ! char **filename;
> ! int numnames = 0;
> ! struct stat statbuf;
>
> ! /*
> ! * we copy all the names out of the directory before we start
> modifying
> ! * it.
> ! *
> ! */
> !
> ! dir = opendir(path);
> ! if (dir == NULL)
> ! return false;
>
> ! while ((file = readdir(dir)) != NULL)
> ! {
> ! if (strcmp(file->d_name, ".") != 0 &&
> strcmp(file->d_name, "..") != 0)
> ! numnames++;
> ! }
> !
> ! rewinddir(dir);
> !
> ! filenames = xmalloc((numnames + 2) * sizeof(char *));
> ! numnames = 0;
> !
> ! while ((file = readdir(dir)) != NULL)
> ! {
> ! if (strcmp(file->d_name, ".") != 0 &&
> strcmp(file->d_name, "..") != 0)
> ! filenames[numnames++] = xstrdup(file->d_name);
> ! }
> !
> ! filenames[numnames] = NULL;
> !
> ! closedir(dir);
> !
> ! /* now we have the names we can start removing things */
> !
> ! for (filename = filenames; *filename; filename++)
> ! {
> ! snprintf(filepath, MAXPGPATH, "%s/%s", path, *filename);
> !
> ! if (stat(filepath, &statbuf) != 0)
> ! return false;
> !
> ! if (S_ISDIR(statbuf.st_mode))
> ! {
> ! /* call ourselves recursively for a directory */
> ! if (!rmtree(filepath, true))
> ! return false;
> ! }
> ! else
> ! {
> ! if (init_unlink(filepath) != 0)
> ! return false;
> ! }
> ! }
> !
> ! if (rmtopdir)
> ! {
> ! if (rmdir(path) != 0)
> ! return false;
> ! }
> !
> ! return true;
> }
>
> + #ifdef WIN32
> +
> + /* workaround for win32 unlink bug, not using logging like in
> port/dirmod.c */
> +
> + /* make sure we call the real unlink from MSVCRT */
> +
> + #ifdef unlink
> + #undef unlink
> + #endif
> +
> + static int
> + init_unlink(const char *path)
> + {
> + while (unlink(path))
> + {
> + if (errno != EACCES)
> + return -1;
> + Sleep(100); /* ms */
> + }
> + return 0;
> + }
> + #endif /* WIN32 */
>
> /*
> * make a copy of the array of lines, with token replaced by
> replacement
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org


From: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
To: <pgsql-hackers(at)postgresql(dot)org>, <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Cannot initdb in cvs tip
Date: 2004-06-20 07:12:19
Message-ID: 1722.24.211.141.25.1087715539.squirrel@www.dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches

John Hansen said:
> On Sun, 2004-06-20 at 08:04, Dave Page wrote:
>> > > although it says it's clearing the contents of the directory, in
>> > > actual fact it leaves the directory structure in place, thus a
>> > > subsequent initdb will not run without a manual clearup.
>> >
>> > Hm. The rmtree() function in initdb.c is responsible for
>> > this, and I see it has WIN32-specific behavior, which is
>> > evidently wrong.
>> > Can you recommend a fix?
>>
>> The current solution does an "rmdir /q /s $PGDATA" if the datadir was
>> created, and "del /q /s $PGDATA" if the directory already existed. The
>> second case will not work, as del will not remove directories.
>> AFAICS, there is no easy way to do this using system() as rmdir won't
>> accept wildcards, so we can't do "del $PGDATA/* && rmdir $PGDATA/*".
>>
>> It seems to me that the simple answer is to put Andrew's recursive
>> unlink code back in (as he suggested), which Bruce removed as rm etc.
>> were being used in commands/dbcommands.c (which should work fine under
>> Windows). Patch below....
>>
>
> you could of course rmdir /s /q $PGDATA && mkdir $PGDATA if the purpose
> is to leave the directory intact if it already existed prior to
> install.
>

No we can't. This was discussed months ago, IIRC. The user might very well
not have the privileges necessary to delete the directory, and might not
have the privileges to recreate it if they do.

The direct recursive delete is not a lot of code, and I must confess I
*hate* having C programs calling system() for such tasks. One of my goals
in rewriting initdb in C was to avoid any calls at all to any external
program other than postgres itself.

cheers

andrew


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, PostgreSQL Win32 port list <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-07-20 18:36:14
Message-ID: 200407201836.i6KIaER11446@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches


Seems it might be time to address this and get it fixed. Win32 doesn't
clean up the directory structure under /data and leave /data unchanged,
and there is no way to do this with a system() command on Win32.

I resisted adding a C version of rmtree during Win32 development because
I was concerned about disturbing the Unix behavior, but at this point I
think we should just move ahead and add a /port function for this and
remove the system() backend and initdb calls to 'rm' for directories.

---------------------------------------------------------------------------

Andrew Dunstan wrote:
> John Hansen said:
> > On Sun, 2004-06-20 at 08:04, Dave Page wrote:
> >> > > although it says it's clearing the contents of the directory, in
> >> > > actual fact it leaves the directory structure in place, thus a
> >> > > subsequent initdb will not run without a manual clearup.
> >> >
> >> > Hm. The rmtree() function in initdb.c is responsible for
> >> > this, and I see it has WIN32-specific behavior, which is
> >> > evidently wrong.
> >> > Can you recommend a fix?
> >>
> >> The current solution does an "rmdir /q /s $PGDATA" if the datadir was
> >> created, and "del /q /s $PGDATA" if the directory already existed. The
> >> second case will not work, as del will not remove directories.
> >> AFAICS, there is no easy way to do this using system() as rmdir won't
> >> accept wildcards, so we can't do "del $PGDATA/* && rmdir $PGDATA/*".
> >>
> >> It seems to me that the simple answer is to put Andrew's recursive
> >> unlink code back in (as he suggested), which Bruce removed as rm etc.
> >> were being used in commands/dbcommands.c (which should work fine under
> >> Windows). Patch below....
> >>
> >
> > you could of course rmdir /s /q $PGDATA && mkdir $PGDATA if the purpose
> > is to leave the directory intact if it already existed prior to
> > install.
> >
>
> No we can't. This was discussed months ago, IIRC. The user might very well
> not have the privileges necessary to delete the directory, and might not
> have the privileges to recreate it if they do.
>
> The direct recursive delete is not a lot of code, and I must confess I
> *hate* having C programs calling system() for such tasks. One of my goals
> in rewriting initdb in C was to avoid any calls at all to any external
> program other than postgres itself.
>
> cheers
>
> andrew
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Dave Page <dpage(at)vale-housing(dot)co(dot)uk>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-07-28 08:29:28
Message-ID: 200407280829.i6S8TSo05040@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches


Dave, now that we are nearing beta, I think we need to correct the
initdb problem with removing the directory on Win32. Would you code
this up as something that sits in /port/dirmod.c and have both initdb
and DROP DATABASE call the C routine rather than call rm -r/rmdir? (I
think those are the only two. DROP TABLESPACE?)

I wanted to keep a solution that was as native to the OS as possible,
but because we can't do that on Win32 and few people like the unix
system call to 'rm', it is time to clean it up.

One question --- why is there a sleep loop needed for unlink in your
patch?

---------------------------------------------------------------------------

Dave Page wrote:
>
>
> > -----Original Message-----
> > From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
> > Sent: 19 June 2004 00:22
> > To: Dave Page
> > Cc: PostgreSQL-development
> > Subject: Re: [HACKERS] Cannot initdb in cvs tip
> >
> > "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk> writes:
> > > I'm getting the following error when trying to initdb with CVS tip.
> >
> > > creating template1 database in
> > C:/msys/1.0/local/pgsql/data/base/1 ...
> > > ERROR: could not open segment 1 of relation 1663/1/1255
> > (target block
> > > 26189776): No such file or directory
> >
> > The target block number is obviously broken :-(. But maybe
> > you have a build consistency problem --- did you try a make
> > distclean and full rebuild?
>
> OK, that cured that one - thanks.
>
> > > although it says it's clearing the contents of the directory, in
> > > actual fact it leaves the directory structure in place, thus a
> > > subsequent initdb will not run without a manual clearup.
> >
> > Hm. The rmtree() function in initdb.c is responsible for
> > this, and I see it has WIN32-specific behavior, which is
> > evidently wrong.
> > Can you recommend a fix?
>
> The current solution does an "rmdir /q /s $PGDATA" if the datadir was
> created, and "del /q /s $PGDATA" if the directory already existed. The
> second case will not work, as del will not remove directories. AFAICS,
> there is no easy way to do this using system() as rmdir won't accept
> wildcards, so we can't do "del $PGDATA/* && rmdir $PGDATA/*".
>
> It seems to me that the simple answer is to put Andrew's recursive
> unlink code back in (as he suggested), which Bruce removed as rm etc.
> were being used in commands/dbcommands.c (which should work fine under
> Windows). Patch below....
>
> Regards, Dave
>
> *** initdb.c.orig Sat Jun 19 22:15:28 2004
> --- initdb.c Sat Jun 19 23:02:10 2004
> ***************
> *** 132,137 ****
> --- 132,144 ----
> static void *xmalloc(size_t size);
> static char *xstrdup(const char *s);
> static bool rmtree(char *path, bool rmtopdir);
> +
> + #ifdef WIN32
> + static int init_unlink(const char *);
> + #else
> + #define init_unlink(x) unlink( (x) )
> + #endif /* WIN32 */
> +
> static char **replace_token(char **lines, char *token, char
> *replacement);
> static char **readfile(char *path);
> static void writefile(char *path, char **lines);
> ***************
> *** 245,264 ****
> static bool
> rmtree(char *path, bool rmtopdir)
> {
> ! char buf[MAXPGPATH + 64];
>
> ! #ifndef WIN32
> ! /* doesn't handle .* files, but we don't make any... */
> ! snprintf(buf, sizeof(buf), "rm -rf \"%s\"%s", path,
> ! rmtopdir ? "" : "/*");
> ! #else
> ! snprintf(buf, sizeof(buf), "%s /s /q \"%s\"",
> ! rmtopdir ? "rmdir" : "del", path);
> ! #endif
>
> ! return !system(buf);
> }
>
>
> /*
> * make a copy of the array of lines, with token replaced by
> replacement
> --- 252,349 ----
> static bool
> rmtree(char *path, bool rmtopdir)
> {
> ! char filepath[MAXPGPATH];
> ! DIR *dir;
> ! struct dirent *file;
> ! char **filenames;
> ! char **filename;
> ! int numnames = 0;
> ! struct stat statbuf;
>
> ! /*
> ! * we copy all the names out of the directory before we start
> modifying
> ! * it.
> ! *
> ! */
> !
> ! dir = opendir(path);
> ! if (dir == NULL)
> ! return false;
>
> ! while ((file = readdir(dir)) != NULL)
> ! {
> ! if (strcmp(file->d_name, ".") != 0 &&
> strcmp(file->d_name, "..") != 0)
> ! numnames++;
> ! }
> !
> ! rewinddir(dir);
> !
> ! filenames = xmalloc((numnames + 2) * sizeof(char *));
> ! numnames = 0;
> !
> ! while ((file = readdir(dir)) != NULL)
> ! {
> ! if (strcmp(file->d_name, ".") != 0 &&
> strcmp(file->d_name, "..") != 0)
> ! filenames[numnames++] = xstrdup(file->d_name);
> ! }
> !
> ! filenames[numnames] = NULL;
> !
> ! closedir(dir);
> !
> ! /* now we have the names we can start removing things */
> !
> ! for (filename = filenames; *filename; filename++)
> ! {
> ! snprintf(filepath, MAXPGPATH, "%s/%s", path, *filename);
> !
> ! if (stat(filepath, &statbuf) != 0)
> ! return false;
> !
> ! if (S_ISDIR(statbuf.st_mode))
> ! {
> ! /* call ourselves recursively for a directory */
> ! if (!rmtree(filepath, true))
> ! return false;
> ! }
> ! else
> ! {
> ! if (init_unlink(filepath) != 0)
> ! return false;
> ! }
> ! }
> !
> ! if (rmtopdir)
> ! {
> ! if (rmdir(path) != 0)
> ! return false;
> ! }
> !
> ! return true;
> }
>
> + #ifdef WIN32
> +
> + /* workaround for win32 unlink bug, not using logging like in
> port/dirmod.c */
> +
> + /* make sure we call the real unlink from MSVCRT */
> +
> + #ifdef unlink
> + #undef unlink
> + #endif
> +
> + static int
> + init_unlink(const char *path)
> + {
> + while (unlink(path))
> + {
> + if (errno != EACCES)
> + return -1;
> + Sleep(100); /* ms */
> + }
> + return 0;
> + }
> + #endif /* WIN32 */
>
> /*
> * make a copy of the array of lines, with token replaced by
> replacement
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Dave Page <dpage(at)vale-housing(dot)co(dot)uk>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-07-28 14:22:42
Message-ID: 4107B6B2.3080801@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches

Bruce Momjian wrote:

>Dave, now that we are nearing beta, I think we need to correct the
>initdb problem with removing the directory on Win32. Would you code
>this up as something that sits in /port/dirmod.c and have both initdb
>and DROP DATABASE call the C routine rather than call rm -r/rmdir? (I
>think those are the only two. DROP TABLESPACE?)
>
>

The small wrinkle here is that rmtree needs to make a copy of the file
names before it starts removing things. In the backend case that means
calling palloc() and friends - am I correct in assuming it is reasonable
to do this in whatever context happens to be current when rmtree is
called? (I promise to make it clean up nicely).

>I wanted to keep a solution that was as native to the OS as possible,
>but because we can't do that on Win32 and few people like the unix
>system call to 'rm', it is time to clean it up.
>
>One question --- why is there a sleep loop needed for unlink in your
>patch?
>
>
>
>

We will just be calling the existing pgunlink() (which has a sleep) in
the Windows cases, so this question becomes moot.

cheers

andrew


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Dave Page <dpage(at)vale-housing(dot)co(dot)uk>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-07-28 14:27:24
Message-ID: 200407281427.i6SEROJ05250@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches

Andrew Dunstan wrote:
> >I wanted to keep a solution that was as native to the OS as possible,
> >but because we can't do that on Win32 and few people like the unix
> >system call to 'rm', it is time to clean it up.
> >
> >One question --- why is there a sleep loop needed for unlink in your
> >patch?
> >
> >
> >
> >
>
> We will just be calling the existing pgunlink() (which has a sleep) in
> the Windows cases, so this question becomes moot.

Great. Thanks. Sorry I delayed addressing this for so long.

Should we look at replacing cp/copy in 7.6?

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Dave Page <dpage(at)vale-housing(dot)co(dot)uk>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-07-28 14:29:31
Message-ID: 22398.1091024971@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> The small wrinkle here is that rmtree needs to make a copy of the file
> names before it starts removing things. In the backend case that means
> calling palloc() and friends - am I correct in assuming it is reasonable
> to do this in whatever context happens to be current when rmtree is
> called?

Sure.

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-07-28 17:34:58
Message-ID: 4107E3C2.6060301@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches

Bruce Momjian wrote:

>Andrew Dunstan wrote:
>
>
>>>I wanted to keep a solution that was as native to the OS as possible,
>>>but because we can't do that on Win32 and few people like the unix
>>>system call to 'rm', it is time to clean it up.
>>>
>>>One question --- why is there a sleep loop needed for unlink in your
>>>patch?
>>>
>>>
>>>
>>>
>>>
>>>
>>We will just be calling the existing pgunlink() (which has a sleep) in
>>the Windows cases, so this question becomes moot.
>>
>>
>
>Great. Thanks. Sorry I delayed addressing this for so long.
>
>

Please check the enclosed patch to see if it does what you want.

>Should we look at replacing cp/copy in 7.6?
>
>
>

probably. Put it as a possible TODO maybe.

cheers

andrew

Attachment Content-Type Size
rmtree.patch text/x-patch 8.9 KB

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-07-31 05:51:09
Message-ID: 200407310551.i6V5p9g29666@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches


Looks good. I will have to do a little adjustment because dirmod is
currently only used by Win32.

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------

Andrew Dunstan wrote:
>
>
> Bruce Momjian wrote:
>
> >Andrew Dunstan wrote:
> >
> >
> >>>I wanted to keep a solution that was as native to the OS as possible,
> >>>but because we can't do that on Win32 and few people like the unix
> >>>system call to 'rm', it is time to clean it up.
> >>>
> >>>One question --- why is there a sleep loop needed for unlink in your
> >>>patch?
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>We will just be calling the existing pgunlink() (which has a sleep) in
> >>the Windows cases, so this question becomes moot.
> >>
> >>
> >
> >Great. Thanks. Sorry I delayed addressing this for so long.
> >
> >
>
> Please check the enclosed patch to see if it does what you want.
>
> >Should we look at replacing cp/copy in 7.6?
> >
> >
> >
>
> probably. Put it as a possible TODO maybe.
>
> cheers
>
> andrew
>
>

>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] Cannot initdb in cvs tip
Date: 2004-08-01 06:19:35
Message-ID: 200408010619.i716JZB28984@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-hackers-win32 pgsql-patches


Patch applied. Thanks.

I made small adjustment for configure.

---------------------------------------------------------------------------

Andrew Dunstan wrote:
>
>
> Bruce Momjian wrote:
>
> >Andrew Dunstan wrote:
> >
> >
> >>>I wanted to keep a solution that was as native to the OS as possible,
> >>>but because we can't do that on Win32 and few people like the unix
> >>>system call to 'rm', it is time to clean it up.
> >>>
> >>>One question --- why is there a sleep loop needed for unlink in your
> >>>patch?
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>We will just be calling the existing pgunlink() (which has a sleep) in
> >>the Windows cases, so this question becomes moot.
> >>
> >>
> >
> >Great. Thanks. Sorry I delayed addressing this for so long.
> >
> >
>
> Please check the enclosed patch to see if it does what you want.
>
> >Should we look at replacing cp/copy in 7.6?
> >
> >
> >
>
> probably. Put it as a possible TODO maybe.
>
> cheers
>
> andrew
>
>

>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073