Thread: Problem changing default data_directory in PG 9.6 + CentOS6

Problem changing default data_directory in PG 9.6 + CentOS6

From
Edilmar LISTAS
Date:
I have an env running a changed data_directory fine in a devel
    machine PG 9.4 using Fedora23.
    Now, I have a server machine with CentOS where I downloaded the RPMs
    from repo <a rel="nofollow" target="_blank"
href="https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm"
      class="ot-anchor aaTEdf" jslog="10929; track:click"
dir="ltr">https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm.
    All the configs run fine if I doesn't change the default
    data_directory. But I need to use the path /sistemas/sat4/bdpg.

    I did these commands:

    mkdir /sistemas/sat4/bdpg
    chown postgres /sistemas/sat4/bdpg
    chmod 700 /sistemas/sat4/bdpg
    su - postgres
    /usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
    exit

    Then, I changed data_directory to /sistemas/sat4/bdpg and tried to
    restart PG:
    service postgresql-9.6 restart
    STOP => OK
    START => FAILED

    I disabled se_linux.
    The file /var/lib/pgsql/9.6/pgstartup.log just said to see future
    output in pg_log.
    The file data/pg_log/postgresql-Mon.log doesn't say anything about
    errors.

    The strange is that startup arises a FAILED message, but the process
    "/usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data" is
    running (and the children logger/checkpointer/etc). But I don't get
    to connect using pgAdmin3. Then, I have to kill manually postmaster
    (because service script doesn't understand postmaster.pid in the new
    data dir), comment data_directory to use default place, start and
    connect to pgAdmin3. Then, start/stop/start/etc run fine lookup for
    postmaster.pid in /var/lib/pgsql/9.6/data.

Re: Problem changing default data_directory in PG 9.6 + CentOS6

From
Melvin Davidson
Date:


On Mon, Oct 17, 2016 at 4:38 PM, Edilmar LISTAS <edilista@intersite.com.br> wrote:
I have an env running a changed data_directory fine in a devel machine PG 9.4 using Fedora23.
Now, I have a server machine with CentOS where I downloaded the RPMs from repo https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm.
All the configs run fine if I doesn't change the default data_directory. But I need to use the path /sistemas/sat4/bdpg.

I did these commands:

mkdir /sistemas/sat4/bdpg
chown postgres /sistemas/sat4/bdpg
chmod 700 /sistemas/sat4/bdpg
su - postgres
/usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
exit

Then, I changed data_directory to /sistemas/sat4/bdpg and tried to restart PG:
service postgresql-9.6 restart
STOP => OK
START => FAILED

I disabled se_linux.
The file /var/lib/pgsql/9.6/pgstartup.log just said to see future output in pg_log.
The file data/pg_log/postgresql-Mon.log doesn't say anything about errors.

The strange is that startup arises a FAILED message, but the process "/usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data" is running (and the children logger/checkpointer/etc). But I don't get to connect using pgAdmin3. Then, I have to kill manually postmaster (because service script doesn't understand postmaster.pid in the new data dir), comment data_directory to use default place, start and connect to pgAdmin3. Then, start/stop/start/etc run fine lookup for postmaster.pid in /var/lib/pgsql/9.6/data.

What is the value of data_directory in postgresql.conf ?

Is there anything in /var/log/postgresql/{log_filename}   ... where {log_file} is the value set in postgresql.conf ?

--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.

Re: Problem changing default data_directory in PG 9.6 + CentOS6

From
Adrian Klaver
Date:
On 10/17/2016 01:38 PM, Edilmar LISTAS wrote:
> I have an env running a changed data_directory fine in a devel machine
> PG 9.4 using Fedora23.
> Now, I have a server machine with CentOS where I downloaded the RPMs
> from repo
> https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm.
> All the configs run fine if I doesn't change the default data_directory.
> But I need to use the path /sistemas/sat4/bdpg.
>
> I did these commands:
>
> mkdir /sistemas/sat4/bdpg
> chown postgres /sistemas/sat4/bdpg
> chmod 700 /sistemas/sat4/bdpg
> su - postgres
> /usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
> exit
>
> Then, I changed data_directory to /sistemas/sat4/bdpg and tried to

Changed data_directory where?

