Re: PostgreSQL Service on Windows does not start if data directory given is relative path

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PostgreSQL Service on Windows does not start if data directory given is relative path
Date: 2014-01-12 07:44:42
Message-ID: CAApHDvq9B6s9vM+19spwLA2W5KMG7hZvhT+tOoy4L1FtV=vzVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jan 7, 2014 at 12:42 AM, Rajeev rastogi
<rajeev(dot)rastogi(at)huawei(dot)com>wrote:

> I have found a case that PostgreSQL as win32 service does not start, if
> the data directory given as relative path.
>
> Error observed in this case is:
>
> “The PostgreSQL on Local Computer started
> and then stopped”.
>
>
>
> This may happen because relative path given will be relative to path from
> where service is registered but
>
> the path from where WIN32 service execution gets invoked may be different
> and hence it won’t be able
>
> to find the data directory.
>
>
>
> I have fixed the same by internally converting the relative path to
> absolute path as it is being done for executable file.
>
>
>
> Attached is the patch with the fix.
>
> Please provide your opinion.
>
>
Hi,

I've not quite got around to testing this yet, but I think the patch is a
good idea as I can see that I can use a relative path when I start
postgres.exe from the command line, I guess the behaviour should likely be
the same when installed as a windows service.

So, I've just been looking over this patch and I'm just wondering about a
few things:

In pgwin32_CommandLine you declare dbPath, it looks like you could declare
this in the scope of; if (pg_config)

In find_my_abs_path you're making a call to StrNCpy, I know you likely just
used find_my_exec as an example here, but I'd say the use of StrNCpy is not
really needed here and is a bit of a waste of cycles. I'd rather see
strlcpy being used as strncpy will needlessly zero the remaining buffer
space.

Also in find_my_abs_path, I'm just wondering if the cwd variable is really
needed, I think you could just use retpath each time and it would also save
a little bit of copying that's done in join_path_components(). By the looks
of it you can just call join_path_components(retpath, retpath, inpath).
Perhaps some people would disagree, but I'm not really seeing the harm in
it and it saves some copying too.

Regards

David Rowley

>
>
> I will add this to Jan 2014 CommitFest.
>
>
>
> *Thanks and Regards,*
>
> *Kumar Rajeev Rastogi *
>
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2014-01-12 07:50:49 Why does numeric_out produce so many trailing zeros?
Previous Message Amit Kapila 2014-01-12 07:11:47 Retain dynamic shared memory segments for postmaster lifetime