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

Lists: pgsql-hackers
From: Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: PostgreSQL Service on Windows does not start if data directory given is relative path
Date: 2014-01-06 11:42:08
Message-ID: BF2827DCCE55594C8D7A8F7FFD3AB7713DDB5BEC@SZXEML508-MBX.china.huawei.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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.

I will add this to Jan 2014 CommitFest.

Thanks and Regards,
Kumar Rajeev Rastogi

Attachment Content-Type Size
pgctl_win32service_rel_dbpath.patch application/octet-stream 2.4 KB

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
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
>
>