Get the App
SLTechnology News&Howtos  ›  Database  › 

Database migration in postgresql production environment

Shulou Source: shulou.com Published: 2022-06-01 16:36:29 10月04日 Update

Because the existing pg environment is overloaded, the current database needs to be migrated to the new environment.

If the amount of data is small, you can use method 1.

Method 1:

Pgsql migrates the database to a new library in different network segments, and the new database environment master-slave high-availability environment has been configured.

First back up the old library

$pg_dump-U peimsmdata-d peimsm > peimsm.sql

Compress

$tar-zcf peimsm.tar.gz peimsm.sql

Transfer the file to the new environment and extract it

$tar-xzf peimsm.tar.gz

Import database

$psql-U peimsmdata-d peimsm < peimsm.sql

But in fact, the amount of data is 50 to 60 million, more than 50 GB, so using the above method will be very time-consuming, so use the following method

Method 2:

The new and old environment is in a network segment

First stop the corresponding business of the old database, and then stop the database service and keepalived service

Then compile postgresql in the main library environment

Clean up the archive file before the latest file in the pg_archive directory using the following command

$pg_archivecleanup. / filename

Transfer all files under the / data/pg_data directory in the old environment to the / data/pg_data directory in the new environment, modify the configuration file, and start the service.

Master-slave synchronization data

...

Configure according to the master-slave configuration document, etc.

Referenc

Https://help.aliyun.com/document_detail/26157.html#h3-url-4

Https://blog.csdn.net/qq_36408250/article/details/80652518

Tags: Data environment database file method configuration master-slave directory service network segment different above small business usage command backup actual actually document Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology Linux Huawei MariaDB