Oracle配置(配置pfile文件)

当生产端应用为Oracle RAC集群,灾备端为单机时,在灾备端创建完数据库后,需要执行相关配置操作。

通过手工复制方法,将生产端数据库必备文件复制至灾备端

  1. 在灾备端创建数据库。

    单实例环境下且数据库是安装在文件系统上时的灾备端数据库环境,需要将生产端的数据库所必须的文件和文件夹拷贝到灾备端,并修改拷贝文件所属的用户和组。包括拷贝以下目录和文件:$ORACLE_BASE\admin\dbname下所有目录;$ORACLE_HOME\network\admin\listener.ora文件;$ORACLE_HOME\network\admin\tnsnames.ora;$ORACLE_HOME\dbs下的密码文件和参数文件到灾备端的相同目录。

  2. 在生产端数据库上,通过spfile文件创建pfile文件。

    1. 执行sqlplus / as sysdba命令,通过OS认证连接生产端数据库实例。
      oracle@suse140:/u01/app/oracle/product/11.2.0/db_1/dbs> export ORACLE_SID=lqraw1 
      oracle@suse140:/u01/app/oracle/product/11.2.0/db_1/dbs> sqlplus / as sysdba 
       
      SQL*Plus: Release 11.2.0.3.0 Production on Fri Jun 26 09:57:08 2020 
       
      Copyright (c) 1982, 2011, Oracle.  All rights reserved. 
       
       
      Connected to: 
      Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
      With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, 
      Data Mining and Real Application Testing options     
    2. 执行show parameter spfile命令,查看spfile文件。
      SQL> show parameter spfile; 
       
      NAME     TYPE  VALUE 
      ------------------------------------ ----------- ------------------------------ 
      spfile     string +LQRAWDATA/lqraw/spfilelqraw.o 
       ra 
           
    3. 执行create pfile='/home/oracle/initlqraw1.ora' from spfile命令,通过spfile文件创建pfile文件。
      SQL> create pfile='/home/oracle/initlqraw1.ora' from spfile;  
       
      File created.

  3. 修改本地的pfile文件,并将修改后的pfile文件复制到灾备端Oracle主机的根目录下。

    图1 修改前pfile文件
    图2 修改后pfile文件

    红色字体部分为修改的内容,具体的修改方法请咨询数据库管理员,以防止修改后对灾备数据库产生影响。

  4. 将灾备端阵列的LUN映射给灾备主机,且数据库存储配置完成;或通过eReplication完成测试,且完成测试流程中配置存储步骤。
  5. 启动灾备端数据库。
  6. 在灾备端数据库上,通过spfile文件创建pfile文件。

    1. 执行sqlplus / as sysdba命令,通过OS认证连接灾备端数据库实例。
      oracle@suse140:/u01/app/oracle/product/11.2.0/db_1/dbs> export ORACLE_SID=lqraw 
      oracle@suse140:/u01/app/oracle/product/11.2.0/db_1/dbs> sqlplus / as sysdba 
       
      SQL*Plus: Release 11.2.0.3.0 Production on Fri Jun 26 09:57:08 2020 
       
      Copyright (c) 1982, 2011, Oracle.  All rights reserved. 
       
       
      Connected to: 
      Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
      With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, 
      Data Mining and Real Application Testing options 
           
    2. 执行startup pfile='/home/oracle/ initlqraw1.ora'命令,通过本地pfile启动数据库。
      SQL> startup pfile='/home/oracle/ initlqraw1.ora';  
      ORACLE instance started. 
       
      Total System Global Area 5144301568 bytes 
      Fixed Size                  2230424 bytes 
      Variable Size            1157629800 bytes 
      Database Buffers         3976200192 bytes 
      Redo Buffers                8241152 bytes 
      Database mounted. 
      Database opened.     
    3. 执行create spfile from pfile='/home/oracle/initlqraw1.ora'命令,创建本地spfile文件。
      SQL> create spfile from pfile='/home/oracle/initlqraw1.ora'; 
       
      File created. 
           
    4. 执行shutdown immediate命令,关闭数据库。
      SQL> shutdown immediate 
      Database closed. 
      Database dismounted. 
      ORACLE instance shut down.
    5. 执行startup命令,启动数据库。
      SQL> startup 
      ORACLE instance started. 
       
      Total System Global Area 5144301568 bytes 
      Fixed Size                  2230424 bytes 
      Variable Size            1157629800 bytes 
      Database Buffers         3976200192 bytes 
      Redo Buffers                8241152 bytes 
      Database mounted. 
      Database opened.
    6. 执行show parameter spfile命令,检查spfile文件已经在本地。
       SQL> show parameter spfile;                   
       
      NAME                                 TYPE        VALUE 
      ------------------------------------ ----------- ------------------------------ 
      spfile                               string      /u01/app/oracle/11.2.0/product 
                                                       /db/dbs/spfilelqraw.ora     

    对于Oracle 12c数据库,以上操作完成后,请执行srvctl modify database -db 数据库名称 -spfile spfile文件本地路径命令,将spfile文件指定到本地路径。

