标签归档:cancel sql

18c新特性:alter system cancel sql

根据18c官方描述cancel sql功能是在18c中引起,但是实测发现在oracle 12.2中已经有了cancel sql功能,可以实现终止掉某个sql的当前sql正在执行的sql语句,而不是传统的直接kill某个会话.ALTER SYSTEM CANCEL SQL语句有四个参数分别为:
cancel_sql

--会话1
SQL> set lines 150
SQL> select * from v$version;

BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production              0
PL/SQL Release 12.2.0.1.0 - Production                                                    0
CORE    12.2.0.1.0      Production                                                        0
TNS for Linux: Version 12.2.0.1.0 - Production                                            0
NLSRTL Version 12.2.0.1.0 - Production                                                    0


SQL> select sid, serial# from v$session where sid in
  2  (select  sid from v$mystat where rownum=1);

       SID    SERIAL#
---------- ----------
       278       4019

SQL> create table t_xifenfei tablespace users as select * from dba_source;

Table created.

SQL> insert into t_xifenfei select * from t_xifenfei;

274132 rows created.                    <<===没有提交

SQL> select count(*)from t_xifenfei;

  COUNT(*)
----------
    548264

SQL> insert into t_xifenfei select * from t_xifenfei;

548264 rows created.     <<===没有提交

SQL> select count(*)from t_xifenfei;

  COUNT(*)
----------
   1096528

SQL> insert into t_xifenfei select * from t_xifenfei;


--会话2
SQL> select count(*)from t_xifenfei;

  COUNT(*)
----------
    274132

SQL> alter system cancel sql '278,4019';

System altered.

SQL> select count(*)from t_xifenfei;

  COUNT(*)
----------
    274132

--会话1
SQL> insert into t_xifenfei select * from t_xifenfei;
insert into t_xifenfei select * from t_xifenfei
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation

SQL> select count(*)from t_xifenfei;

  COUNT(*)
----------
   1096528

这里可以看到会话1的最后一个insert被cancel,但是前面两个没有提交的insert没有被回滚/提交,看到了cancel sql的功能的实现.

发表在 ORACLE 12C, ORACLE 18C | 标签为 , , | 评论关闭