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 2005 Forums
 Transact-SQL (2005)
 How long has a database been running

Author  Topic 

netslave
Starting Member

9 Posts

Posted - 2007-12-28 : 12:54:49
I'm trying to find out how long a specific database has been running. I can check the create date of the tempdb to see how long SQL Server has been running, but that's not exactly what I need.

Is there a way to find when a database was brought online?

Thanks!

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-12-28 : 13:15:09
Look at the created date output from this:
exec sp_helpdb



CODO ERGO SUM
Go to Top of Page

netslave
Starting Member

9 Posts

Posted - 2007-12-28 : 14:26:41
Hmm, well, that will tell me the create date, but how about how long it has been running since it's last shut down?

Say for instance, I bring the server down over night. The next day, I'd like to be able to see that the database has been running since 12:00 am or something like that.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-12-28 : 15:46:52
It will be the same as when SQL Server was started. When SQL Server starts, it brings up all databases during initial recovery.



CODO ERGO SUM
Go to Top of Page

netslave
Starting Member

9 Posts

Posted - 2007-12-28 : 15:57:03
What if one of the databases went offline for some reason (manual or something else), but SQL server was still running?
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-12-28 : 22:59:01
Then have to check sql server log, there is entry when you take db online/offline.
Go to Top of Page

netslave
Starting Member

9 Posts

Posted - 2007-12-31 : 10:28:15
Is there any way to do this programatically say with a query or something? I've thought about writing a trigger or something to write into a history table the datetime of when the database is brought online.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-12-31 : 23:25:14
But you can't create trigger on system table.
Go to Top of Page

netslave
Starting Member

9 Posts

Posted - 2008-01-02 : 15:21:47
What else can I do other then manually look at the server log? Are there no tables or views that contain this information? I sure can't find them if so.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-02 : 15:30:43
look in the log?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-01-02 : 16:17:45
This may help you find what you want:

exec master.dbo.xp_readerrorlog





CODO ERGO SUM
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-01-02 : 16:28:17
But what happens if you cycle the error log on a scheduled basis? The information may be in an old log that has been deleted already. You could of course save more log files, but there's always that possibility that the database server hasn't been restarted in a very long time and you don't have all of the error log since the restart.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

netslave
Starting Member

9 Posts

Posted - 2008-01-02 : 16:41:07
THANKS!!
Go to Top of Page

netslave
Starting Member

9 Posts

Posted - 2008-01-02 : 16:46:34
tkizer,

Maybe periodically copy the log over to the table that I'll eventually query to get the data?
Go to Top of Page
   

- Advertisement -