1

案例|rac 添加表空间误将数据文件放本地处理办法 -m6米乐安卓版下载

jiekexu之路 2020-11-16
1170

作者 | jiekexu

来源 | jiekexu之路(id: jiekexu_it)

转载请联系授权 | (微信id:xxq1426321293)

大家好,我是 jiekexu,很高兴又和大家见面了,今天分享一篇案例 rac 添加表空间误将数据文件放本地处理办法本文首发于微信公众号【jiekexu之路】,欢迎点击上方蓝字关注我,标星或置顶,更多干货第一时间到达!
不管是 10g、11g、12c ,rac 架构的数据文件均是存放在共享存储上的,但是由于扩容时误操作少写一个符号,则会将数据文件建立到本地文件系统上的 $oracle_home/dbs 目录下,这样当然不会立即出错,也提示添加成功,但当另外一个节点访问此数据文件上面的数据时就会报错 ora-1157、ora-1110 提示无法锁定该数据文件,导致出现异常应用无法访问此数据。
当出现上面的错误时,虽不是什么致命的错误,但也是比较麻烦的,对应用访问、操作造成了很大的麻烦。下面一起来看一看 10g、11g 中出现此类问题该如何解决,12c 及以上版本还没有案例,不过也是大同小异了。
一、发现问题
不过,在 10g 中还是有一点点的差别,10g rac 没有 asm 共享存储使用的是裸设备,在添加表空间时并没有类似 ‘ data’ 这样的关键字,只有 /dev/xxx 这样的设备,那么怎么会出现添加到本地文件系统中了呢?这个可以从 alert 日志中查看,以下是从日志中发现的内容:
[/oracle/admin/jieke/bdump]$tail -5000 alert_jieke1.log | grep jiekexu
alter tablespace jiekexu add datafile '/dev/rora_8g_157' size 8g
ora-1537 signalled during: alter tablespace jiekexu add datafile '/dev/rora_8g_157' size 8g...
alter tablespace jiekexu add datafile '/dev/rora_4g_26' size 4g
ora-1537 signalled during: alter tablespace jiekexu add datafile '/dev/rora_4g_26' size 4g...
alter tablespace jiekexu add datafile '/dev/rora_4g_26' size 4g
ora-1537 signalled during: alter tablespace jiekexu add datafile '/dev/rora_4g_26' size 4g...
alter tablespace jiekexu add datafile '/dev/rora_30g_256' size 30g
ora-1119 signalled during: alter tablespace jiekexu add datafile '/dev/rora_30g_256' size 30g...
alter tablespace jiekexu add datafile '/dev/rora_8g_256' size 8g
ora-1119 signalled during: alter tablespace jiekexu add datafile '/dev/rora_8g_256' size 8g...
alter tablespace jiekexu add datafile '/dev/rora_8g_256' size 8g
ora-1119 signalled during: alter tablespace jiekexu add datafile '/dev/rora_8g_256' size 8g...
alter tablespace jiekexu add datafile 'ora_8g_158' size 8g
completed: alter tablespace jiekexu add datafile 'ora_8g_158' size 8g
可以发现有很多 ora-1119 的错误,这些错误都是由于裸设备已经添加进数据库了无法再次添加,可最后一个  'ora_8g_158' 添加成功了,但正是这个文件就被添加到本地了,这里也没有报错,操作人员误以为已经添加成功了,没去做检查,导致后面问题的发生。
sql> select tablespace_name,file_id,file_name from dba_data_files where file_name not like '/dev/rora%';

tablespace_name file_id file_name
------------------------------ ---------- --------------------------------------------------------
jiekexu 239 oracle/product/10.2.0/db_1/dbs/ora_8g_158
二、解决问题
当出现这个问题时,紧急处理办法就是先将业务切到一个节点上,即出错的节点,或者允许的话可将其另一个节点直接关闭,然后得想办法将此数据文件迁移到它原来的共享裸设备中,其实也很简单,大概就是先 offline 数据文件,然后 rman 中  copy 此数据文件,接着数据库中 alter  database rename 数据文件, 做 recover 恢复,然后 online 即可。
当然,将其迁移到裸设备共享文件系统中的前提条件就是要有裸设备,经过存储和系统层面的添加,划分出如下四块裸设备:
sql> !ls -lrt dev/rora_*g_25*
crw-rw-rw- 1 oracle dba 39,289 nov 15 20:40 dev/rora_16g_256
crw-rw-rw- 1 oracle dba 39,290 nov 15 20:45 dev/rora_16g_257
crw-rw-rw- 1 oracle dba 39,291 nov 15 20:48 dev/rora_32g_258
crw-rw-rw- 1 oracle dba 39,292 nov 15 20:50 dev/rora_32g_259
使用前面做好的裸设备迁移,下面是一个完整的步骤:
-- offline 此数据文件 
sql> alter database datafile '/oracle/product/10.2.0/db_1/dbs/ora_8g_158' offline;
database altered.
sql> select tablespace_name,file_id,file_name,online_status from dba_data_files where file_name not like '/dev/rora%';

