Subscribe to Posts by Email

Subscriber Count

    696

Disclaimer

All information is offered in good faith and in the hope that it may be of use for educational purpose and for Database community purpose, but is not guaranteed to be correct, up to date or suitable for any particular purpose. db.geeksinsight.com accepts no liability in respect of this information or its use. This site is independent of and does not represent Oracle Corporation in any way. Oracle does not officially sponsor, approve, or endorse this site or its content and if notify any such I am happy to remove. Product and company names mentioned in this website may be the trademarks of their respective owners and published here for informational purpose only. This is my personal blog. The views expressed on these pages are mine and learnt from other blogs and bloggers and to enhance and support the DBA community and this web blog does not represent the thoughts, intentions, plans or strategies of my current employer nor the Oracle and its affiliates or any other companies. And this website does not offer or take profit for providing these content and this is purely non-profit and for educational purpose only. If you see any issues with Content and copy write issues, I am happy to remove if you notify me. Contact Geek DBA Team, via geeksinsights@gmail.com

Pages

12c Database : Move datafile online, no offline or rename required going forward

12c Introduced the datafiles movement online, Earlier to 12c we have to

	a) offline the datafile
	b) Move the datafile to new location using os command
	c) Rename the datafile for data dictionary update
	d) Online the datafile

From 12c, its just need a command "alter database move datafile" Lets see how it works

	[oracle@Geek DBA12c admin]$ sqlplus / as sysdba

	SQL*Plus: Release 12.1.0.1.0 Production on Mon Sep 2 12:43:54 2013

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

	Connected to:
	Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
	With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

	SQL> select file_name from dba_data_files;

	FILE_NAME
	--------------------------------------------------------------------------------
	/u01/app/oracle/oradata/DB12c/system01.dbf
	/u01/app/oracle/oradata/DB12c/sysaux01.dbf
	/u01/app/oracle/oradata/DB12c/undotbs01.dbf
	/u01/app/oracle/oradata/DB12c/users01.dbf

Create new directory to hold the datafile mkdir -p /u01/app/oracle/oradata/DB12c/new

 Let's mimic some activity on users tablespace to ensure move operation wont affect the DML operation In one session

	SQL> create table t tablespace users as select * from dba_objects;

	Table created.

	SQL> begin
	  2  for i in 1..100 loop
	  3  insert into t select * from dba_objects;
	  4  end loop;
	  5  commit;
	  6  end;
	  7  /
Session insert operation in progress...... 

Open another session and move the datafile

	SQL> alter database move datafile '/u01/app/oracle/oradata/DB12c/users01.dbf' to '/u01/app/oracle/oradata/DB12c/new/users01.dbf';

	Database altered.

As you observed the insert operation above does not affecting the move operation. Lets check how does the data dictionary looks like.

	SQL> select file_name from dba_data_files;

	FILE_NAME
	--------------------------------------------------------------------------------
	/u01/app/oracle/oradata/DB12c/system01.dbf
	/u01/app/oracle/oradata/DB12c/sysaux01.dbf
	/u01/app/oracle/oradata/DB12c/new/users01.dbf
	/u01/app/oracle/oradata/DB12c/undotbs01.dbf

Another Check in OS level too

	ls -ltr /u01/app/oracle/oradata/DB12c/new/users01.dbf
	-rw-r-----. 1 oracle oinstall 5251072 Sep  2 12:45 /u01/app/oracle/oradata/DB12c/new/users01.dbf

	ls -ltr /u01/app/oracle/oradata/DB12c/
	total 1754712
	drwxr-x---. 2 oracle oinstall      4096 Sep  2 08:33 pdbseed
	-rw-r-----. 1 oracle oinstall  52429312 Sep  2 08:37 redo02.log
	drwxr-x---. 2 oracle oinstall      4096 Sep  2 08:38 pdb12c
	-rw-r-----. 1 oracle oinstall  52429312 Sep  2 10:37 redo03.log
	-rw-r-----. 1 oracle oinstall  62922752 Sep  2 12:37 temp01.dbf
	-rw-r-----. 1 oracle oinstall  89137152 Sep  2 12:42 undotbs01.dbf
	-rw-r-----. 1 oracle oinstall 807411712 Sep  2 12:45 system01.dbf
	-rw-r-----. 1 oracle oinstall 723525632 Sep  2 12:45 sysaux01.dbf
	drwxr-xr-x. 2 oracle oinstall      4096 Sep  2 12:45 new
	-rw-r-----. 1 oracle oinstall  52429312 Sep  2 12:45 redo01.log
	-rw-r-----. 1 oracle oinstall  17973248 Sep  2 12:45 control01.ctl

As you see above, the user01.dbf datafile is not in the oradata directory.

Check the table count just in case to check the table contains rows or not 😉

	SQL> select count(*) from t;

	  COUNT(*)
	----------

                    9163831

 

This is very cool nice feature for Level 1 support DBA's where you can reduce these steps (Offlining and copying the files at OS and rename and then online). All in one shot

Comments are closed.