Step by step how to move 'data' directory from one file system to another in postgresql

Updated: Feb 11, 2021


 

source data directory : /opt/edb/as10/data

target data directory : /data

====================================

1- login to the system


[root@Node1 ~]# su - enterprisedb

Last login: Tue May 26 12:02:16 IST 2020 on pts/0

-bash-4.2$


2- Check the data directory of the database

-bash-4.2$ psql

psql.bin (10.11.19)

Type "help" for help.

edb=# show data_directory ;

data_directory

--------------------

/opt/edb/as10/data

(1 row)


3--Check status of db server

-bash-4.2$ . pgplus_env.sh

-bash-4.2$ pg_ctl status

pg_ctl: server is running (PID: 1524)

/opt/edb/as10/bin/edb-postgres "-D" "/opt/edb/as10/data"


4-Stop the server

-bash-4.2$ pg_ctl stop

waiting for server to shut down.... done

server stopped


5-Now copy the contents of old data directory(from #2) to our new data directory (/data)

-bash-4.2$ tar cvf - ./*| (cd /data; tar xvf - .)

-bash-4.2$ cd /data/

check if all the files/folders have been copied from old to new data directory


6- Now change the location of new data directory in postgresql.conf & pgplus_env.sh


-bash-4.2$ vi postgresql.conf

data_directory= '/data'


-bash-4.2$ vi pgplus_env.sh

export PGDATA=/data


7- Now start the postgres services & check the new data directory being reflected


-bash-4.2$ . pgplus_env.sh

-bash-4.2$ pg_ctl start

waiting for server to start....2020-05-26 12:18:16 IST LOG: listening on IPv4 address "0.0.0.0", port 5444

2020-05-26 12:18:16 IST LOG: listening on IPv6 address "::", port 5444

2020-05-26 12:18:16 IST LOG: listening on Unix socket "/tmp/.s.PGSQL.5444"

2020-05-26 12:18:16 IST LOG: redirecting log output to logging collector process

2020-05-26 12:18:16 IST HINT: Future log output will appear in directory "log".

done

server started

-bash-4.2$ psql

psql.bin (10.11.19)

Type "help" for help.


edb=# show data_directory ;

data_directory

----------------

/data

(1 row)


97 views0 comments

Recent Posts

See All

This is the step by step documents to install and configure Enterprisedb Failover Manager (EFM) 4.2 in RHEL 8 #EDB #EFM #postgrsql 1- Prerequisite : - EDB v12 is installed in the primary and master s