tablespace_name                   file_id file_name                                                              online_
------------------------------ ---------- ---------------------------------------------------------------------- -------
jiekexu                               239 /oracle/product/10.2.0/db_1/dbs/ora_8g_158                             recover
sql> exit
disconnected from oracle database 10g enterprise edition release 10.2.0.4.0 - 64bit production
with the partitioning, real application clusters, olap, data mining
and real application testing options
--rman copy
[/home/oracle]$rman target

recovery manager: release 10.2.0.4.0 - production on sun nov 15 20:31:07 2020

米乐app官网下载 copyright (c) 1982, 2007, oracle. all rights reserved.

connected to target database: jieke (dbid=1237164921)

rman> copy datafile '/oracle/product/10.2.0/db_1/dbs/ora_8g_158' to '/dev/rora_16g_256';

starting backup at 15-nov-20
using target database control file instead of recovery catalog
allocated channel: ora_disk_1
channel ora_disk_1: sid=643 instance=jieke1 devtype=disk
channel ora_disk_1: starting datafile copy
input datafile fno=00239 name=/oracle/product/10.2.0/db_1/dbs/ora_8g_158
output filename=/dev/rora_16g_256 tag=tag20201115t203119 recid=186 stamp=1056573097
channel ora_disk_1: datafile copy complete, elapsed time: 00:00:25
finished backup at 15-nov-20

starting control file and spfile autobackup at 15-nov-20
piece handle=/oracle/product/10.2.0/db_1/dbs/c-1237164921-20201115-0b comment=none
finished control file and spfile autobackup at 15-nov-20

rman> exit

recovery manager complete.
--数据库里 rename 和 recover
[/home/oracle]$sqlplus as sysdba

sql*plus: release 10.2.0.4.0 - production on sun nov 15 20:32:13 2020

米乐app官网下载 copyright (c) 1982, 2007, oracle. all rights reserved.


connected to:
oracle database 10g enterprise edition release 10.2.0.4.0 - 64bit production
with the partitioning, real application clusters, olap, data mining
and real application testing options

sql> set line 345
sql> col file_name for a99
sql> select tablespace_name,file_id,file_name,online_status from dba_data_files where file_name not like '/dev/rora%';

tablespace_name file_id file_name online_
------------------------------ ---------- --------------------------------------------------------------------------------------------------- -------
jiekexu 239 oracle/product/10.2.0/db_1/dbs/ora_8g_158 recover

sql> select tablespace_name,file_id,file_name,online_status from dba_data_files where file_name like '/dev/rora_16g_256%';

no rows selected

--这里 recover 报错是由于需要先做 rename 才可以。
sql> recover datafile '/dev/rora_16g_256';
ora-01179: file dev/rora_16g_256 does not exist


sql> alter database rename file '/oracle/product/10.2.0/db_1/dbs/ora_8g_158' to '/dev/rora_16g_256';

database altered.

sql> select tablespace_name,file_id,file_name,online_status from dba_data_files where file_name like '/dev/rora_16g_256%';

tablespace_name file_id file_name online_
------------------------------ ---------- --------------------------------------------------------------------------------------------------- -------
jiekexu 239 dev/rora_16g_256 recover

sql> recover datafile '/dev/rora_16g_256';
media recovery complete.
sql> select tablespace_name,file_id,file_name,online_status from dba_data_files where file_name not like '/dev/rora%';

no rows selected

sql> alter database datafile '/dev/rora_16g_256' online;

database altered.

sql> select tablespace_name,file_id,file_name,online_status from dba_data_files where file_name like '/dev/rora_16g_256%';

tablespace_name file_id file_name online_
------------------------------ ---------- --------------------------------------------------------------------------------------------------- -------
jiekexu 239 dev/rora_16g_256 online

如下是 alert 日志中出现的步骤,可作为参考:

三、添加表空间数据文件

迁移完成后另一节点便可以正常访问此数据文件中的数据了,最后要说的一点就是这个裸设备该怎么添加数据文件呢?一是查看 dba_data_files.file_name 确认以前的数据文件位置,或者查看 alert 日志查看添加成功的记录,两者均可:

-- alert 日志中搜索关键字 jieke001 查看以前添加成功的日志即可确认。
[/app/oracle/admin/jieke/bdump]$tail -5000 alert_jieke1.log | grep jieke001
alter tablespace jieke001 add datafile '/dev/rora_30g_251' size 29g
completed: alter tablespace jieke001 add datafile '/dev/rora_30g_251' size 29g
alter tablespace jieke001 add datafile '/dev/rora_30g_252' size 29g
completed: alter tablespace jieke001 add datafile '/dev/rora_30g_252' size 29g
alter tablespace jieke001 add datafile '/dev/rora_30g_253' size 29g
completed: alter tablespace jieke001 add datafile '/dev/rora_30g_253' size 29g
alter tablespace jieke001 add datafile '/dev/rora_30g_254' size 29g
completed: alter tablespace jieke001 add datafile '/dev/rora_30g_254' size 29g
alter tablespace jieke001 add datafile '/dev/rora_30g_255' size 29g
completed: alter tablespace jieke001 add datafile '/dev/rora_30g_255' size 29g

如下是一个成功添加的案例,可参考:

