People are capable of all kinds of good thinking, but some just don't see what's right in front of their noses.
Home
 

Move DB files to new location

In my opinion, we should  perform database migration/movement programmatically in order to achieve an automated task, freeing up human resources from tedious tasks.

dbmove

SQL Server

1) ALTER DATABASE <dbname> SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
2) ALTER DATABASE <dbname> SET OFFLINE;
3) ALTER DATABASE <dbname> MODIFY FILE 
4) (
5)    Name = <dbname>_Data,
6)    Filename = '<new_path>\<file>.MDF'
7) );
8) ALTER DATABASE dbname MODIFY FILE 
9) (
10)   Name = <dbname>_Log, 
11)   Filename = '<new_path>\<file>.LDF'
12) );

Then we manually move the files from their current location to <new_path> and then bring them back online

1) ALTER DATABASE <dbname> SET ONLINE;
2) ALTER DATABASE my SET MULTI_USER;

Oracle

1) alter tablespace <tsname> offline;
2) cp <old_path>/<file>.dbf <new_path>/<file>.dbf
3) alter tablespace <tsname> rename datafile '<old_path>/<file>.dbf' 
   to '<new_path>/<file>.dbf';
4) alter tablespace <tsname> online;
5) rm <old_path>/<file>.dbf

but also in a database that has closed

1) shutdown immediate
2) startup mount;
3) cp <old_path>/<file>.dbf <new_path>/<file>.dbf
4) alter database rename file '<old_path>/<file>.dbf' to 
   '<new_path>/<file>.dbf';
5) alter database open;
6) rm <old_path>/<file>.dbf

May 25, 2012 This post was written by Categories: ITOracleSQL Tagged with:
No comments yet


Leave a Reply

Top