通过创建数据库的方法,在灾备端生成容灾必备文件

  1. 在灾备端创建数据库。

    非Windows操作系统下的dbca、Windows操作系统下Database Configuration Assistant。

    创建数据库后的spfile文件的存放在本地或LUN上。

  2. 确认spfile文件的存放方式。

    检查非Windows操作系统下“$ORACLE_HOME/dbs”,Windows操作系统下“%ORACLE_HOME%/database”目录中是否存在“spfile${ORACLE_SID}.ora”和“init${ORACLE_SID}.ora”文件。

    • 仅存在“spfile${ORACLE_SID}.ora”:数据库使用spfile文件方式,且存放在本地。
    • 仅存在“init${ORACLE_SID}.ora”:
      • “init${ORACLE_SID}.ora”文件中存在“SPFILE=’+ASMDISKGROUP/xxx/spfile${ORACLE_SID}.ora’”字段类型内容,数据库使用spfile文件方式,且存放在LUN上。
      • “init${ORACLE_SID}.ora”文件不存在“SPFILE=’+ASMDISKGROUP/xxx/spfile${ORACLE_SID}.ora’”字段类型内容:数据库使用spfile文件方式,且存放在本地。
    • “spfile${ORACLE_SID}.ora”和“init${ORACLE_SID}.ora”文件同时存在:数据库使用spfile文件方式,且存放在本地。
    • “spfile${ORACLE_SID}.ora”和“init${ORACLE_SID}.ora”都不存在:数据库不存在。

  3. 可选: 如果spfile文件存放在LUN上时,需要将灾备端数据库的spfile文件存放在本地。

    1. 启动数据库实例。
    2. 执行cat initautoasm.ora命令,查看spfile文件信息。
      bash-4.2$ cat initautoasm.ora  
      SPFILE='+PG_AUTOASM$_DATA/autoasm/spfileautoasm.ora'  
      bash-4.2$ export ORACLE_SID=autoasm     
    3. 执行sqlplus / as sysdba命令,通过OS认证连接在灾备端数据库实例。
      bash-4.2$ sqlplus / as sysdba                          
       
      SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 16 09:32:39 2020 
       
      Copyright (c) 1982, 2011, Oracle.  All rights reserved. 
       
       
      Connected to: 
      Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
      With the Partitioning, Automatic Storage Management, OLAP, Data Mining 
      and Real Application Testing options 
           
    4. 执行create pfile='/home/oracle/initautoasm.ora' from spfile命令,通过spfile文件创建pfile文件。
      SQL> create pfile='/home/oracle/initautoasm.ora' from spfile; 
       
      File created.     
    5. 执行shutdown immediate命令,关闭数据库。
      SQL> shutdown immediate; 
      Database closed. 
      Database dismounted. 
      ORACLE instance shut down.     
    6. 执行startup pfile='/home/oracle/initautoasm.ora'命令,通过本地pfile启动数据库。
      SQL> startup pfile='/home/oracle/initautoasm.ora';  
      ORACLE instance started. 
       
      Total System Global Area 5144301568 bytes 
      Fixed Size                  2230424 bytes 
      Variable Size            1157629800 bytes 
      Database Buffers         3976200192 bytes 
      Redo Buffers                8241152 bytes 
      Database mounted. 
      Database opened.     
    7. 执行create spfile from pfile='/home/oracle/initautoasm.ora'命令,创建本地spfile文件。
      SQL> create spfile from pfile='/home/oracle/initautoasm.ora'; 
       
      File created.     
    8. 执行shutdown immediate命令,关闭数据库。
    9. 执行startup命令,启动数据库。
      SQL> startupORACLE instance started. 
       
      Total System Global Area 5144301568 bytes 
      Fixed Size                  2230424 bytes 
      Variable Size            1157629800 bytes 
      Database Buffers         3976200192 bytes 
      Redo Buffers                8241152 bytes 
      Database mounted. 
      Database opened.     
    10. 执行show parameter spfile命令,检查spfile文件已经在本地。
      SQL> show parameter spfile;                  
       
      NAME                                 TYPE        VALUE 
      ------------------------------------ ----------- ------------------------------ 
      spfile                               string      /u01/app/oracle/11.2.0/product 
                                                       /db/dbs/spfileautoasm.ora     

    对于Oracle 12c数据库,以上操作完成后,请执行srvctl modify database -db 数据库名称 -spfile spfile文件本地路径命令,将spfile文件指定到本地路径。


版权所有 © 华为技术有限公司