更新时间:2023-11-23 GMT+08:00
分享

长事务阻塞Undo空间回收

问题现象

  1. pg_log中打印如下错误:
    snapshot too old! the undo record has been forcibly discarded
    xid xxx, the undo size xxx of the transaction exceeds the threshold xxx. trans_undo_threshold_size xxx,undo_space_limit_size xxx. 

    在真实报错信息中,上文中的xxx为实际数据。

  2. global_recycle_xid(Undo子系统的全局回收事务XID)长时间不发生变化。

  3. pg_running_xacts与pg_stat_activity视图查询存在长事务,阻塞oldestxmin和global_recycle_xid推进。如果pg_running_xacts中查询活跃事务的xmin和gs_txid_oldestxmin相等,且通过pid查询pg_stat_activity查询线程执行语句时间过长,则表明有长事务卡主了回收。
    select * from pg_running_xacts where xmin::text::bigint<>0 and vacuum <> 't' order by xmin::text:bigint asc 	limit 5;
    select * from gs_txid_oldextxmin();
    select * from pg_stat_activity where pid = 长事务所在线程PID;

处理方法

通过pg_terminate_session(pid, sessionid)终止长事务所在的会话(提醒:长事务无固定快速恢复手段,强制结束SQL语句为其中一种常用操作,属于高危操作,执行需谨慎,执行前需与业务及华为技术确认,避免造成业务失败或报错)。

分享:

    相关文档

    相关产品