当前位置:网站首页>[Postgres] Postgres database migration
[Postgres] Postgres database migration
2022-06-30 02:28:00 【master336】
Catalog
Environmental statement
This content completes the test based on the following environment
| term | Configuration instructions | remarks |
|---|---|---|
| operating system | CentOS7 | |
| PG Data version | 9.6.24 | |
| Operating system users | root/postgres | |
| Data volume | user (20)、 role (20)、 database (2)、schema(42)、 Data volume ( about 160W That's ok ) | Data file approx 640M |
Backup
The data backup
# Create a backup storage folder ( Make sure postgres The user has permission )
cd /home
mkdir posrgres
chown -R postgres postgres/
# Switch postgres user
su - posrgres
# Perform backup
pg_dumpall -U postgres -v -f u_postgres.backup
File backup
Default location of data file :/var/lib/pgsql/9.6
# Switch to the data storage location
cd /var/lib/pgsql/9.6
# Stop database service
systemctl stop postgresql-9.6
# Compressed data file
tar -cvf data.tar.gz data/
# Got data.tar.gz This is the compressed data backup file
Migration scheme 1 : Data file migration
Migrate data files
This process needs to be stopped first pg database
Complete the file backup
# Ensure that process services are stopped
systemctl stop postgresql-9.6
cd /home
# Create a migration Directory And modify the authority
mkdir pgdata
## Modify attribution
chown -R postgres pgdata/
## Modify the permissions ( must )
chmod 700 pgdata/
# Switch to pg user
su - postgres
# Copy data file to new location
cp -rf data/* /home/pgdata/
Modify the location of the service data file
# Edit service profile
vim /usr/lib/systemd/system/postgresql-9.6.service
# Modify the data file path of the configuration file
modify :Environment=PGDATA=/var/lib/pgsql/9.6/data/
by :Environment=PGDATA=/home/pgdata/
# Save and exit
# Restart the system
reboot
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-NzbxucV4-1655303214806)(file://C:\Users\dongz\AppData\Roaming\marktext\images\2022-06-15-21-21-41-image.png?msec=1655299475495)]](/img/45/7074aa766640160a3b6f00b109cb2f.png)
Migration scheme II : Data reduction method
This scheme is based on pg Database support for backup and restore , Using this method, it is strongly recommended to operate on the same version of the database
For data backup, see **【 The data backup 】** chapter
Upload data backup file
# Create a backup file location
cd /home
mkdir postgres
# Upload the backup file to the storage location in the previous step ( Upload process omitted )
mv u_postgres.backup postgres/
# Modify the permissions
chown -R postgres postgres/
Use psql Restore
# Switching users
su - postgres
# Switch data backup directory
cd /home/postgres/
# Perform recovery ( Ignore mistakes ,"postgres" Built in role reason )
psql -U postgres -f u_postgres.backup
# Perform recovery ( Stop on error , Don't suggest )
#psql -U postgres --set ON_ERROR_STOP=on -f u_postgres.backup
Common problems and Solutions
The permission is too large

- The permission of the migration target directory is too large
terms of settlement : Modify the permissions ( must )
chmod 700 pgdata/
Directory error or insufficient permissions

- The directory caused by incorrect operation cannot be recognized as a valid path or is caused by incorrect permission modification
terms of settlement : Modify the folder where the data file is located to posrgres all
chown -R postgres pgdata
chown 700 pgdata
# The swappable postgres Test read and write permissions

边栏推荐
- Vs realize quick replacement function
- SQL injection -day17
- Steam elements hidden in science and Technology Education
- SSL证书格式转化的两种方法
- DHU programming exercise
- Le Code autojs peut - il être chiffré? Oui, présentation des techniques de chiffrement autojs
- Matlab code running tutorial (how to run the downloaded code)
- Pytorch学习(二)
- 隐藏在科技教育中的steam元素
- Blitzkrieg companies with DDoS attacks exceeding 100gbps in 2014
猜你喜欢

VScode如何Debug(调试)进入标准库文件/第三方包源码

SQL injection -day17

What files does a CA digital certificate contain? How to view SSL certificate information?

Digicert、Sectigo、Globalsign代码签名证书的区别

Jenkins continuous integration environment build 8 (configure mailbox server to send build results)

PR second training notes

Le Code autojs peut - il être chiffré? Oui, présentation des techniques de chiffrement autojs

CA数字证书包含哪些文件?如何查看SSL证书信息?

How to use SMS to deliver service information to customers? The guide is here!

Bubble sort
随机推荐
Jupyter notebook displays a collection of K-line graphs
Global communication infrastructure faces apt, robotics and DDoS; The weakest mobile network
【干货分享】最新WHQL徽标认证申请流程
DHU programming exercise
Recommendations for agileplm database parameter optimization
What is digicert smart seal?
Large scale DDoS attacks and simulated DDoS tests against VoIP providers
DHU programming exercise
26. common interview questions of algorithm
How to use SMS to deliver service information to customers? The guide is here!
FDA ESG regulation: digital certificate must be used to ensure communication security
每周推荐短视频:为什么理论正确但得不到预期结果?
SQL injection -day17
【npm】解决使用npm安装TypeORM的报错问题
dhu编程练习
[NPM] solve the problem of error reporting when installing typeorm with NPM
Alphassl digital certificate
Five cheapest wildcard SSL certificate brands
How vscode debugs into standard library files / third-party package source code
DHU programming exercise