Thread: pg_ctl with unix domain socket?

pg_ctl with unix domain socket?

From
Josef Wolf
Date:
Hello,

I have created a fresh cluster with

   initdb -D /some/path/pgtest

I can start postgres to run on unix domain socket serving this cluster with:

   postgres -D /some/path/pgtest -h '' -k /some/path/pgtest

But I'd like to use pg_ctl instead, in order to have clean control:

   PGPORT=/some/path/pgtest pg_ctl -D/some/path/pgtest -l postgreslog start


Any hints how to use pg_ctl to start/stop postgresql on a unix domain socket?

Re: pg_ctl with unix domain socket?

From
Abbas
Date:


On Tue, Sep 1, 2009 at 4:58 PM, Josef Wolf <jw@raven.inka.de> wrote:
Hello,

I have created a fresh cluster with

  initdb -D /some/path/pgtest

I can start postgres to run on unix domain socket serving this cluster with:

  postgres -D /some/path/pgtest -h '' -k /some/path/pgtest

But I'd like to use pg_ctl instead, in order to have clean control:

  PGPORT=/some/path/pgtest pg_ctl -D/some/path/pgtest -l postgreslog start

PGPORT should be the port number on which the Postgresql server is running(5432 is default), and  PGDATA=some/path/pgtest .

To start the postgresql server using pg_ctl you can use,

pg_ctl -D PGDATA start

to stop ,

pg_ctl -D PGDATA stop

....
Abbas.


Any hints how to use pg_ctl to start/stop postgresql on a unix domain socket?

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: pg_ctl with unix domain socket?

From
Josef Wolf
Date:
On Tue, Sep 01, 2009 at 05:28:46PM +0530, Abbas wrote:
> On Tue, Sep 1, 2009 at 4:58 PM, Josef Wolf <jw@raven.inka.de> wrote:

Thanks for your fast response, Abbas!

> > I have created a fresh cluster with
> >   initdb -D /some/path/pgtest
> >   PGPORT=/some/path/pgtest pg_ctl -D/some/path/pgtest -l postgreslog start
>
> PGPORT should be the port number on which the Postgresql server is
> running(5432 is default), and  PGDATA=some/path/pgtest .

Yeah, I see.  But I do not want it to bind to network socket.  I want it to
bind to a unix domain socket  _only_.

While all other postgres commands accept an absolute path as port
specification, meaning to use a unix domain socket, pg_ctl seems to behave
differently.

e.g: I can start postgres on a unix domain socket _only_ with following
parameters:

   postgres -D /some/path/pgtest -h '' -k /some/path/pgtest

But pg_ctl don't seem to have an option to do the same.

Re: pg_ctl with unix domain socket?

From
"Daniel Verite"
Date:
    Josef Wolf wrote:

> > PGPORT should be the port number on which the Postgresql server is
> > running(5432 is default), and  PGDATA=some/path/pgtest .
>
> Yeah, I see.  But I do not want it to bind to network socket.  I want it to
> bind to a unix domain socket  _only_.

Typically this is done by setting listen_addresses (in postgresql.conf) to an
empty list, as explained here:

http://www.postgresql.org/docs/8.4/static/runtime-config-connection.html#RUNT
IME-CONFIG-CONNECTION-SETTINGS

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org

Re: pg_ctl with unix domain socket?

From
Adrian Klaver
Date:
On Tuesday 01 September 2009 4:28:22 am Josef Wolf wrote:
> Hello,
>
> I have created a fresh cluster with
>
>    initdb -D /some/path/pgtest
>
> I can start postgres to run on unix domain socket serving this cluster
> with:
>
>    postgres -D /some/path/pgtest -h '' -k /some/path/pgtest
>
> But I'd like to use pg_ctl instead, in order to have clean control:
>
>    PGPORT=/some/path/pgtest pg_ctl -D/some/path/pgtest -l postgreslog start
>
>
> Any hints how to use pg_ctl to start/stop postgresql on a unix domain
> socket?

1) In postgresql.conf make listen_addresses empty per instructions:

http://www.postgresql.org/docs/8.4/interactive/runtime-config-connection.html#GUC-LISTEN-ADDRESSES
listen_addresses (string)

    Specifies the TCP/IP address(es) on which the server is to listen for
connections from client applications. The value takes the form of a
comma-separated list of host names and/or numeric IP addresses. The special
entry * corresponds to all available IP interfaces. If the list is empty, the
server does not listen on any IP interface at all, in which case only
Unix-domain sockets can be used to connect to it. The default value is
localhost, which allows only local "loopback" connections to be made. This
parameter can only be set at server start.

2) Use the -o switch to pass commands to postgres. See below:

http://www.postgresql.org/docs/8.4/interactive/app-pg-ctl.html
-o options

    Specifies options to be passed directly to the postgres command.

    The options are usually surrounded by single or double quotes to ensure that
they are passed through as a group.

--
Adrian Klaver
aklaver@comcast.net

Re: pg_ctl with unix domain socket?

From
Josef Wolf
Date:
On Tue, Sep 01, 2009 at 06:34:21AM -0700, Adrian Klaver wrote:
> On Tuesday 01 September 2009 4:28:22 am Josef Wolf wrote:

Thanks for your help, Adrian!

[ ... ]
> > Any hints how to use pg_ctl to start/stop postgresql on a unix domain
> > socket?
>
> 1) In postgresql.conf make listen_addresses empty per instructions:

