ITPub博客

首页 > 数据库 > Oracle > 移动数据文件名中含有特殊字符的数据文件方法

移动数据文件名中含有特殊字符的数据文件方法

原创 Oracle 作者:super_sky 时间:2012-12-07 15:49:07 0 删除 编辑
在生产环境,发现有一个数据文件名称中包含特殊字符。现在有个需求,需要将该数据文件移动到其他目录,这就导致了无法使用
alter database rename file '' to '';来修改文件名称了。

在测试环境,测试使用rman copy命令来解决这个问题。
获取将要移动的数据文件file#;假如,我们要移动file#=7的文件"/ora10g/oradata/ora10g/users02.dbf"到"/ora10g/backup/users02.dbf"
$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.4.0 - Production on Fri Dec 7 15:45:32 2012

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, OLAP, Data Mining and Real Application Testing options

SQL> select file#,name from v$datafile;

     FILE#
----------
NAME
--------------------------------------------------------------------------------
         1
/ora10g/oradata/ora10g/system01.dbf

         2
/ora10g/oradata/ora10g/undotbs01.dbf

         3
/ora10g/oradata/ora10g/sysaux01.dbf


     FILE#
----------
NAME
--------------------------------------------------------------------------------
         4
/ora10g/oradata/ora10g/users01.dbf

         5
/ora10g/oradata/ora10g/example01.dbf

         6
/ora10g/oradata/ora10g/system02.dbf


     FILE#
----------
NAME
--------------------------------------------------------------------------------
         7
/ora10g/oradata/ora10g/users02.dbf


7 rows selected.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
$

登陆到rman,使用copy命令
$ rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Fri Dec 7 15:45:55 2012

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: ORA10G (DBID=4115709917)

RMAN> copy datafile 7 to '/ora10g/backup/users02.dbf';

Starting backup at 07-DEC-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=256 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00007 name=/ora10g/oradata/ora10g/users02.dbf
output filename=/ora10g/backup/users02.dbf tag=TAG20121207T154619 recid=29 stamp=801416796
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
Finished backup at 07-DEC-12

Starting Control File and SPFILE Autobackup at 07-DEC-12
piece handle=/ora10g/backup/c-4115709917-20121207-00 comment=NONE
Finished Control File and SPFILE Autobackup at 07-DEC-12

修改oracle数据字典中的记录。

RMAN> run
2> {
3> set newname for datafile 7 to '/ora10g/backup/users02.dbf';
4> switch datafile 7;
5> }

executing command: SET NEWNAME
using target database control file instead of recovery catalog

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of switch command on default channel at 12/07/2012 15:48:56
ORA-19623: file 7 is open
名称的修改需要将数据库启动到mount状态。

RMAN> shutdown immediate

database closed
database dismounted
Oracle instance shut down

RMAN> startup mount;

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area    2147483648 bytes

Fixed Size                     2168928 bytes
Variable Size                496887712 bytes
Database Buffers            1644167168 bytes
Redo Buffers                   4259840 bytes

RMAN> run
2> {set newname for datafile 7 to '/ora10g/backup/users02.dbf';
3> switch datafile 7;
4> }

executing command: SET NEWNAME

datafile 7 switched to datafile copy
input datafile copy recid=29 stamp=801416796 filename=/ora10g/backup/users02.dbf

RMAN>

RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/07/2012 15:50:24
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/ora10g/backup/users02.dbf'

RMAN> recover datafile 7;

Starting recover at 07-DEC-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=266 devtype=DISK

starting media recovery
media recovery complete, elapsed time: 00:00:02

Finished recover at 07-DEC-12
由于我们是在数据库打开状态copy的数据文件,所以需要对其进行恢复。
RMAN> alter database open;

database opened

RMAN> exit
恢复后,数据库打开。

数据文件检查。
Recovery Manager complete.
$
$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.4.0 - Production on Fri Dec 7 15:50:54 2012

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, OLAP, Data Mining and Real Application Testing options

SQL> set linesize 200
SQL> col name format a50
SQL>
SQL> select file#,name from v$datafile;

     FILE# NAME
---------- --------------------------------------------------
         1 /ora10g/oradata/ora10g/system01.dbf
         2 /ora10g/oradata/ora10g/undotbs01.dbf
         3 /ora10g/oradata/ora10g/sysaux01.dbf
         4 /ora10g/oradata/ora10g/users01.dbf
         5 /ora10g/oradata/ora10g/example01.dbf
         6 /ora10g/oradata/ora10g/system02.dbf
         7 /ora10g/backup/users02.dbf

7 rows selected.

SQL> 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/11590946/viewspace-750756/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-01-11

  • 博文量
    77
  • 访问量
    807922