数据恢复|数据库运维:RAC环境下不同实例的参数文件选择与设置
【云和恩墨,提供7*24最专业的数据恢复(Oracle,MySQL)服务,致力于为您的数据库系统做最后一道安全防护!服务热线:010-59007017-7030】数据恢复|数据库运维|性能优化|安全保障
参数文件是Oracle数据库文件中级别最低,也是最基本的文件,但是也是数据库实例启动第一个涉及的文件。如果参数文件缺失或者某些参数设置错误,数据库就无法启动。
我们思考一个问题: V$SPPARAMETER 参数本身就包含了 SID 列,SPFILE 中本身就包含了所有实例的设置,那么查询 GV$SPPARAMETER 视图是否就意义不大呢,GV$SPPARAMETER 是否有意义?
看看这样一种情形:RAC 的各个节点可以使用统一的 SPFILE 启动,同样也可以选择不同的 SPFILE 来进行启动,这时 GV$SPPARAMETER 视图中获取结果,才是真正各个实例 SPFILE 中设置的结果,其意义由此体现。
这样说比较难以理解,看一个简单的例子:
SQL> select inst_id, name, value
2 from gv$system_parameter
3 where name = 'open_cursors';INST_ID NAME VALUE
---------- ------------------------------ --------------------------------------------------
1 open_cursors 600
2 open_cursors 400SQL> select sid, name, value
2 from v$spparameter
3 where name = 'open_cursors';SID NAME VALUE
---------- ------------------------------ --------------------------------------------------
* open_cursors 300
test1 open_cursors 500
test2 open_cursors 700SQL> select inst_id, sid, name, value
2 from gv$spparameter
3 where name = 'open_cursors';INST_ID SID NAME VALUE
---------- ---------- ------------------------------ ------------------------------------
1 * open_cursors 300
1 test1 open_cursors 500
1 test2 open_cursors 700
2 * open_cursors 300
2 test1 open_cursors 500
2 test2 open_cursors 700已选择6行。
SQL> select inst_id, name, value
2 from gv$system_parameter
3 where name = 'spfile';INST_ID NAME VALUE
---------- ------------------------------ --------------------------------------------------
1 spfile +DATA/test/spfiletest.ora
2 spfile +DATA/test/spfiletest.ora
下面里面内存中参数来创建 SPFILE,并利用新建的 SPFILE 来启动当前实例:
SQL> create spfile='/export/home/oracle/spfiletest1.ora' from memory;
文件已创建。
SQL> host
$ vi /export/home/oracle/inittest1.ora
"/export/home/oracle/inittest1.ora" [New file]
spfile=/export/home/oracle/spfiletest1.ora"/export/home/oracle/inittest1.ora" [New file] 2 lines, 44 characters
$ exitSQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup pfile=/export/home/oracle/inittest1.ora
ORACLE 例程已经启动。Total System Global Area 776896512 bytes
Fixed Size 2098776 bytes
Variable Size 246069672 bytes
Database Buffers 524288000 bytes
Redo Buffers 4440064 bytes
数据库装载完毕。
数据库已经打开。
下面检查 spfile 中的设置:
SQL> select inst_id, name, value
2 from gv$system_parameter
3 where name = 'spfile';INST_ID NAME VALUE
---------- ------------------------------ --------------------------------------------------
1 spfile /export/home/oracle/spfiletest1.ora
2 spfile +DATA/test/spfiletest.oraSQL> select inst_id, name, value
2 from gv$system_parameter
3 where name = 'open_cursors';INST_ID NAME VALUE
---------- ------------------------------ --------------------------------------------------
1 open_cursors 600
2 open_cursors 400SQL> select sid, name, value
2 from v$spparameter
3 where name = 'open_cursors';SID NAME VALUE
---------- ------------------------------ --------------------------------------------------
test1 open_cursors 600
test2 open_cursors 400SQL> select inst_id, sid, name, value
2 from gv$spparameter
3 where name = 'open_cursors';INST_ID SID NAME VALUE
---------- ---------- ------------------------------ --------------------------------
2 * open_cursors 300
2 test1 open_cursors 500
2 test2 open_cursors 700
1 test1 open_cursors 600
1 test2 open_cursors 400
可以看到,由于两个实例采用了不同的 SPFILE,导致两个实例上设置的对方实例的初始化参数值,与对方实例上当前设置值不符。
在上面的例子中,两个实例上真正的参数设置查询方式为:
SQL> select inst_id, sid, name, value
2 from gv$spparameter
3 where name = 'open_cursors'
4 and substr(sid, -1) = to_char(inst_id);INST_ID SID NAME VALUE
---------- ---------- ------------------------------ -----------------------------------
2 test2 open_cursors 700
1 test1 open_cursors 600
由此我们可以看到,在不同场景之下,获取真实参数的过程可能是一波三折,疏为不易的。