I could get it running with putting listen_addresses='' in postgresql.conf
and then running

    pg_ctl -Ddb -o "-h '' -k `pwd`/db" -l postgreslog start

    pg_ctl -Ddb -o "-h '' -k `pwd`/db" -l postgreslog stop

Thanks to all who helped

Re: pg_ctl with unix domain socket?

From
Josef Wolf
Date:
On Tue, Sep 01, 2009 at 04:47:25PM +0200, Josef Wolf wrote:
> On Tue, Sep 01, 2009 at 06:34:21AM -0700, Adrian Klaver wrote:
> > On Tuesday 01 September 2009 4:28:22 am Josef Wolf wrote:
> [ ... ]
> > > Any hints how to use pg_ctl to start/stop postgresql on a unix domain
> > > socket?
> > 1) In postgresql.conf make listen_addresses empty per instructions:
> I could get it running with putting listen_addresses='' in postgresql.conf
> and then running

BTW: it works fine without the listen_address='' setting in postgresql.conf

>     pg_ctl -Ddb -o "-h '' -k `pwd`/db" -l postgreslog start

This works, but when I add the -w option, it waits all the 60 seconds. So
for some reason, pg_ctl does not notice that postgres is ready to accept
connections. This problem seems to happen only when starting. Stopping works
immediately.

Any ideas?

Re: pg_ctl with unix domain socket?

From
Adrian Klaver
Date:
On Thursday 03 September 2009 12:20:02 pm Josef Wolf wrote:
> On Tue, Sep 01, 2009 at 04:47:25PM +0200, Josef Wolf wrote:
> > On Tue, Sep 01, 2009 at 06:34:21AM -0700, Adrian Klaver wrote:
> > > On Tuesday 01 September 2009 4:28:22 am Josef Wolf wrote:
> >
> > [ ... ]
> >
> > > > Any hints how to use pg_ctl to start/stop postgresql on a unix domain
> > > > socket?
> > >
> > > 1) In postgresql.conf make listen_addresses empty per instructions:
> >
> > I could get it running with putting listen_addresses='' in
> > postgresql.conf and then running
>
> BTW: it works fine without the listen_address='' setting in postgresql.conf
>
> >     pg_ctl -Ddb -o "-h '' -k `pwd`/db" -l postgreslog start
>
> This works, but when I add the -w option, it waits all the 60 seconds. So
> for some reason, pg_ctl does not notice that postgres is ready to accept
> connections. This problem seems to happen only when starting. Stopping
> works immediately.
>
> Any ideas?

My playing around with this seems to indicate that the -k switch is causing the
problem. Changing the default location of the socket seems to throw things off.

--
Adrian Klaver
aklaver@comcast.net

Re: pg_ctl with unix domain socket?

From
Tom Lane
Date:
Josef Wolf <jw@raven.inka.de> writes:
>> pg_ctl -Ddb -o "-h '' -k `pwd`/db" -l postgreslog start

> This works, but when I add the -w option, it waits all the 60 seconds.

I don't believe pg_ctl is smart enough to dredge the -k option out of -o
and figure out that it has to look there for the socket.

In general I'd advise against using -k, as that will break nearly all
clients not only pg_ctl.  If you need to put the socket in a nonstandard
place, it's most convenient to wire the knowledge into libpq by changing
DEFAULT_PGSOCKET_DIR at build time.  AFAIR that requires manually
editing pg_config_manual.h.

            regards, tom lane

Re: pg_ctl with unix domain socket?

From
Josef Wolf
Date:
On Fri, Sep 04, 2009 at 01:33:06PM -0400, Tom Lane wrote:
> Josef Wolf <jw@raven.inka.de> writes:
> >> pg_ctl -Ddb -o "-h '' -k `pwd`/db" -l postgreslog start
>
> > This works, but when I add the -w option, it waits all the 60 seconds.
>
> I don't believe pg_ctl is smart enough to dredge the -k option out of -o
> and figure out that it has to look there for the socket.
>
> In general I'd advise against using -k, as that will break nearly all
> clients not only pg_ctl.  If you need to put the socket in a nonstandard
> place, it's most convenient to wire the knowledge into libpq by changing
> DEFAULT_PGSOCKET_DIR at build time.  AFAIR that requires manually
> editing pg_config_manual.h.

Ugh, but how to configure it at runtime, then?

The goal I want to achieve is to get testing/development environments for
rails with postgres relative to the working copy of the checked out
directory.  Not having this relative prevents multiple working copies
to run tests in parallel because they all would use the same database.


Re: pg_ctl with unix domain socket?

From
Tom Lane
Date:
Josef Wolf <jw@raven.inka.de> writes:
> On Fri, Sep 04, 2009 at 01:33:06PM -0400, Tom Lane wrote:
>> In general I'd advise against using -k, as that will break nearly all
>> clients not only pg_ctl.

> Ugh, but how to configure it at runtime, then?

You don't.  You could configure it at build time, perhaps, same as you
configure the installation prefix path --- but you're just creating
unnecessary pain for yourself.

> The goal I want to achieve is to get testing/development environments for
> rails with postgres relative to the working copy of the checked out
> directory.  Not having this relative prevents multiple working copies
> to run tests in parallel because they all would use the same database.

The standard way to run multiple installations in parallel is to run
them on different port numbers.  There is no reason to move the socket
directory.

            regards, tom lane