Database learning can never stop. Based on the previous posts on the basics I saw few comments asking to cover some of the basics in a one liner mode. In this blog post, we will talk about the database fundamentals of system DB’s, what are the DB files and what are the filegroups. I get an opportunity to talk to a lot of developers who come from the compete platform and are often asking these fundamental and basic questions. I am sure this blog post will help them understand these fundamentals.
- Master: composed of system tables that keep track of server installation as a whole and all other databases that are eventually created. Master DB has system catalogs that keep info about disk space, file allocations and usage, configuration settings, endpoints, logins, etc.
- Model: template database. Gets cloned when a new database is created. Any changes that one would like be applied by default to a new database should be made here
- Tempdb: re-created every time SQL Server instance is restarted. Holds intermediate results created internally by SQL Server during query processing and sorting, maintaining row versions, etc. Recreated from the model database. Sizing and configuration of tempdb is critical for SQL Server performance.
- Resource [hidden database]: stores executable system objects such as stored system procedures and functions. Allows for very fast and safe upgrades.
- MSDB: used by the SQL Server Agent service and other companion services. Used for backups, replication tasks, Service Broker, supports jobs, alerts, log shipping, policies, database mail and recovery of damaged pages.
- Primary data files: every database must have at least one primary data file that keeps track of all the rest of the files in the database. Has the extension .mdf.
- Secondary data files: a database may have zero or more secondary data files. Has the extension .ndf.
- Log files: every database has at least one log file that contains information necessary to recover all transactions in a database. Has the extension .ldf.
Creating a Database
- New user database files must be at least 3 MB or larger including the transaction log
- The default size of the data file is the size of the primary data file of the model database (2 MB) and the default size of the log file is 0.5 MB
- If LOG ON is not specified but data files are specified during a create database, the size of the log file is 25% of the sum of the sizes of all the data files.
Expanding or Shrinking a Database
- Automatic File Expansion:
- The file property FILEGROWTH determines how automatic expansion happens
- File property MAXSIZE sets the upper limit on the size
- Same as doing DBCC SHRINKDATABASE (dbname, 25). Leave 25 % free space in the database after the shrink
- Thread performs autoshrink as often as 30 minutes, very resource intensive
- Can group data files for a database into filegroups for allocation and administration purposes.
- Improves performance by controlling the placement of data and indexes into specific filegroups on specific drives or volumes.
- Filegroup containing the primary data file is called the primary filegroup, there is only one primary filegroup.
- Default filegroup: there is at least one filegroup with the property of DEFAULT, can be changed by DBA.
- Use cases when -not- to use filegroups:
- DBA might decide to spread out the I/O for a database: easiest way is to create a database file on a RAID device.
- DBA might want multiple files, perhaps to create a database that uses more space than is available on a single drive: can be accomplished by doing CREATE DATABASE with a list of files on separate drives
- DBA might want to have different tables assigned to different drives or to use the table and index partitioning feature in SQL Server.
- Allows backup of parts of the database.
- Table is created on a single filegroup, allows for backup of critical tables by backing up selected filegroups.
- Same for restoration. Database can be online as soon as primary filegroup is restored, but only objects on the restored filegroups will be available.
Given the nature of content, also look at the other topics we have discussed before.
Thanks for reading this far. Feel free to pass your comments too.Share this article
This entry was posted on Monday, November 19th, 2012 at 08:30 and is filed under Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.