由于客户环境的堡垒机常常会莫名的断开链接,也不是简单的超时,由于有时候即便你一直在操做,也可能会断。
这样对于操做一些耗时长且中途中断可能会致使异常的操做就很危险,而最简单的避免方法就是将其写到脚本中,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