RAC环境下,初始化参数文件与但实例下参数文件有些异同,主要表现在初始化参数可以为多个实例公用,也可以单独设置各个实例的初始化参数。对于那些非共用的初始化参数则必须要单独设置,而共用的则可以单独设置,但一般不建议这么用。本文描述RAC 环境下参数文件(spfile)的相关管理工作。
有关RAC环境下的重要参数描述,请参考:RAC 环境下重要参数
- 1、参数文件的位置
- SQL> show parameter instance_name
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- instance_name string ora10g1
- SQL> show parameter spfile;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string +DG1/ora10g/spfileora10g.ora
- SQL> show parameter instance_name
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- instance_name string ora10g2
- SQL> show parameter spfile
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string +DG1/ora10g/spfileora10g.ora
- SQL> show parameter cluster
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- cluster_database boolean TRUE
- cluster_database_instances integer 2
- oracle@bo2dbp:~> cd /u01/oracle/admin/ora10g
- oracle@bo2dbp:/u01/oracle/admin/ora10g> ls
- adump bdump cdump dpdump hdump pfile udump
- oracle@bo2dbp:/u01/oracle/admin/ora10g> cd pfile
- oracle@bo2dbp:/u01/oracle/admin/ora10g/pfile> ls -hltr
- total 4.0K
- -rw-r----- 1 oracle oinstall 2.7K 2012-09-27 12:12 init.ora.8272012121245
- oracle@bo2dbp:/u01/oracle/admin/ora10g/pfile> cd $ORACLE_HOME/dbs
- oracle@bo2dbp:/u01/oracle/db/dbs> ls *.ora
- init+ASM1.ora initdw.ora initGOBO1A_tmp.ora initGOBO4A.ora init.ora initora10g1.ora
- oracle@bo2dbp:/u01/oracle/db/dbs> more initora10g1.ora
- SPFILE='+DG1/ora10g/spfileora10g.ora'
- oracle@bo2dbs:/u01/oracle/db/dbs> more initora10g2.ora
- SPFILE='+DG1/ora10g/spfileora10g.ora'
- #由上面的查询可知RAC环境下的参数文件通常都存放在RAW或者ASM中,缺省路径为$ORACLE_HOME/dbs/init{ORACLE_SID}.ora
- #各个实例只是存放pfile文件,pfile文件的内容是指向spfile文件的位置,即告诉,兄弟,你去xx去找那个spfile吧,哈哈,,,
- #注,Oracle数据库启动时会先找spfile${ORACLE_SID.ora},如果对应的spfile不存在则找spfile.ora
- #如果spfile.ora找不到,则找相应的pfile(init{ORACLE_SID}.ora)
- #那,要是都找不到呢,那就是用缺省的init.ora尝试启动实例
- 2、参数文件的备份
- 参数文件备份的方式有很多种,一般情况下当启用了RMAN自动备份控制文件时,会自动备份参数文件。
- 其次是手工备份参数文件,这种方式通常是将spfile内容转换为pfile,说简单点,转为文本文件保存,文件名任意。
- 建议在修改参数文件之前先手工备份参数文件,使用命令: create pfile=['<dir>'] from spfile;
- 注,单实例情形下,如果使用spfile文件启动实例,可以通过上面的方式直接备份,RAC环境下这么干,那就把pfile文件给覆盖了
- 因此,RAC环境下建议为pfile文件指定不同的文件名。如当前为initora10g1.ora,则可以指定为initora10g1.ora.bak
- SQL> create pfile='/u01/oracle/db/dbs/initora10g1.ora.bak' from spfile;
- File created.
- SQL> ho ls /u01/oracle/db/dbs/*ora10g*
- /u01/oracle/db/dbs/hc_ora10g1.dat /u01/oracle/db/dbs/initora10g1.ora.bak
- /u01/oracle/db/dbs/initora10g1.ora /u01/oracle/db/dbs/orapwora10g1
- SQL> ho more /u01/oracle/db/dbs/initora10g1.ora.bak
- ora10g2.__db_cache_size=142606336
- ora10g1.__db_cache_size=163577856
- ora10g1.__java_pool_size=4194304
- ora10g2.__java_pool_size=4194304
- ora10g1.__large_pool_size=4194304
- ora10g2.__large_pool_size=4194304
- ora10g2.__shared_pool_size=180355072
- ora10g1.__shared_pool_size=159383552
- ora10g1.__streams_pool_size=0
- ora10g2.__streams_pool_size=0
- *.audit_file_dest='/u01/oracle/admin/ora10g/adump'
- *.background_dump_dest='/u01/oracle/admin/ora10g/bdump'
- *.cluster_database_instances=2
- *.cluster_database=true
- *.compatible='10.2.0.3.0'
- *.control_files='+DG2/ora10g/controlfile/current.286.795096347',
- '+REV/ora10g/controlfile/current.295.795096347'
- *.core_dump_dest='/u01/oracle/admin/ora10g/cdump'
- *.db_block_size=8192
- *.db_create_file_dest='+DG2'
- *.db_domain=''
- *.db_file_multiblock_read_count=16
- *.db_name='ora10g'
- *.db_recovery_file_dest='+REV'
- *.db_recovery_file_dest_size=2147483648
- *.dispatchers='(PROTOCOL=TCP) (SERVICE=ora10gXDB)'
- ora10g2.instance_number=2
- ora10g1.instance_number=1
- *.job_queue_processes=10
- ora10g1.local_listener='local_lsnr_ora10g1'
- ora10g2.local_listener='local_lsnr_ora10g2'
- *.open_cursors=300
- *.pga_aggregate_target=112197632
- *.processes=150
- *.remote_listener='REMOTE_LSNR_ORA10G'
- *.remote_login_passwordfile='exclusive'
- *.sga_target=337641472
- ora10g2.thread=2
- ora10g1.thread=1
- *.undo_management='AUTO'
- ora10g2.undo_tablespace='UNDOTBS2'
- ora10g1.undo_tablespace='UNDOTBS1'
- *.user_dump_dest='/u01/oracle/admin/ora10g/udump'
- 对于上面的参数文件里列出的信息,如果参数前面带有星号,则表明当前的参数为共用参数,前面有实例名的则为实例参数
- 3、参数文件的修改
- 参数文件中参数修改方式如下:
- alter system|session set parametername = values scope = memory | spfile |both sid = 'sid' | ‘*’;
- scope
- memory : 只对当前有效,下次启动则失效
- spfile : 只对spfile 修改,必须经过下一次启动才生效,当前的实例没有修改
- both :内存与参数文件都将修改,当不指定scope时,缺省为both.
- system | session
- system : system级别有效,影响整个系统及所有使用者
- session : 仅当前session有效,一旦退出之后将实效
- 'sid' | ‘*’
- 这个在RAC环境下使用的较为频繁,指定sid_name则当前指定的实例生效,如果指定 '*',则所有实例生效
- 注,缺省情况下为sid='*',因此修改是不要忘了,如果没有指定sid,则RAC上的所有实例都会被修改
- 下面是修改示例
- SQL> show parameter instance_name
- NAME TYPE VALUE
- ------------------------------------ ----------- -------------------
- instance_name string ora10g1
- SQL> show parameter pga
- NAME TYPE VALUE
- ------------------------------------ ----------- -------------------
- pga_aggregate_target big integer 107M
- SQL> alter system set pga_aggregate_target=100m scope=both sid='ora10g1'; -->将ora10g1的pga改为100m
- System altered.
- SQL> alter system set pga_aggregate_target=90m sid='ora10g2'; -->将ora10g2的pga改为90m
- System altered.
- SQL> show parameter pga -->当前的pga已经被改为100m
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- pga_aggregate_target big integer 100M
- SQL> conn system/oracle@ora10g2 -->连接到实例 ora10g2
- Connected.
- SQL> show parameter instance_name
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- instance_name string ora10g2
- SQL> show parameter pga -->此时pga的值显示为90m
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- pga_aggregate_target big integer 90M
- SQL> create pfile='/u01/oracle/db/dbs/initora10g1.ora.emp' from spfile;
- create pfile='/u01/oracle/db/dbs/initora10g1.ora.emp' from spfile
- *
- ERROR at line 1:
- ORA-01031: insufficient privileges -->缺乏权限,因为当前连接的是instance ora10g2
- SQL> conn system/oracle@ora10g1
- Connected.
- SQL> create pfile='/u01/oracle/db/dbs/initora10g1.ora.tmp' from spfile;
- File created.
- SQL> ho cat /u01/oracle/db/dbs/initora10g1.ora.tmp |grep pga
- *.pga_aggregate_target=112197632 #新的pfile文件中同时存在pga的值
- ora10g1.pga_aggregate_target=104857600 #有两个指定了实例名,此时谁生效呢?我们前面已经查询出了结果
- ora10g2.pga_aggregate_target=94371840 #同一参数,有实例名的值将优先有带*的参数值
- SQL> alter system reset pga_aggregate_target sid='ora10g1';-->使用reset方式重置pga,或恢复缺省值
- -->如果需要保留两个新改的参数,建议reset之前的共用参数以避免混淆
- System altered. -->在reset原来的参数时,不指定sid或sid='*'
- SQL> show parameter pga
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- pga_aggregate_target big integer 100M
- SQL> conn system/oracle@ora10g2
- Connected.
- SQL> alter system reset pga_aggregate_target sid='ora10g2';
- System altered.
- #Author : Robinson
- #Blog : http://blog.csdn.net/robinson_0612
- SQL> show parameter pga
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- pga_aggregate_target big integer 90M
- oracle@bo2dbp:~> srvctl stop instance -d ora10g -i ora10g1
- oracle@bo2dbp:~> srvctl start instance -d ora10g -i ora10g1
- SQL> show parameter instance_name
- NAME TYPE VALUE
- ------------------------------------ ----------- -------------------
- instance_name string ora10g1
- SQL> show parameter pga
- NAME TYPE VALUE
- ------------------------------------ ----------- -------------------
- pga_aggregate_target big integer 107M
- 4、spfile文件位置的修改
- SQL> show parameter spfile;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string +DG1/ora10g/spfileora10g.ora
- SQL> create spfile='+REV/ORA10G/spfileora10g.ora'
- 2 from pfile='/u01/oracle/db/dbs/initora10g1.ora.bak';
- File created.
- SQL> ho echo "spfile='+REV/ORA10G/spfileora10g.ora'" >/u01/oracle/db/dbs/initora10g1.ora
- SQL> ho more /u01/oracle/db/dbs/initora10g1.ora
- spfile='+REV/ORA10G/spfileora10g.ora'
- SQL> startup force;
- SQL> show parameter spfile;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string +REV/ora10g/spfileora10g.ora
- SQL> shutdown immediate;
- SQL> exit
- oracle@bo2dbp:~> ssh bo2dbs
- Last login: Fri Sep 28 15:42:59 2012 from 192.168.1.108
- oracle@bo2dbs:~> echo "spfile='+REV/ORA10G/spfileora10g.ora'" >/u01/oracle/db/dbs/initora10g2.ora
- oracle@bo2dbs:~> srvctl stop database -d ora10g
- oracle@bo2dbs:~> srvctl start database -d ora10g
- oracle@bo2dbs:~> export ORACLE_SID=ora10g2
- oracle@bo2dbs:~> sqlplus / as sysdba
- SQL> show parameter pfile; -->查看时还是使用之前的spfile文件
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string +DG1/ora10g/spfileora10g.ora
- oracle@bo2dbs:~> srvctl config database -d ora10g -a
- bo2dbp ora10g1 /u01/oracle/db
- bo2dbs ora10g2 /u01/oracle/db
- DB_NAME: ora10g
- ORACLE_HOME: /u01/oracle/db
- SPFILE: +DG1/ora10g/spfileora10g.ora
- DOMAIN: null
- DB_ROLE: null
- START_OPTIONS: null
- POLICY: AUTOMATIC
- ENABLE FLAG: DB ENABLED
- #下面将参数文件路径更新到ocr,此时数据库并未shutdown,生产环境建议先停止数据库然后再修改
- oracle@bo2dbs:~> srvctl modify database -d ora10g -p '+REV/ORA10G/spfileora10g.ora'
- oracle@bo2dbs:~> srvctl stop database -d ora10g
- oracle@bo2dbs:~> srvctl config database -d ora10g -a
- bo2dbp ora10g1 /u01/oracle/db
- bo2dbs ora10g2 /u01/oracle/db
- DB_NAME: ora10g
- ORACLE_HOME: /u01/oracle/db
- SPFILE: +REV/ORA10G/spfileora10g.ora
- DOMAIN: null
- DB_ROLE: null
- START_OPTIONS: null
- POLICY: AUTOMATIC
- ENABLE FLAG: DB ENABLED
- oracle@bo2dbs:~> srvctl start database -d ora10g
- oracle@bo2dbs:~> sqlplus / as sysdba
- SQL> show parameter spfile;
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- spfile string +REV/ora10g/spfileora10g.ora
- #使用srvctl start启动时,不会依赖类似于单实例环境或rac环境下的sqlplus启动数据库时按顺序寻找spfile文件,
- #而是直接根据ocr中spfile文件位置启动数据库。
- 转:http://blog.csdn.net/leshami/article/details/8278931