代码改变世界

Oracle数据库文件路径变更

2014-09-12 19:36  AlfredZhao  阅读(15301)  评论(3编辑  收藏  举报

环境:RHEL 6.4 + Oracle 11.2.0.3

情景一:只是部分普通数据文件迁移,可以在线操作。

1.将对应表空间offline,移动数据文件到新路径

2.数据文件alter database rename file '' to '';

3.再将表空间online

情景二:所有数据文件迁移。

本文是针对情景二的实验,需求:主机/oradata挂节点变更为/usr2.在/usr2建立oradata文件夹来存放之前/oradata的所有文件。

操作步骤:

1.查看当前数据库的数据文件,临时文件,日志文件,控制文件,参数文件等信息。

2.根据当前spfile创建pfile文件,正常关闭数据库,移动源数据库文件到新的存储路径。

3.修改数据库参数文件,更改控制文件路径为新的存储路径,用改好的pfile文件启动数据库到mount状态。

4.重定向数据库的所有数据文件、日志文件路径,然后正常打开数据库。

5.核查各文件路径没有问题,根据当前pfile创建spfile,重启数据库实例。

1.查看当前数据库的数据文件,临时文件,日志文件,控制文件,参数文件等信息。

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/sysdata/jingyu/system01.dbf
/oradata/sysdata/jingyu/sysaux01.dbf
/oradata/sysdata/jingyu/undotbs01.dbf
/oradata/sysdata/jingyu/users01.dbf

SQL> select name from v$tempfile; 

NAME
--------------------------------------------------------------------------------
/oradata/sysdata/jingyu/temp01.dbf

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/oradata/sysdata/jingyu/redo03.log
/oradata/sysdata/jingyu/redo02.log
/oradata/sysdata/jingyu/redo01.log

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/oradata/sysdata/jingyu/control01.ctl
/opt/app/oracle/fast_recovery_area/jingyu/control02.ctl

SQL> show parameter pfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /opt/app/oracle/product/11.2.0
                                                 /dbhome_1/dbs/spfilejingyu.ora

2.根据当前spfile创建pfile文件,正常关闭数据库,移动源数据库文件到新的存储路径。

SQL> create pfile from spfile;

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

--移动源数据库文件到新的存储路径:
a.建立/usr2。 
b./etc/fstab配置,更改/oradata为/usr2。
c.mount /usr2 
d./usr2下建立oradata文件夹。 
e./usr2下文件移动到/usr2/oradata下。 
f.处理相关目录权限。
g.umount -l /oradata

3.修改数据库参数文件,更改控制文件路径为新的存储路径,用改好的pfile文件启动数据库到mount状态。

[oracle@JY-DB /]$ cd $ORACLE_HOME/dbs
[oracle@JY-DB dbs]$ more initjingyu.ora 
jingyu.__db_cache_size=6677331968
jingyu.__java_pool_size=33554432
jingyu.__large_pool_size=33554432
jingyu.__oracle_base='/opt/app/oracle'#ORACLE_BASE set from environment
jingyu.__pga_aggregate_target=5402263552
jingyu.__sga_target=8086618112
jingyu.__shared_io_pool_size=0
jingyu.__shared_pool_size=1275068416
jingyu.__streams_pool_size=0
*.audit_file_dest='/opt/app/oracle/admin/jingyu/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oradata/sysdata/jingyu/control01.ctl','/opt/app/oracle/fast_recovery_area/jingyu/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='jingyu'
*.db_recovery_file_dest='/opt/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=10737418240
*.diagnostic_dest='/opt/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=jingyuXDB)'
*.memory_target=13459521536
*.open_cursors=1000
*.processes=1500
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=1655
*.undo_tablespace='UNDOTBS1'

SQL> startup pfile='$ORACLE_HOME/dbs/initjingyu.ora' nomount
ORACLE instance started.

Total System Global Area 1.3429E+10 bytes
Fixed Size                  2241064 bytes
Variable Size            6744444376 bytes
Database Buffers         6677331968 bytes
Redo Buffers                4636672 bytes
SQL> alter database mount;

Database altered.

4.重定向数据库的所有数据文件、日志文件路径,然后正常打开数据库。

SQL> alter database rename file '/oradata/sysdata/jingyu/system01.dbf' to '/usr2/oradata/sysdata/jingyu/system01.dbf';

Database altered.

SQL> alter database rename file '/oradata/sysdata/jingyu/sysaux01.dbf' to '/usr2/oradata/sysdata/jingyu/sysaux01.dbf';

Database altered.

SQL> alter database rename file '/oradata/sysdata/jingyu/undotbs01.dbf' to '/usr2/oradata/sysdata/jingyu/undotbs01.dbf';   

Database altered.

SQL> alter database rename file '/oradata/sysdata/jingyu/temp01.dbf' to '/usr2/oradata/sysdata/jingyu/temp01.dbf';

Database altered.

SQL> alter database rename file '/oradata/sysdata/jingyu/users01.dbf' to '/usr2/oradata/sysdata/jingyu/users01.dbf';

Database altered.

SQL> alter database rename file '/oradata/sysdata/jingyu/redo01.log' to '/usr2/oradata/sysdata/jingyu/redo01.log';

Database altered.

SQL> alter database rename file '/oradata/sysdata/jingyu/redo02.log' to '/usr2/oradata/sysdata/jingyu/redo02.log';

Database altered.

SQL> alter database rename file '/oradata/sysdata/jingyu/redo03.log' to '/usr2/oradata/sysdata/jingyu/redo03.log';

Database altered.

SQL> alter database open;

Database altered.

5.核查各文件路径没有问题,根据当前pfile创建spfile,重启数据库实例。

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/usr2/oradata/sysdata/jingyu/system01.dbf
/usr2/oradata/sysdata/jingyu/sysaux01.dbf
/usr2/oradata/sysdata/jingyu/undotbs01.dbf
/usr2/oradata/sysdata/jingyu/users01.dbf

SQL> select name from v$tempfile; 

NAME
--------------------------------------------------------------------------------
/usr2/oradata/sysdata/jingyu/temp01.dbf

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/usr2/oradata/sysdata/jingyu/redo03.log
/usr2/oradata/sysdata/jingyu/redo02.log
/usr2/oradata/sysdata/jingyu/redo01.log

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/usr2/oradata/sysdata/jingyu/control01.ctl
/opt/app/oracle/fast_recovery_area/jingyu/control02.ctl

SQL> show parameter pfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string
SQL> create spfile from pfile;

File created.

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

SQL> startup
ORACLE instance started.

Total System Global Area 1.3429E+10 bytes
Fixed Size                  2241064 bytes
Variable Size            6744444376 bytes
Database Buffers         6677331968 bytes
Redo Buffers                4636672 bytes
Database mounted.
Database opened.