> restart PG:
> service postgresql-9.6 restart
> STOP => OK
> START => FAILED
>
> I disabled se_linux.
> The file /var/lib/pgsql/9.6/pgstartup.log just said to see future output
> in pg_log.
> The file data/pg_log/postgresql-Mon.log doesn't say anything about errors.
>
> The strange is that startup arises a FAILED message, but the process
> "/usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data" is running

So /var/lib/pgsql/9.6/data is where the original install is?

Best guess is that some script is starting the original install and when
you go to start your custom location it fails because the new cluster is
trying to use the port(5432 I am assuming) as the original cluster.

Have you tried giving the new cluster a different port number, say 5442,
and the starting it?


> (and the children logger/checkpointer/etc). But I don't get to connect
> using pgAdmin3. Then, I have to kill manually postmaster (because
> service script doesn't understand postmaster.pid in the new data dir),
> comment data_directory to use default place, start and connect to
> pgAdmin3. Then, start/stop/start/etc run fine lookup for postmaster.pid
> in /var/lib/pgsql/9.6/data.

So you either need to change the start script to point to the new
cluster or create a new one for it.



--
Adrian Klaver
adrian.klaver@aklaver.com


Re: Problem changing default data_directory in PG 9.6 + CentOS6

From
Edilmar LISTAS
Date:
1) I changed /etc/rc.d/init.d/postgresql-9.6 like this:
PGDATA=/sistemas/sat4/bdpg
#PGDATA=/var/lib/pgsql/9.6/data

2) I copied postgresql.conf and pg_hba.conf from /var/lib/pgsql/9.6/data
to /sistemas/sat4/bdpg

3) I changed postgresql.conf like this:
data_directory = '/sistemas/sat4/bdpg'

4) service postgresql-9.6 start
Iniciando o serviço postgresql-9.6: [FAILED]

In my devel machine, I only did step 3), PG starts lookup for default
configs in /var/lib/pgsql/data and uses my databases in the alternative
path /sistemas/sat4/bdpg.


Em 17-10-2016 21:22, Adrian Klaver escreveu:
> On 10/17/2016 01:38 PM, Edilmar LISTAS wrote:
>> I have an env running a changed data_directory fine in a devel machine
>> PG 9.4 using Fedora23.
>> Now, I have a server machine with CentOS where I downloaded the RPMs
>> from repo
>> https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm.
>>
>> All the configs run fine if I doesn't change the default data_directory.
>> But I need to use the path /sistemas/sat4/bdpg.
>>
>> I did these commands:
>>
>> mkdir /sistemas/sat4/bdpg
>> chown postgres /sistemas/sat4/bdpg
>> chmod 700 /sistemas/sat4/bdpg
>> su - postgres
>> /usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
>> exit
>>
>> Then, I changed data_directory to /sistemas/sat4/bdpg and tried to
>
> Changed data_directory where?
>
>> restart PG:
>> service postgresql-9.6 restart
>> STOP => OK
>> START => FAILED
>>
>> I disabled se_linux.
>> The file /var/lib/pgsql/9.6/pgstartup.log just said to see future output
>> in pg_log.
>> The file data/pg_log/postgresql-Mon.log doesn't say anything about
>> errors.
>>
>> The strange is that startup arises a FAILED message, but the process
>> "/usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data" is running
>
> So /var/lib/pgsql/9.6/data is where the original install is?
>
> Best guess is that some script is starting the original install and when
> you go to start your custom location it fails because the new cluster is
> trying to use the port(5432 I am assuming) as the original cluster.
>
> Have you tried giving the new cluster a different port number, say 5442,
> and the starting it?
>
>
>> (and the children logger/checkpointer/etc). But I don't get to connect
>> using pgAdmin3. Then, I have to kill manually postmaster (because
>> service script doesn't understand postmaster.pid in the new data dir),
>> comment data_directory to use default place, start and connect to
>> pgAdmin3. Then, start/stop/start/etc run fine lookup for postmaster.pid
>> in /var/lib/pgsql/9.6/data.
>
> So you either need to change the start script to point to the new
> cluster or create a new one for it.
>
>
>



Re: Problem changing default data_directory in PG 9.6 + CentOS6

From
Melvin Davidson
Date:


On Tue, Oct 18, 2016 at 10:20 AM, Edilmar LISTAS <edilista@intersite.com.br> wrote:
1) I changed /etc/rc.d/init.d/postgresql-9.6 like this:
PGDATA=/sistemas/sat4/bdpg
#PGDATA=/var/lib/pgsql/9.6/data