sql> alter tablespace jieke001 add datafile '/dev/rora_16g_257' size 15g;

tablespace altered.

sql> alter tablespace jieke001 add datafile '/dev/rora_32g_258' size 30g;

tablespace altered.

sql> select tablespace_name,file_id,file_name,online_status from dba_data_files where file_name not like '/dev/rora%';

no rows selected

sql> alter tablespace jieke001 add datafile '/dev/rora_32g_259' size 30g;

tablespace altered.

sql> col tablespace_name for a28
select a.tablespace_name,round(total/1024/1024/1024) "total g",round(free/1024/1024/1024) "free g",round((total-free)/total,4)*100 "used%"
from (select tablespace_name,sum(bytes) free from dba_free_space group by tablespace_name ) a,(select tablespace_name,sum(bytes) total from dba_data_files
group by tablespace_name) b where a.tablespace_name=b.tablespace_name order by 4;
sql> 2 3
tablespace_name total g free g used%
---------------------------- ---------- ---------- ----------
jkxsystem 24 24 .09
system 8 7 12.2
users 12 10 19.08
sysaux 4 1 78.25
jiekexu 59 12 79.05
undotbs2 12 2 86.3
jieke001 2657 356 86.6
undotbs1 23 3 87.08

8 rows selected.

sql> select inst_id,status, count(*) from gv$session where type <> 'background' group by inst_id,status order by 3;

inst_id status count(*)
---------- -------- ----------
2 active 2
1 active 4
1 inactive 14
2 inactive 16

sql> set line 345
col instance_name for a15
col host_name for a30
select inst_id,instance_name,host_name,status,version,startup_time from gv$instance;
sql> sql> sql>
inst_id instance_name host_name status version startup_time
---------- --------------- ------------------------------ ------------ ----------------- ------------
1 jieke1 jiekexu1 open 10.2.0.4.0 23-oct-20
         2 jieke2       jiekexu2                            open         10.2.0.4.0        15-nov-20


四、11g rac 如何做?


11g 或者以上可以使用 asmcmd copy 本地文件到磁盘组,这是一个很不错的新功能,那么通常在 11g 及以上 rac 中,由于忘记写盘号 " "  导致出现问题。

sql> alter tablespace idx_space add datafile 'data' size 20g autoextend off;


tablespace altered.


--当另一个节点访问此数据时也会报错 
sql> select count(*) from table_xxxs;
select count(*) from table_xxxs
*
error at line 1:
ora-01157: cannot identify/lock data file 222 - see dbwr trace file
ora-01110: data file 222: '/app/product/11.2.0/db/dbs/data'


这样便添加到本地文件系统了,还没有任何报错,下面我们来看看具体的操作步骤:


1、切换日志、offline 要迁移的数据文件                

---多次切换日志
sql> alter system switch logfile;
sql> alter system switch logfile;
sql> alter system switch logfile;
sql> alter system checkpoint;
sql> alter system checkpoint;
--查看要迁移的文件号
select file_id,tablespace_name,file_name from dba_data_files where tablespace_name='&tablespace_name';
-- offline 要迁移的 datafile
sql> alter database datafile &file_id offline;  --》这里写数据文件 id 或者全路径文件均可
--查看该数据文件是否 offline:
col name for a55
select file#,name,status from gv$datafile where file#='&file_id';

2、拷贝本地文件到asm

--切换到 grid 用户
su - grid
--asmcmd 复制本地数据文件到 asm diskgroup
asmcmd> ls
jiekedbs/
asmcmd> cd data
asmcmd> cd datafile
asmcmd> pwd
data/jiekedbs/datafile
--asmcmd> cp '/app/product/11.2.0/db/dbs/data' ./
asmcmd> cp '/app/product/11.2.0/db/dbs/data'  ' data/jiekedbs/datafile/idx_space222.dbf'
copying /app/product/11.2.0/db/dbs/data -> data/jiekedbs/datafile/idx_space222.dbf
asmcmd>

3、修改控制文件信息,online 数据文件

su - oracle
sqlplus / as sysdba
-- 重命名 datafile
sql> alter database rename file '/app/product/11.2.0/db/dbs/data' to ' data/jiekedbs/datafile/idx_space222.dbf';
-- recover and online 数据文件
sql> alter database recover datafile &file_id;
-- online 数据文件
sql> alter database datafile &file_id online;

4、检查验证

-- 查看是否迁移成功,并查看迁移后数据文件的状态
select file_id,tablespace_name,file_name from dba_data_files where tablespace_name='&tablespace_name';


select file#,name,status from gv$datafile where file#='&file_id';


多次切换日志,检查数据库告警日志有无报错,发现无异常,另一节点也可以正常访问了,说明问题已解决,本地文件系统的数据文件后期可清理了。



好咯,今天的分享就到这里了,如果本文对您有一丁点儿帮助,请多支持“在看”与转发,不求小费了哪怕是一个小小的赞,您的鼓励都将是我熬夜写文章最大的动力,让我有一直写下去的动力,最后一起加油,奥利给



一键三连分享、在看与点赞”,给我充点儿电吧~
文章转载自,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

网站地图