GBase 8a
其他
文章

952、953版本多VC审计日志汇总任务

发表于2025-12-17 15:15:1028次浏览1个评论

之前由于系统表gbase.audit_log_bak1损坏,导致转储一直失败产生了大量积压,下面的任务增加了转储之前对表gbase.audit_log_bak1的修复。

use vc xxxx;

use gclusterdb;

delimiter #
CREATE EVENT "summary_adit_lg"
ON SCHEDULE EVERY 60 MINUTE
STARTS '2025-8-6 00:00:00'
ON COMPLETION PRESERVE
ENABLE
LOCAL
DO
begin
declare errno int;
declare msg text;
declare exit handler for sqlexception begin get diagnostics condition 1 errno = gbase_errno, msg = message_text;
create table if not exists import_audit_log_errors(err_time datetime, hostname varchar(64), err_no int, msg_txt varchar(1024)) CHARSET=utf8mb4;
insert into import_audit_log_errors values (now(), @@hostname, errno, substr(msg, 0, 1024));
end;
create table if not exists "audit_log_express" (
 "hostname" varchar(64) DEFAULT NULL,
 "thread_id" int(11) DEFAULT NULL,
 "taskid" bigint(20) DEFAULT NULL,
 "start_time" datetime DEFAULT NULL,
 "end_time" datetime DEFAULT NULL,
 "user_host" varchar(4096) DEFAULT NULL,
 "uid" bigint(20) DEFAULT NULL,
 "user" varchar(128) DEFAULT NULL,
 "host_ip" varchar(32) DEFAULT NULL,
 "query_time" time DEFAULT NULL,
 "rows" bigint(20) DEFAULT NULL,
 "vc_id" varchar(64) DEFAULT NULL,
 "db" varchar(512) DEFAULT NULL,
 "table_list" varchar(4096) DEFAULT NULL,
 "sql_text" varchar(8191) DEFAULT NULL,
 "sql_type" varchar(16) DEFAULT NULL,
 "sql_command" varchar(32) DEFAULT NULL,
 "operators" varchar(256) DEFAULT NULL,
 "status" varchar(16) DEFAULT NULL,
 "conn_type" varchar(16) DEFAULT NULL
) ENGINE=EXPRESS DEFAULT CHARSET=utf8mb4 TABLESPACE='sys_tablespace';
set self sql_mode = '';
set _gbase_query_path = on;
set @cnt=0;select count(1) into @cnt from information_schema.tables where table_name='audit_log_bak2' and table_schema='gbase';
if @cnt=1 then drop self table gbase.audit_log_bak2;end if;
create self table gbase.audit_log_bak2 like gbase.audit_log;
set @cnt=0;select count(1) into @cnt from information_schema.tables where table_name='audit_log_bak1' and table_schema='gbase';
if @cnt=1 then repair table gbase.audit_log_bak1;insert into audit_log_express select @@hostname as hostname,thread_id,taskid,start_time,end_time,user_host,uid,user,host_ip,query_time,rows,vc_id,db,substr(table_list,0,4096),to_char(substr(sql_text, 0, 8191)),sql_type,sql_command,operators,status,conn_type from gbase.audit_log_bak1;drop self table gbase.audit_log_bak1; end if;
rename self table gbase.audit_log to gbase.audit_log_bak1, gbase.audit_log_bak2 to gbase.audit_log;
repair table gbase.audit_log_bak1;insert into audit_log_express select @@hostname as hostname,thread_id,taskid,start_time,end_time,user_host,uid,user,host_ip,query_time,rows,vc_id,db,substr(table_list,0,4096),to_char(substr(sql_text, 0, 8191)),sql_type,sql_command,operators,status,conn_type from gbase.audit_log_bak1;
drop self table gbase.audit_log_bak1;
end #

 

评论

登录后才可以发表评论
用户头像
levvel发表于 3个月前
读书破万卷,下笔如有神