全局变量 写全比较稳妥
set的时候自动加both , reset时不是自动both
Applies to:
Oracle Database - Enterprise Edition - Version 11.2.0.4 and later
Information in this document applies to any platform.
Symptoms
When the OPTIMIZER_FEATURES_ENABLE parameter value is reset using:
alter system reset optimizer_features_enable scope=both;
This resets the value to the original in v$parameter and v$spparameter, but not in the v$sys_optimizer_env or v$ses_optimizer_env.
Due to this, the newer sessions will still be using the modified value instead of the original value.
Consider the below testcase:
- Original settings:
show parameter OPTIMIZER_FEATURES_ENABLE;
NAME TYPE VALUE
------------------------------------ -----------
optimizer_features_enable string 19.1.0
- Modifying the OFE to '12.1.0.2' at system level:
ALTER SYSTEM SET OPTIMIZER_FEATURES_ENABLE='12.1.0.2' scope=both sid='*';
System altered.
- New value gets applied as below:
show parameter OPTIMIZER_FEATURES_ENABLE;
NAME TYPE VALUE
------------------------------------ -----------
optimizer_features_enable string 12.1.0.2
select name,value from v$ses_optimizer_env where sid=sys_context('USERENV','SID') and name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
select name,value from v$sys_optimizer_env where name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
- Reset the value to original:
alter system reset OPTIMIZER_FEATURES_ENABLE scope=both sid='*';
System altered.
show parameter OPTIMIZER_FEATURES_ENABLE;
NAME TYPE VALUE
------------------------------------ -----------
optimizer_features_enable string 19.1.0 <<<<<<<<<< this is correct as we ran a 'reset'
- However, checking the details in v$ses_optimizer_env or v$sys_optimizer_env still shows the modified value:
select name,value from v$ses_optimizer_env where sid=sys_context('USERENV','SID') and name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
select name,value from v$sys_optimizer_env where name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
This is wrong since RESET command was issued and hence it should should display the default value of 19.1.0 and not the new value.
At this time, any new session launched will continue to use OFE as the modified value in the execution plan:
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('12.1.0.2')
DB_VERSION('19.1.0')
Changes
Cause
BUG 32234845 - ALTER SYSTEM RESET DOES NOT UPDATE V$SYS_OPTIMIZER_ENV OR V$SES_OPTIMIZER_ENV
Solution
Suggested workaround is to re-start the database once after running the 'reset' command. This will make the OFE revert back to the original value for all the sessions.
SQL> show parameter OPTIMIZER_FEATURES_ENABLE;
optimizer_features_enable string 19.1.0
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
* optimizer_features_enable string
SQL> alter system SET OPTIMIZER_FEATURES_ENABLE='12.1.0.2';
System altered.
node1:
SQL> show parameter OPTIMIZER_FEATURES_ENABLE;
optimizer_features_enable string 12.1.0.2
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
* optimizer_features_enable string 12.1.0.2
SQL> select name,value from v$sys_optimizer_env where name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
SQL> select name,value from v$ses_optimizer_env where sid=sys_context('USERENV','SID') and name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
node2:
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
* optimizer_features_enable string 12.1.0.2
SQL>
SQL> show parameter OPTIMIZER_FEATURES_ENABLE;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 12.1.0.2
SQL>
SQL> select name,value from v$sys_optimizer_env where name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
SQL> select name,value from v$ses_optimizer_env where sid=sys_context('USERENV','SID') and name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
-----alter system set 什么都不加全生效了
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE;
System altered.
node1:node2: 也可以去掉,但是node2重启又变了。
SQL> alter system SET OPTIMIZER_FEATURES_ENABLE='12.1.0.2' sid='cdb2';
System altered.
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE scope=both sid='*';
System altered.
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 19.1.0
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
cdb2 optimizer_features_enable string 12.1.0.2
SQL>
SQL>
SQL>
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE scope=both sid='*';
System altered.
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 19.1.0
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
cdb2 optimizer_features_enable string 12.1.0.2
SQL>
node2:重启变回来了
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
cdb2 optimizer_features_enable string 12.1.0.2
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 19.1.0
SQL> startup force
ORACLE instance started.
Total System Global Area 608170680 bytes
Fixed Size 9167544 bytes
Variable Size 557842432 bytes
Database Buffers 33554432 bytes
Redo Buffers 7606272 bytes
Database mounted.
Database opened.
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
cdb2 optimizer_features_enable string 12.1.0.2 --所以重启要变回来
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 12.1.0.2
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE;---只有cdb2有,这样不能reset
alter system reset OPTIMIZER_FEATURES_ENABLE
*
ERROR at line 1:
ORA-32010: cannot find entry to delete in SPFILE
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE sid='cdb2';---reset时没有both又不生效
System altered.
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 12.1.0.2
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
* optimizer_features_enable string
-----set的时候不要both, reset时要both
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE scope=both; 没有both要出错,有both可以改,不用指定sid
System altered.
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 19.1.0
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
* optimizer_features_enable string
SQL> startup force
ORACLE instance started.
Total System Global Area 608170680 bytes
Fixed Size 9167544 bytes
Variable Size 557842432 bytes
Database Buffers 33554432 bytes
Redo Buffers 7606272 bytes
Database mounted.
Database opened.
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
* optimizer_features_enable string
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 19.1.0
SQL>
要alter system reset OPTIMIZER_FEATURES_ENABLE scope=both sid='*';或者重启
SQL> select name,value from v$ses_optimizer_env where sid=sys_context('USERENV','SID') and name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
SQL> select name,value from v$sys_optimizer_env where name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 12.1.0.2
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
* optimizer_features_enable string
SQL> show parameter OPTIMIZER_FEATURES_ENABLE;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 12.1.0.2
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE sid='*';
alter system reset OPTIMIZER_FEATURES_ENABLE sid='*'
*
ERROR at line 1:
ORA-32010: cannot find entry to delete in SPFILE
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE scope=both sid='*';
System altered.
SQL>
SQL>
SQL>
SQL>
SQL> show parameter OPTIMIZER_FEATURES_ENABLE;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 19.1.0
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
* optimizer_features_enable string
SQL> select name,value from v$sys_optimizer_env where name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 19.1.0
SQL>
SQL> select name,value from v$ses_optimizer_env where sid=sys_context('USERENV','SID') and name='optimizer_features_enable';
NAME VALUE
-------------------------------------------------- -------------------------
optimizer_features_enable 19.1.0
SQL>
----给2机单独设置的
SQL> alter system SET OPTIMIZER_FEATURES_ENABLE='12.1.0.2' sid='cdb2';
System altered.
SQL> show parameter OPTIMIZER_FEATURES_ENABLE;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 12.1.0.2
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
cdb2 optimizer_features_enable string 12.1.0.2
在node1 执行
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE scope=both sid='*';
SQL> alter system reset OPTIMIZER_FEATURES_ENABLE scope=both sid='*';
System altered.
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
* optimizer_features_enable string
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 19.1.0
node2:node1上设置后设置可以生效,但是重启后会变回去。因为设置了sid='cdb2';,所以这个sid='cdb2';不要单独设置
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
cdb2 optimizer_features_enable string 12.1.0.2
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 19.1.0
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.20.0.0.0
[oracle@rac2 ~]$ s
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Oct 12 03:09:53 2024
Version 19.20.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.20.0.0.0
SQL> startup force;
ORACLE instance started.
Total System Global Area 608170680 bytes
Fixed Size 9167544 bytes
Variable Size 557842432 bytes
Database Buffers 33554432 bytes
Redo Buffers 7606272 bytes
Database mounted.
Database opened.
SQL> show spparameters OPTIMIZER_FEATURES_ENABLE
SID NAME TYPE VALUE
-------- ----------------------------- ----------- ----------------------------
cdb2 optimizer_features_enable string 12.1.0.2
SQL> show parameters OPTIMIZER_FEATURES_ENABLE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_features_enable string 12.1.0.2
SQL>