Oracle RAC环境 加错数据文件 的修复 归档非归档都没问题

Oracle Database - Enterprise Edition - Version 10.2.0.1 and later

Information in this document applies to any platform.

Goal

In Real Application Cluster (RAC) environments the datafiles need to be on the shared storage. It is possible that a datafile gets added to a tablespace on the local filesystem instead of the shared storage subsystem by mistake.

When another instance tries to contact the local file it will error out with:

ORA-01157: cannot identify/lock data file 10

ORA-01110: data file 10: '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/DATA'

Typically this happens when the datafile needed to be added to ASM but the '+'-sign is omitted when specifying the diskgroup. In this case the datafile will be created in the default directory specified by the 'db_create_file_dest' parameter which defaults to $ORACLE_HOME/dbs.

This article explains how you can resolve this issue when the database is in archivelog mode and when the database is running in noarchivelog mode.

Solution

Note: Starting in 12c the process can be simplified using the new "online move" feature, see:

12C New Feature : Move a Datafile Online (Doc ID 1566797.1)

A. When the database is running in archivelog mode

Note: You need to have all the archive files since the creation of the datafile (when it was added to the tablespace)

  1. Find out the exact file name, file location, size and file number:

SQL> select file_id, file_name, bytes, online_status from dba_data_files where tablespace_name = '<tablespace_name>';

FILE_ID FILE_NAME BYTES ONLINE_STATUS


8 +DATA/<DB NAME>/datafile/data.258.832695063 10485760 ONLINE

10 /u01/app/oracle/product/11.2.0/dbhome_1/dbs/DATA 10485760 ONLINE <<---

  1. Put the datafile offline

SQL> alter database datafile 10 offline;

  1. Recreate the datafile on the shared storage, please note that you need to do this on the node where the physical file resides and you need to specify the size retrieved in step 1

SQL> alter database create datafile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/DATA' as '+DATA' size 10485760;

从0开始新建这个datafile,也可以拿现有的作为底

  1. Recover the datafile

SQL> recover datafile 10;

  1. Place the datafile back online

SQL> alter database datafile 10 online;

Note: In some specific or particular case the end-user might copy the physical file by mistake again to another physical location on the same or another node. When performing the solution there is no risk in data lost between the different versions of the physical files because the 'alter database create datafile ', always recovers starting from the online redolog that was current at the moment the datafile was created originally, so it doesn't matter what happened with the datafile in between as long as we have all the archive logs since the datafile creation.

B. When the database is running in NOarchivelog mode

  1. Find out the exact file name, file location, size and file number and stop the instance on the node where you added the file.

SQL> select file_id, file_name, bytes, online_status from dba_data_files where tablespace_name = '<tablespace_name>';

FILE_ID FILE_NAME BYTES ONLINE_STATUS


8 +DATA/<DB NAME>/datafile/data.258.832695063 10485760 ONLINE

10 /u01/app/oracle/product/11.2.0/dbhome_1/dbs/DATA 10485760 ONLINE <---

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

  1. Move the datafile to the shared storage

2.1 using ASMCMD cp command (11g and above from Grid Infrastructure home user environment setting ORACLE_SID to ASM instance etc)

asmcmd

ASMCMD> cd <diskgroup>/<dbname>/DATAFILE

example: DATA/ORCL/DATAFILE

ASMCMD> cp /u01/app/oracle/product/11.2.0/dbhome_1/dbs/DATA +DATA/<DB NAME>/DATAFILE/test02.dbf

ASMCMD> ls -l

Type Redund Striped Time Sys Name

N test02.dbf => +DATA/ASM/DATAFILE/DATA.340.849266075 <<---

DATAFILE UNPROT COARSE JUN 03 10:00:00 Y SYSAUX.261.818315029

...

--OR--

2.2 Using RMAN:

RMAN> copy datafile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/DATA' to '+DATA';

Starting backup at 06-JAN-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=8 instance=<DB NMAE> device type=DISK

channel ORA_DISK_1: starting datafile copy

input datafile file number=00010 name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/DATA

output file name=+DATA/<DB NAME>/DATAFILE/DATA.340.849266075 tag=TAG20140106T132548 RECID=1 STAMP=836141162

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15

Finished backup at 06-JAN-14

  1. Mount the database:

SQL> startup mount;

ORACLE instance started.

...

Database mounted.

  1. Rename the datafile:

SQL> alter database rename file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/DATA' to '+DATA/<DB NAME>/DATAFILE/test02.dbf';

  1. Open the DB:

SQL> alter database open;

Database altered.

  1. You still need to restart the other instances as well otherwise you will still get errors when the instance is trying to access the non-existing file
相关推荐
不羁。。7 小时前
【撸靶笔记】第八关:GET - Blind - Boolian Based - Single Quotes
数据库·sql·mybatis
AwhiteV8 小时前
利用图数据库高效解决 Text2sql 任务中表结构复杂时占用过多大模型上下文的问题
数据库·人工智能·自然语言处理·oracle·大模型·text2sql
麻辣清汤11 小时前
结合BI多维度异常分析(日期-> 商家/渠道->日期(商家/渠道))
数据库·python·sql·finebi
未来之窗软件服务18 小时前
数据库优化提速(一)之进销存库存管理—仙盟创梦IDE
数据库·sql·数据库调优
MrZhangBaby21 小时前
SQL-leetcode—3374. 首字母大写 II
linux·sql·leetcode
Java小白程序员1 天前
SQL 语句进阶实战:从基础查询到性能优化全指南
数据库·sql·性能优化
君不见,青丝成雪1 天前
Hadoop技术栈(四)HIVE常用函数汇总
大数据·数据库·数据仓库·hive·sql
不羁。。1 天前
【撸靶笔记】第七关:GET - Dump into outfile - String
数据库·笔记·oracle
python_chai1 天前
从数据汇总到高级分析,SQL 查询进阶实战(下篇)—— 分组、子查询与窗口函数全攻略
数据库·sql·mysql