原作者:罗海鸥
适用范围
openGauss/MogDB
问题概述
数据库崩溃或者会话异常终止时,未清理的文件会侵蚀存储空间。
问题原因
数据库崩溃或者会话异常终止时,数据库不会清理回滚事务中创建的文件。
db1=# begin ;
BEGIN
db1=# create table t1(id int);
CREATE TABLE
db1=# insert into t1 values(1);
INSERT 0 1
db1=# select pg_relation_filepath('t1');
pg_relation_filepath
----------------------
base/16775/41449
(1 row)
db1=# select * from pg_tables where tablename='t1';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecreator | created | last
_ddl_time
------------+-----------+------------+------------+------------+----------+-------------+--------------+-------------------------------+-------------
------------------
public | t1 | omm | | f | f | f | omm | 2024-01-02 11:20:32.627504+08 | 2024-01-02 1
1:20:32.627504+08
(1 row)
kill掉数据库进程
[omm@luo data]$ ll base/16775/41449
-rw------- 1 omm omm 8192 Jan 2 11:20 base/16775/41449
[omm@luo data]$
[omm@luo data]$ ps -ef|grep mogdb
omm 26844 1 22 11:19 ? 00:00:29 /opt/mogdb/app/bin/mogdb -D /opt/mogdb/data
omm 27366 6582 0 11:22 pts/1 00:00:00 grep --color=auto mogdb
[omm@luo data]$ kill -9 26844
启动数据库
[omm@luo data]$ gs_om -t start
Starting cluster.
=========================================
[SUCCESS] luo
2024-01-02 11:22:34.876 [unknown] [unknown] localhost 47175492758656 0[0:0#0] 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets
2024-01-02 11:22:34.876 [unknown] [unknown] localhost 47175492758656 0[0:0#0] 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets
2024-01-02 11:22:34.883 [unknown] [unknown] localhost 47175492758656 0[0:0#0] 0 [BACKEND] WARNING: Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (16 Mbytes) or shared memory (3489 Mbytes) is larger.
=========================================
Successfully started.
数据库中未提交的事务已回滚
db1=#
db1=# select * from pg_tables where tablename='t1';
could not send data to server: Broken pipe
The connection to the server was lost. Attempting reset: Succeeded.
db1=# select * from pg_tables where tablename='t1';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | tablecreator | created | last_ddl_time
------------+-----------+------------+------------+------------+----------+-------------+--------------+---------+---------------
(0 rows)
db1=# \d
No relations found.
文件未清理
[omm@luo data]$ ll base/16775/41449
-rw------- 1 omm omm 8192 Jan 2 11:20 base/16775/41449
解决方案
逻辑导出和导入如:
gs_dump -Fp -f /home/omm/db1.sql db1
drop database db1;
create database db1;
gsql -r db1 -f /home/omm/db1.sql
参考文档
无