The postings on this site are my own and do not represent my Employer's positions, advice or strategies.

LifeAsBob - Blog

 

Home

No Ads ever, except search!
Friday, April 26, 2024 Login
Public

Missed Backups - Cursor skipping databases ! 12/19/2007 9:45:22 AM

We have had this problem since SQL Server 2005, all versions, service packs and hotfixes.

A cursor of system databases that randomly skips / leaves out  certain databases depending on how the cursor is declared.

Generally we have maintenance jobs, custom (not maintenance plans), that declare a cursor and loop through each database to perform some task, dbcc, reindex / defragment, backup etc.

The syntax is generally:

DECLARE dbreindex_cursor CURSOR FOR
 SELECT name
 FROM master.sys.databases
 WHERE name NOT IN ('tempdb', 'model','master','msdb')
 AND State <> 1 --not being loaded/restored
 ORDER BY name

THIS IS NOT 100% RELIABLE !!! 

The only way we catch this is we have a job that tracks DBCC's and Backups and then a SSRS Report that shows any database without a dbcc or backup in the past 24 hours.  What we find is that occassionaly it will "skip" a database with the above syntax.  We can never reproduce it on demand, and the only way we can find it happenning is with this report.  Now we do have 100's of SQL Servers and only see it on one or two every couple weeks, but it is maddenning to trouble shooot.

Eventually we changed the cursor to use a different syntax, and it never has happenned on a server using the below syntax ..

DECLARE dbreindex_cursor CURSOR  Local Forward_Only STATIC READ_ONLY TYPE_WARNING FOR
 SELECT name
 FROM master.sys.databases
 WHERE name NOT IN ('tempdb', 'model','master','msdb')
 AND State <> 1 --not being loaded/restored
 ORDER BY name

I've hardle ever seen a refernce to this, we did let our MS Rep and TAM know, but since it is so rare and can not be reproduced never really could figure out what is wrong with the above cursor. 

I have seen one other reference with someone else experiencing the same thing, so I know we are not alone... http://groups.google.com/group/comp.databases.ms-sqlserver/browse_thread/thread/d4e6549cf10cfe0c/4211b0612a33368f?lnk=st&q=sql+server+2005+cursor+databases&rnum=3&hl=en#

Pay particular attention to how a cursor is declared in sql server 2005....something is more "sensitive"...

 

 

 


Blog Home