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

From: "Peter Koczan" <pjkoczan(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #4092: initdb fails if the xlog directory is the same as [pg_data]/pg_xlog
Date: 2008-04-04 22:11:25
Message-ID: 200804042211.m34MBOhf048426@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 4092
Logged by: Peter Koczan
Email address: pjkoczan(at)gmail(dot)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"));

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Premek Paska 2008-04-05 15:05:42 Re: BUG #4084: Some DST timezones switche to summer time (one week) later
Previous Message John Smith 2008-04-04 17:47:24 Re: BUG #4089: When available disk space is low pg_stop_backup() fails, as do subsequent recovery attempts.