30
Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Embed Size (px)

Citation preview

Page 1: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Database Configurationand Maintenance

Exam 70-432

1 / 30

Page 2: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Configuring Files and Filegroups

SQL Server uses two different types of files—data and transaction log files.

Filegroups are a logical structure,defined within a database, that map a database

and the objects contained within a database,to the data files on disk. Filegroups can contain

more than one data file.The proportional fill algorithm is designed to allow

a resize operation to occur at a filegrouplevel. In other words, all files within a filegroup

expand at the same time.2 / 30

Confi guring Files and

Filegroups

Confi guring Database Options

Maintainig Database Integrity

Page 3: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

File Extensions (just naming convention) :

• .mdf - primary filegroup, • .ndf - all other data files, • .ldf - transaction logs

3 / 30

Confi guring Files and

Filegroups

Confi guring Database Options

Maintainig Database Integrity

Page 4: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

You should have a file with an

.mdf extension within a filegroup named PRIMARY, a file with an .ndf extension in a filegroup

with any name that you choose, and the transaction log with an .ldf extension. Besides being the logical definition for one or more files that defines the

storage boundary

for an object, filegroups have a property called DEFAULT.

ALTER DATABASE <database name> MODIFY FILEGROUP <filegroup name> DEFAULT

Following the initial creation of the database, you add filegroups as needed to separate

the storage of objects within the database. You also add files to filegroups to increase the disk

I/O available to the objects stored on the filegroup, thereby reducing disk bottlenecks.

4 / 30

Confi guring Files and

Filegroups

Confi guring Database Options

Maintainig Database Integrity

Page 5: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Transaction Logs• all changes are written to the

transaction log prior to a commit being issued. In addition, the writes to the transaction log

must occur directly to disk.• SQL Server writes sequentially to the

transaction log• data files

underneath a database are isolating the transaction log to a dedicated set of disks

5 / 30

Confi guring Files and

Filegroups

Confi guring Database Options

Maintainig Database Integrity

Page 6: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

6 / 30

Confi guring Files and

Filegroups

Page 7: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

FILESTREAM data• The files are stored

in a folder on the operating system, but are linked directly into a database where the files can

be backed up, restored, full-text-indexed, and combined with other structured data

• You define the location for FILESTREAM data ina database by designating a filegroup within the database

to be used for storage withthe CONTAINS FILESTREAM property.

• The FILENAME property defined for a FILESTREAMfilegroup specifies the path to a folder.

7 / 30

Confi guring Files and

Filegroups

Confi guring Database Options

Maintainig Database Integrity

Page 8: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

tempdb DatabaseSQL Server uses tempdb for worktables used

ingrouping/sorting operations, worktables to

support cursors, the version store supportingsnapshot isolation level, and overfl ow for

table variables. You can also cause index buildoperations to use space in tempdb.

8 / 30

Confi guring Files and

Filegroups

Confi guring Database Options

Maintainig Database Integrity

Page 9: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Lesson Summary• You can define one or more data and log fi

les for the physical storage of a database.• Data fi les are associated to a fi legroup

within a database.• Filegroups provide the logical storage

container for objects within a database.• Files can be stored using the new

FILESTREAM capabilities.

9 / 30

Confi guring Files and

Filegroups

Confi guring Database Options

Maintainig Database Integrity

Page 10: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

10 / 30

Page 11: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

11 / 20

Page 12: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Confi guring Database Options

The recovery models available in SQL Server 2008 are:• Full

• Bulk-logged• Simple

BEST PRACTICES RECOVERY MODELSEvery production database that accepts transactions should be set

to the Full recovery model. By placing the database in the Full recovery model, you can maximize the restore

options that are possible.

12 / 30

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 13: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

THE BULK-LOGGED RECOVERY MODELBCP

BULK INSERT SELECT. . .INTOCREATE INDEX

ALTER INDEX. . .REBUILDBulk-logged recovery model does not log every

change to the transactionlog, you cannot recover a database to a point in

time13 / 30

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 14: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

THE SIMPLE RECOVERY MODELexactly as the Full recovery model

But

Simple recovery model cannot be recovered to a point in time.

Each time the databasecheckpoint process executes, the

committed portion of the transaction log is discarded.