2) I copied postgresql.conf and pg_hba.conf from /var/lib/pgsql/9.6/data to /sistemas/sat4/bdpg

3) I changed postgresql.conf like this:
data_directory = '/sistemas/sat4/bdpg'

4) service postgresql-9.6 start
Iniciando o serviço postgresql-9.6: [FAILED]

In my devel machine, I only did step 3), PG starts lookup for default configs in /var/lib/pgsql/data and uses my databases in the alternative path /sistemas/sat4/bdpg.


Em 17-10-2016 21:22, Adrian Klaver escreveu:
On 10/17/2016 01:38 PM, Edilmar LISTAS wrote:
I have an env running a changed data_directory fine in a devel machine
PG 9.4 using Fedora23.
Now, I have a server machine with CentOS where I downloaded the RPMs
from repo
https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm.

All the configs run fine if I doesn't change the default data_directory.
But I need to use the path /sistemas/sat4/bdpg.

I did these commands:

mkdir /sistemas/sat4/bdpg
chown postgres /sistemas/sat4/bdpg
chmod 700 /sistemas/sat4/bdpg
su - postgres
/usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
exit

Then, I changed data_directory to /sistemas/sat4/bdpg and tried to

Changed data_directory where?

restart PG:
service postgresql-9.6 restart
STOP => OK
START => FAILED

I disabled se_linux.
The file /var/lib/pgsql/9.6/pgstartup.log just said to see future output
in pg_log.
The file data/pg_log/postgresql-Mon.log doesn't say anything about
errors.

The strange is that startup arises a FAILED message, but the process
"/usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data" is running

So /var/lib/pgsql/9.6/data is where the original install is?

Best guess is that some script is starting the original install and when
you go to start your custom location it fails because the new cluster is
trying to use the port(5432 I am assuming) as the original cluster.

Have you tried giving the new cluster a different port number, say 5442,
and the starting it?


(and the children logger/checkpointer/etc). But I don't get to connect
using pgAdmin3. Then, I have to kill manually postmaster (because
service script doesn't understand postmaster.pid in the new data dir),
comment data_directory to use default place, start and connect to
pgAdmin3. Then, start/stop/start/etc run fine lookup for postmaster.pid
in /var/lib/pgsql/9.6/data.

So you either need to change the start script to point to the new
cluster or create a new one for it.






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


Instead of
>4) service postgresql-9.6 start

Try:
sudo su postgres
pg_ctl start -D /sistemas/sat4/bdpg

If that works, then your problem is in the postgresql service file
--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.

Re: Problem changing default data_directory in PG 9.6 + CentOS6

