如何修改审计日志的表结构?

warning: 这篇文章距离上次修改已过1648天,其中的内容可能已经有所变动。
审计日志表表结构
11.5_r12.4_R1.1版本对审计日志表表结构增加了4列。
原表结构:
start_time 开始执行的时间
user_host 登陆的用户名和host
query_time sql 执行的时间
rows 返回结果集行数
db sql 执行的当前数据库名
sql_text sql 内容
conn_type 用户登陆方式(CAPI、ODBC、JDBC、ADO)

审计日志表新增列的内容如下:
Taskid 全局唯一的任务号
End_time SQL执行结束的时间
Sql_type 标识SQL类型,DDL,DML,DQL,OTHERS
Status 标识SQL执行成功还是失败,SUCCESS,FAILED

项目上手动修改表结构。

修改审计日志表结构的方法
1)由于审计日志表是系统表,需要手工修改每个节点gcluster和gnode的审计日志表的表结构
2)修改审计日志表结构时需要关闭审计日志功能,set global audit_log=off;
3)修改审计日志表结构之前需要执行:set sql_mode=’’;
4)修改表结构有两种方法

  • 方法一,直接在原表上增加列

    Alter self table audit_log add column taskid bigint not null first;
    Alter self table audit_log add column end_time timestamp not null after start_time;
    Alter self table audit_log add column sql_type mediumtext not null after sql_text;
    Alter self table audit_log add column status mediumtext not null after sql_type;

  • 方法二,创建新表,倒数据后,替换原表

    Taskid bigint not null,
    Start_time timestamp not null,
    End_time timestamp not null,
    User_host mediumtext not null,
    Query_time time not null,
    Rows integer not null,
    Db varchar(512) not null,
    Sql_text mediumtext not null,
    Sql_type mediumtext not null,
    Status mediumtext not null,
    Conn_type mediumtext not null
    ) engine =gssys character set utf8 comment=’Audit log’;
    Insert into audit_log_new(start_time, user_host, query_time, rows, db, sql_text, conn_type) select * from audit_log;
    Alter self table audit_log rename to audit_log_bak;
    Alter self table audit_log_new rename to audit_log;
    5)替换完成后需要重新开启审计日志功能: set global audit_log=on;

最后修改于:2020年10月28日 16:33

添加新评论