Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Attach DB - How long?

Author  Topic 

riggsy
Starting Member

1 Post

Posted - 2005-08-18 : 06:31:10
One of the DBA's from our sister company is trying to re-attach a database, unfortunately he has no db skills whatsoever and has failed to perform regular db/log backups therefore his file sizes are as follows: mdf = 70GB, ldf= 60GB.
The attach job has been left running for approx 3 hours at present and has still not completed, is this likely to take hours before it comes back online again?

I've never attempted to reattach a db with such large log files before so I'm unable to give him any advice, my databases usually attach in seconds. Is the delay he is experiencing due to the large log size?

Kristen
Test

22859 Posts

Posted - 2005-08-18 : 06:49:14
I've not tried that one!

Restoring a database (from a backup file) to a new database, with files that large, would take ages IME.

Assuming the files being attached are "clean" (i.e. copied when SQL Server was NOT running, or when DB was detached) then doing a single-file-attach of just the MDF might work, and be quicker - that will recreate a new, empty, LDF file AFAIK

Kristen
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-08-18 : 06:51:37
3 hours? sp_attach_db runs in seconds for me, even with VLDBs ... something is wrong.

Jay White
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-08-18 : 10:32:01
quote:
Originally posted by Page47

3 hours? sp_attach_db runs in seconds for me, even with VLDBs ... something is wrong.

Jay White




Did he detach the database in the middle of a long running transaction, like an index rebuild? If so, the whole transaction will be rolled back, which can take hours depending on how much work had to be undone.

Is the process doing any IOs?

Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-08-18 : 12:39:35
Can he just use the sp_attach_single_file_db instead of sp_attach_db? You'll lose whatever is in the tlog, but possibly he can afford that.

Tara
Go to Top of Page

SQLTEAMSteve
Starting Member

8 Posts

Posted - 2005-08-18 : 13:09:07
There's no version of the original database online currently? I'd send him info on how to shrink files @ the log/mdf level, THEN make a backup, restore, etc.

_________________________
Stephen R Montgomery
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-08-18 : 13:30:58
I didn't know you could detach mid-transaction ... I wouldn't a thunk it would work that way.

Jay White
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-08-18 : 14:21:07
quote:
Originally posted by Page47

I didn't know you could detach mid-transaction ... I wouldn't a thunk it would work that way.

Jay White




Not using detach it doesn't - but sometimes I've seen people detach a database by killing SQL and copying the files to try to avoid having to rollback a long-running transaction.

Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-08-18 : 15:27:33
Paul,

If you stop the MSSQLSERVER service while a long running transaction was running, then when the service is started up, the transaction is rolled back prior to the database being made available. Why isn't this true in the scenario you mentioned? Is the data partially committed?

Tara
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-18 : 15:34:14
"Not using detach it doesn't - but sometimes I've seen people detach a database by killing SQL and copying the files to try to avoid having to rollback a long-running transaction"

Darn it, I've been giving people advice that "So long as SQL Server was stopped when you copied the files ..."

Of course if they did an emergency stop, and then copied the files ..., there might be significant large transactions that would need rolling back ...

Actually what happens if you do a single-file-attach in those circumstances? - Does SQL have some way of knowing that some pages are not "real"?

Mine-field ... why can't folks use Tara's Blogg's Sprocs to do some decent backups?! :-(

Kristen
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-08-18 : 16:56:52
quote:
Originally posted by SQLTEAMSteve

There's no version of the original database online currently? I'd send him info on how to shrink files @ the log/mdf level, THEN make a backup, restore, etc.

_________________________
Stephen R Montgomery




Shrinking the data files has no effect on the backup size, only on the size of file needed to do the restore. Backup doesn't backup the unused space. It could be a highwatermarking issue he's having during creation of the file to restore into...

Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-08-18 : 17:04:05
I've caused some confusion - my apologies.

If the database is shutdown cleanly, then copying files works fine.

If the server is hard-shutdown such that the database is not cleanly shutdown, then copying the files will cause a potentially long rollback on attach.

Tara - you're right. What I meant was I'd seen people mistakenly try to avoid that by doing a hard shutdown and copying the files (i.e. not understanding how recovery works)

IIRC, single-file attach doesn't work for a database that has a current log LSN > the last checkpoint LSN, but I may be wrong and don't have sql2k box handy to check.

Thanks

Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-19 : 03:13:49
Paul, thanks for the clarification, I'm clear on the issues now.

Kristen
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-08-19 : 10:13:05
quote:
Originally posted by paulrandal
Did he detach the database in the middle of a long running transaction, like an index rebuild? If so, the whole transaction will be rolled back, which can take hours depending on how much work had to be undone.


OK, so in this quote, you are saying "detach" but not meaning "by running sp_detach_db", but rather meaning "drop kick the SQL Server and copy data files" ...

When someone pulls the plug on SQL, without a polite shut down of the service, I don't consider that "detaching" ...

Jay White
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-08-19 : 11:35:56
quote:
Originally posted by Page47

quote:
Originally posted by paulrandal
Did he detach the database in the middle of a long running transaction, like an index rebuild? If so, the whole transaction will be rolled back, which can take hours depending on how much work had to be undone.


OK, so in this quote, you are saying "detach" but not meaning "by running sp_detach_db", but rather meaning "drop kick the SQL Server and copy data files" ...

When someone pulls the plug on SQL, without a polite shut down of the service, I don't consider that "detaching" ...

Jay White




I should have quoted detach - sorry for the confusion.

Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page
   

- Advertisement -