From
Edilmar LISTAS
Date:
Em 18-10-2016 11:33, Melvin Davidson escreveu:
>
>
> On Tue, Oct 18, 2016 at 10:20 AM, Edilmar LISTAS
> <edilista@intersite.com.br <mailto:edilista@intersite.com.br>> wrote:
>
>     1) I changed /etc/rc.d/init.d/postgresql-9.6 like this:
>     PGDATA=/sistemas/sat4/bdpg
>     #PGDATA=/var/lib/pgsql/9.6/data
>
>     2) I copied postgresql.conf and pg_hba.conf from
>     /var/lib/pgsql/9.6/data to /sistemas/sat4/bdpg
>
>     3) I changed postgresql.conf like this:
>     data_directory = '/sistemas/sat4/bdpg'
>
>     4) service postgresql-9.6 start
>     Iniciando o serviço postgresql-9.6: [FAILED]
>
>     In my devel machine, I only did step 3), PG starts lookup for
>     default configs in /var/lib/pgsql/data and uses my databases in the
>     alternative path /sistemas/sat4/bdpg.
>
>
>     Em 17-10-2016 21:22, Adrian Klaver escreveu:
>
>         On 10/17/2016 01:38 PM, Edilmar LISTAS wrote:
>
>             I have an env running a changed data_directory fine in a
>             devel machine
>             PG 9.4 using Fedora23.
>             Now, I have a server machine with CentOS where I downloaded
>             the RPMs
>             from repo
>             https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
>             <https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm>.
>
>             All the configs run fine if I doesn't change the default
>             data_directory.
>             But I need to use the path /sistemas/sat4/bdpg.
>
>             I did these commands:
>
>             mkdir /sistemas/sat4/bdpg
>             chown postgres /sistemas/sat4/bdpg
>             chmod 700 /sistemas/sat4/bdpg
>             su - postgres
>             /usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
>             exit
>
>             Then, I changed data_directory to /sistemas/sat4/bdpg and
>             tried to
>
>
>         Changed data_directory where?
>
>             restart PG:
>             service postgresql-9.6 restart
>             STOP => OK
>             START => FAILED
>
>             I disabled se_linux.
>             The file /var/lib/pgsql/9.6/pgstartup.log just said to see
>             future output
>             in pg_log.
>             The file data/pg_log/postgresql-Mon.log doesn't say anything
>             about
>             errors.
>
>             The strange is that startup arises a FAILED message, but the
>             process
>             "/usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data"
>             is running
>
>
>         So /var/lib/pgsql/9.6/data is where the original install is?
>
>         Best guess is that some script is starting the original install
>         and when
>         you go to start your custom location it fails because the new
>         cluster is
>         trying to use the port(5432 I am assuming) as the original cluster.
>
>         Have you tried giving the new cluster a different port number,
>         say 5442,
>         and the starting it?
>
>
>             (and the children logger/checkpointer/etc). But I don't get
>             to connect
>             using pgAdmin3. Then, I have to kill manually postmaster
>             (because
>             service script doesn't understand postmaster.pid in the new
>             data dir),
>             comment data_directory to use default place, start and
>             connect to
>             pgAdmin3. Then, start/stop/start/etc run fine lookup for
>             postmaster.pid
>             in /var/lib/pgsql/9.6/data.
>
>
>         So you either need to change the start script to point to the new
>         cluster or create a new one for it.
>
>
>
>
>
>
>     --
>     Sent via pgsql-general mailing list (pgsql-general@postgresql.org
>     <mailto:pgsql-general@postgresql.org>)
>     To make changes to your subscription:
>     http://www.postgresql.org/mailpref/pgsql-general
>     <http://www.postgresql.org/mailpref/pgsql-general>
>
>
>
> I*nstead of
>>4) service postgresql-9.6 start
> *
> *
> Try:
> *
> *sudo su postgres
> *
> *pg_ctl start -D /sistemas/sat4/bdpg*
> *
> *
> *If that works, then your problem is in the postgresql service file
> *
> *-- *
> *Melvin Davidson*
> I reserve the right to fantasize.  Whether or not you
> wish to share my fantasy is entirely up to you.

This works...
/usr/pgsql-9.6/bin/pg_ctl -D /sistemas/sat4/bdpg -l logfile start
but psql doesn't log:
-bash-4.1$ psql
Senha:
psql: fe_sendauth: no password supplied

If I use the default data_directory = /var/lib/pgsql/9.6/data, psql runs
fine without password.


Re: Problem changing default data_directory in PG 9.6 + CentOS6

From
Edilmar LISTAS
Date:
Hi,

After some tests, really the problem is with original script from PG 9.6
RPM /etc/rc.d/init.d/postgresql-9.6. If I run pg_ctl, start/stop with
the new data_directory works fine!

