From ef15be046965c37b2ecebfd632419ae6b60b69ea Mon Sep 17 00:00:00 2001 From: "zhuhong.lee" <275516080@qq.com> Date: Wed, 27 Mar 2024 16:52:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:Oracle=2019c=20=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E8=AF=AD=E5=8F=A5=E6=8A=A5=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81CONTINOUS=5FMINE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/engines/oracle.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index ab86c04e7a..7f19a394ff 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -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 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) From 1430728c74471d7789e3e43c754e0a6dcb982848 Mon Sep 17 00:00:00 2001 From: "zhuhong.lee" <275516080@qq.com> Date: Wed, 27 Mar 2024 17:24:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96Oracle=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=9F=A5=E7=9C=8B=E6=97=B6=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E5=9B=9E=E6=94=B6=E7=AB=99=E5=86=85=E7=9A=84=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/engines/oracle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 7f19a394ff..7e23d5184e 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -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} ) From 5e3b021c440467cc7b25c9fc4ed3c4b26808d0d9 Mon Sep 17 00:00:00 2001 From: "zhuhong.lee" <275516080@qq.com> Date: Thu, 28 Mar 2024 14:44:47 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D=E5=8F=8ABlack=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/engines/oracle.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/sql/engines/oracle.py b/sql/engines/oracle.py index 7e23d5184e..7dfad3bbaa 100644 --- a/sql/engines/oracle.py +++ b/sql/engines/oracle.py @@ -1268,19 +1268,19 @@ def backup(self, workflow, cursor, begin_time, end_time): AND b.rn =1 """ # 使用logminer抓取回滚SQL # 12c以下版本用此SQL - logmnr_start_sql_old = f"""begin + 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_new = f"""begin + 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;""" + 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() @@ -1295,16 +1295,24 @@ def backup(self, workflow, cursor, begin_time, end_time): # 判断数据库版本,12c及以上版本手动添加redo文件来分析 if int(self.server_version[0]) > 11: cursor.execute(redo_files_sql) - rows=cursor.fetchall() - for index,row in enumerate(rows): + 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;") + 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) + 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_sql_old) + cursor.execute(logmnr_start_before12c_sql) cursor.execute(undo_sql) rows = cursor.fetchall() cursor.execute(logmnr_end_sql)