14 / 30

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 15: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

ALTER DATABASE database_nameSET RECOVERY { FULL | BULK_LOGGED |

SIMPLE }

15 / 30

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 16: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Damaged Pages

The PAGE_VERIFYCHECKSUM option can be enabled, which allows you to discover and log damaged

pages

16 / 30

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 17: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Auto OptionsAUTO_CLOSE

AUTO_SHRINKAUTO_CREATE_STATISTICSAUTO_UPDATE_STATISTICS

AUTO_UPDATE_STATISTICS_ASYNCH

17 / 30

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 18: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Change TrackingTo prevent the changes of multiple users

from overriding each other,each row in a table that has been enabled

for change tracking

18 / 20

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 19: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

AccessAccess to a database can be controlled through several options

The status of a database:ONLINE, OFFLINE, or EMERGENCY (db_owner role)

READ_ONLY or READ_WRITE

SINGLE_USER, RESTRICTED_USER(db_owner, dbcreator, and sysadmin roles),and MULTI_USER

ROLLBACK, ROLLBACK IMMEDIATE, ROLLBACK AFTER <number of seconds>

19 / 20

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 20: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Collation SequencesSQL Server has the capability to store

character data that spans every possible written language

The collation sequence for an instance can be overridden at a database level by specifying

the COLLATE clause in either the CREATE DATABASE or ALTER DATABASE command.

20 / 30

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 21: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Lesson Summary• You can set the recovery model for a database to

Full, Bulk-logged, or Simple.• You can back up transaction logs for a database in

the Full or Bulk-logged recoverymodel.

• The AUTO_SHRINK option shrinks a database fi le when there is more than 25 percent

of free space in the fi le.• You can track and log damaged pages by enabling

the PAGE_VERIFY CHECKSUM option.

21 / 30

Confi guring Database Options

Maintainig Database Integrity

Confi guring Files and

Filegroups

Page 22: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

22 / 30

Page 23: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

23 / 30

Page 24: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Maintaining Database Integrity

Database Integrity ChecksPAGE_VERIFY. The page

verifi cation can be set to either TORN_PAGE_DETECTION or CHECKSUM. The PAGE_VERIFY

TORN_PAGE_DETECTION option exists for backwards compatibility and should not be used

BEST PRACTICES PAGE VERIFICATIONYou should enable the PAGE_VERIFY CHECKSUM option

on every production database

24 / 30

Maintainig Database Integrity

Confi guring Database Options

Confi guring Files and

Filegroups

Page 25: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

When DBCC CHECKDB is executed, SQL Server performs all the following actions:

• Checks page allocation within the database• Checks the structural integrity of all tables and indexed views• Calculates a checksum for every data and index page to compare

against the storedchecksum

• Validates the contents of every indexed view• Checks the database catalog

• Validates Service Broker data within the database25 / 30

Maintainig Database Integrity

Confi guring Database Options

Confi guring Files and

Filegroups

Page 26: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

To accomplish these checks, DBCC CHECKDB executes the following commands:

• DBCC CHECKALLOC, to check the page allocation of the database

• DBCC CHECKCATALOG, to check the database catalog

• DBCC CHECKTABLE, for each table and view in the database to check the

structuralintegrity

26 / 30

Maintainig Database Integrity

Confi guring Database Options

Confi guring Files and

Filegroups

Page 27: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Lesson Summary

• The PAGE_VERIFY CHECKSUM option should be enabled for every production database

to detect any structural integrity errors.• When a corrupt page is encountered, the page is logged to the

suspect_pages table inthe msdb database. If a database is participating in a Database

Mirroring session, SQLServer automatically retrieves a copy of the page from the mirror,

replaces the page onthe principal, and logs an entry in the

sys.dm_db_mirroring_auto_page_repair view.• DBCC CHECKDB is used to check the logical and physical

consistency of a database.27 / 30

Maintainig Database Integrity

Confi guring Database Options

Confi guring Files and

Filegroups

Page 28: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

28 / 30

Page 29: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

29 / 30

Page 30: Database Configuration and Maintenance Database Configuration and Maintenance Exam 70-432 1 / 30

Database Configurationand Maintenance

Dziękuję za uwagę

Tomasz Gacek

30 / 30