当前位置:网站首页>[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

边栏推荐
- VScode如何Debug(调试)进入标准库文件/第三方包源码
- 網上炒股安全麼?炒股需要開戶嗎?
- Four, forty, fourhundred swatches
- How to display all keys through redis cli- How to show ALL keys through redis-cli?
- DDoS attacks - are we really at war?
- dhu编程练习
- Implement vs to run only one source file at a time
- DHU programming exercise
- [论]【DSTG】Dynamic SpatiotemporalGraph Convolutional Neural Networks for Traffic Data Imputation
- Network neuroscience——网络神经科学综述
猜你喜欢

Five cheapest wildcard SSL certificate brands

Realization of a springboard machine

How does payment splitting help B2B bulk commodity transactions?

Several key points recorded after reviewing redis design and Implementation

选购通配符SSL证书注意事项

归并排序

NPDP产品经理国际认证考试报名有什么要求?

Matlab code running tutorial (how to run the downloaded code)

Créer des compétences exquises dans l'éducation des créateurs

ROS Bridge 笔记(01)— apt 安装、源码编译安装、安装依赖、运行显示
随机推荐
速看 2021-2022年23项重大网络犯罪统计数据
Insert sort directly
Openlayers 3 built in interaction
DDoS threat situation gets worse
每周推荐短视频:为什么理论正确但得不到预期结果?
学术汇报(academic presentation)/PPT应该怎么做?
Heap sort
Implement vs to run only one source file at a time
Est - ce que la bourse en ligne est sécurisée? Dois - je ouvrir un compte pour la spéculation boursière?
How long is the general term of the bank's financial products?
vs实现快速替换功能
NCA: the nine year old has launched a DDoS attack
新考纲下的PMP考试有多难?全面解析
SQL injection -day17
有流量,但没有销售?增加网站销量的 6 个步骤
ROS bridge notes (01) - APT installation, source code compilation and installation, installation dependency, and operation display
dhu编程练习
Several key points recorded after reviewing redis design and Implementation
打造創客教育中精湛技藝
代码签名、驱动签名的常见问题解答