【练习】数据文件的更改:改名或改路径 users01.dbf-->users01_bak.dbf

方法一:
1.将数据文件的状态offline

SQL> select file_name,tablespace_name from dba_data_files where file_name like '%user%';

FILE_NAME
--------------------------------------------------------------------------------
TABLESPACE_NAME
------------------------------
/u01/app/oracle/oradata/ORA11GR2/users01.dbf
USERS

SQL> alter tablespace users offline;

Tablespace altered.

SQL> select name,status from v$datafile;

NAME
--------------------------------------------------------------------------------
STATUS
--------------------------------------------------
/u01/app/oracle/oradata/ORA11GR2/system01.dbf
SYSTEM

/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf
ONLINE

/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf
ONLINE


NAME
--------------------------------------------------------------------------------
STATUS
--------------------------------------------------
/u01/app/oracle/oradata/ORA11GR2/users01.dbf
OFFLINE

/u01/app/oracle/oradata/ORA11GR2/example01.dbf
ONLINE

2.操作系统层面完成真正mv改名操作

SQL> ! mv /u01/app/oracle/oradata/ORA11GR2/users01.dbf /u01/app/oracle/oradata/ORA11GR2/users01_bak.dbf

3.数据库层面修改数据文件名--->告诉数据库

SQL> alter database rename file 
  2  '/u01/app/oracle/oradata/ORA11GR2/users01.dbf' to
  3  '/u01/app/oracle/oradata/ORA11GR2/users01_bak.dbf';

Database altered.

4.把更改完之后的文件置为Online对外提供服务
表空间->online

SQL> alter tablespace users online;

Tablespace altered.

SQL> select name,status from v$datafile;

NAME                                                                          STATUS
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------
/u01/app/oracle/oradata/ORA11GR2/system01.dbf                                 SYSTEM
/u01/app/oracle/oradata/ORA11GR2/sysaux01.dbf                                 ONLINE
/u01/app/oracle/oradata/ORA11GR2/undotbs01.dbf                                ONLINE
/u01/app/oracle/oradata/ORA11GR2/users01_bak.dbf                              ONLINE
/u01/app/oracle/oradata/ORA11GR2/example01.dbf                                ONLINE

方法二:(适用所有数据文件,但是系统文件只能用这种方式)
1、shutdown 关库

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

2.操作系统层面真正执行mv

SQL> ! mv /u01/app/oracle/oradata/ORA11GR2/users01_bak.dbf /u01/app/oracle/oradata/ORA11GR2/users01.dbf

3.启动到mount

SQL> startup mount
ORACLE instance started.

Total System Global Area  830930944 bytes
Fixed Size                  2257800 bytes
Variable Size             536874104 bytes
Database Buffers          289406976 bytes
Redo Buffers                2392064 bytes
Database mounted.

4.先通知数据库要更改数据库的结构-->rename

SQL> alter database rename file
  2  '/u01/app/oracle/oradata/ORA11GR2/users01_bak.dbf' to
  3  '/u01/app/oracle/oradata/ORA11GR2/users01.dbf';

Database altered.

SQL> alter database open;

Database altered.
原文地址:https://www.cnblogs.com/tomatoes-/p/6120339.html