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.
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
0
25
May
Leave a Reply
You must be logged in to post a comment.