Thread: Struggling to change default data location

Struggling to change default data location

From
Geoff Caplan
Date:
Hi folks

Having a nightmare changing the default data location in 7.1

I uninstalled and re-installed 7.1 on RedHat 6.2 from the rpms with a
clean system. With the help of this list, I have set $PGDATA in my
shell config file and exported the value.

Postgres utilities such as initdb now recognise $PGDATA and I have
setup a system at my desired location.

initdb does not write a postmaster.opt file at the new location. On
system startup, it does write the .opt file to /var/lib/pgsql/data.
Editing this file with the new datapath does not change the behaviour
below.

At this stage - here is what I get...

$ /usr/bin/pg_ctl -D /www/dbdata -l logfile start
    postmaster successfully started
$ pg_ctl status
    pg_ctl: postmaster or postgres is not running
$ ps ax | grep postmaster
    582 ?        S      0:00 /usr/bin/postmaster -D /var/lib/pgsql/data

Please note:

- postmaster is running, but pg_ctl can't find it
- postmaster has started with the default datapath and is ignoring
  $PGDATA

I get the same result if I launch automatically during startup.

Can anyone please help me make some sense of this? I am losing the
will to live...

Geoff Caplan



Re: Struggling to change default data location

From
Peter Eisentraut
Date:
Geoff Caplan writes:

> initdb does not write a postmaster.opt file at the new location. On
> system startup, it does write the .opt file to /var/lib/pgsql/data.

The environment initdb runs in when it runs at system startup is probably
not the one you set up.  Check the /etc/init.d/postgresql file for
details.

> Editing this file with the new datapath does not change the behaviour
> below.

It's not intended to.

> At this stage - here is what I get...
>
> $ /usr/bin/pg_ctl -D /www/dbdata -l logfile start
>     postmaster successfully started
> $ pg_ctl status
>     pg_ctl: postmaster or postgres is not running

pg_ctl -D /www/dbdata status

> $ ps ax | grep postmaster
>     582 ?        S      0:00 /usr/bin/postmaster -D /var/lib/pgsql/data

Peculiar.  Can you run

sh -x /usr/bin/pg_ctl -D /www/dbdata -l logfile start

and look how the shell command that starts the postmaster looks like?

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: Struggling to change default data location

From
"Geoff Caplan"
Date:
Peter, thanks for your patience with a newbie. I think my stuckness stems
from 2 issues:

1) Starting environment

> The environment initdb runs in when it runs at system startup is probably
> not the one you set up.  Check the /etc/init.d/postgresql file for
> details.

This is certainly true, as my settings are overridden. I have had a look at
this file, but I am still not clear what environment it is reading when it
sets $PGDATA.  Can you clarify where this environment
config file should be (on RedHat)?

2) Passing parameters to postmaster during starup

Also, the init.d script uses pg_ctl to start the postmaster. I need to pass
the -i parameter using the "postmaster" utility. (As I understand it, in
past releases of these
RPMs -i was set as a default). At what point in the startup sequence can you
pass "postmaster" utility params to the postmaster process?

I will spare you from the output from your diagnostic script till I can get
these basics sorted out...

Thanks again

Geoff Caplan




Re: Struggling to change default data location

From
Peter Eisentraut
Date:
Geoff Caplan writes:

> > The environment initdb runs in when it runs at system startup is probably
> > not the one you set up.  Check the /etc/init.d/postgresql file for
> > details.
>
> This is certainly true, as my settings are overridden. I have had a look at
> this file, but I am still not clear what environment it is reading when it
> sets $PGDATA.  Can you clarify where this environment
> config file should be (on RedHat)?

There is no config file; the location is wired in fairly deeply.  You're
probably better off mounting your data volume at the appropriate place.

> Also, the init.d script uses pg_ctl to start the postmaster. I need to pass
> the -i parameter using the "postmaster" utility. (As I understand it, in
> past releases of these
> RPMs -i was set as a default). At what point in the startup sequence can you
> pass "postmaster" utility params to the postmaster process?

You put options in the postgresql.conf file (under /var/lib/pgsql/data or
whereever PGDATA ends up...).

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: Re: Struggling to change default data location

From
"Oliver Elphick"
Date:
"Geoff Caplan" wrote:
  >Peter, thanks for your patience with a newbie. I think my stuckness stems
  >from 2 issues:
  >
  >1) Starting environment
  >
  >> The environment initdb runs in when it runs at system startup is probably
  >> not the one you set up.  Check the /etc/init.d/postgresql file for
  >> details.
  >
  >This is certainly true, as my settings are overridden. I have had a look at
  >this file, but I am still not clear what environment it is reading when it
  >sets $PGDATA.  Can you clarify where this environment
  >config file should be (on RedHat)?

I can't speak for RedHat, but this is a general description of what happens
at boot time, which may help you to work out what is happening:

after the kernel starts running it starts a program called init, which is
responsible for setting up the multi-user environment and all services,
either directly or indeirectly.  At one point in the process, the system
changes into multi-user mode and runs the scripts for the default run-level.
These scripts are usually linked to files in /etc/init.d/.

All this is done with the permissions and identity of the Unix superuser,
so it is necessary for the postgresql startup script to arrange to become
the postgresql superuser to start the postmaster (which root is not
allowed to do).  The command to change identity is su, and it makes a
difference whether the script uses `su postgres' or `su - postgres'; the
latter should set up the postgres login environment, but the former will not.

  >2) Passing parameters to postmaster during starup
  >
  >Also, the init.d script uses pg_ctl to start the postmaster. I need to pass
  >the -i parameter using the "postmaster" utility. (As I understand it, in
  >past releases of these
  >RPMs -i was set as a default). At what point in the startup sequence can you
  >pass "postmaster" utility params to the postmaster process?

Another way to do this is to set options in postgresql.conf; have a line
in it that says:

TCPIP_SOCKET = yes

almost all options can be set there.  See Administrator's Guide (7.1 version)
section 3.4


--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "Submit yourselves therefore to God. Resist the devil,
      and he will flee from you."          James 4:7