BUG #4092: initdb fails if the xlog directory is the same as [pg_data]/pg_xlog

Поиск
Список
Период
Сортировка
От Peter Koczan
Тема BUG #4092: initdb fails if the xlog directory is the same as [pg_data]/pg_xlog
Дата
Msg-id 200804042211.m34MBOhf048426@wwwmaster.postgresql.org
обсуждение исходный текст
Ответы Re: BUG #4092: initdb fails if the xlog directory is the same as [pg_data]/pg_xlog  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
The following bug has been logged online:

Bug reference:      4092
Logged by:          Peter Koczan
Email address:      pjkoczan@gmail.com
PostgreSQL version: 8.3.1
Operating system:   Red Hat Enterprise Linux 5
Description:        initdb fails if the xlog directory is the same as
[pg_data]/pg_xlog
Details:

If you call initdb where you specify pg_xlog (-X option) to be in the
"normal" place, it fails when creating the symlink. For instance.

$ initdb -X /local/postgres/pg_xlog /local/postgres
...
initdb: could not create symbolic link: File exists
initdb: removing data directory /local/postgres
(more cleanup)
...

This is a problem for people like me who use an auto-config tool to help
manage their database clusters. It would also be nice in the case that a
wrapper script (what I currently use) can't detect that the directories
would be the same, either from relative paths or existing symlinks.

Submitted for your approval is a patch to src/bin/initdb/initdb.c that
corrects this by looking at the errno generated from the symlink call. If
it's EEXIST, that means that it tried to symlink pg_xlog to itself (and
failed) and the existing pg_xlog directory remains. Basically, initdb runs
as if it ignored -X and politely informs the user that the symlink failed.

Peter

Index: src/bin/initdb/initdb.c
===================================================================
RCS file:
/s/postgresql-8.3.1/src/CVSROOT/postgresql-8.3.1/src/bin/initdb/initdb.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 initdb.c
*** src/bin/initdb/initdb.c     31 Mar 2008 20:26:30 -0000      1.1.1.1
--- src/bin/initdb/initdb.c     4 Apr 2008 21:19:45 -0000
***************
*** 3068,3076 ****
  #ifdef HAVE_SYMLINK
                if (symlink(xlog_dir, linkloc) != 0)
                {
!                       fprintf(stderr, _("%s: could not create symbolic
link \"%s\": %s\n"),
!                                       progname, linkloc,
strerror(errno));
!                       exit_nicely();
                }
  #else
                fprintf(stderr, _("%s: symlinks are not supported on this
platform"));
--- 3068,3083 ----
  #ifdef HAVE_SYMLINK
                if (symlink(xlog_dir, linkloc) != 0)
                {
!                       if (errno == EEXIST)
!                       {
!                               fprintf(stderr, _("%s: Attempted to symlink
pg_xlog to itself...Skipping...\n"), progname);
!                       }
!                       else
!                       {
!                               fprintf(stderr, _("%s: could not create
symbolic link \"%s\": %s\n"),
!                                               progname, linkloc,
strerror(errno));
!                               exit_nicely();
!                       }
                }
  #else
                fprintf(stderr, _("%s: symlinks are not supported on this
platform"));

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #4089: When available disk space is low pg_stop_backup() fails, as do subsequent recovery attempts.
Следующее
От: "Mikael Omma"
Дата:
Сообщение: BUG #4090: ECPG Selecting table with NULL values