背景是這樣的,公司在做自動化測驗,需要頻繁restore 資料庫。目前用的是存盤程序,大致是查詢出變動的表,然后將這些表情況,從另一個user中copy initial data 到當前user相對應的表,完成資料重置。但現在遇到的問題是,只能用XE 版本的oracle,因此運行記憶體最多只有2G,在重置資料庫的時候,耗時太長,有時候甚至需要10-15分鐘。想求助除了用以上我說的存盤程序的方法,還有什么更效率省時的重置資料庫的方法?
附上restore db 的存盤程序如下,希望有大神可以指點一二。
create or replace procedure reloadDB as
counter number(10);
sql_statement varchar2(255);
cursor cur_test is
select table_name
from all_tables
where owner = 'TANGO_DEV'
and table_name not in ('MODIFICATIONS$', 'PLAN_TABLE')
and table_name not in
(select mview_name
from all_mviews
where owner = 'TANGO_DEV');
begin
/* no support for foreign key constraints! */
/* truncate and reload all tables that has been changed*/
sql_statement := 'SELECT sum(COUNT_MODIFICATIONS) FROM TANGO_DEV.MODIFICATIONS$ WHERE TABLE_NAME = :tablename';
for rec_table in cur_test loop
execute immediate sql_statement
into counter
using upper(rec_table.table_name);
if counter > 0 then
execute immediate 'ALTER TABLE TANGO_DEV.' || rec_table.table_name || ' DISABLE ALL TRIGGERS';
execute immediate 'TRUNCATE TABLE TANGO_DEV.' || rec_table.table_name;
execute immediate 'INSERT /*+append parallel(4,a)*/ INTO TANGO_DEV.' || rec_table.table_name || ' a SELECT * FROM SAVE_TANGO_DEV.' || rec_table.table_name ||' NOLOGGING';
execute immediate 'ALTER TABLE TANGO_DEV.' || rec_table.table_name || ' ENABLE ALL TRIGGERS';
end if;
end loop;
/* delete concurrent entrys */
execute immediate 'DELETE ' || 'TANGO_DEV' ||
'.MODIFICATIONS$ where concurrent_entry = 1';
/* reset modification counter */
execute immediate 'UPDATE ' || 'TANGO_DEV' ||
'.MODIFICATIONS$ SET COUNT_MODIFICATIONS = 0';
commit;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/240622.html
標籤:高級技術
下一篇:2020-12-26:mysql中,表person有欄位id、name、age、sex,id是主鍵,name是普通索引,age和sex沒有索引。select *
