Change Postgres Default Data Directory

Quick Guide:

service postgresql stop
or
systemctl stop postgresql

mkdir /home/data
cp -rf /var/lib/pgsql/#version#/data /home/.
chmod -R 700 /home/data
chown -R postgres:postgres /home/data

Edit:
/home/data/postgresql.conf
point:
data_directory = '/home/data' # use data in another directory
hba_file = '/home/data/pg_hba.conf' # host-based authentication file
ident_file = '/home/data/pg_ident.conf' # ident configuration file

For CENTOS 6.x:
Edit the startup file:
/etc/init.d/postgresql
/etc/init.d/postgresql-version
Change:
PGDATA = /home/data

service postgresql start
or
systemctl start postgresql

Explanation:

1. Stop the services

service postgresql stop or systemctl stop postgresql

2. Create new data directory with the appropriate users and rights, copy the data to new location:

mkdir /home/data

cp -rf /var/lib/pgsql/#version#/data /home/.

chmod -R 700 /home/data

chown -R postgres:postgres /home/data

3. Edit the configuration file: /home/data/postgresql.conf

data_directory = '/home/data' # use data in another directory

hba_file = '/home/data/pg_hba.conf' # host-based authentication file

ident_file = '/home/data/pg_ident.conf' # ident configuration file

4. For centos 6.x, edit the startup file: /etc/init.d/postgresql

PGDATA = /home/data

5. Start Service

   service postgresql start
   or
   systemctl start postgresql

 

 

 

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*