PostgreSQL的一主两从集群搭建部署 (两同步)
一、实验环境
虚拟机名 | IP | 身份 | 简称 |
---|---|---|---|
keep-postgres12-node1 | 192.168.122.87 | 主节点 | node1 |
keep-postgres12-node2 | 192.168.122.89 | 备节点 | node2 |
keep-postgres12-node3 | 192.168.122.90 | 备节点 | node3 |
二、安装数据库
源码包方式(主)
1、创建用户
[root@keep-postgres12-node1 ~]# groupadd postgres
[root@keep-postgres12-node1 ~]# useradd -g postgres postgres -m -s /bin/bash
[root@keep-postgres12-node1 ~]# echo "Database@123" | passwd --stdin postgres
2、修改服务器内核信息
[root@keep-postgres12-node1 ~]# echo '# 最大共享内存段大小 (默认值68719476736)
kernel.shmmax = 68719476736
# 可以使用的共享内存的总量 (默认值4294967296)
kernel.shmall = 4294967296
# 整个系统共享内存段的最大数目
kernel.shmmni = 4096
# 每个信号对象集的最大信号对象数
kernel.sem = 50100 64128000 50100 1280
# 文件句柄的最大数量
fs.file-max = 7672460
# 应用程序可使用的IPv4端口范围
net.ipv4.ip_local_port_range = 9000 65000
# 套接字接收缓冲区大小的缺省值
net.core.rmem_default = 1048576
# 套接字发送缓冲区大小的缺省值
net.core.wmem_default = 262144
# 套接字发送缓冲区大小的最大值
net.core.wmem_max = 1048576' >> /etc/sysctl.conf# 使参数生效
[root@keep-postgres12-node1 ~]# sysctl -p
3、安装依赖包
[root@keep-postgres12-node1 ~]# yum install gcc gcc-c++ zlib-devel readline-devel perl-ExtUtils-Embed pam-devel openssl openssl-devel cmake libxslt-devel libxml2-devel openldap-devel python-devel tcl tcl-devel bison flex xmlto -y
4、创建数据库目录
[root@keep-postgres12-node1 ~]# mkdir /data
[root@keep-postgres12-node1 ~]# mkdir /data/postgres12.2
[root@keep-postgres12-node1 ~]# chown -R postgres: /data
5、创建环境变量
[root@keep-postgres12-node1 ~]# su - postgres
[postgres@keep-postgres12-node1 ~]$ echo 'export PGPORT=5432
export PG_HOME=/data/postgres12.2
export PATH=$PG_HOME/bin:$PATH
export PGDATA=$PG_HOME/data
export LD_LIBRARY_PATH=$PG_HOME/lib
export LANG=en_US.utf8' >> ~/.bash_profile && source ~/.bash_profile
6、下载源码包,并解压
链接1:https://ftp.postgresql.org/pub/source
链接2:https://www.postgresql.org/ftp/source/
# 安装postgresql-12.2版本
# 下载postgresql-12.2源码包
[postgres@keep-postgres12-node1 ~]$ cd /data
[postgres@keep-postgres12-node1 data]$ wget https://ftp.postgresql.org/pub/source/v12.2/postgresql-12.2.tar.bz2
# 解压源码包
[postgres@keep-postgres12-node1 data]$ tar -xf postgresql-12.2.tar.bz2
7、编译源码包
[postgres@keep-postgres12-node1 postgresql-12.2]$ ./configure --prefix=/data/postgres12.2 --with-pgport=5432 --with-openssl --with-perl \
--with-tcl --with-python --with-pam --without-ldap --with-libxml --with-libxslt \
--enable-thread-safety --with-wal-blocksize=16 --with-blocksize=8
# 包括第三方插件全部编译,包含文档和所有的contirb
[postgres@keep-postgres12-node1 postgresql-12.2]$ gmake world
8、安装数据库
[postgres@keep-postgres12-node1 postgresql-12.2]$ make && make install
9、配置wal日志目录
[postgres@keep-postgres12-node1 postgresql-12.2]$ # 用于保存wal日志
[postgres@keep-postgres12-node1 postgresql-12.2]$ mkdir $PG_HOME/arch
10、初始化数据库
[postgres@keep-postgres12-node1 postgresql-12.2]$ # 创建目录
[postgres@keep-postgres12-node1 postgresql-12.2]$ mkdir $PG_HOME/data
[postgres@keep-postgres12-node1 postgresql-12.2]$ # 初始化数据库集簇
[postgres@keep-postgres12-node1 postgresql-12.2]$ # --data-checksums 主从复制时需要
[postgres@keep-postgres12-node1 postgresql-12.2]$ initdb -D $PGDATA -W --data-checksums
11、启动数据库
[postgres@keep-postgres12-node1 postgresql-12.2]$ pg_ctl -D $PGDATA start
12、创建数据库用户和数据库
[postgres@keep-postgres12-node1 data]$ psql -d postgres -p 5432
postgres=# create database testdb;
postgres=# create user keep with Superuser password 'keep';
13、配置远程连接
# 配置连接
[postgres@keep-postgres12-node1 data]$ cd $PGDATA
[postgres@keep-postgres12-node1 data]$ sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" postgresql.conf
[postgres@keep-postgres12-node1 data]$ echo 'host all all 0.0.0.0/0 md5' >> pg_hba.conf
# 重启数据库
[postgres@keep-postgres12-node1 data]$ pg_ctl stop
[postgres@keep-postgres12-node1 data]$ pg_ctl -D $PGDATA start
# 验证远程连接
[postgres@keep-postgres12-node1 data]$ psql -d testdb -U keep -p 5432 -h 192.168.140.96
14、配置数据库日志
[postgres@keep-postgres12-node1 data]$ echo "# Add settings for extensions here
log_destination='csvlog'
logging_collector=on
log_directory='pg_log'
log_filename='postgresql-%Y-%m-%d.log'
log_truncate_on_rotation=off
log_rotation_age=1d
log_rotation_size=0
log_error_verbosity=verbose" >> $PGDATA/postgresql.conf
源码包方式(备 node2/node3)
1、创建用户
[root@keep-postgres12-node2 ~]# groupadd postgres
[root@keep-postgres12-node2 ~]# useradd -g postgres postgres -m -s /bin/bash
[root@keep-postgres12-node2 ~]# echo "Database@123" | passwd --stdin postgres
2、修改服务器内核信息
[root@keep-postgres12-node2 ~]# echo '# 最大共享内存段大小 (默认值68719476736)
kernel.shmmax = 68719476736
# 可以使用的共享内存的总量 (默认值4294967296)
kernel.shmall = 4294967296
# 整个系统共享内存段的最大数目
kernel.shmmni = 4096
# 每个信号对象集的最大信号对象数
kernel.sem = 50100 64128000 50100 1280
# 文件句柄的最大数量
fs.file-max = 7672460
# 应用程序可使用的IPv4端口范围
net.ipv4.ip_local_port_range = 9000 65000
# 套接字接收缓冲区大小的缺省值
net.core.rmem_default = 1048576
# 套接字发送缓冲区大小的缺省值
net.core.wmem_default = 262144
# 套接字发送缓冲区大小的最大值
net.core.wmem_max = 1048576' >> /etc/sysctl.conf# 使参数生效
[root@keep-postgres12-node2 ~]# sysctl -p
3、安装依赖包
[root@keep-postgres12-node2 ~]# yum install gcc gcc-c++ zlib-devel readline-devel perl-ExtUtils-Embed pam-devel openssl openssl-devel cmake libxslt-devel libxml2-devel openldap-devel python-devel tcl tcl-devel bison flex xmlto -y
4、创建数据库目录
[root@keep-postgres12-node2 ~]# mkdir /data
[root@keep-postgres12-node2 ~]# mkdir /data/postgres12.2
[root@keep-postgres12-node2 ~]# chown -R postgres: /data
5、创建环境变量
[root@keep-postgres12-node2 ~]# su - postgres
[postgres@keep-postgres12-node2 ~]$ echo 'export PGPORT=5432
export PG_HOME=/data/postgres12.2
export PATH=$PG_HOME/bin:$PATH
export PGDATA=$PG_HOME/data
export LD_LIBRARY_PATH=$PG_HOME/lib
export LANG=en_US.utf8' >> ~/.bash_profile && source ~/.bash_profile
6、下载源码包,并解压
链接1:https://ftp.postgresql.org/pub/source
链接2:https://www.postgresql.org/ftp/source/
# 安装postgresql-12.2版本
# 下载postgresql-12.2源码包
[postgres@keep-postgres12-node2 ~]$ cd /data
[postgres@keep-postgres12-node2 data]$ wget https://ftp.postgresql.org/pub/source/v12.2/postgresql-12.2.tar.bz2
# 解压源码包
[postgres@keep-postgres12-node2 data]$ tar -xf postgresql-12.2.tar.bz2
7、编译源码包
[postgres@keep-postgres12-node2 postgresql-12.2]$ ./configure --prefix=/data/postgres12.2 --with-pgport=5432 --with-openssl --with-perl \
--with-tcl --with-python --with-pam --without-ldap --with-libxml --with-libxslt \
--enable-thread-safety --with-wal-blocksize=16 --with-blocksize=8
# 包括第三方插件全部编译,包含文档和所有的contirb
[postgres@keep-postgres12-node2 postgresql-12.2]$ gmake world
8、安装数据库
[postgres@keep-postgres12-node2 postgresql-12.2]$ make && make install
9、配置wal日志目录
[postgres@keep-postgres12-node1 postgresql-12.2]$ # 用于保存wal日志
[postgres@keep-postgres12-node1 postgresql-12.2]$ mkdir $PG_HOME/arch
配置互信
1、配置主机名
# keep-postgres12-node1
[root@keep-postgres12-node1 ~]# echo '192.168.122.87 keep-postgres12-node1
192.168.122.88 keep-postgres12-node2
192.168.122.90 keep-postgres12-node3' >> /etc/hosts# keep-postgres12-node2
[root@keep-postgres12-node2 ~]# echo '192.168.122.87 keep-postgres12-node1
192.168.122.88 keep-postgres12-node2
192.168.122.90 keep-postgres12-node3' >> /etc/hosts# keep-postgres12-node3
[root@keep-postgres12-node3 ~]# echo '192.168.122.87 keep-postgres12-node1
192.168.122.88 keep-postgres12-node2
192.168.122.90 keep-postgres12-node3' >> /etc/hosts
2、配置postgres用户互信
# keep-postgres12-node1
[postgres@keep-postgres12-node1 ~]$ ssh-keygen
[postgres@keep-postgres12-node1 ~]$ ssh-copy-id keep-postgres12-node1
[postgres@keep-postgres12-node1 ~]$ ssh-copy-id keep-postgres12-node2
[postgres@keep-postgres12-node1 ~]$ ssh-copy-id keep-postgres12-node3# 验证
[postgres@keep-postgres12-node1 ~]$ ssh keep-postgres12-node1
[postgres@keep-postgres12-node1 ~]$ ssh keep-postgres12-node2
[postgres@keep-postgres12-node1 ~]$ ssh keep-postgres12-node3
# keep-postgres12-node2
[postgres@keep-postgres12-node2 ~]$ ssh-keygen
[postgres@keep-postgres12-node2 ~]$ ssh-copy-id keep-postgres12-node1
[postgres@keep-postgres12-node2 ~]$ ssh-copy-id keep-postgres12-node2
[postgres@keep-postgres12-node2 ~]$ ssh-copy-id keep-postgres12-node3# 验证
[postgres@keep-postgres12-node2 ~]$ ssh keep-postgres12-node1
[postgres@keep-postgres12-node2 ~]$ ssh keep-postgres12-node2
[postgres@keep-postgres12-node2 ~]$ ssh keep-postgres12-node3
# keep-postgres12-node3
[postgres@keep-postgres12-node3 ~]$ ssh-keygen
[postgres@keep-postgres12-node3 ~]$ ssh-copy-id keep-postgres12-node1
[postgres@keep-postgres12-node3 ~]$ ssh-copy-id keep-postgres12-node2
[postgres@keep-postgres12-node3 ~]$ ssh-copy-id keep-postgres12-node3# 验证
[postgres@keep-postgres12-node3 ~]$ ssh keep-postgres12-node1
[postgres@keep-postgres12-node3 ~]$ ssh keep-postgres12-node2
[postgres@keep-postgres12-node3 ~]$ ssh keep-postgres12-node3
三、修改主节点配置
1、创建同步用户
# 数据库需要在线状态
[postgres@keep-postgres12-node1 ~]$ psql -c "create role replrole login replication encrypted password 'ReplRole@123';"
2、配置$PGDATA/pg_hba.conf
[postgres@keep-postgres12-node1 ~]$ echo 'host replication replrole keep-postgres12-node1 trust
host replication replrole keep-postgres12-node2 trust
host replication replrole keep-postgres12-node3 trust
' >> $PGDATA/pg_hba.conf
3、修改数据库参数
[postgres@keep-postgres12-node1 ~]$ echo "wal_level = replica
max_wal_senders=20
wal_keep_segments =64
# 开启归档
archive_mode = on
archive_command = 'cp %p /data/postgres12.2/arch/%f'
restore_command = 'cp /data/postgres12.2/arch/%f %p'
recovery_target_timeline = 'latest'
# full_page_writes是控制是否开启全页写入
full_page_writes = on
# 将每个磁盘页的全部内容写入到WAL
wal_log_hints = on
# 配置同步,此时pg2的优先级比pg3的要高
# 一个节点的sync_state为sync,剩下的是potential
synchronous_standby_names = 'standby_pg2,standby_pg3'
# 默认值为 on
# 可以设置为remote_write,对主库性能有利
# 开启同步模式,此刻需要强同步,数据无法入库
synchronous_commit = on
" >> $PGDATA/postgresql.conf
4、重启数据库
[postgres@keep-postgres12-node1 ~]$ pg_ctl restart
5、synchronous_standby_names参数详解
# 该参数指定流复制中需要同步复制的服务器列表,需要配置standby服务器的名字
# 情况一:(无顺序要求)
# 只有这三台备机会被选为同步备机,即其中一个会被选为活动的同步备机,其余两台将处于备用状态。
synchronous_standby_names = 'standby_pg1,standby_pg2,standby_pg3'# 设置WAL日志强同步至N个节点中的某M个节点
# 情况二:(无顺序要求)
# 只有这三台备机会被选为同步备机,即其中一个会被选为活动的同步备机,其余两台将处于备用状态。
synchronous_standby_names = 'ANY 1 (standby_pg1,standby_pg2,standby_pg3)'# 情况三:(无顺序要求)
# 只有这三台备机会被选为同步备机,即其中两个会被选为活动的同步备机,其余一台将处于备用状态。
synchronous_standby_names = 'ANY 2 (standby_pg1,standby_pg2,standby_pg3)'# 情况四:(按照指定节点的顺序)
# 从括号中列出的备机中按顺序选择前两台作为同步备机,选择不了两台节点时,则会无法操作。
synchronous_standby_names = 'FIRST 2 (standby_pg1,standby_pg2,standby_pg3)'
四、修改备节点配置
node2 配置
1、进行数据恢复
[postgres@keep-postgres12-node2 ~]$ pg_basebackup -h keep-postgres12-node1 -p 5432 -U replrole -R -F p -P -D $PG_HOME/data
2、修改standby.signal配置
[postgres@keep-postgres12-node2 data]$ cd $PGDATA
[postgres@keep-postgres12-node2 data]$ cat standby.signal
primary_conninfo = 'host=keep-postgres12-node1 port=5432 user=replrole password=ReplRole@123 application_name=standby_pg2 options=''-c wal_sender_timeout=5000'''
restore_command = 'cp /data/postgres12.2/arch/%f %p'
archive_cleanup_command = 'pg_archivecleanup /data/postgres12.2/arch %r'
standby_mode = on
3、修改postgresql.auto.conf配置
# 注意:强同步需要注意在postgresql.auto.conf中加入application_name=standby_pg2
[postgres@keep-postgres12-node2 data]$ cat postgresql.auto.conf
primary_conninfo = 'user=replrole passfile=''/home/postgres/.pgpass'' host=''keep-postgres12-node1'' application_name=standby_pg2 port=5432 sslmode=prefer sslcompression=0 gssencmode=disable krbsrvname=postgres target_session_attrs=any'
node3 配置
1、进行数据恢复
[postgres@keep-postgres12-node3 ~]$ pg_basebackup -h keep-postgres12-node1 -p 5432 -U replrole -R -F p -P -D $PG_HOME/data
2、修改standby.signal配置
[postgres@keep-postgres12-node3 data]$ cd $PGDATA
[postgres@keep-postgres12-node3 data]$ cat standby.signal
primary_conninfo = 'host=keep-postgres12-node1 port=5432 user=replrole password=ReplRole@123 application_name=standby_pg3 options=''-c wal_sender_timeout=5000'''
restore_command = 'cp /data/postgres12.2/arch/%f %p'
archive_cleanup_command = 'pg_archivecleanup /data/postgres12.2/arch %r'
standby_mode = on
3、修改postgresql.auto.conf配置
# 注意:强同步需要注意在postgresql.auto.conf中加入application_name=standby_pg3
[postgres@keep-postgres12-node3 data]$ cat postgresql.auto.conf
primary_conninfo = 'user=replrole passfile=''/home/postgres/.pgpass'' host=''keep-postgres12-node1'' application_name=standby_pg3 port=5432 sslmode=prefer sslcompression=0 gssencmode=disable krbsrvname=postgres target_session_attrs=any'
五、启动数据同步
# 注意:主库修改synchronous_standby_names = ‘standby_pg2’ 后,需等待备库接收主库发送的WAL日志流并写入WAL文件,之后才向客户端返回成功。
1、主库检查点
[postgres@keep-postgres12-node1 ~]$ pg_controldata
pg_control version number: 1201
Catalog version number: 201909212
Database system identifier: 7435168474920575893
Database cluster state: `in production`
pg_control last modified: Tue 10 Dec 2024 04:23:13 PM CST
Latest checkpoint location: 0/2E000060
Latest checkpoint's REDO location: 0/2E000028
Latest checkpoint's REDO WAL file: 00000007000000000000002E
Latest checkpoint's TimeLineID: 7
Latest checkpoint's PrevTimeLineID: 7
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0:640
Latest checkpoint's NextOID: 24913
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 0
Latest checkpoint's oldestXID: 480
Latest checkpoint's oldestXID's DB: 1
Latest checkpoint's oldestActiveXID: 640
Latest checkpoint's oldestMultiXid: 1
Latest checkpoint's oldestMulti's DB: 1
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: Tue 10 Dec 2024 04:23:13 PM CST
Fake LSN counter for unlogged rels: 0/3E8
Minimum recovery ending location: 0/0
Min recovery ending loc's timeline: 0
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: replica
wal_log_hints setting: on
max_connections setting: 100
max_worker_processes setting: 8
max_wal_senders setting: 20
max_prepared_xacts setting: 0
max_locks_per_xact setting: 64
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 16384
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
Data page checksum version: 1
Mock authentication nonce: 2fd610c9c82cf604c47448c0e7c842aa9ac4944e8fea828fcc0d2425b6f3a6e4
2、启动备库
node2
[postgres@keep-postgres12-node2 data]$ pg_ctl start
node3
[postgres@keep-postgres12-node3 data]$ pg_ctl start
3、查看备库日志
node2
[postgres@keep-postgres12-node2 pg_log]$ tail -f postgresql-2024-12-10.csv2024-12-10 16:20:45.667 CST,,,24030,,6757f9dd.5dde,1,,2024-12-10 16:20:45 CST,,0,LOG,00000,"ending log output to stderr",,"Future log output will go to log destination ""csvlog"".",,,,,,"PostmasterMain, postmaster.c:1300",""
2024-12-10 16:20:45.672 CST,,,24032,,6757f9dd.5de0,1,,2024-12-10 16:20:45 CST,,0,LOG,00000,"database system was interrupted; last known up at 2024-12-10 16:13:44 CST",,,,,,,,"StartupXLOG, xlog.c:6269",""
2024-12-10 16:20:45.894 CST,,,24032,,6757f9dd.5de0,2,,2024-12-10 16:20:45 CST,,0,LOG,00000,"entering standby mode",,,,,,,,"StartupXLOG, xlog.c:6324",""
2024-12-10 16:20:45.906 CST,,,24032,,6757f9dd.5de0,3,,2024-12-10 16:20:45 CST,1/0,0,LOG,00000,"redo starts at 0/2B000060",,,,,,,,"StartupXLOG, xlog.c:7037",""
2024-12-10 16:20:45.907 CST,,,24032,,6757f9dd.5de0,4,,2024-12-10 16:20:45 CST,1/0,0,LOG,00000,"consistent recovery state reached at 0/2B000138",,,,,,,,"CheckRecoveryConsistency, xlog.c:7880",""
2024-12-10 16:20:45.908 CST,,,24030,,6757f9dd.5dde,2,,2024-12-10 16:20:45 CST,,0,LOG,00000,"database system is ready to accept read only connections",,,,,,,,"sigusr1_handler, postmaster.c:5153",""
2024-12-10 16:20:45.923 CST,,,24046,,6757f9dd.5dee,1,,2024-12-10 16:20:45 CST,,0,LOG,00000,"started streaming WAL from primary at 0/2C000000 on timeline 7",,,,,,,,"WalReceiverMain, walreceiver.c:371",""
node3
[postgres@keep-postgres12-node3 pg_log]$ tail -f postgresql-2024-12-10.csv2024-12-10 16:24:45.339 CST,,,25094,,6757facd.6206,1,,2024-12-10 16:24:45 CST,,0,LOG,00000,"ending log output to stderr",,"Future log output will go to log destination ""csvlog"".",,,,,,"PostmasterMain, postmaster.c:1300",""
2024-12-10 16:24:45.344 CST,,,25096,,6757facd.6208,1,,2024-12-10 16:24:45 CST,,0,LOG,00000,"database system was interrupted; last known up at 2024-12-10 16:23:13 CST",,,,,,,,"StartupXLOG, xlog.c:6269",""
2024-12-10 16:24:45.637 CST,,,25096,,6757facd.6208,2,,2024-12-10 16:24:45 CST,,0,LOG,00000,"entering standby mode",,,,,,,,"StartupXLOG, xlog.c:6324",""
2024-12-10 16:24:45.649 CST,,,25096,,6757facd.6208,3,,2024-12-10 16:24:45 CST,1/0,0,LOG,00000,"redo starts at 0/2E000028",,,,,,,,"StartupXLOG, xlog.c:7037",""
2024-12-10 16:24:45.651 CST,,,25096,,6757facd.6208,4,,2024-12-10 16:24:45 CST,1/0,0,LOG,00000,"consistent recovery state reached at 0/2E000100",,,,,,,,"CheckRecoveryConsistency, xlog.c:7880",""
2024-12-10 16:24:45.652 CST,,,25094,,6757facd.6206,2,,2024-12-10 16:24:45 CST,,0,LOG,00000,"database system is ready to accept read only connections",,,,,,,,"sigusr1_handler, postmaster.c:5153",""
2024-12-10 16:24:45.672 CST,,,25104,,6757facd.6210,1,,2024-12-10 16:24:45 CST,,0,LOG,00000,"started streaming WAL from primary at 0/2F000000 on timeline 7",,,,,,,,"WalReceiverMain, walreceiver.c:371",""
4、检查数据库进程
# keep-postgres12-node1
[postgres@keep-postgres12-node1 ~]$ ps -ef | grep postgres
postgres 26423 1 0 16:17 ? 00:00:00 /data/postgres12.2/bin/postgres
postgres 26424 26423 0 16:17 ? 00:00:00 postgres: logger
postgres 26426 26423 0 16:17 ? 00:00:00 postgres: checkpointer
postgres 26427 26423 0 16:17 ? 00:00:00 postgres: background writer
postgres 26428 26423 0 16:17 ? 00:00:00 postgres: walwriter
postgres 26429 26423 0 16:17 ? 00:00:00 postgres: autovacuum launcher
postgres 26430 26423 0 16:17 ? 00:00:00 postgres: archiver last was 00000007000000000000002E.00000028.backup
postgres 26431 26423 0 16:17 ? 00:00:00 postgres: stats collector
postgres 26432 26423 0 16:17 ? 00:00:00 postgres: logical replication launcher
postgres 27747 26423 0 16:20 ? 00:00:00` postgres: walsender replrole 192.168.122.89(54134) streaming 0/2F000148`
postgres 28509 26423 0 16:24 ? 00:00:00 `postgres: walsender replrole 192.168.122.90(62200) streaming 0/2F000148`# keep-postgres12-node2
[postgres@keep-postgres12-node2 data]$ ps -ef | grep postgres
postgres 24030 1 0 16:20 ? 00:00:00 /data/postgres12.2/bin/postgres
postgres 24031 24030 0 16:20 ? 00:00:00 postgres: logger
postgres 24032 24030 0 16:20 ? 00:00:00 postgres: startup recovering 00000007000000000000002F
postgres 24042 24030 0 16:20 ? 00:00:00 postgres: checkpointer
postgres 24043 24030 0 16:20 ? 00:00:00 postgres: background writer
postgres 24045 24030 0 16:20 ? 00:00:00 postgres: stats collector
postgres 24046 24030 0 16:20 ? 00:00:00 `postgres: walreceiver streaming 0/2F000148`# keep-postgres12-node3
[postgres@keep-postgres12-node3 data]$ ps -ef | grep postgres
postgres 25094 1 0 16:24 ? 00:00:00 /data/postgres12.2/bin/postgres
postgres 25095 25094 0 16:24 ? 00:00:00 postgres: logger
postgres 25096 25094 0 16:24 ? 00:00:00 postgres: startup recovering 00000007000000000000002F
postgres 25100 25094 0 16:24 ? 00:00:00 postgres: checkpointer
postgres 25101 25094 0 16:24 ? 00:00:00 postgres: background writer
postgres 25103 25094 0 16:24 ? 00:00:00 postgres: stats collector
postgres 25104 25094 0 16:24 ? 00:00:00 `postgres: walreceiver streaming 0/2F000148`
六、验证数据同步
1、主库检查同步状态
一节点sync_state 为sync,一节点为potential
[postgres@keep-postgres12-node1 data]$ psql
postgres=# \x
Expanded display is on.
postgres=# SELECT * FROM pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 27747
usesysid | 16642
usename | replrole
application_name | standby_pg2
client_addr | 192.168.122.89
client_hostname | keep-postgres12-node2
client_port | 54134
backend_start | 2024-12-10 16:20:45.918235+08
backend_xmin |
state | streaming
sent_lsn | 0/2F000148
write_lsn | 0/2F000148
flush_lsn | 0/2F000148
replay_lsn | 0/2F000148
write_lag |
flush_lag |
replay_lag |
sync_priority | 1
sync_state | sync
reply_time | 2024-12-10 16:36:26.891383+08
-[ RECORD 2 ]----+------------------------------
pid | 29698
usesysid | 16642
usename | replrole
application_name | standby_pg3
client_addr | 192.168.122.90
client_hostname | keep-postgres12-node3
client_port | 62202
backend_start | 2024-12-10 16:31:09.071909+08
backend_xmin |
state | streaming
sent_lsn | 0/2F000148
write_lsn | 0/2F000148
flush_lsn | 0/2F000148
replay_lsn | 0/2F000148
write_lag |
flush_lag |
replay_lag |
sync_priority | 2
sync_state | potential
reply_time | 2024-12-10 16:36:29.798595+08
2、测试数据同步
-- 主库执行
drop table if exists employees_multi_sync CASCADE;
CREATE TABLE employees_multi_sync (id SERIAL PRIMARY KEY,name VARCHAR(100),position VARCHAR(100),department VARCHAR(100),hire_date DATE
);INSERT INTO employees_multi_sync (name, position, department, hire_date)
SELECT 'Employee ' || (generate_series(1, 200))::text,'Position ' || (generate_series(1, 200))::text,'Department ' || (random() *(200-1)+1)::text,'2010-01-01'::date + (generate_series(1, 200) * interval '1 day');-- 备库查询数据
select count(1) from employees_multi_sync ;
-- 计算两边的md5值
SELECT md5(string_agg(id::text || '-' ||name || '-' ||position || '-' ||department || '-' ||TO_CHAR(hire_date, 'YYYY-MM-DD'),',')
) AS row_md5
FROM employees_multi_sync;
七、主备切换
1、停主库
[postgres@keep-postgres12-node1 ~]$ pg_ctl stop -m fast
2、主从切换
备库升主
# 切换之后,$PGDATA下原有的 standby.signal 文件不存在了
[postgres@keep-postgres12-node2 ~]$ pg_ctl promote
查看状态
[postgres@keep-postgres12-node2 ~]$ pg_controldata | grep -i cluster
Database cluster state: `in production`
3、检查原备库的配置(现主)
检查配置文件postgresql.auto.conf
[postgres@keep-postgres12-node2 data]$ cat postgresql.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
# 检查是否进行注释,配置还是当作备库,自相矛盾
# primary_conninfo = 'user=replrole passfile=''/home/postgres/.pgpass'' host=''keep-postgres12-node1'' application_name=standby_pg2 port=5432 sslmode=prefer sslcompression=0 gssencmode=disable krbsrvname=postgres target_session_attrs=any'
检查配置文件postgresql.conf
# 修改synchronous_standby_names
[postgres@keep-postgres12-node2 data]$ vim postgresql.conf
synchronous_standby_names = 'standby_pg1,standby_pg3'
检查状态
# 此处进程应为 walwriter,表示还是备机状态。若修改了postgresql.auto.conf,需重启数据库
[postgres@keep-postgres12-node2 data]$ ps -ef | grep postgres
postgres 25288 1 0 Dec02 ? 00:00:00 /data/postgres12.2/bin/postgres
postgres 25289 25288 0 Dec02 ? 00:00:00 postgres: logger
postgres 25294 25288 0 Dec02 ? 00:00:02 postgres: checkpointer
postgres 25295 25288 0 Dec02 ? 00:00:02 postgres: background writer
postgres 25296 25288 0 Dec02 ? 00:00:00 postgres: stats collector
postgres 29058 25288 0 16:11 ? 00:00:00 postgres: `walwriter`
postgres 29059 25288 0 16:11 ? 00:00:00 postgres: autovacuum launcher
postgres 29060 25288 0 16:11 ? 00:00:00 postgres: archiver last was 000000030000000000000020.partial
postgres 29061 25288 0 16:11 ? 00:00:00 postgres: logical replication launcher[postgres@keep-postgres12-node2 data]$ pg_ctl restart# 重启数据库后,备机状态为未连接,不会启动walsender
[postgres@keep-postgres12-node2 data]$ ps -ef | grep postgres
postgres 32261 1 0 16:20 ? 00:00:00 /data/postgres12.2/bin/postgres
postgres 32262 32261 0 16:20 ? 00:00:00 postgres: logger
postgres 32264 32261 0 16:20 ? 00:00:00 postgres: checkpointer
postgres 32265 32261 0 16:20 ? 00:00:00 postgres: background writer
postgres 32266 32261 0 16:20 ? 00:00:00 postgres: walwriter
postgres 32267 32261 0 16:20 ? 00:00:00 postgres: autovacuum launcher
postgres 32268 32261 0 16:20 ? 00:00:00 postgres: archiver
postgres 32269 32261 0 16:20 ? 00:00:00 postgres: stats collector
postgres 32270 32261 0 16:20 ? 00:00:00 postgres: logical replication launcher
4、备库配置standby.signal文件
node1
# standby.signal文件需要新建
[postgres@keep-postgres12-node1 data]$ cat standby.signal
# 添加以下内容
primary_conninfo = 'host=keep-postgres12-node2 port=5432 user=replrole password=ReplRole@123 application_name=standby_pg1 options=''-c wal_sender_timeout=5000'''
restore_command = 'cp /data/postgres12.2/arch/%f %p'
archive_cleanup_command = 'pg_archivecleanup /data/postgres12.2/arch %r'
standby_mode = on
node3
# standby.signal文件需要新建
[postgres@keep-postgres12-node1 data]$ cat standby.signal
# 修改host为keep-postgres12-node2
primary_conninfo = 'host=keep-postgres12-node2 port=5432 user=replrole password=ReplRole@123 application_name=standby_pg3 options=''-c wal_sender_timeout=5000'''
restore_command = 'cp /data/postgres12.2/arch/%f %p'
archive_cleanup_command = 'pg_archivecleanup /data/postgres12.2/arch %r'
standby_mode = on
5、备库修改配置文件postgresql.auto.conf
node1
[postgres@keep-postgres12-node1 data]$ cat postgresql.auto.conf
# 添加以下内容
primary_conninfo = 'user=replrole passfile=''/home/postgres/.pgpass'' host=''keep-postgres12-node2'' application_name=standby_pg2 port=5432 sslmode=prefer sslcompression=0 gssencmode=disable krbsrvname=postgres target_session_attrs=any'
node3
[postgres@keep-postgres12-node1 data]$ cat postgresql.auto.conf
# 修改host为keep-postgres12-node2
primary_conninfo = 'user=replrole passfile=''/home/postgres/.pgpass'' host=''keep-postgres12-node2'' application_name=standby_pg3 port=5432 sslmode=prefer sslcompression=0 gssencmode=disable krbsrvname=postgres target_session_attrs=any'
6、启动备库
node1
[postgres@keep-postgres12-node1 data]$ pg_ctl restart
node3
[postgres@keep-postgres12-node3 data]$ pg_ctl restart
7、检查数据库进程
# 备库 node1
[postgres@keep-postgres12-node1 ~]$ ps -ef | grep postgres
postgres 440 1 0 16:52 ? 00:00:00 /data/postgres12.2/bin/postgres
postgres 441 440 0 16:52 ? 00:00:00 postgres: logger
postgres 442 440 0 16:52 ? 00:00:00 postgres: startup recovering 000000080000000000000032
postgres 446 440 0 16:52 ? 00:00:00 postgres: checkpointer
postgres 447 440 0 16:52 ? 00:00:00 postgres: background writer
postgres 448 440 0 16:52 ? 00:00:00 postgres: stats collector
postgres 449 440 0 16:52 ? 00:00:00 `postgres: walreceiver streaming 0/320001C0`# 主库
[postgres@keep-postgres12-node2 ~]$ ps -ef | grep postgres
postgres 25853 1 0 16:47 ? 00:00:00 /data/postgres12.2/bin/postgres
postgres 25854 25853 0 16:47 ? 00:00:00 postgres: logger
postgres 25856 25853 0 16:47 ? 00:00:00 postgres: checkpointer
postgres 25857 25853 0 16:47 ? 00:00:00 postgres: background writer
postgres 25858 25853 0 16:47 ? 00:00:00 postgres: walwriter
postgres 25859 25853 0 16:47 ? 00:00:00 postgres: autovacuum launcher
postgres 25860 25853 0 16:47 ? 00:00:00 postgres: archiver
postgres 25861 25853 0 16:47 ? 00:00:00 postgres: stats collector
postgres 25862 25853 0 16:47 ? 00:00:00 postgres: logical replication launcher
postgres 26311 25853 0 16:52 ? 00:00:00 `postgres: walsender replrole 192.168.122.90(16994) streaming 0/320001C0`
postgres 26312 25853 0 16:52 ? 00:00:00 `postgres: walsender replrole 192.168.122.87(18939) streaming 0/320001C0`# 备库 node3
[postgres@keep-postgres12-node3 ~]$ ps -ef | grep postgres
postgres 31097 1 0 16:52 ? 00:00:00 /data/postgres12.2/bin/postgres
postgres 31098 31097 0 16:52 ? 00:00:00 postgres: logger
postgres 31099 31097 0 16:52 ? 00:00:00 postgres: startup recovering 000000080000000000000032
postgres 31103 31097 0 16:52 ? 00:00:00 postgres: checkpointer
postgres 31104 31097 0 16:52 ? 00:00:00 postgres: background writer
postgres 31105 31097 0 16:52 ? 00:00:00 postgres: stats collector
postgres 31106 31097 0 16:52 ? 00:00:00 `postgres: walreceiver streaming 0/320001C0`
8、检查同步状态
[postgres@keep-postgres12-node2 ~]$ psql
postgres=# \x
Expanded display is on.
postgres=# SELECT * FROM pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 26311
usesysid | 16642
usename | replrole
application_name | standby_pg3
client_addr | 192.168.122.90
client_hostname | keep-postgres12-node3
client_port | 16994
backend_start | 2024-12-10 16:52:56.465729+08
backend_xmin |
state | streaming
sent_lsn | 0/32036768
write_lsn | 0/32036768
flush_lsn | 0/32036768
replay_lsn | 0/32036768
write_lag |
flush_lag |
replay_lag |
sync_priority | 2
sync_state | potential
reply_time | 2024-12-10 16:56:27.053456+08
-[ RECORD 2 ]----+------------------------------
pid | 26312
usesysid | 16642
usename | replrole
application_name | standby_pg1
client_addr | 192.168.122.87
client_hostname | keep-postgres12-node1
client_port | 18939
backend_start | 2024-12-10 16:52:58.753138+08
backend_xmin |
state | streaming
sent_lsn | 0/32036768
write_lsn | 0/32036768
flush_lsn | 0/32036768
replay_lsn | 0/32036768
write_lag |
flush_lag |
replay_lag |
sync_priority | 1
sync_state | sync
reply_time | 2024-12-10 16:56:27.047169+08
9、验证是否同步
-- 主库执行
drop table if exists employees_multi_sync1 CASCADE;
CREATE TABLE employees_multi_sync1 (id SERIAL PRIMARY KEY,name VARCHAR(100),position VARCHAR(100),department VARCHAR(100),hire_date DATE
);INSERT INTO employees_multi_sync1 (name, position, department, hire_date)
SELECT 'Employee ' || (generate_series(1, 200))::text,'Position ' || (generate_series(1, 200))::text,'Department ' || (random() *(200-1)+1)::text,'2010-01-01'::date + (generate_series(1, 200) * interval '1 day');-- 备库查询数据
select count(1) from employees_multi_sync1 ;
-- 计算两边的md5值
SELECT md5(string_agg(id::text || '-' ||name || '-' ||position || '-' ||department || '-' ||TO_CHAR(hire_date, 'YYYY-MM-DD'),',')
) AS row_md5
FROM employees_multi_sync1;
八、pg_rewind 工具
当主备集群中的备库意外崩溃,且经过长时间,归档日志又被删除了,需要把这段时间的增量数据同步回来,那么就可以用 到pg_rewind 工具进行同步。pg_rewind 使一个PostgreSQL 数据目录与另一个数据目录一致。
[postgres@keep-postgres12-node1 ~]$ pg_rewind --target-pgdata $PGDATA --source-server='host=keep-postgres12-node2 port=5432 user=keep password=keep dbname=postgres' -P
pg_rewind帮助命令
[postgres@keep-postgres12-node1 ~]$ pg_rewind --help
pg_rewind resynchronizes a PostgreSQL cluster with another copy of the cluster.Usage:pg_rewind [OPTION]...Options:-D, --target-pgdata=DIRECTORY existing data directory to modify--source-pgdata=DIRECTORY source data directory to synchronize with--source-server=CONNSTR source server to synchronize with-n, --dry-run stop before modifying anything-N, --no-sync do not wait for changes to be writtensafely to disk-P, --progress write progress messages--debug write a lot of debug messages-V, --version output version information, then exit-?, --help show this help, then exit
相关文章:
PostgreSQL的一主两从集群搭建部署 (两同步)
一、实验环境 虚拟机名IP身份简称keep-postgres12-node1192.168.122.87主节点node1keep-postgres12-node2192.168.122.89备节点node2keep-postgres12-node3192.168.122.90备节点node3 二、安装数据库 源码包方式(主) 1、创建用户 [rootkeep-postgre…...
CPT203 Software Engineering 软件工程 Pt.5 软件测试(中英双语)
文章目录 8. 软件测试8.1 Testing(测试)8.1.1 A note of testing under the V & A framework8.1.2 The Basics8.1.3 The Goals8.1.4 The Stages 8.2 Developing testing(开发测试)8.2.1 Unit testing(单元测试&…...
在 Blazor 和 ASP.NET Core 中使用依赖注入和Scoped 服务实现数据共享方法详解
依赖注入(Dependency Injection,简称 DI)是一种设计模式,用于将对象的依赖关系从对象内部解耦出来,由外部容器进行管理和提供。在 Blazor 和 ASP.NET Core 中,DI 是内置的核心功能,它通过服务生…...
【信号滤波 (下)】采样条件,多种滤波算法对比(Matlab/C++)
目录 一、信号采样条件采样定理ADC的SPS设置 二、常用滤波算法对比A.滑动平均滤波B.陷波滤波陷波滤波器简介FIR(有限脉冲响应)滤波器和IIR(无限脉冲响应)滤波器 基于IIR实现陷波滤波滤波原理讲解双二阶滤波器计算过程陷波滤波优势 在上一篇中,介绍了信号时域到频域的…...
将广播发送和接收端实现一遍,完成一个发送端发送信息,对应多个接收端接收信息实验。
1、将广播发送和接收端实现一遍,完成一个发送端发送信息,对应多个接收端接收信息实验。 接受端 #include<myhead.h> #define handel_err(res,val) if(val-1){perror(res);return-1;} int main(int argc, const char *argv[]) {int rfdsocket(AF_…...
Nginx 负载均衡详解
一、Nginx 简介 Nginx 是一个高性能的开源 Web 服务器和反向代理服务器,以其轻量级、高并发、低内存消耗等特点著称。Nginx 不仅适用于静态资源的快速分发,还广泛应用于负载均衡、反向代理等场景。通过Nginx,可以轻松地构建一个高效、可靠且…...
自动驾驶新纪元:城区NOA功能如何成为智能驾驶技术的分水岭
目录 一、NOA 的定义 二、NOA 的主要特点 导航集成 场景覆盖 智能决策 高级感知能力 驾驶员参与 三、NOA 的优势 四、NOA的衡量指标 定性评价指标 安全性评价指标定义 可靠性评价指标定义 舒适性评价指标定义 通行效率评价指标 定量评价指标 五、代表厂商的实测…...
FFmpeg 编码和解码
文章目录 音频格式AACADIF音频数据交换格式ADTS音频数据传输流 音频解码音频编码 视频格式H264GOP图像组I帧,P帧,B帧H264压缩技术H264压缩级别H264视频级别H264码流结构SPSPPS 解码视频编码视频 音频格式 AAC AAC全称 Advanced Audio Coding࿰…...
【Ubuntu】Ubuntu server 18.04 搭建Slurm并行计算环境(包含NFS)
Ubuntu server 18.04 搭建Slurm并行计算环境(包含NFS) 一、Munge 认证模块 1.1、安装 munge 主节点和子节点都安装munge #安装 sudo apt update && sudo apt install munge libmunge-dev#设置开机启动 sudo systemctl enable munge sudo syste…...
WPF 绘制过顶点的圆滑曲线 (样条,贝塞尔)
在一个WPF项目中要用到样条曲线,必须过顶点,圆滑后还不能太走样,捣鼓一番,发现里面颇有玄机,于是把我多方抄来改造的方法发出来,方便新手: 如上图,看代码吧: ----------…...
Spring 的不同事务传播行为
目录 Spring 的不同事务传播行为 PROPAGATION_REQUIRES_NEW事务传播行为什么情况下会使用? 一、PROPAGATION_REQUIRES_NEW的含义 二、使用场景 三、注意事项 PROPAGATION_NESTED事务传播行为什么情况下会使用? 一、PROPAGATION_NESTED的含义 二、使用场景 三、嵌套事…...
PlantUML 时序图 基本例子
基本的例子 序列-> 用于绘制两个参与者之间的信息。参与者不必明确声明。 要有一个点状的箭头,就用--> 也可以用<- 和<-- 。这不会改变绘图,但可能提高可读性。注意,这只适用于顺序图,其他图的规则不同。 plantum…...
QILSTE H8-C414SY高亮黄光LED灯珠 发光二极管LED
在电子组件的复杂世界中,H8-C414SY型号的LED以其精确的技术参数和卓越的性能,成为了工程师和技术人员不可忽视的选择。本文将通过对这款高亮黄光LED的技术参数进行深入分析,增加文本的复杂性和突发性,以提供一份详尽的技术参考。 …...
git clone 和 conda 换源
文章目录 git clone 通过 sshconda 创建虚拟环境通过 env.yml 文件conda 换源 git clone 通过 ssh git clone ssh://用户名IP地址:/仓库名字.gitconda 创建虚拟环境通过 env.yml 文件 conda env create -f environment.ymlconda 换源 Step 1 生成 .bashrc 文件在家目录下。…...
Spring Boot 多数据源解决方案:dynamic-datasource-spring-boot-starter 的奥秘(下)
在上一篇博客《Spring Boot 多数据源解决方案:dynamic-datasource-spring-boot-starter 的奥秘》介绍了dynamic-datasource-spring-boot-starter的自动配置类和配置属性类之后,本文继续来剖析多数据源是如何切换的,什么时候切换的。 前文中提…...
移动 APP 设计规范参考
一、界面设计规范 布局原则: 内容优先:以内容为核心进行布局,突出用户需要的信息,简化页面导航,提升屏幕空间利用率.一致性:保持界面元素风格一致,包括颜色、字体、图标等,使用户在…...
yolov6算法及其改进
yolov6算法及其改进 1、YOLOV6简介2、RepVGG重参思想3、YOLOv6架构改进3.1、Backbone方面3.2、SPP改进3.3、Neck改进3.4、Head改进 4、正负样本匹配与损失函数4.1、TaskAligned样本匹配4.2、VFL Loss分类损失函数4.3、SIOU损失函数4.4、DFL损失函数 1、YOLOV6简介 YOLOv6设计主…...
java自定义注解对枚举类型参数的校验
目录 1.前提准备条件 1.1 pom.xml文件依赖: 1.2 枚举类: 1.3 controller接口: 1.4 实体参数: 1.5 knife4j的配置 2.实现要求 3.实现步骤 3.1 自定义注解类: 3.2 使用注解: 3.3 添加注解校验类: …...
K8S-LLM:用自然语言轻松操作 Kubernetes
在 Kubernetes (K8s) 的日常管理中,复杂的命令行操作常常让开发者感到头疼。无论是部署应用、管理资源还是调试问题,都需要记住大量的命令和参数。Kubernetes 作为容器编排的行业标准,其强大的功能伴随着陡峭的学习曲线和复杂的命令行操作。这…...
【GO基础学习】gin的使用
文章目录 模版使用流程参数传递路由分组数据解析和绑定gin中间件 模版使用流程 package mainimport ("net/http""github.com/gin-gonic/gin" )func main() {// 1.创建路由r : gin.Default()// 2.绑定路由规则,执行的函数// gin.Context&#x…...
【PCIe 总线及设备入门学习专栏 4.5 -- PCIe Message and PCIe MSI】
文章目录 PCIe Message 与 MSIPCIe Message 和 MSI 的作用与关系MSI 的配置与寄存器MSI 和 ARM GIC 的关系示例:MSI 在 ARM GIC 的实际应用总结 PCIe Message 与 MSI 本文将介绍 PCIe message 的作用以及message 与 MSI 的关系,再介绍 MSI 如何配置以及…...
sklearn_pandas.DataFrameMapper的用法
文章目录 介绍主要作用基本用法示例对不同列应用不同的转换器对多列应用相同的转换器输出为 Pandas DataFrame 注意事项转换器的适用性:输出格式:与 scikit-learn 的兼容性: 介绍 DataFrameMapper 是 sklearn-pandas 库中的一个工具…...
【2024年-7月-27日-开源社区openEuler实践记录】剖析 elease - management:优化软件发布流程的开源方案
开篇介绍 大家好,我是 fzr123,在软件开发流程管控领域探索许久,今天要给大家详细说说release - management这个极具价值的开源项目。在软件开发的生命周期里,发布管理至关重要,它关乎着软件能否稳定、高效且按时交付&…...
CPT203 Software Engineering 软件工程 Pt.1 概论和软件过程(中英双语)
文章目录 1.Introduction1.1 What software engineering is and why it is important(什么是软件工程,为什么它很重要)1.1 We can’t run the modern world without software(我们的世界离不开软件)1.1.1 What is Soft…...
Mysql数据库Redo日志和Undo日志的理解
数据库redo日志和undo日志 1、redo日志1.1 redo日志的作用1.1.1 不使用redo日志的问题1.1.2 使用redo日志的好处 1.2 redo日志刷盘策略 2、undo日志2.1 undo日志的作用2.2 undo日志的简要生成过程 1、redo日志 事务的4大特性(ACID):原子性、…...
大厂高频总线协议面试题及参考答案(几百家面试题挑选最高频精华)
目录 请介绍一下 SPI 总线协议及其工作原理,包括 SPI 有哪四种模式以及四根线的电气特性是什么? SPI 通信的波特率是多少,时钟来源是什么?SPI 的帧长度和数据格式是怎样的? 请简述 IIC 协议及其工作原理,包括 IIC 协议最多能挂载多少个从设备? IIC 总线上挂不同的设备…...
使用策略模式时的一个生效问题
策略模式的替换场景: 1:产品有默认策略A,B,项目扩展策略C,此为正常扩展。 2:产品有默认策略A,B,项目需要改写策略B,此为项目替换默认策略。 3:产品有默认策略A,B,项目扩展策略C,产品需要反向扩展…...
活动预告 |【Part2】 Azure 在线技术公开课:迁移和保护 Windows Server 和 SQL Server 工作负载
课程介绍 通过 Microsoft Learn 免费参加 Microsoft Azure 在线技术公开课,掌握创造新机遇所需的技能,加快对 Microsoft 云技术的了解。参加我们举办的“迁移和保护 Windows Server 和 SQL Server 工作负载”活动,了解 Azure 如何为将工作负载…...
关于 PCB线路板细节锣槽问题 的解决方法
若该文为原创文章,转载请注明原文出处 本文章博客地址:https://hpzwl.blog.csdn.net/article/details/144783817 长沙红胖子Qt(长沙创微智科)博文大全:开发技术集合(包含Qt实用技术、树莓派、三维、OpenCV…...
机器学习特征选择
一、特征选择概述 在实际的数据集中,往往包含了大量的特征,但并非所有特征都对我们要预测的目标变量(如分类任务中的类别标签,回归任务中的数值目标)有积极作用。有些特征可能携带的信息量极少,甚至会引入…...
第R5周:天气预测
🍨 本文为🔗365天深度学习训练营 中的学习记录博客🍖 原作者:K同学啊 任务说明:该数据集提供了来自澳大利亚许多地点的大约 10 年的每日天气观测数据。你需要做的是根据这些数据对RainTomorrow进行一个预测,…...
【每日学点鸿蒙知识】ets匿名类、获取控件坐标、Web显示iframe标签、软键盘导致上移、改变Text的背景色
1、HarmonyOS ets不支持匿名类吗? 不支持,需要显式标注对象字面量的类型,可以参考以下文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/typescript-to-arkts-migration-guide-V5#%E9%9C%80%E8%A6%81%E6%…...
【Vim Masterclass 笔记02】第3章:Vim 核心知识 + L08:Vim 核心浏览命令 + L09:Vim 核心浏览命令同步练习
文章目录 Section 3:Vim Essentials(Vim 核心知识)S03L08 Essential Navigation Commands1 光标的上下左右移动2 上 / 下翻页3 基于单词前移4 基于单词后移5 重新定位视图中的文本(页面重绘)6 定位到所在行的行首7 光标…...
Spring Boot教程之四十:使用 Jasypt 加密 Spring Boot 项目中的密码
如何使用 Jasypt 加密 Spring Boot 项目中的密码 在本文中,我们将学习如何加密 Spring Boot 应用程序配置文件(如 application.properties 或 application.yml)中的数据。在这些文件中,我们可以加密用户名、密码等。 您经常会遇到…...
unity 按钮发送数据到服务器端
1. canvas 明显大于 main camera显示范围 按钮设置 reset 2 设置场景背景图片 2. 如何设置 sense 与背景图大小一致 stretch 没有生效 手动拖拽到 camera 大小 3 将button 按钮拖拽到背景image 中...
【TG\SE二次开发】天工CAD二次开发-c++模板介绍
VS的安装的环境: 1. Visual Studio EnterPrise 2022版本 2. 涉及到的工作负荷: 使用C的桌面开发、通用Windows平台开发 3. 特别要求的单个组件: 适用于最新的v143生成工具的CATL(x86和x64)组件、适用于最新的v143生…...
C语言预处理
预处理 C语言的编译步骤 预处理编译汇编链接 C语言的预处理 预处理就是在源文件编译之前,所进行的一部分预备操作,这部分操作是由预处理程序自动完成;当源文件在编译时,编译器会自动调用预处理程序来完成预处理操作执行的解析…...
DPIN基金会在曼谷发布全球去中心化GPU算力网络计划
12月12日,DPIN基金会在泰国曼谷举行的“DPIN—AIDePIN全球共识发布会”上,展示了其构建全球去中心化GPU算力网络的宏伟蓝图与愿景。DPIN基金会致力于开发一个基于人工智能与去中心化物理基础设施网络(DePIN)的高性能计算平台&…...
ONNX Runtime gpu版本安装
ONNX Runtime版本与cudatoolkit版本对应关系:NVIDIA - CUDA | onnxruntime onnx runtime发的版本:Releases microsoft/onnxruntime onnx runtime 官网:ONNX Runtime | Home onnx和onnx runtime版本对应关系:Compatibility | o…...
深入理解 MVCC 与 BufferPool 缓存机制
深入理解 MVCC 与 BufferPool 缓存机制 在 MySQL 数据库中,MVCC(Multi-Version Concurrency Control)多版本并发控制机制和 BufferPool 缓存机制是非常重要的概念,它们对于保证数据的一致性、并发性以及提升数据库性能起着关键作用…...
RockyLinux介绍及初始化
文章目录 一、背景二、下载 RockyLinux9 镜像三、环境初始化四、安装 Docker 环境 一、背景 这里讲一个小故事: 我们都知道Linux 内核是由芬兰计算机科学家林纳斯托瓦兹 (Linus Torvalds) 于 1991 年首次开发的,随后有一个非常重要的公司RetHat成立&am…...
Python中切片操作符
在Python中,切片是一种操作符,允许你获取序列(如列表、元组、字符串)的一部分。切片操作返回序列的一个子集,这个子集是一个新的对象,与原始序列是独立的。切片操作通常用于列表、元组、字符串等。 切片语…...
python -【es】基本使用
一. 前言 在Python中使用Elasticsearch(ES)通常涉及安装Elasticsearch的Python客户端库,然后通过该库与Elasticsearch集群进行交互。 二. 基本使用 1. 安装Elasticsearch Python客户端库 首先,你需要安装elasticsearch库。你可…...
JVM实战—5.G1垃圾回收器的原理和调优
大纲 1.G1垃圾回收器的工作原理 2.G1分代回收原理—性能为何比传统GC好 3.使用G1垃圾回收器时应如何设置参数 4.如何基于G1垃圾回收器优化性能 5.问题汇总 1.G1垃圾回收器的工作原理 (1)ParNew CMS的组合有哪些痛点 (2)G1垃圾回收器 (3)G1如何实现垃圾回收的停顿时间是…...
Python爬虫(selenium)从网站获取信息并存入数据库(mysql)
简介: 在本篇博客中,我们将介绍如何使用Python编写一个简单的网络爬虫,从指定网站上获取图书信息,并将这些信息存入数据库。这个项目涉及到Python编程、selenium爬虫技术以及数据库操作等内容,适合对这些领域感兴趣的初…...
spring中使用@Validated,什么是JSR 303数据校验,spring boot中怎么使用数据校验
文章目录 一、JSR 303后台数据校验1.1 什么是 JSR303?1.2 为什么使用 JSR 303? 二、Spring Boot 中使用数据校验2.1 基本注解校验2.1.1 使用步骤2.1.2 举例Valid注解全局统一异常处理 2.2 分组校验2.2.1 使用步骤2.2.2 举例Validated注解Validated和Vali…...
RabbitMQ中的异步Confirm模式:提升消息可靠性的利器
在现代分布式系统中,消息队列(Message Queue)扮演着至关重要的角色,它能够解耦系统组件、提高系统的可扩展性和可靠性。RabbitMQ作为一款广泛使用的消息队列中间件,提供了多种机制来确保消息的可靠传递。其中ÿ…...
C++ 设计模式:代理模式(Proxy Pattern)
链接:C 设计模式 链接:C 设计模式 - 门面模式 链接:C 设计模式 - 中介者 链接:C 设计模式 - 适配器 代理模式(Proxy Pattern)是一种结构型设计模式,它为其他对象提供一种代理以控制(…...
41.1 预聚合提速实战项目之需求分析和架构设计
本节重点介绍 : 需求分析架构设计 需求分析 使用预聚合提速查询并且降低高基数查询对后端的压力用户无需变更grafana上的查询语句,后端自动替换效果图 架构设计 架构图 解决方案说明 heavy_query对用户侧表现为查询速度慢在服务端会导致资源占用过多甚至打挂…...
学习路之VScode--自定义按键写注释(插件)
1. 安装 "KoroFileHeader" 插件 首先,在 VScode 中搜索并安装名为 "KoroFileHeader" 的插件。你可以通过在扩展商店中搜索插件名称来找到并安装它。 2. 进入 VScode 设置页面 点击 VScode 左下角的设置图标,然后选择 "设置&q…...