Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do you compact a Sql Server Database?

We have a SQL Server 2000 database that holds most of our teams databases running on a relatively old server.

Lately we have been having some weird slow down issues on some of our database calls in various applications. (So I know it isn't application specific)

It was mentioned to me that we should look into compacting some of our databases. What are some general rules of thumb for doing this?

Is compacting a database just considered to be general maintenance? Is there a magic number of databases, tables, or records that might lead to this slow down and thus be helped be a compaction?

Number of actively used databases: 6

Average size of database: 20MB with the exception of Fogbugz, that is about 11000MB

like image 923
Mike Fielden Avatar asked Nov 23 '09 13:11

Mike Fielden


People also ask

Does shrinking database improve performance?

Shrinking the database to a minimum required and releasing most of the unused space is possible. This may be a positive move as the larger freed space will improve performance. But shrinking may affect your database performance significantly, if not properly done.

Is it recommended to shrink data file in SQL Server?

Recommendations. A shrink operation is most effective after an operation that creates a large amount of unused storage space, such as a large DELETE statement, truncate table, or a drop table operation. Most databases require some free space to be available for regular day-to-day operations.

What happens when we shrink database?

Shrinking data files recovers space by moving pages of data from the end of the file to unoccupied space closer to the front of the file. When enough free space is created at the end of the file, data pages at end of the file can deallocated and returned to the file system.


1 Answers

You don't compact a SQL Server database (you "SHRINK" it) unless you really need to. It's not MS Access and won't reclaim unused space (well, it can, but it masks a more important problem)

More likely, you have a index/statistic problem:

  • out of data stats
  • fragmented indexes
  • missing indexes

For starters with that database size (small), I'd suggest you look

  • at "maintenance plans" to start with to ensure the DBs are in tip-top condition
  • for missing indexes
like image 64
gbn Avatar answered Sep 28 '22 09:09

gbn