Oracle移动数据文件

Oracle移动数据文件「这是我参与11月更文挑战的第27天,活动详情查看:2021最后一次更文挑战」 11G and before 分为不停机和停机两种方式: 一、不停机移动数据文件 完整步骤: 1、确认开启归档模式 2、

「这是我参与11月更文挑战的第27天,活动详情查看:2021最后一次更文挑战

11G and before

分为不停机和停机两种方式

一、不停机移动数据文件

完整步骤:

1、确认开启归档模式

2、offline数据文件

3、物理层移动数据文件(可重命名)

4、逻辑层rename数据文件路径及名称

5、recover恢复数据文件

6、online数据文件

--开启归档模式
SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /archivelog
Oldest online log sequence     1
Current log sequence           2
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 
SQL> 
SQL> startup mount
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size                  2253664 bytes
Variable Size             452988064 bytes
Database Buffers         1140850688 bytes
Redo Buffers                7319552 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

--offline数据文件
SQL> /

     FILE# NAME                                                         STATUS
---------- ------------------------------------------------------------ -------
         1 /oradata/orcl11g/system01.dbf                                SYSTEM
         2 /oradata/orcl11g/sysaux01.dbf                                ONLINE
         3 /oradata/orcl11g/undotbs01.dbf                               ONLINE
         4 /oradata/orcl11g/users01.dbf                                 ONLINE
         5 /oradata/orcl11g/example01.dbf                               ONLINE
         6 /oradata/orcl11g/test01.dbf                                  ONLINE
         7 /oradata/ORCL11G/datafile/o1_mf_test_j7jgpq7k_.dbf           ONLINE

7 rows selected.

SQL> alter database datafile 7 offline;

Database altered.

--物理层移动数据文件
SQL> !mv /oradata/ORCL11G/datafile/o1_mf_test_j7jgpq7k_.dbf /oradata/orcl11g/test02.dbf

SQL> !ls /oradata/orcl11g/test02.dbf
/oradata/orcl11g/test02.dbf

--逻辑层rename数据文件
SQL> alter database rename file '/oradata/ORCL11G/datafile/o1_mf_test_j7jgpq7k_.dbf' to '/oradata/orcl11g/test02.dbf';

Database altered.

--恢复数据文件
SQL> recover datafile 7;
Media recovery complete.

--online数据文件
SQL> alter database datafile 7 online;

Database altered.

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

     FILE# NAME                                                         STATUS
---------- ------------------------------------------------------------ -------
         1 /oradata/orcl11g/system01.dbf                                SYSTEM
         2 /oradata/orcl11g/sysaux01.dbf                                ONLINE
         3 /oradata/orcl11g/undotbs01.dbf                               ONLINE
         4 /oradata/orcl11g/users01.dbf                                 ONLINE
         5 /oradata/orcl11g/example01.dbf                               ONLINE
         6 /oradata/orcl11g/test01.dbf                                  ONLINE
         7 /oradata/orcl11g/test02.dbf                                  ONLINE

7 rows selected.

二、停机移动数据文件

完整步骤:

1、关闭数据库

2、物理层移动数据文件(可重命名)

3、开启数据库到mount

4、逻辑层rename数据文件路径及名称

5、开启数据库

--创建一个TEST表空间,发现建在了/oradata/ORCL11G/下,希望移动到/oradata/orcl11g/下
SQL> create tablespace TEST;

Tablespace created.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/orcl11g/system01.dbf
/oradata/orcl11g/sysaux01.dbf
/oradata/orcl11g/undotbs01.dbf
/oradata/orcl11g/users01.dbf
/oradata/orcl11g/example01.dbf
/oradata/ORCL11G/datafile/o1_mf_test_j7jfm30c_.dbf

--尝试在线移动数据文件
SQL> alter database rename file '/oradata/ORCL11G/datafile/o1_mf_test_j7jfm30c_.dbf' to '/oradata/orcl11g/test01.dbf';
alter database rename file '/oradata/ORCL11G/datafile/o1_mf_test_j7jfm30c_.dbf' to '/oradata/orcl11g/test01.dbf'
*
ERROR at line 1:
ORA-01511: error in renaming log/data files
ORA-01121: cannot rename database file 6 - file is in use or recovery
ORA-01110: data file 6: '/oradata/ORCL11G/datafile/o1_mf_test_j7jfm30c_.dbf'

--报错ORA-01121
[oracle@orcl11g:/home/oracle]$ oerr ORA 01121
01121, 00000, "cannot rename database file %s - file is in use or recovery"
// *Cause:  Attempted to use ALTER DATABASE RENAME to rename a
//          datafile that is online in an open instance or is being recovered.
// *Action: Close database in all instances and end all recovery sessions.

明确无法在线移动数据文件,需要关闭数据库。

--操作系统层面移动数据文件,并且重命名
[oracle@orcl11g:/oradata/ORCL11G/datafile]$ ll
total 102408
-rw-r----- 1 oracle oinstall 104865792 Apr 15 20:55 o1_mf_test_j7jfm30c_.dbf
[oracle@orcl11g:/oradata/ORCL11G/datafile]$ mv o1_mf_test_j7jfm30c_.dbf /oradata/orcl11g/
control01.ctl  example01.dbf  redo01.log     redo02.log     redo03.log     sysaux01.dbf   system01.dbf   temp01.dbf     undotbs01.dbf  users01.dbf    
[oracle@orcl11g:/oradata/ORCL11G/datafile]$ mv o1_mf_test_j7jfm30c_.dbf /oradata/orcl11g/test01.dbf
[oracle@orcl11g:/oradata/ORCL11G/datafile]$ ll /oradata/orcl11g/test01.dbf 

--开启数据库到mount
SQL> startup mount
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size                  2253664 bytes
Variable Size             452988064 bytes
Database Buffers         1140850688 bytes
Redo Buffers                7319552 bytes
Database mounted.

--rename数据文件名称
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/orcl11g/system01.dbf
/oradata/orcl11g/sysaux01.dbf
/oradata/orcl11g/undotbs01.dbf
/oradata/orcl11g/users01.dbf
/oradata/orcl11g/example01.dbf
/oradata/ORCL11G/datafile/o1_mf_test_j7jfm30c_.dbf

6 rows selected.

SQL> alter database rename file '/oradata/ORCL11G/datafile/o1_mf_test_j7jfm30c_.dbf' to '/oradata/orcl11g/test01.dbf';

Database altered.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/orcl11g/system01.dbf
/oradata/orcl11g/sysaux01.dbf
/oradata/orcl11g/undotbs01.dbf
/oradata/orcl11g/users01.dbf
/oradata/orcl11g/example01.dbf
/oradata/orcl11g/test01.dbf

6 rows selected.

--开启数据库
SQL> alter database open;

Database altered.

12C and later

支持在线移动数据文件:

可参考:Online Move Datafile in Oracle Database 12c Release 1 (12.1)

语法如下:

ALTER DATABASE MOVE DATAFILE ( 'filename' | 'ASM_filename' | file_number )
 [ TO ( 'filename' | 'ASM_filename' ) ]
 [ REUSE ] [ KEEP ]

blog.csdn.net/m0_50546016…

今天的文章Oracle移动数据文件分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/19433.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注