Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复Oracle 19c备份时报错不支持CONTINOUS_MINE #2553

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix:Oracle 19c 生成回滚语句报不支持CONTINOUS_MINE问题
  • Loading branch information
ZhuhongLee authored and LeoQuote committed Mar 28, 2024
commit ef15be046965c37b2ecebfd632419ae6b60b69ea
33 changes: 30 additions & 3 deletions sql/engines/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,25 +1259,52 @@ def backup(self, workflow, cursor, begin_time, end_time):
key `idx_sql_rollback_01` (`workflow_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"""
)
# 获取redo files列表
redo_files_sql = f"""SELECT
b.MEMBER
FROM v$log a,
(SELECT GROUP#,MEMBER,row_number() OVER(PARTITION BY group# ORDER BY MEMBER) rn FROM v$logfile) b
WHERE a.GROUP# =b.GROUP#
AND b.rn =1 """
# 使用logminer抓取回滚SQL
logmnr_start_sql = f"""begin
# 12c以下版本用此SQL
logmnr_start_sql_old = f"""begin
LeoQuote marked this conversation as resolved.
Show resolved Hide resolved
dbms_logmnr.start_logmnr(
starttime=>to_date('{begin_time}','yyyy-mm-dd hh24:mi:ss'),
endtime=>to_date('{end_time}','yyyy/mm/dd hh24:mi:ss'),
options=>dbms_logmnr.dict_from_online_catalog + dbms_logmnr.continuous_mine);
end;"""
# 12c及以上版本用此SQL
logmnr_start_sql_new = f"""begin
dbms_logmnr.start_logmnr(
starttime=>to_date('{begin_time}','yyyy-mm-dd hh24:mi:ss'),
endtime=>to_date('{end_time}','yyyy/mm/dd hh24:mi:ss'),
options=>dbms_logmnr.dict_from_online_catalog);
end;"""
undo_sql = f"""select
xmlagg(xmlparse(content sql_redo wellformed) order by scn,rs_id,ssn,rownum).getclobval() ,
xmlagg(xmlparse(content sql_undo wellformed) order by scn,rs_id,ssn,rownum).getclobval()
from v$logmnr_contents
where SEG_OWNER not in ('SYS')
where SEG_OWNER not in ('SYS','AUDSYS')
and session# = (select sid from v$mystat where rownum = 1)
and serial# = (select serial# from v$session s where s.sid = (select sid from v$mystat where rownum = 1 ))
group by scn,rs_id,ssn order by scn desc"""
logmnr_end_sql = f"""begin
dbms_logmnr.end_logmnr;
end;"""
cursor.execute(logmnr_start_sql)
# 判断数据库版本,12c及以上版本手动添加redo文件来分析
if int(self.server_version[0]) > 11:
cursor.execute(redo_files_sql)
rows=cursor.fetchall()
for index,row in enumerate(rows):
if index == 0:
cursor.execute("BEGIN dbms_logmnr.add_logfile('"+ str(row[0]) + "', dbms_logmnr.new); END;")
else:
cursor.execute("BEGIN dbms_logmnr.add_logfile('"+ str(row[0]) + "', dbms_logmnr.addfile); END;")
cursor.execute(logmnr_start_sql_new)
# 12c以下版本使用以下logminer
else:
cursor.execute(logmnr_start_sql_old)
cursor.execute(undo_sql)
rows = cursor.fetchall()
cursor.execute(logmnr_end_sql)
Expand Down