How do I ... Determine Database Growth If I Am Not Tracking It?
If your database has grown considerably and you're not sure when or why it happened, you'll be hard pressed to figure out the answer unless you're tracking changes in database size. Luckily, if you are performing regular full backups, you can get this information from the SQL logs.
When you create a full backup, SQL creates an entry in the SQL Log that looks like the following:
Database backed up. Database: PSP, creation date(time): 2008/12/22(18:25:10), pages dumped: 171, first LSN: 39:41:37, last LSN: 39:59:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'c:\Bak\PSP.bak'}). This is an informational message only. No user action is required.
So we can look for these statements in the SQL logs, parse out the pages dumped, and calculate the size of the used portion of the database.
The Script:
Declare
Hi Rob,
This is cool but can you see which table has increased based on the geven scenario?
BudaCli.
What you don't know won't hurt you but what you know will make you plan to know better
There is nothing concerning table sizes logged to the SQL log. If you want this detail of information, you must track it yourself.
THis is really very helpful scrip. Thanks!
You can also query the info held about backups in MSDB:
use msdb
go
select physical_name, file_size, backupset.backup_size, backup_start_date
from backupfile, backupset
where logical_name = '<logical file name>'
and
backupfile.backup_set_id = backupset.backup_set_id
This gives you roughly the size of the datafile, and the size that's being used. Very interesting if you plot it on a graph in excel as you can use trendlines to estimate database growth.
Excellent suggestion Natalie!!
The problem I had was that the PM was asking for more information than was available in the msdb backup tables. Their database had grown 160 GB's in size over three months and no one knew why or when it had grown so much.
As you suggested, I was able to chart the growth of their database for them and pinpoint when their database had grown by 120 GB's in a single day.
This is really good script. I was working on a script to capture DB growth data but this will give me immediate result which is great.
Thanks for sharing a script.
Thanks,
Mukesh
Thanks for the feedback, Mukesh!!
The following scripts can be downloaded as text files. You will need to change the file extension to .ps1 in order to execute them. Backup a database Restore a database Scan a server to find a free port Query DNS to get the FQDN of a server
To see some examples of my other forms of writing, please visit my page on WritersCafe.org. It is almost exclusively horror fiction, but I sometimes throw other things in there too from time to time. There's one science fiction story, a couple of poems, and quite a few humor pieces as well.
Look for me in the SQL Q&A section of the August, 2007 issue of TechNet Magazine. August issue of TechNet Magazine's SQL Q&A column