由於客戶環境的堡壘機常常會莫名的斷開鏈接,也不是簡單的超時,由於有時候即便你一直在操做,也可能會斷。
這樣對於操做一些耗時長且中途中斷可能會致使異常的操做就很危險,而最簡單的避免方法就是將其寫到腳本中,nohup掛到後臺去執行。
本文以在線建立索引爲例,好比給jingyu用戶下T1表建立table_name,table_type兩個字段的聯合索引。sql
vi createidx.sh sqlplus / as sysdba <<EOF set timing on CREATE INDEX jingyu.IDX_T1 ON jingyu.T1(table_name,table_type) tablespace DBS_D_JINGYU parallel 8 online; alter INDEX jingyu.IDX_T1 noparallel; EOF nohup sh createidx.sh > createidx.log &
關於索引的大小、臨時表空間使用等預估能夠經過預查看建立索引的語句來得到比較準確的參考:shell
--這裏沒加online是由於測試online不會顯示具體的索引預估大小 explain plan for CREATE INDEX jingyu.IDX_T1 ON jingyu.T1(table_name,table_type) tablespace DBS_D_JINGYU; --查看執行計劃 set lines 1000 pages 1000 select * from table(dbms_xplan.display()); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2186317495 --------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------- | 0 | CREATE INDEX STATEMENT | | 8 | 152 | 3 (0)| 00:00:01 | | 1 | INDEX BUILD NON UNIQUE| IDX_T1 | | | | | | 2 | SORT CREATE INDEX | | 8 | 152 | | | | 3 | TABLE ACCESS FULL | T1 | 8 | 152 | 2 (0)| 00:00:01 | --------------------------------------------------------------------------------- Note ----- - estimated index size: 65536 bytes 14 rows selected.
[oracle@jystdrac1 ~]$ tail -20f createidx.log Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options sys@CRMDB> sys@CRMDB> Index created. Elapsed: 00:01:31.41 sys@CRMDB> Index altered. Elapsed: 00:00:05.64 sys@CRMDB> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options