Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Detach and Attach database move filegroup Expand / Collapse
Author
Message
Posted Wednesday, March 17, 2010 7:59 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, June 10, 2014 3:03 AM
Points: 25, Visits: 97
Experts,

I need your advice with regards to the action i am planning to do during my maintenance activity. I never did this before and need your expert advice.

I am going to move my 2 mdf and 1 ndf file in my filegroup located in my drive E to other drive partition.
Please advice if my steps are correct and will not have any lost data in my transaction logs.

1. Detach mydb
2. move 2 mdf and 1 ndf file to drive F which has more space.
3. Attach mydb with the new filegroup drive location which is F:\...

Please advice if this process will not cause me any lost data in the transaction logs.

Thanks.

Arnet
Post #885179
Posted Wednesday, March 17, 2010 9:09 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:09 PM
Points: 21,252, Visits: 14,960
I suggest two more things before starting any of that.

1. Backup the database
2. Disable access to the server for all connections not related to you, the team, or whomever is working on the project for the duration of the project.

And then of course, make sure to do it during a maintenance window.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #885186
Posted Wednesday, March 17, 2010 11:04 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, June 10, 2014 3:03 AM
Points: 25, Visits: 97
CirquedeSQLeil (3/17/2010)
I suggest two more things before starting any of that.

1. Backup the database
2. Disable access to the server for all connections not related to you, the team, or whomever is working on the project for the duration of the project.

And then of course, make sure to do it during a maintenance window.


Thanks for your suggestion.

Is this mean that I will not have any data lost after doing this once i did the procedures mentioned?

Thanks,
Arnet
Post #885232
Posted Wednesday, March 17, 2010 11:17 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:09 PM
Points: 21,252, Visits: 14,960
If you follow all these steps, you should be fine as far as data loss goes.

In other words, you will have your bases covered and should be protected against data loss.

I might add one more step to the backup - copy the backup to another server somewhere (thus have two copies). This is an extra precautionary step.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #885239
Posted Wednesday, March 17, 2010 11:25 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, June 10, 2014 3:03 AM
Points: 25, Visits: 97
CirquedeSQLeil (3/17/2010)
If you follow all these steps, you should be fine as far as data loss goes.

In other words, you will have your bases covered and should be protected against data loss.

I might add one more step to the backup - copy the backup to another server somewhere (thus have two copies). This is an extra precautionary step.


Thanks for your wonderful advice. This will make me comfortable now.

Post #885244
Posted Wednesday, March 17, 2010 11:31 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:09 PM
Points: 21,252, Visits: 14,960
You're welcome.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #885250
Posted Wednesday, March 17, 2010 11:37 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, December 10, 2013 1:30 PM
Points: 183, Visits: 209
running the below alter DB restricted user will make sure all transactions have been completed before the detach. Running something like the below will make sure you have as little issue as possible

USE MASTER
GO
BACKUP DATABASE DBName
TO...
GO
ALTER DATABASE DBName SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE

BACKUP DATABASE DBName
TO...
WITH DIFFERENTIAL

SP_DETACH_DB 'DBName'

GO

XP_CMDSHELL 'COPY file1'
XP_CMDSHELL 'COPY file2'
XP_CMDSHELL 'COPY file3'
GO
SP_Attach_DB 'DBName', 'File1', ...
GO
ALTER DATABASE DBName SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO
Post #885254
Posted Thursday, March 18, 2010 2:08 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:58 PM
Points: 42,466, Visits: 35,532
You cannot lose data in a detach/attach. SQL Server supports the ACID requirements for relational databases. D stands for durability, meaning once a transaction has committed, the changes that transaction made are durable and will not be lost.

Sure, take a backup in case something goes wrong and tell the users that the app won't be available for the period, but that's just good common sense.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #885306
Posted Thursday, March 18, 2010 10:28 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, December 20, 2013 9:25 AM
Points: 389, Visits: 357
JDixon-385826 (3/17/2010)
running the below alter DB restricted user will make sure all transactions have been completed before the detach. Running something like the below will make sure you have as little issue as possible

USE MASTER
GO
BACKUP DATABASE DBName
TO...
GO
ALTER DATABASE DBName SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE

BACKUP DATABASE DBName
TO...
WITH DIFFERENTIAL

SP_DETACH_DB 'DBName'

GO

XP_CMDSHELL 'COPY file1'
XP_CMDSHELL 'COPY file2'
XP_CMDSHELL 'COPY file3'
GO
SP_Attach_DB 'DBName', 'File1', ...
GO
ALTER DATABASE DBName SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO


I would exclude this step, won't make any difference.

BACKUP DATABASE DBName
TO...
WITH DIFFERENTIAL





EnjoY!
Post #885711
Posted Thursday, March 18, 2010 9:11 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, December 10, 2013 1:30 PM
Points: 183, Visits: 209
well I agree you do not need the diff backup but if you want to be 100% forsure you covered all basis I would keep it
Post #886040
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse