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 all commits
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
43 changes: 39 additions & 4 deletions sql/engines/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get_all_tables(self, db_name, **kwargs):

def get_group_tables_by_db(self, db_name):
data = {}
table_list_sql = f"""SELECT table_name, comments FROM dba_tab_comments WHERE owner = :db_name"""
table_list_sql = f"""SELECT a.table_name,a.comments FROM dba_tab_comments a,all_tables b WHERE a.table_name=b.table_name AND a.owner=b.owner AND a.owner=:db_name"""
result = self.query(
db_name=db_name, sql=table_list_sql, parameters={"db_name": db_name}
)
Expand Down Expand Up @@ -1259,25 +1259,60 @@ 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_before12c_sql = 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 + dbms_logmnr.continuous_mine);
end;"""
# 12c及以上版本用此SQL
logmnr_start_sql = 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)
# 12c以下版本使用以下logminer
else:
cursor.execute(logmnr_start_before12c_sql)
cursor.execute(undo_sql)
rows = cursor.fetchall()
cursor.execute(logmnr_end_sql)
Expand Down
Loading