Oracle数据库迁移数据文件到新路径

1.先查看当前数据库参数文件等信息

[oracle@zzw ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Tue Jul 20 11:09:35 2021

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1778384896 bytes
Fixed Size                  8621712 bytes
Variable Size             687866224 bytes
Database Buffers         1073741824 bytes
Redo Buffers                8155136 bytes
Database mounted.
Database opened.
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/z01/app/oracle/oradata/zzw/system01.dbf
/z01/app/oracle/oradata/zzw/sysaux01.dbf
/z01/app/oracle/oradata/zzw/undotbs01.dbf
/z01/app/oracle/oradata/zzw/users02.dbf
/z01/app/oracle/oradata/zzw/users01.dbf

SQL> select name from v$tempfile; 

NAME
--------------------------------------------------------------------------------
/z01/app/oracle/oradata/zzw/temp01.dbf

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/z01/app/oracle/oradata/zzw/redo03.log
/z01/app/oracle/oradata/zzw/redo02.log
/z01/app/oracle/oradata/zzw/redo01.log

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/z01/app/oracle/oradata/zzw/control01.ctl
/z01/app/oracle/oradata/zzw/control02.ctl

SQL> show parameter pfile

NAME                                 TYPE
------------------------------------ ----------------------
VALUE
------------------------------
spfile                               string
/z01/app/oracle/product/12.0.1
/db_1/dbs/spfilezzw.ora

 2.创建pfile文件,关闭数据库,移动数据库文件到新路径

SQL> create pfile from spfile;

File created.

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

 移动源数据库文件这里使用的是Oracle用户来操作,如果使用root用户记得给赋权

[oracle@zzw ~]$ mkdir /u02
[oracle@zzw /]$ cd /u02/
[oracle@zzw u02]$ mkdir oradata
[oracle@zzw u02]$ cd oradata/
[oracle@zzw u02]$ cp /z01/app/oracle/oradata/zzw/* /u02/oradata/
[oracle@zzw oradata]$ ll
总用量 2181324
-rw-r----- 1 oracle oinstall  10600448 7月  20 11:15 control01.ctl
-rw-r----- 1 oracle oinstall  10600448 7月  20 11:15 control02.ctl
-rw-r----- 1 oracle oinstall 209715712 7月  20 11:15 redo01.log
-rw-r----- 1 oracle oinstall 209715712 7月  20 11:15 redo02.log
-rw-r----- 1 oracle oinstall 209715712 7月  20 11:15 redo03.log
-rw-r----- 1 oracle oinstall 545267712 7月  20 11:15 sysaux01.dbf
-rw-r----- 1 oracle oinstall 849354752 7月  20 11:15 system01.dbf
-rw-r----- 1 oracle oinstall  33562624 7月  20 11:15 temp01.dbf
-rw-r----- 1 oracle oinstall  73408512 7月  20 11:15 undotbs01.dbf
-rw-r----- 1 oracle oinstall   6561792 7月  20 11:15 users01.dbf
-rw-rw---- 1 oracle oinstall 104865792 7月  20 11:15 users02.dbf

3.,更改控制文件路径,用改好的pfile文件启动数据库到mount状态

[oracle@zzw ~]$ cd $ORACLE_HOME/dbs
[oracle@zzw dbs]$ vi initzzw.ora 
zzw.__data_transfer_cache_size=0
zzw.__db_cache_size=1224736768
zzw.__inmemory_ext_roarea=0
zzw.__inmemory_ext_rwarea=0
zzw.__java_pool_size=16777216
zzw.__large_pool_size=83886080
zzw.__oracle_base='/z01/app/oracle'#ORACLE_BASE set from environment
zzw.__pga_aggregate_target=603979776
zzw.__sga_target=1778384896
zzw.__shared_io_pool_size=67108864
zzw.__shared_pool_size=335544320
zzw.__streams_pool_size=33554432
*.audit_file_dest='/z01/app/oracle/admin/zzw/adump'
*.audit_trail='db'
*.compatible='12.2.0'
*.control_files='/u02/oradata/control01.ctl','/u02/oradata/control02.ctl'
*.db_block_size=8192
*.db_name='zzw'
*.diagnostic_dest='/z01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=zzwXDB)'
*.enable_goldengate_replication=TRUE
*.local_listener='LISTENER_ZZW'
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=565m
*.processes=640
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=1693m
"initzzw.ora" 30L, 976C written

更改控制文件路径 *.control_files='/u02/oradata/control01.ctl','/u02/oradata/control02.ctl'

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

Total System Global Area 1778384896 bytes
Fixed Size                  8621712 bytes
Variable Size             687866224 bytes
Database Buffers         1073741824 bytes
Redo Buffers                8155136 bytes
SQL> alter database mount;                               

Database altered.

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

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/system01.dbf' to '/u02/oradata/system01.dbf';

Database altered.

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/sysaux01.dbf' to '/u02/oradata/sysaux01.dbf';

Database altered.

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/temp01.dbf' to '/u02/oradata/temp01.dbf';

Database altered.

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/undotbs01.dbf' to '/u02/oradata/undotbs01.dbf';

Database altered.

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/users01.dbf' to '/u02/oradata/users01.dbf';

Database altered.

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/users02.dbf' to '/u02/oradata/users02.dbf';             

Database altered.

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/redo01.log' to '/u02/oradata/redo01.log';

Database altered.

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/redo02.log' to '/u02/oradata/redo02.log';

Database altered.

SQL> alter database rename file '/z01/app/oracle/oradata/zzw/redo03.log' to '/u02/oradata/redo03.log';

Database altered.

5.检查各文件路径,创建spfile,重启数据库。

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u02/oradata/system01.dbf
/u02/oradata/sysaux01.dbf
/u02/oradata/undotbs01.dbf
/u02/oradata/users02.dbf
/u02/oradata/users01.dbf

SQL>  select name from v$tempfile; 

NAME
--------------------------------------------------------------------------------
/u02/oradata/temp01.dbf

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u02/oradata/redo03.log
/u02/oradata/redo02.log
/u02/oradata/redo01.log

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u02/oradata/control01.ctl
/u02/oradata/control02.ctl

SQL> show parameter pfile

NAME                                 TYPE
------------------------------------ ----------------------
VALUE
------------------------------
spfile                               string

SQL> create spfile from pfile;

File created.

SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 1778384896 bytes
Fixed Size                  8621712 bytes
Variable Size             687866224 bytes
Database Buffers         1073741824 bytes
Redo Buffers                8155136 bytes
Database mounted.
Database opened.

你可能感兴趣的:(oracle)