Skip to content

Commit ef15be0

Browse files
ZhuhongLeeLeoQuote
authored andcommitted
fix:Oracle 19c 生成回滚语句报不支持CONTINOUS_MINE问题
1 parent 5f556a5 commit ef15be0

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

sql/engines/oracle.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,25 +1259,52 @@ def backup(self, workflow, cursor, begin_time, end_time):
12591259
key `idx_sql_rollback_01` (`workflow_id`)
12601260
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"""
12611261
)
1262+
# 获取redo files列表
1263+
redo_files_sql = f"""SELECT
1264+
b.MEMBER
1265+
FROM v$log a,
1266+
(SELECT GROUP#,MEMBER,row_number() OVER(PARTITION BY group# ORDER BY MEMBER) rn FROM v$logfile) b
1267+
WHERE a.GROUP# =b.GROUP#
1268+
AND b.rn =1 """
12621269
# 使用logminer抓取回滚SQL
1263-
logmnr_start_sql = f"""begin
1270+
# 12c以下版本用此SQL
1271+
logmnr_start_sql_old = f"""begin
12641272
dbms_logmnr.start_logmnr(
12651273
starttime=>to_date('{begin_time}','yyyy-mm-dd hh24:mi:ss'),
12661274
endtime=>to_date('{end_time}','yyyy/mm/dd hh24:mi:ss'),
12671275
options=>dbms_logmnr.dict_from_online_catalog + dbms_logmnr.continuous_mine);
12681276
end;"""
1277+
# 12c及以上版本用此SQL
1278+
logmnr_start_sql_new = f"""begin
1279+
dbms_logmnr.start_logmnr(
1280+
starttime=>to_date('{begin_time}','yyyy-mm-dd hh24:mi:ss'),
1281+
endtime=>to_date('{end_time}','yyyy/mm/dd hh24:mi:ss'),
1282+
options=>dbms_logmnr.dict_from_online_catalog);
1283+
end;"""
12691284
undo_sql = f"""select
12701285
xmlagg(xmlparse(content sql_redo wellformed) order by scn,rs_id,ssn,rownum).getclobval() ,
12711286
xmlagg(xmlparse(content sql_undo wellformed) order by scn,rs_id,ssn,rownum).getclobval()
12721287
from v$logmnr_contents
1273-
where SEG_OWNER not in ('SYS')
1288+
where SEG_OWNER not in ('SYS','AUDSYS')
12741289
and session# = (select sid from v$mystat where rownum = 1)
12751290
and serial# = (select serial# from v$session s where s.sid = (select sid from v$mystat where rownum = 1 ))
12761291
group by scn,rs_id,ssn order by scn desc"""
12771292
logmnr_end_sql = f"""begin
12781293
dbms_logmnr.end_logmnr;
12791294
end;"""
1280-
cursor.execute(logmnr_start_sql)
1295+
# 判断数据库版本,12c及以上版本手动添加redo文件来分析
1296+
if int(self.server_version[0]) > 11:
1297+
cursor.execute(redo_files_sql)
1298+
rows=cursor.fetchall()
1299+
for index,row in enumerate(rows):
1300+
if index == 0:
1301+
cursor.execute("BEGIN dbms_logmnr.add_logfile('"+ str(row[0]) + "', dbms_logmnr.new); END;")
1302+
else:
1303+
cursor.execute("BEGIN dbms_logmnr.add_logfile('"+ str(row[0]) + "', dbms_logmnr.addfile); END;")
1304+
cursor.execute(logmnr_start_sql_new)
1305+
# 12c以下版本使用以下logminer
1306+
else:
1307+
cursor.execute(logmnr_start_sql_old)
12811308
cursor.execute(undo_sql)
12821309
rows = cursor.fetchall()
12831310
cursor.execute(logmnr_end_sql)

0 commit comments

Comments
 (0)