There are two methods of migrating:
(1) Reinitialize the PostgreSQL database, specify a new data path at initialization---PGDATA, and then restore the original database backup in the new environment. But this method is a little cumbersome.
(2) Copy all the existing database files directly to the new database path and then restart the database service
The second method is relatively simple, so describe the second method in detail:
1. After PostgreSQL is installed, the default database path is/var/lib/pgsql/9.x/data
2, create a new path as the database data path, if it is/home/data
sudo mkdir/home/data
sudo chown-r postgres:postgres data
sudo chmod data
The final command is mandatory, or the database is started back to the problematic
3, File copy,
To stop the PostgreSQL service first
sudo systemctl stop PostgreSQL
sudo su-postgres
cp-rf/var/lib/pgsql/9.x/data/*/home/data
4. Modify the service file
Find Vim/usr/lib/systemd/system/postgresql*.service
Modify the file in the
environment=pgdata=/var/lib/pgsql/9.4/data/
To modify it to its own new data path:
environment=pgdata=/home/data/
Now that all the modifications have been done, this method is relatively simple, but the premise is that PostgreSQL has been added as a service to SYSTEMCTL, which requires attention
5, at this time can restart PostgreSQL, but, try a few methods are not successful, only re-start the system, can
Reboot system
Then start the Postgres service
sudo systemctl restart Posrgresql
Everything is the same as it used to be! Successfully complete data migration.
In order to avoid the work of data migration, in the future when you deploy PostgreSQL, you should take into account the problem of system partitioning, to avoid using the default data path
PostgreSQL database Path Migration