PostgreSQL Database Path Migration

Source: Internet
Author: User
Tags file copy postgresql

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.