Em 18-10-2016 13:49, Edilmar LISTAS escreveu:
> Em 18-10-2016 11:33, Melvin Davidson escreveu:
>>
>>
>> On Tue, Oct 18, 2016 at 10:20 AM, Edilmar LISTAS
>> <edilista@intersite.com.br <mailto:edilista@intersite.com.br>> wrote:
>>
>>     1) I changed /etc/rc.d/init.d/postgresql-9.6 like this:
>>     PGDATA=/sistemas/sat4/bdpg
>>     #PGDATA=/var/lib/pgsql/9.6/data
>>
>>     2) I copied postgresql.conf and pg_hba.conf from
>>     /var/lib/pgsql/9.6/data to /sistemas/sat4/bdpg
>>
>>     3) I changed postgresql.conf like this:
>>     data_directory = '/sistemas/sat4/bdpg'
>>
>>     4) service postgresql-9.6 start
>>     Iniciando o serviço postgresql-9.6: [FAILED]
>>
>>     In my devel machine, I only did step 3), PG starts lookup for
>>     default configs in /var/lib/pgsql/data and uses my databases in the
>>     alternative path /sistemas/sat4/bdpg.
>>
>>
>>     Em 17-10-2016 21:22, Adrian Klaver escreveu:
>>
>>         On 10/17/2016 01:38 PM, Edilmar LISTAS wrote:
>>
>>             I have an env running a changed data_directory fine in a
>>             devel machine
>>             PG 9.4 using Fedora23.
>>             Now, I have a server machine with CentOS where I downloaded
>>             the RPMs
>>             from repo
>>
>> https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
>>
>>
>> <https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm>.
>>
>>
>>             All the configs run fine if I doesn't change the default
>>             data_directory.
>>             But I need to use the path /sistemas/sat4/bdpg.
>>
>>             I did these commands:
>>
>>             mkdir /sistemas/sat4/bdpg
>>             chown postgres /sistemas/sat4/bdpg
>>             chmod 700 /sistemas/sat4/bdpg
>>             su - postgres
>>             /usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
>>             exit
>>
>>             Then, I changed data_directory to /sistemas/sat4/bdpg and
>>             tried to
>>
>>
>>         Changed data_directory where?
>>
>>             restart PG:
>>             service postgresql-9.6 restart
>>             STOP => OK
>>             START => FAILED
>>
>>             I disabled se_linux.
>>             The file /var/lib/pgsql/9.6/pgstartup.log just said to see
>>             future output
>>             in pg_log.
>>             The file data/pg_log/postgresql-Mon.log doesn't say anything
>>             about
>>             errors.
>>
>>             The strange is that startup arises a FAILED message, but the
>>             process
>>             "/usr/pgsql-9.6/bin/postmaster -D /var/lib/pgsql/9.6/data"
>>             is running
>>
>>
>>         So /var/lib/pgsql/9.6/data is where the original install is?
>>
>>         Best guess is that some script is starting the original install
>>         and when
>>         you go to start your custom location it fails because the new
>>         cluster is
>>         trying to use the port(5432 I am assuming) as the original
>> cluster.
>>
>>         Have you tried giving the new cluster a different port number,
>>         say 5442,
>>         and the starting it?
>>
>>
>>             (and the children logger/checkpointer/etc). But I don't get
>>             to connect
>>             using pgAdmin3. Then, I have to kill manually postmaster
>>             (because
>>             service script doesn't understand postmaster.pid in the new
>>             data dir),
>>             comment data_directory to use default place, start and
>>             connect to
>>             pgAdmin3. Then, start/stop/start/etc run fine lookup for
>>             postmaster.pid
>>             in /var/lib/pgsql/9.6/data.
>>
>>
>>         So you either need to change the start script to point to the new
>>         cluster or create a new one for it.
>>
>>
>>
>>
>>
>>
>>     --
>>     Sent via pgsql-general mailing list (pgsql-general@postgresql.org
>>     <mailto:pgsql-general@postgresql.org>)
>>     To make changes to your subscription:
>>     http://www.postgresql.org/mailpref/pgsql-general
>>     <http://www.postgresql.org/mailpref/pgsql-general>
>>
>>
>>
>> I*nstead of
>>> 4) service postgresql-9.6 start
>> *
>> *
>> Try:
>> *
>> *sudo su postgres
>> *
>> *pg_ctl start -D /sistemas/sat4/bdpg*
>> *
>> *
>> *If that works, then your problem is in the postgresql service file
>> *
>> *-- *
>> *Melvin Davidson*
>> I reserve the right to fantasize.  Whether or not you
>> wish to share my fantasy is entirely up to you.
>
> This works...
> /usr/pgsql-9.6/bin/pg_ctl -D /sistemas/sat4/bdpg -l logfile start
> but psql doesn't log:
> -bash-4.1$ psql
> Senha:
> psql: fe_sendauth: no password supplied
>
> If I use the default data_directory = /var/lib/pgsql/9.6/data, psql runs
> fine without password.
>
>



Re: Problem changing default data_directory in PG 9.6 + CentOS6

From
Devrim Gündüz
Date:
Hi,

On Mon, 2016-10-17 at 17:38 -0300, Edilmar LISTAS wrote:
> I have an env running a changed data_directory fine in a devel machine PG 9.4
> using Fedora23. 
> Now, I have a server machine with CentOS where I downloaded the RPMs from
> repo https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/p
> gdg-centos96-9.6-3.noarch.rpm.
> All the configs run fine if I doesn't change the default data_directory. But
> I need to use the path /sistemas/sat4/bdpg.
>
> I did these commands:
>
> mkdir /sistemas/sat4/bdpg
> chown postgres /sistemas/sat4/bdpg
> chmod 700 /sistemas/sat4/bdpg
> su - postgres 
> /usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
> exit
>
> Then, I changed data_directory to /sistemas/sat4/bdpg and tried to restart
> PG:
> service postgresql-9.6 restart
> STOP => OK
> START => FAILED

