數(shù)據(jù)庫data目錄下存在大量core文件導(dǎo)致磁盤爆滿

1、問題描述

hghac集群中某個(gè)數(shù)據(jù)庫節(jié)點(diǎn)宕機(jī),初步排查后發(fā)現(xiàn)磁盤爆滿。繼續(xù)排查發(fā)現(xiàn)數(shù)據(jù)庫data目錄下存在大量core文件,導(dǎo)致磁盤空間不足。

2、問題原因

[root@test-1 /]# /opt/HighGo/tools/hghac/hghactl  list
+ Cluster: test (6982441441117241376) -+--------------+----+-----------+
| Member | Host | Role | State | TL | Lag in MB |
+--------+-------------------+---------+--------------+----+-----------+
| test-0 | 192.168.10.1:5866 | Leader | running | 22 | |
| test-1 | 192.168.10.2:5866 | Replica | start failed | | unknown |
| test-2 | 192.168.10.3:5866 | Replica | running | 22 | 0.0 |
| test-3 | 192.168.10.4:5866 | Replica | start failed | | unknown |
+--------+-------------------+---------+--------------+----+-----------+
[root@test-1 /]# ps -ef |grep postgres |grep -v grep
[root@test-1 /]# cd $PGDATA
[root@test-1 data]# ll
total 2085495568
-rw-------. 1 root root 3100 Jul 8 14:39 audit_param.conf
-rw-------. 1 root root 224 Jul 8 14:39 backup_label.old
drwx------. 6 root root 4096 Jul 14 17:40 base
-rw-------. 1 root root 8891727872 Jul 15 10:19 core.28081
-rw-------. 1 root root 8891727872 Jul 15 10:04 core.28122
-rw-------. 1 root root 8891858944 Jul 15 10:09 core.28124
…………
-rw-------. 1 root root 7112949760 Jul 15 11:10 core.30885
-rw-------. 1 root root 7116390400 Jul 15 11:10 core.30905
-rw-------. 1 root root 8891727872 Jul 8 17:46 core.32
-rw-------. 1 root root 8891727872 Jul 8 17:47 core.39
-rw-------. 1 root root 32 Jul 15 10:19 current_logfiles
drwx------. 2 root root 4096 Jul 15 09:03 global
drwx------. 4 root root 4096 Jul 12 09:02 hgaudit
drwx------. 2 root root 4096 Jul 15 00:00 hgdb_log
-rw-------. 1 root root 1094 Jul 8 14:39 patroni.dynamic.json
drwx------. 2 root root 4096 Jul 8 14:39 pg_commit_ts
drwx------. 2 root root 4096 Jul 8 14:39 pg_dynshmem
-rw-------. 1 root root 751 Jul 15 17:47 pg_hba.conf
-rw-------. 1 root root 751 Jul 15 11:10 pg_hba.conf.backup
-rw-------. 1 root root 1636 Jul 8 14:39 pg_ident.conf
-rw-------. 1 root root 1636 Jul 15 11:10 pg_ident.conf.backup
drwx------. 4 root root 4096 Jul 15 09:03 pg_logical
drwx------. 4 root root 4096 Jul 8 14:39 pg_multixact
drwx------. 2 root root 4096 Jul 15 10:19 pg_notify
drwx------. 2 root root 4096 Jul 12 09:02 pg_replslot
drwx------. 2 root root 4096 Jul 8 14:39 pg_serial
drwx------. 2 root root 4096 Jul 8 14:39 pg_snapshots
drwx------. 2 root root 4096 Jul 15 11:10 pg_stat
drwx------. 2 root root 4096 Jul 12 09:02 pg_stat_tmp
drwx------. 2 root root 4096 Jul 8 14:59 pg_subtrans
drwx------. 2 root root 4096 Jul 8 14:39 pg_tblspc
drwx------. 2 root root 4096 Jul 8 14:39 pg_twophase
-rw-------. 1 root root 3 Jul 8 14:39 PG_VERSION
drwx------. 3 root root 45056 Jul 15 09:03 pg_wal
drwx------. 2 root root 4096 Jul 8 14:39 pg_xact
-rw-------. 1 root root 113 Jul 14 17:54 postgresql.auto.conf
-rw-------. 1 root root 28596 Jul 8 14:39 postgresql.base.conf
-rw-------. 1 root root 28596 Jul 15 11:10 postgresql.base.conf.backup
-rw-r--r--. 1 root root 1967 Jul 15 17:47 postgresql.conf
-rw-r--r--. 1 root root 1967 Jul 15 11:10 postgresql.conf.backup
-rw-------. 1 root root 464 Jul 15 10:19 postmaster.opts
-rw-------. 1 root root 32 Jul 8 14:39 secure_param.conf
-rw-r--r--. 1 root root 0 Jul 15 17:47 standby.signal
[root@test-1 data]# df -h
Filesystem Size Used Avail Use% Mounted on
overlay 901G 20G 836G 3% /
tmpfs 64M 0 64M 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
/dev/sda2 901G 20G 836G 3% /etc/hosts
/dev/mapper/mpathj 2.0T 2.0T 0 100% /opt/hgdb_data
/dev/sdb1 1008M 100M 858M 11% /boot

對(duì)core文件進(jìn)行簡(jiǎn)單排查

[root@test-1 data]# file core.28122
core.28122: from 'cp pg_xlog/000000160000000500000049 /archive/000000160000000500000049'

由此推測(cè),core文件由cp命令產(chǎn)生,該cp命令為歸檔參數(shù) archieve_command 配置。

仔細(xì)查看系統(tǒng)日志記錄(/var/log/messages),發(fā)現(xiàn)系統(tǒng)出現(xiàn)過OOM(Out of Memory)事件。也就是說數(shù)據(jù)庫使用了過量?jī)?nèi)存導(dǎo)致系統(tǒng)發(fā)出了kill命令,于是歸檔進(jìn)程崩潰,導(dǎo)致產(chǎn)生了core文件。

3、解決方案

如果我們想阻止core文件的產(chǎn)生,可以設(shè)置core file的size limit為0。

# vi /etc/profile 
然后,在profile中添加:
ulimit -c 0 (KB)
# source /etc/profile

使用source命令使之馬上生效。
建議優(yōu)先解決進(jìn)程崩潰問題,再設(shè)置/etc/profile。