在12c中,create spfile命令又有了新的参数变更,引入了as copy选项,这个变化是由于一个Bug引入的。
通过以下的测试和验证过程,大家会发现新版本中的这个变化,避免在新版本中遭遇陷阱。以下验证环境为Oracle RAC 12.1.0.2.0,先记录当前DB的资源配置。
[oracle@rac12-node1 ~]$ srvctl config database -db rac12
Database unique name:rac12
Database name:rac12
Oracle home:/u01/app/oracle/product/12.1.0
Oracle user:oracle
Spfile:+DATA/rac12/spfilerac12.ora
Password file:+DATA/RAC12/PASSWORD/pwdrac12.276.902472499
Domain:
Start option:open
Stop option:immediate
Database role:PRIMARY
Management policy:AUTOMATIC
Server pools:racpool
Disk Groups:DATA
Mount point paths:
Services:racdb
Type:RAC
Start concurrency:
Stop concurrency:
OSDBA group:dba
OSOPER group:dba
Database instances:
Configured nodes:
Database is policy managed
对于RAC环境,一般都推荐使用共享的SPFILE,方便维护初始化参数。下面的连续测试主要观察命令执行后对这个参数的影响。
首先测试生成PFILE或者SPFILE,同时指定生成文件的位置,请注意后者直接导致了集群参数文件指向的变更。
SQL>create pfile='/tmp/ffile.ora' from spfile='+DATA/rac12/spfilerac12.ora';
File created. SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:+DATA/rac12/spfilerac12.ora
SQL>create spfile='/tmp/ffile.spfile' from pfile='/tmp/ffile.ora';
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/ffile.spfile
从内存生成PFILE或者SPFILE,同时指定生成文件的位置,后者对于SPFILE同样更新了集群配置。
SQL> create pfile='/tmp/fmem.ora' from memory;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/ffile.spfile
SQL>create spfile='/tmp/fmem.spfile' from memory;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/fmem.spfile
从文件生成PFILE或者SPFILE,不指定生成文件的位置。
SQL> create pfile from spfile='DATA/rac12/spfilerac12.ora';
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/fmem.spfile
SQL>create spfile from pfile='/tmp/ffile.ora';
File created
SQL>! srvctl config database -db rac12|grep -i'spfile'
Spfile:+DATA/spfilerac12_1.ora
指定生成文件位置,但源文件默认使用默认位置。
SQL> create pfile='/tmp/ffile2.ora' from spfile;
File created.
SQL>!srvctl config database -db rac12|grep -i 'spfile'
Spfile:+DATA/spfilerac12_1.ora
SQL>create spfile='/tmp/ffile2.spfile' from pfile;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/ffile2.spfile
生成文件和源文件均使用默认位置。
SQL>create pfile from spfile;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/ffile2.spfile
SQL>create spfile from pfile;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:+DATA/spfilerac12_1.ora
通过测试可见每一次生成SPFILE,都同时更新了Database资源配置里面的SPFILE设定!
由于这个命令执行时没有任何提示会更新Database资源设定,所以很容易导致SPFILE的设定被更改到某个节点的本地文件系统,这样有可能会导致其他节点在重启动之后找不到指定的SPFILE,从而启动失败。
幸运的是,通常RAC在安装完成后,在初始化参数的默认位置($ORACLE_HOME/dbs)一般会创建一个PFILE,里面用SPFILE参数指向了共享的SPFILE。
[oracle@rac12-node3 ~] $ cd $ORACLE_HOME/dbs
[oracle@rac12-node3 dbs] $ ls
hc_rac12_3.dat id_rac12_3.dat init.ora initrac12_3.ora
[oracle@rac12-node3 dbs] $ cat initrac12_3.ora
SPFILE='+DATA/rac12/spfilerac12.ora'
[oracle@rac12-node3 dbs] $
这会如果不知情地执行了之前的创建操作,这会导致部分节点使用不同的SPFILE:
在MOS网站上搜索,确认如下Bug,Oracle提供了补丁修正
Bug 18799993 -CREATE SPFILE updates the DB resource by default as of 12.1 (Doc ID 18799993.8)。
在以下Bug描述中,Oracle详细阐述了这个问题,这是一个仅在RAC环境中出现的问题,并在补丁中提供了AS COPY选项。
As of 12c creating an spfile also updates the spfile location in the cluster. This is different to 11.2 behaviour and can affect scripts that create a local SPFILE that is not accessible to other RAC nodes.
Rediscovery Notes After an spfile is created, the spfile location is updated in the cluster. Other nodes may then be unable to access the new spfile.
Workaround None other than be sure to create SPFILE on a shared disk accessible to all nodes.
Note: This fix extends the CREATE SPFILE syntax to add an "AS COPY" option. If 'AS COPY' is specified the cluster wide spfile location is not updated.
安装后进行简单测试。
SQL>create spfile='/tmp/aferpatch_ffile.spfile' from pfile='/tmp/ffile.ora';
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile.spfile
SQL>create spfile='/tmp/aferpatch_fmen.spfile' from memory;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile.spfile
SQL>create spfile='/tmp/aferpatch_ffile2.spfile' from pfile;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile2.spfile
SQL>create spfile from pfile='/tmp/ffile.ora';
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile2.spfile
SQL>create spfile from memory;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile2.spfile
SQL>create spfile from pfile;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile2.spfile
可以看到有一些改变,现在create spfile from pfile命令只有在指定生成文件路径才会更新Database资源配置,create spfile from memory不再更新Database资源配置。
继续来检查as copy的使用情况。
SQL>create spfile='/tmp/aferpatch_ffile.spfile'from pfile='/tmp/ffile.ora' as copy;
File created.
SQL>! srvctl config database -db rac12|grep -i'spfile'
Spfile:/tmp/aferpatch_ffile2.spfile
SQL>create spfile='/tmp/aferpatch_ffile.spfile' from pfile as copy;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile2.spfile
SQL>create spfile='/tmp/aferpatch_ffile.spfile' from memory as copy;
ERROR at line 1:
ORA-009333:SQL command not properly ended
SQL>create spfile from pfile='/tmp/ffile.ora' as copy;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile2.spfile
SQL>create spfile from pfile as copy;
File created.
SQL>! srvctl config database -db rac12|grep -i 'spfile'
Spfile:/tmp/aferpatch_ffile2.spfile
SQL>create spfile from memory as copy;
ERROR at line 1:
ORA-00933:SQL command not properly ended
可以看到from memory不支持as copy选项,同时加了as copy选项后,即使指定了spfile生成文件的路径,也不再更新Database资源配置。
通过以上测试和验证过程,得出以下结论。
- create spfile from memory:不支持as copy选项,但是也不再更新Database资源配置。
- createspfile from pfile:在指定生成文件路径而且不加as copy选项时,仍然会更新Database资源配置。
通过这个案例可以看出,一个新的版本变化,会改变很多数据库细节上的行为。如果不关注这些细节,就有可能在运维时遭遇困境。所以当我们使用一个新版本时,需要尽可能关注新特性,并保持对于数据库修正的持续跟踪。
节选自《Oracle性能优化与诊断案例精选第七章》