PostgreSQL 11数据库参数优化
服务器资源状况:
32GB内存
4路8核心CPU,逻辑核心32颗
postgresql.conf配置文件部分参数:
shared_buffers
设置为系统内存的40%,过多无益
work_mem
单个查询排序所用内存,work_mem*所有用户数的全部查询数=占用系统内存,因此如果并发用户很多,此参数不宜设置多大,比如设置为128MB,如果同时有10个并发查询,则会占用1280MB系统内存
maintenance_work_mem
维护类工作使用的内存,比如VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY等,因为每一个数据库session同时只能执行一个此类操作,因为可以将其设置的大一点儿,可以提高此类操作的性能。
effective_cache_size
用于query planner估算系统可用内存,并不是真正的分配内存,可以设置为系统内存的1/2到3/4大小。
调优参数汇总:
1 | shared_buffers = 12GB |
References:
[1]Tuning Your PostgreSQL Server
[2]PGTune
rman configure命令
rman备份时出现错误:
1 | RMAN-03009: failure of Control File and SPFILE Autobackup command on ORA_DISK_1 channel at 10/01/2019 00:31:53 |
是因为rman配置了控制文件自动备份,但是设置的自动备份路径早已经失效了
所以需要关闭控制文件自动备份配置,并恢复默认设置:
1 | RMAN> CONFIGURE CONTROLFILE AUTOBACKUP OFF; |
CLEAR用于恢复默认设置,比如控制文件自动备份的默认设置是OFF,所以也可以这样关闭控制文件自动备份:
1 | RMAN> CONFIGURE CONTROLFILE AUTOBACKUP CLEAR; |
查看全部配置选项:
1 | RMAN> SHOW ALL; |
References:
[1]RMAN Configure Command
redis sentinel主从复制高可用安装配置
redis sentinel与cluster是不同的,虽然都是分布式系统,sentinel只是实现高可用,而cluster则可以进一步实现数据分片和负载均衡。
sentinel配置至少需要三个节点。
后面采用如下的配置,三个独立的节点,数字代表节点编号,M代表Master,S代表Sentinel,R代表Replica
+----+
M1
S1
+----+
+—-+ +—-+
R2 —-+—- R3
S2 S3
+—-+ +—-+
Configuration: quorum = 2
安装
1 | # apt install redis-server redis-sentinel |
redis-server配置
配置文件为/etc/redis/redis.conf
所有的server节点注释掉bind本地回环地址这一行,并且将protect-mode设置为no
1 | #bind 127.0.0.1 ::1 |
请注意网络安全风险,如果节点直连互联网,可以添加安全认证,或者只bind到内部网络地址
slave节点2和3需要添加replicaof配置项:
1 | replicaof ip_of_master 6379 |
diskless配置
如果redis只是用于存储session,可以无需持久化到硬盘,进一步提高性能
注释掉配置文件中的所有save行,replica参数设置如下即可:
1 | # save 900 1 |
redis-sentinel配置
配置文件为/etc/redis/sentinel.conf
注释掉
1 | #bind 127.0.0.1 ::1 |
请注意网络安全风险,如果节点直连互联网,可以添加安全认证,或者只bind到内部网络地址
sentinel monitor配置为
1 | sentinel monitor mymaster ip_of_master 6379 2 |
其他参数,比如down-after-milliseconds,failover-timeout,parallel-syncs等都使用系统默认值即可。
注意:sentinel启动时会自动生成sentinel myid用于在集群中标识本实例,生成后只要不删除会一直使用这个id,如果其他节点复制本节点的配置文件,注意要注释或删除掉已经生成的myid,因为sentinel集群中所有的实例要有不同的myid
sentinel集群状态
1 | $ redis-cli -p 26379 |
可以看到当前的master节点信息,num-slaves表明有几个replica,num-other-sentinels表明除本节点外有几个其他的sentinel节点。
relipa节点的信息
1 | 127.0.0.1:26379> sentinel slaves mymaster |
sentinel节点的信息:
1 | 127.0.0.1:26379> sentinel sentinels mymaster |
redis-service优化配置
1、TCP BACKLOG
/var/log/redis/redis-server.log中有警告:
1 | WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. |
查看当前配置
1 | $ cat /proc/sys/net/core/somaxconn |
显然主机的tcp backlog设置过低了,不能很好的支持大量的并发连接,应该把对应的参数调高
系统参数文件/etc/sysctl.conf末尾添加:
1 | net.core.somaxconn = 10240 |
使其生效
1 | $ sudo sysctl -p |
/etc/redis/redis.conf文件中修改tcp-backlog为4096或更高,但不能超过系统参数设置,重启redis后生效。
2、overcommit_memory
/var/log/redis/redis-server.log中有警告:
1 | WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. |
一般在低内存条件时,此参数才会派上用场
系统参数文件/etc/sysctl.conf末尾添加:
1 | vm.overcommit_memory = 1 |
使其生效
1 | $ sudo sysctl -p |
3、关闭透明巨页
/var/log/redis/redis-server.log中有警告:
1 | WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. |
开启透明巨页会有些问题,可以通过grub传递内核参数来关闭透明巨页
/etc/default/grub文件中GRUB_CMDLINE_LINUX_DEFAULT中添加transparent_hugepage=never
1 | GRUB_CMDLINE_LINUX_DEFAULT="quiet transparent_hugepage=never" |
然后更新grub配置,重启生效
1 | $ sudo update-grub |
4、repl-backlog-size参数
这个参数是为replica保持数据的缓冲区大小,当replica离线时,使用此缓冲为其保存数据,当replica重新上线可以不用执行full sync,使用partial sync就可以了,默认设置为1MB,显然太小了,可以根据单位时间内业务数据多少、支持replica离线时间、内存大小等因素设置此参数,比如设置为16MB以上。
5、client-output-buffer-limit参数
References:
[1]Replication
[2]Redis Sentinel Documentation
[3]Redis Sentinel 与 Redis Cluster
standby数据库rman备份错误RMAN-10006
在物理备库上执行rman备份时出现错误:
1 | MAN-00601: fatal error in recovery manager |
这是oracle的一个bug
Metalink NoteID:1080134.1.
Cause
Unpublished Bug 4230058: FAIL TO CONNECT TO RMAN AFTER PHYSICAL STANDBY IS OPENED READ ONLY
If the standby database is opened readonly and then managed recovery is restarted without bouncing the database, queries against v$session_longops will fail with:
ORA-01219: database not open: queries allowed on fixed tables/views only
RMAN likewise will fail trying to access this view with RMAN-10006 error.
Solution
Restart the standby database after opening it in READ ONLY mode before restarting the Managed Recovery process.
最简单的解决方案就是重启standby实例,还有一个方法是修改数据库参数,但是如果备库转换为主库,这个参数可能会有影响,所以还是重启实例最简单。
References:
[1]RMAN backup of physical standby fails RMAN-10006 querying v$session_longops (Doc ID 1080134.1)
[2]Standby上执行RMAN报错RMAN-10006错误处理
[3]9208物理standby备份报错
oracle 10g使用物理备库恢复主库损坏/丢失的数据文件
0 症状
oracle 10g dataguard主库某一数据文件发现有损坏,使用dbv检测数据文件:
1 | cmd> dbv file=E:\\oracle\\product\\10.2.0\\db_1\\database\\afsts.dbf feedback=100 |
操作系统中拷贝数据文件会出现错误”无法复制 AFSTS: 数据错误(循环冗余检查)。”,事件查看器中发现错误“设备 \Device\Harddisk1\DR1 有一个不正确的区块。”,数据文件有物理损坏。
此时数据文件无法拷贝和删除,需要将数据文件离线,然后用chkdsk系统工具修复,或者使用“分区”右键属性里的”工具”->”查错”->“开始检查”,选中“自动修复文件系统错误”
1 | cmd> chkdsk e: /F /I /C |
/I和/C用于跳过部分检查,减少扫描时间。
修复错误后,数据文件的内容可能已经不正确了,需要使用standby数据库数据文件恢复。
注:使用rman restore数据文件可以直接恢复,无需提前修复文件系统错误。
1 修复
1.1 首先确保用于恢复的数据文件是没有损坏的
备库端:
a. dbv检查
1 | cmd> dbv file=E:\\oracle\\product\\10.2.0\\db_1\\database\\afsts.dbf feedback=100 |
确保Total Pages Failing (Data),Total Pages Failing (Index),Total Pages Failing (Seg) 和Total Pages Marked Corrupt皆为0
b. rman检查
找出数据文件的编号
1 | sql> select FILE#,NAME,STATUS from v$datafile where name like '%AFSTS.DBF%'; |
数据文件检查
1 | $ rman target sys/password@db_feich; |
因为物理standby是mounted状态,是不可写的。所以此检查对于正在进行日志恢复的standby是无法实施的。
1.2 备库端操作
备份数据文件
1 | $ rman target sys/password@db_standby; |
1.3 主库端操作
a. 将备库备份的数据文件拷贝到主库相同的目录结构下
b. 将备份加入恢复目录catalog
1 | $ rman target sys/password@db_primary; |
c. 数据文件离线
1 | $ sqlplus sys/password@db_primary as sysdba; |
d. restore/recover数据文件
1 | $ rman target sys/password@db_primary; |
e. 数据文件上线
1 | RMAN> sql 'alter database datafile 20 online'; |
f. 检查数据文件完整性
1 | RMAN> backup validate check logical datafile 20; |
也可以再用dbv检查一下
完毕,也可以用主库数据文件恢复备库丢失或损坏的数据文件,只不过操作方向不同而已。
References:
[1]Recovering the primary database’s datafile using the physical standby, and vice versa (Doc ID 453153.1)
[2]Recover the Primary Database’s datafile using a copy of a Physical Standby Database’s Datafile
[3]Recovering a corrupted/lost datafile on Primary database from the Standby database
[4]Steps to recover the standby database’s datafile using a backup of the primary database’s data file
dataguard物理备库exp导出数据
物理备库是可以以只读模式打开的,然后就可以exp数据出来了,注意备库readonly模式打开时,是没有在apply日志的,所有exp出来的数据会少了主库在这段时间更新的数据。
备库端:
1 | SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; |
然后exp数据库:
1 | $ exp ... |
最后备库重新开始apply日志就好了:
1 | SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION; |
cassandra替换当掉的种子节点
分为两个步骤,首先用新的节点替换宕机的节点,其次把新节点提升为种子节点。
替换故障节点
1、nodetool status
命令找到DN节点的ip地址比如192.168.0.82,后面会用到这个ip地址。
2、新节点安装与集群其他节点一样版本的cassandra,然后停止cassandra服务,并清除节点全部数据
1 | $ sudo systemctl stop cassandra |
3、设置参数文件cassandra.yaml和cassandra-rackdc.properties或者 cassandra-topology.properties
auto_bootstrap要设置为true,因为新节点要从种子节点获取数据。
cluster_name设置为要加入的集群的名字
linsten_address和rpc_address设置为本机ip
endpoint_snitch 要与集群其他节点一致,然后修改对应的属性文件
seed_provider只要要提供一个集群中现有的种子节点,但不要将新添加节点的地址加入,因为种子节点并不会bootstrap,等新节点bootstrap完成后再将新节点提升为种子节点。
可以提取集群中其他节点的配置文件,只对应修改新节点独有的参数即可。
4、使用 replace_address 选项启动新节点
修改/etc/cassandra/cassandra-env.sh 文件,添加选项:
1 | JVM_OPTS="$JVM_OPTS -Dcassandra.replace_address=192.168.0.82" |
这里的ip地址就是上面找到的要被替换的节点ip地址
5、启动新节点
等新节点bootstrap完成后再执行以下步骤,并且需要去掉replace_address选项
6、cassandra-rackdc.properties或cassandra-topology.properties文件中去掉被替换的节点
7、从集群中移除当掉的节点
1 | $ nodetool removenode <hostid> |
nodetool status命令可以获取到节点的hostid
提升为种子节点
新添加节点bootstrap完成之后,可以提升为种子节点。
1、因为种子节点不能bootstrap,所以需要将其cassandra.yaml文件中的auto_bootstrap参数设置为false
2、在集群所有节点执行以下操作:
将cassandra.yaml配置文件中的种子列表中去掉被替换的节点,将新添加节点的地址加入种子列表,然后重启节点。
注意不要并行操作,最好一个节点接一个节点的逐一操作。
References:
[1]Replacing a dead node or dead seed node
[2]Replace a Dead Node in a Scylla Cluster
[3]Replacing a dead seed node
[4]nodetool removenode
Storwize v3700: CMMVC8020E
v3700从服务界面新建系统时,提示:
CMMVC8020E: 存在存储集群标识时尝试创建集群
无法创建新系统,是因为以前的集群信息尚未完全清除干净,在机柜配置界面重置集群标识,再次尝试新建系统成功。
如果还是不行,可以尝试[1]里面讲的方法,ssh登录进存储,执行以下命令:
1 | satask chenclosurevpd -resetclusterid |
没有尝试,或许可以。
References:
[1][SOLVED] Storwize v3700: CMMVC8020E