当前位置:网站首页>Postgresql14 installation and master-slave configuration
Postgresql14 installation and master-slave configuration
2022-07-28 14:04:00 【Step on the path of the pit】
Catalog
Create master-slave synchronization user
Verify master-slave synchronization
Main database verification method
1. Version environment
Server system : CentOS 7
PostgreSQL edition : 14.2
Main database intranet IP : 172.16.98.200
From database Intranet IP : 172.16.98.201
The user who performs the operation : commonuser
Service installation directory : /data/app/postgreSql
Data storage directory : /data/appData/postgreSql
Log storage directory : /data/logs/postgreSql
2. Master database operations
2.1 Installation services
If postgresql It is installed. You can skip the steps in this section , Direct basis 《2.2 Create master-slave synchronization user 》 In this section
# Download installation package cd /opt wget https://repo.huaweicloud.com/postgresql/source/v14.2/postgresql-14.2.tar.gz # decompression postgresql package tar -xf postgresql-14.2.tar.gz # Install dependency packages yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake # Create directory mkdir -pv /data/appData/postgreSql # Data directory mkdir -pv /data/logs/postgreSql # Log directory mkdir -pv /data/appData/postgreSql/pg_archive/xlog_files # Archive Directory , Premise :archive_mode = on # Allow archiving # Create user group commonuser And create users commonuser useradd commonuser # Modify the permissions chown -R commonuser.commonuser /data/app/postgreSql chown -R commonuser.commonuser /data/appData/postgreSql chown -R commonuser.commonuser /data/logs/postgreSql # Compilation and installation cd postgresql-14.2 ./configure --prefix=/data/app/postgreSql make && make install # Switch users to commonuser Initialization data su - commonuser cd /data/app/postgreSql export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/data/app/postgreSql/libhub" /data/app/postgreSql/bin/initdb -D /data/appData/postgreSql --encoding=UTF8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 cp -avf /data/app/postgreSql/postgresql.conf /data/appData/postgreSql/ echo "host all all 0.0.0.0/0 trust" >> /data/appData/postgreSql/pg_hba.conf # Start the service /data/app/postgreSql/bin/pg_ctl start -D /data/appData/postgreSql/ # Sign in pg /data/app/postgreSql/bin/psql -h 127.0.0.1 -p 5432 -U postgres # Create user /data/app/postgreSql/bin/createuser -U commonuser -h127.0.0.1 -p5432 -s postgres /data/app/postgreSql/bin/psql -d postgres -U commonuser -h127.0.0.1 -p5432 -c "create user synthetic_user with superuser password '123456';"
2.2 Create master-slave synchronization user
# If installed postgresql It is recommended to backup first , The backup operation reference is as follows :
# Create a backup SQL File storage directory mkdir -p /data/appData/backup /data/app/backup /data/tmp ## Export system library cd /data/appData/postgreSql/ /data/app/postgreSql/bin/pg_dumpall -U postgres -h 127.0.0.1 -p 5432 -f /data/appData/postgreSql/all_DB.sql # Out of Service bash /data/app/postgreSql/scripts/postgreSql stop # Backup file cd /data/app cp -arp /data/app/postgreSql /data/app/backup/ cp -arp /data/appData/postgreSql /data/appData/backup/ # Create master-slave synchronization user create role repl login replication encrypted password '123456';
2.3 pg_hba.conf To configure
# Add slave network segment echo "host replication repl Slave Library ip/24 md5" >> /data/appData/postgreSql/pg_hba.conf
2.4 postgresql.conf To configure
vim /data/appData/postgreSql/postgresql.conf listen_addresses = '*' # To monitor all ip wal_level = hot_standby # Hot standby mode archive_mode = on # Allow archiving archive_command = 'cp %p /data/appData/postgreSql/pg_archive/xlog_files/%f' # This directory needs to be created max_wal_senders = 32 # Maximum number of processes synchronized wal_sender_timeout = 60s # The timeout time for the stream replication host to send data max_connections = 200 # maximum connection , From library max_connections It must be larger than the main warehouse
2.5 Restart the main library
/data/app/postgreSql/bin/pg_ctl restart -D /data/appData/postgreSql/
3. Operation from database
3.1 Installation services
# decompression postgresql package tar -xf postgreSql.tar.gz -C /data/app/ # Create directory mkdir -pv /data/appData/postgreSql mkdir -pv /data/logs/postgreSql
Note that the slave library does not need the initialization steps in the master library installation process , Use pg_basebackup Command to synchronize data from the main library
# Synchronize data from the master database /data/app/postgreSql/bin/pg_basebackup -h Main library ip -p 5432 -U repl -F p -P -D /data/appData/postgreSql # Input repl User password :123456
Parameter description :
-h Specify the hostname of the connected database or IP Address
-U Specify the user name of the connection
-F Specifies the output format , Support p( Original output ) perhaps t(tar Format output ).
-P Indicates that it is allowed to print the backup progress in real time during the backup process .
-D Specify which directory to write the backup to , Must be an empty directory
3.2 postgresql.conf To configure
from PostgreSQL 12 The beginning has been removed recovery.conf file , Related configurations are merged into postgresql.conf in , Because of configuration postgresql.conf It is synchronized from the main database , Here you need to modify some configurations , Change the configuration of the slave Library .
vim /data/appData/postgreSql/postgresql.conf ## Remove or comment wal_level, This configuration is not required from the Library # wal_level = hot_standby ## Modify or add the following max_standby_streaming_delay=30s # Optional , Maximum delay for stream replication wal_receiver_status_interval=10s # Optional , The maximum interval between reporting status to the main library hot_standby_feedback=on # Optional , Feed back to the main database when querying conflicts max_connections=1000 # The maximum number of connections is generally greater than the main database primary_conninfo = 'host=172.16.98.200 port=5432 user=repl password=123456' # Indicates the main database connection information recovery_target_timeline = 'latest' # It means to recover the latest data
3.3 establish standby.signal
establish standby.signal file , Declare from library
echo "standby_mode = on" >> /data/appData/postgreSql/standby.signal
3.4 Start from library
/data/app/postgreSql/bin/pg_ctl start -D /data/appData/postgreSql/
4. Verify master-slave synchronization
4.1 Main database verification method
4.1.1 Check the process
ps aux |grep "sender"|grep -v "grep" # return postgres: walsender repl 172.16.98.201(53768) streaming
4.1.2 Check the table to verify
# Log in to the main library /data/app/postgreSql/bin/psql -h 127.0.0.1 -p 5432 -U postgres # perform select postgres=# select pid,application_name,state,client_addr,sync_priority,sync_state from pg_stat_replication; # return async
4.2 Verify from library
ps aux |grep "receiver" |grep -v "grep" # return postgres: walreceiver streaming
边栏推荐
- ES6 what amazing writing methods have you used
- R language test sample proportion: use prop The test function performs the single sample proportion test to calculate the confidence interval of the p value of the successful sample proportion in the
- POJ3259虫洞题解
- 《机器学习》(周志华) 第6章 支持向量 学习心得 笔记
- [security] read rfc6749 and understand the authorization code mode under oauth2.0
- R语言因子数据的表格和列联表(交叉表)生成:使用summay函数分析列表查看卡方检验结果判断两个因子变量是否独立(使用卡方检验验证独立性)
- Remember to use pdfbox once to parse PDF and obtain the key data of PDF
- RSA用私钥加密数据公钥解密数据(不是签名验证过程)
- Understanding of stack and practical application scenarios
- To build agile teams, these methods are indispensable
猜你喜欢
随机推荐
R language uses LM function to build linear regression model and subset function to specify subset of data set to build regression model (use floor function and length function to select the former pa
R语言因子数据的表格和列联表(交叉表)生成:使用summay函数分析列表查看卡方检验结果判断两个因子变量是否独立(使用卡方检验验证独立性)
修订版 | 目标检测:速度和准确性比较(Faster R-CNN,R-FCN,SSD,FPN,RetinaNet和YOLOv3)...
Do you really know esmodule
Thoroughly master binary search
【LVGL事件(Events)】事件代码
Uva1599 ideal path problem solution
A label_ File download (download attribute)
regular expression
30 day question brushing plan (IV)
Using fail2ban to protect web servers from DDoS Attacks
《机器学习》(周志华) 第6章 支持向量 学习心得 笔记
Socket类关于TCP字符流编程的理解学习
POJ3259虫洞题解
DXF reading and writing: align the calculation of the position of the dimension text in the middle and above
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize violin diagrams, set the palette parameter, and customize the border colors of violin diagrams at different l
正则表达式
30 day question brushing plan (III)
作为一个程序员,如何高效的管理时间?
URL related knowledge points









