Oracle 数据库的参数文件有两种一种是 pfile(初始化参数文件),
还有一种是 spfile(服务器初始化参数文件),是一个二进制文件,不可读;
实际上 spfile 是 pfile 衍生过来的一新参数文件,应用 9i 以后的版本,在 9i 之前的版本都不支持,只支持 pfile;
而且 pfile 是不能通过 oracle 命令来进行备份的,只有 spfile 才支持备份。
通过 RMAN 的备份来实现参数文件的恢复,仅适用于 9i 以后
01、通过 rman 备份参数文件:
- spfile
- pfile
1)备份
rman target /
backup tag hfedu7pfile format '/backup/full/hfedu7_pfile_hfzcdb_%s_%p_%t' (spfile);
02、备份完之后,我们可以看到如下备份信息:
list backup of spfile;
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
4 Full 96.00K DISK 00:00:00 2022-01-27 19:06:13
BP Key: 4 Status: AVAILABLE Compressed: NO Tag: hfedu7PFILE
Piece Name: /backup/full/hfedu7_pfile_hfzcdb_6_1_1089745573
SPFILE Included: Modification time: 2022-01-27 19:03:33
SPFILE db_unique_name: hfzcDB
03、模拟参数文件丢失:
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ---------------------------------
spfile string/oracle/app/oracle/product/19c/db_1/dbs/spfilehfzcdb.ora
删除参数文件:
[oracle@hfedudb~]$ rm /oracle/app/oracle/product/19c/db_1/dbs/spfilehfzcdb.ora
恢复步骤:
--/*丢失参数文件如何恢复
--备份
rman target /
RMAN> backup tag hfedu7pfile format '/backup/full/hfedu7_pfile_hfzcdb_%s_%p_%t' (spfile);
RMAN> list backup of spfile;
hfeduSQL> startup
--ORA-01078: failure in processing system parameters
--LRM-00109: could not open parameter file '/oracle/app/oracle/product/19c/db_1/dbs/inithfzcdb.ora'
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$vi inithfzcdb.ora
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$cat inithfzcdb.ora
--db_name=hfzcdb
--也可以用rman强制启动到nomount状态
hfeduSQL> startup nomount
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$rman target/
RMAN> restore spfile from '/archive/HFZCDB/autobackup/2023_04_01/o1_mf_s_1133006784_l2hcg0sm_.bkp';
hfeduSQL> shutdown abort
hfeduSQL> startup
--也可以直接通过init.ora文件恢复,根据 init.ora文件内容重新创建 spfilehfzcdb.ora,
--结束*/
操作:
[oracle@hfzcdb91:/archive/HFZCDB/archivelog/2023_04_01]$rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Sat Apr 1 12:06:12 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: HFZCDB (DBID=797496974)
RMAN> backup tag hfedu7pfile format '/backup/full/hfedu7_pfile_hfzcdb_%s_%p_%t' (spfile);
Starting backup at 2023-04-01 12:06:21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=3413 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2023-04-01 12:06:23
channel ORA_DISK_1: finished piece 1 at 2023-04-01 12:06:24
piece handle=/backup/full/hfedu7_pfile_hfzcdb_20_1_1133006783 tag=hfedu7PFILE co mment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2023-04-01 12:06:24
Starting Control File and SPFILE Autobackup at 2023-04-01 12:06:24
piece handle=/archive/HFZCDB/autobackup/2023_04_01/o1_mf_s_1133006784_l2hcg0sm_. bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2023-04-01 12:06:25
RMAN> list backup of spfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
7 Full 42.98M DISK 00:00:01 2023-03-31 19:31:39
BP Key: 7 Status: AVAILABLE Compressed: NO Tag: TAG20230331T193138
Piece Name: /archive/HFZCDB/autobackup/2023_03_31/o1_mf_s_1132947098_l2f k4vcx_.bkp
SPFILE Included: Modification time: 2023-03-31 19:29:23
SPFILE db_unique_name: HFZCDB
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
8 Full 42.98M DISK 00:00:00 2023-03-31 20:00:27
BP Key: 8 Status: AVAILABLE Compressed: NO Tag: TAG20230331T200027
Piece Name: /archive/HFZCDB/autobackup/2023_03_31/o1_mf_s_1132948827_l2f ltvl0_.bkp
SPFILE Included: Modification time: 2023-03-31 19:59:24
SPFILE db_unique_name: HFZCDB
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
10 Full 42.98M DISK 00:00:01 2023-04-01 10:00:57
BP Key: 10 Status: AVAILABLE Compressed: NO Tag: TAG20230401T100056
Piece Name: /archive/HFZCDB/autobackup/2023_04_01/o1_mf_s_1132999256_l2h 42sgy_.bkp
SPFILE Included: Modification time: 2023-03-31 22:00:09
SPFILE db_unique_name: HFZCDB
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
11 Full 42.98M DISK 00:00:00 2023-04-01 10:12:51
BP Key: 11 Status: AVAILABLE Compressed: NO Tag: TAG20230401T101251
Piece Name: /archive/HFZCDB/autobackup/2023_04_01/o1_mf_s_1132999971_l2h 4s3b1_.bkp
SPFILE Included: Modification time: 2023-04-01 10:04:24
SPFILE db_unique_name: HFZCDB
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
12 Full 42.98M DISK 00:00:01 2023-04-01 11:54:33
BP Key: 12 Status: AVAILABLE Compressed: NO Tag: TAG20230401T115432
Piece Name: /archive/HFZCDB/autobackup/2023_04_01/o1_mf_s_1133006072_l2h bqs3y_.bkp
SPFILE Included: Modification time: 2023-04-01 11:42:22
SPFILE db_unique_name: HFZCDB
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
13 Full 96.00K DISK 00:00:00 2023-04-01 12:06:23
BP Key: 13 Status: AVAILABLE Compressed: NO Tag: hfedu7PFILE
Piece Name: /backup/full/hfedu7_pfile_hfzcdb_20_1_1133006783
SPFILE Included: Modification time: 2023-04-01 11:54:40
SPFILE db_unique_name: HFZCDB
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
14 Full 42.98M DISK 00:00:00 2023-04-01 12:06:24
BP Key: 14 Status: AVAILABLE Compressed: NO Tag: TAG20230401T120624
Piece Name: /archive/HFZCDB/autobackup/2023_04_01/o1_mf_s_1133006784_l2h cg0sm_.bkp
SPFILE Included: Modification time: 2023-04-01 11:54:40
SPFILE db_unique_name: HFZCDB
RMAN> exit
Recovery Manager complete.
[oracle@hfzcdb91:/archive/HFZCDB/archivelog/2023_04_01]$sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Apr 1 12:07:21 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SYS@hfzcdb> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /oracle/app/oracle/product/19c
/db_1/dbs/spfilehfzcdb.ora
SYS@hfzcdb> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Pr oduction
Version 19.3.0.0.0
[oracle@hfzcdb91:/archive/HFZCDB/archivelog/2023_04_01]$rm /oracle/app/oracle/pr oduct/19c/db_1/dbs/spfilehfzcdb.ora
[oracle@hfzcdb91:/archive/HFZCDB/archivelog/2023_04_01]$sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Apr 1 12:07:57 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SYS@hfzcdb> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@hfzcdb>
Network error: Software caused connection abort
────────────────────────────────────────────────────────────────────────────────
Session stopped
- Press <return> to exit tab
- Press R to restart session
- Press S to save terminal output to file
Network error: Software caused connection abort
────────────────────────────────────────────────────────────────────────────────
Session stopped
- Press <return> to exit tab
- Press R to restart session
- Press S to save terminal output to file
┌────────────────────────────────────────────────────────────────────┐
│ • MobaXterm 20.6 • │
│ (SSH client, X-server and networking tools) │
│ │
│ ➤ SSH session to root@111.120.16.9 │
│ • SSH compression : ✔ │
│ • SSH-browser : ✔ │
│ • X11-forwarding : ✔ (remote display is forwarded through SSH) │
│ • DISPLAY : ✔ (automatically set on remote server) │
│ │
│ ➤ For more info, ctrl+click on help or visit our website │
└────────────────────────────────────────────────────────────────────┘
Last login: Sat Apr 1 11:13:54 2023 from 172.30.21.154
[root@hfzcdb91 ~]# su root
[root@hfzcdb91 ~]# su - oracel
su: user oracel does not exist
[root@hfzcdb91 ~]# su - oracle
Last login: Sat Apr 1 11:37:58 CST 2023 on pts/0
[oracle@hfzcdb91:/home/oracle]$sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Apr 1 12:27:21 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to an idle instance.
hfeduSQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/oracle/app/oracle/product/19c/db_1/db s/inithfzcdb.ora'
hfeduSQL> exit
Disconnected
[oracle@hfzcdb91:/home/oracle]$cd $ORACLE_HOEM/dbs
-bash: cd: /dbs: No such file or directory
[oracle@hfzcdb91:/home/oracle]$cd $ORACLE_HOME
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1]$cd dbs/
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$ls
c-797496974-20230331-00 hc_hfzcdb.dat lkDUMMY orapwhfzcdb
cntrlhfzcdb.dbf init.ora lkHFZCDB snapcf_hfzcdb.f
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$vi inithfzcdb.ora
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$cat inithfzcdb.ora
db_name=hfzcdb
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Apr 1 12:29:56 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to an idle instance.
hfeduSQL> startup nomount 【也可以在rman中启动】
ORACLE instance started.
Total System Global Area 306183456 bytes
Fixed Size 8895776 bytes
Variable Size 239075328 bytes
Database Buffers 50331648 bytes
Redo Buffers 7880704 bytes
hfeduSQL> exi
SP2-0042: unknown command "exi" - rest of line ignored.
hfeduSQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Pr oduction
Version 19.3.0.0.0
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$rman target/
Recovery Manager: Release 19.0.0.0.0 - Production on Sat Apr 1 12:30:26 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: HFZCDB (not mounted)
RMAN> restore spfile from '/archive/HFZCDB/autobackup/2023_04_01/o1_mf_s_1133006784_l2hcg0sm_.bkp ';
Starting restore at 2023-04-01 12:31:09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /archive/HFZCDB/autobackup/2023_04_01/o1_mf_ s_1133006784_l2hcg0sm_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2023-04-01 12:31:11
RMAN> exit
Recovery Manager complete.
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$ls
c-797496974-20230331-00 hc_hfzcdb.dat init.ora lkHFZCDB snapcf_hfzcdb.f
cntrlhfzcdb.dbf inithfzcdb.ora lkDUMMY orapwhfzcdb spfilehfzcdb.ora
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$ls -lst
total 131900
4 -rw-r----- 1 oracle oinstall 3584 Apr 1 12:31 spfilehfzcdb.ora
4 -rw-rw----. 1 oracle oinstall 1544 Apr 1 12:30 hc_hfzcdb.dat
4 -rw-r--r-- 1 oracle oinstall 15 Apr 1 12:29 inithfzcdb.ora
43920 -rw-r----- 1 oracle oinstall 44974080 Apr 1 12:06 snapcf_hfzcdb.f
43920 -rw-r----- 1 oracle oinstall 44974080 Mar 31 19:53 cntrlhfzcdb.dbf
4 -rw-r----- 1 oracle oinstall 24 Mar 31 19:44 lkDUMMY
44032 -rw-r----- 1 oracle oinstall 45088768 Mar 31 17:40 c-797496974-20230331-00
4 -rw-r-----. 1 oracle oinstall 2048 Mar 2 23:01 orapwhfzcdb
4 -rw-r-----. 1 oracle oinstall 24 Mar 2 22:00 lkHFZCDB
4 -rw-r--r--. 1 oracle oinstall 3079 May 14 2015 init.ora
[oracle@hfzcdb91:/oracle/app/oracle/product/19c/db_1/dbs]$sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Apr 1 12:32:02 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
hfeduSQL> shutdown abort
ORACLE instance shut down.
hfeduSQL> startup
ORACLE instance started.
Total System Global Area 2466249672 bytes
Fixed Size 8899528 bytes
Variable Size 671088640 bytes
Database Buffers 1778384896 bytes
Redo Buffers 7876608 bytes
Database mounted.
Database opened.
hfeduSQL>