场景:生产环境下,使用添加数据文件方式为某索引表空间扩容,使用一段时间后发现命名规则有误。
解决:修改数据文件的命名。
方式:使用toad工具或sqlplus
操作:
这次尝试使用toad管理工具,来代替之前使用指令的方式。本次记录为开阔使用工具的体验感。但实际工作中,如果时间上允许仍建议使用命令来完成。
(1)、表空间脱机操作
说明一下:有两个表空间不能脱机!system表空间、undo表空间。
toad图形界面如下:

或者用命令:
先查询表空间的信息
SQL> select t2.file#,t1.name,t2.name from v$tablespace t1, v$datafile t2 where t1.ts# = t2.ts#;

再使用offline命令对指定表空间脱机
SQL> alter tablespace users offline;
Tablespace altered.
(2)、物理复制数据文件,到新路径并重新命名
在ASM下查看一下文件操作指令都有哪些:
使用help。
ASMCMD> help
asmcmd [-V] [-v
] [--privilege
] [-p] [command] asmcmd_no_conn_str Starts asmcmd (if no parameters) or executes the command with given parameters asmcmd [-V] [-v
] [--privilege
] [-p] [command] Specify the connect string after the -c option to use the listener to connect. By default, ASMCMD asks for a password in a non-echoing prompt, unless the password is specified as part of the connect string. The connect identifier is in the form of "host:port:sid", with the host and the port being option. Host defaults to "localhost" and port to 1521. If the sid is not specified as a part of the connect identifier, then it is read from the environment variable ORACLE_SID. If no connect string is used, then environment variables ORACLE_HOME and ORACLE_SID determine the instance to which the program connects, and asmcmd establishes a bequeath connection to the it, in the same manner as a SQLPLUS / AS SYSASM. The user must be a member of the SYSDBA group to exercise this option. Specifying the -V option prints the asmcmd version number and exits immediately. Specifying the -v option prints extra information that can help advanced users diagnose problems. Specify the --privilege option to choose the type of connection. There are only two possibilities: connecting as SYSASM or as SYSDBA. The default value if this option is unspecified is SYSASM: Specifying the -p option allows the current directory to be displayed in the command prompt, like so: ASMCMD [+DATA/ORCL/CONTROLFILE] > The parameter command specifies one of the following commands, along with its parameters. Type "help [command]" to get help on a specific ASMCMD command. commands: -------- md_backup, md_restore lsattr, setattr cd, cp, du, find, help, ls, lsct, lsdg, lsof, mkalias mkdir, pwd, rm, rmalias chdg, chkdg, dropdg, iostat, lsdsk, lsod, mkdg, mount offline, online, rebal, remap, umount dsget, dsset, lsop, shutdown, spbackup, spcopy, spget spmove, spset, startup chtmpl, lstmpl, mktmpl, rmtmpl chgrp, chmod, chown, groups, grpmod, lsgrp, lspwusr, lsusr mkgrp, mkusr, orapwusr, passwd, rmgrp, rmusr volcreate, voldelete, voldisable, volenable, volinfo volresize, volset, volstat
执行复制重定向操作:
ASMCMD> cp +OCR_DATA/xzzyk/tbs_xzxt_zyk_index_02.dbf +OCR_DATA/xzzyk/tbs_xzxt_zyk_kksj_index_02.dbf
copying +OCR_DATA/xzzyk/tbs_xzxt_zyk_index_02.dbf -> +OCR_DATA/xzzyk/tbs_xzxt_zyk_kksj_index_02.dbf
这一步,在toad里是无法实现的。如toad界面上也提示了,需要我们到操作系统下手工完成文件的copy。

(3)、重定向新的数据文件
在手工把asm下的文件重新定向后,我们可以使用toad直接修改路径及文件信息。如下:

在上面红框区域,修改重定向的位置即可。
或使用指令:
如果先前利用cp完成了重定向的重命名,例如下:
[oracle@bjbank bjbank]$ cp users01.dbf users_01.dbf
再在sqlplus下执行rename指令,如下:
SQL> alter database rename file '/home/u01/app/oracle/oradata/bjbank/users01.dbf' to '/home/u01/app/oracle/oradata/bjbank/users_01.dbf';
Database altered.
(4)、把表空间online
在上步修改过数据文件的路径信息后,执行execute命令,把表空间online。
最后online后,点击close关闭即可,如下:


或者使用命令,例如:
假设之前是对datafile 4进行的脱