On CentOS, the appropriate way to do this is described in README file shipped
with the RPMs. Related part is:

===========================================================================
As an example, let us create a secondary postmaster called, creatively enough,
'secondary'.  Here are the steps:
1.)     create a hard link in /etc/rc.d/init.d (or equivalent location)
        to postgresql-9.6 named 'secondary-9.6' : ln postgresql
secondary   Pick
        a name not already used in /etc/rc.d/init.d!
2.)     create a file in /etc/sysconfig/pgsql named secondary.  This file is
        a shell script -- typically you would define PGDATA, and PGOPTS
        here.  Since $PGDATA/postgresql.conf will override many of these
        settings, except PGDATA, you might be surprised on startup.
3.)     create the target PGDATA.
4.)     Initdb the targe PGDATA as documented in the main documentation.
        Automatic initdb may or may not work for you, so a manual one is
        preferred.  This must be done as user 'postgres'
5.)     Edit postgresql.conf to change the port, address, tcpip settings, etc.
6.)     Start the postmaster with 'service secondary-9.6 start'.
============================================================================

Regards,
--
Devrim GÜNDÜZ
EnterpriseDB: http://www.enterprisedb.com
PostgreSQL Danışmanı/Consultant, Red Hat Certified Engineer
Twitter: @DevrimGunduz , @DevrimGunduzTR

Attachment

Re: Problem changing default data_directory in PG 9.6 + CentOS6

From
Edilmar LISTAS
Date:
Em 18-10-2016 16:53, Devrim Gündüz escreveu:
>
> Hi,
>
> On Mon, 2016-10-17 at 17:38 -0300, Edilmar LISTAS wrote:
>> I have an env running a changed data_directory fine in a devel machine PG 9.4
>> using Fedora23.
>> Now, I have a server machine with CentOS where I downloaded the RPMs from
>> repo https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/p
>> gdg-centos96-9.6-3.noarch.rpm.
>> All the configs run fine if I doesn't change the default data_directory. But
>> I need to use the path /sistemas/sat4/bdpg.
>>
>> I did these commands:
>>
>> mkdir /sistemas/sat4/bdpg
>> chown postgres /sistemas/sat4/bdpg
>> chmod 700 /sistemas/sat4/bdpg
>> su - postgres
>> /usr/pgsql-9.6/bin/initdb -D /sistemas/sat4/bdpg
>> exit
>>
>> Then, I changed data_directory to /sistemas/sat4/bdpg and tried to restart
>> PG:
>> service postgresql-9.6 restart
>> STOP => OK
>> START => FAILED
>
> On CentOS, the appropriate way to do this is described in README file shipped
> with the RPMs. Related part is:
>
> ===========================================================================
> As an example, let us create a secondary postmaster called, creatively enough,
> 'secondary'.  Here are the steps:
> 1.)     create a hard link in /etc/rc.d/init.d (or equivalent location)
>         to postgresql-9.6 named 'secondary-9.6' : ln postgresql
> secondary   Pick
>         a name not already used in /etc/rc.d/init.d!
> 2.)     create a file in /etc/sysconfig/pgsql named secondary.  This file is
>         a shell script -- typically you would define PGDATA, and PGOPTS
>         here.  Since $PGDATA/postgresql.conf will override many of these
>         settings, except PGDATA, you might be surprised on startup.
> 3.)     create the target PGDATA.
> 4.)     Initdb the targe PGDATA as documented in the main documentation.
>         Automatic initdb may or may not work for you, so a manual one is
>         preferred.  This must be done as user 'postgres'
> 5.)     Edit postgresql.conf to change the port, address, tcpip settings, etc.
> 6.)     Start the postmaster with 'service secondary-9.6 start'.
> ============================================================================
>
> Regards,
>

Thank you very much.
I did these additional cmds and all worked fine!
cd /etc/rc.d/init.d
ln postgresql-9.6 pgsat
cd /etc/sysconfig/pgsql
echo "PGDATA=/sistemas/sat4/bdpg" > pgsat
service pgsat start
chkconfig --add pgsat
chkconfig pgsat on
chkconfig postgresql-9.6 off