Untitled

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Agenda

Relational Engine
Storage Engine
SQL OS
New Features of SQL Server 2012
Q&A
SQL Server Architecture
Protocol Used Area
SQL Server Components
Databases
Database Files and File Groups
Transaction Logs
Backup and Recovery
Microsoft Cluster Server
Protocols
Disaster Recovery
SQL Server Databases
System databases
Master
Model
MSDB
Resource
Tempdb
User databases
SQL Server Files
Binaries
Datafiles (.mdf, .ndf)
Transaction log files (.ldf)
Backup files and snapshot files
File groups
SQL Server Transaction Log

When the end of the logical log reaches the end of the physical log file,
the new log records wrap around to the start of the physical log file.
SQL Server Recovery Model
Recovery Description Work Loss Exposure Recover to point
Model in time?
Simple No log Changes since the most Can recover only to
backups recent backup are the end of a backup
unprotected
Full Requires log Normally none Can recover to a
backups specific point in
time
Bulk logged Requires log If the log is damaged or Point in time is not
backups bulk-logged operations supported
occurred since the most
recent log backup, changes
since the last backup must
be redone

9
Microsoft Cluster Server

Elements of a Failover Cluster Instance


 A failover cluster instance can run on one or more computers that are participating nodes of a failover
cluster. The number of participating nodes is limited only by the operating system.
 A failover cluster instance contains:
 A combination of one or more disks in a Microsoft Cluster Service (MSCS) cluster group, also known as
a resource group.
 Each resource group can contain at most one instance of SQL Server.
 A network name for the failover cluster instance.
 One or more IP addresses assigned to the failover cluster instance.
 One instance of SQL Server 2005 that includes SQL Server, SQL Server Agent, and the Full-text Search
(FTS) service.

Implementation Considerations
 Hardware
 Software
 Network
Relational Engine
Query Processor
It includes the components of SQL Server that
determine what your query exactly needs to do and
the best way to do it. It manages the execution of
queries as it requests data from the storage engine
and processes the results returned
Different Tasks of Relational Engine:

Query Processing
Memory Management
Thread and Task Management
Buffer Management
Distributed Query Processing
Query Processing

 SELECT SQL Statement (SELECT [CustomerID], [CompanyName], [City], [Region]


FROM [Northwind].[dbo].[Customers]
WHERE [Country] = 'Germany'
ORDER BY [CompanyName]) then
press Ctrl+K,it will display the following:
 Reading the Graphical Execution Plan
 the execution plan for the aforementioned query and we'll begin the
discussion on how to read such a plan. It is slightly nonsensical to those of us
in Western culture and you'll see why in a second.
Select “where clause” evaluation order

select a from table where c=1 and d=2


• There are no guarantees for evaluation order. The optimizer will try to find the most
efficient way to execute the query, using available information.
• In above case, since c is indexed(assume) and d isn't, the optimizer should look into the
index to find all rows that match the predicate on c, then retrieve those rows from the
table data to evaluate the predicate on d.
• However, if it determines that the index on c isn't very selective (although not in
example, a gender column is rarely usefully indexed), it may decide to do the table scan
anyway, but Default order is :
1. FROM clause
2. WHERE clause
3. GROUP BY clause
4. HAVING clause
5. SELECT clause
6. ORDER BY clause
Storage Engine
Storage Engine is responsible for the following:

Storage of data

Retrieval of data
Data Pages in Buffer Pool – Data Stored in Memory Cache

• if there is any way one can know how much data in a table is stored
in the memory cache?
• if there are multiple indexes on table (and used in a query), were the
data of the single table stored multiple times in the memory cache or
only for a single time?

Query ,run to figure out what kind of data is stored in the cache
SELECT COUNT(*) AS cached_pages_count,
name AS BaseTableName, IndexName,
IndexTypeDesc
FROM sys.dm_os_buffer_descriptors AS bd
INNER JOIN
(
SELECT s_obj.name, s_obj.index_id,
s_obj.allocation_unit_id, s_obj.OBJECT_ID,
i.name IndexName, i.type_desc IndexTypeDesc
FROM
(
Database Files
When we talk about any database in SQL server,

there are 2 types of files that are created at the disk


level

1.Data file
2.Log file
Data file
 Data file physically stores the data in data pages.
The size for Data Page is 8KB.
Data pages are logically organized in extents
Extents
Extents are logical units in the database
combination of 8 data pages i.e. 64 KB forms an
extent
Extents can be of two types:
a)Mixed
b)Uniform
Log files
Do not contain pages; they contain a series of log
records.
Need to updated it ……………….
Log files
It also known as write ahead log.
 It stores modification to the database (DML and DDL).
Sufficient information is logged to be able to:
Roll back transactions if requested
Recover the database in case of failure
Write Ahead Logging is used to create log entries
 Transaction logs are written in chronological order in
a circular way
 Truncation policy for logs is based on the recovery
model
SQL OS

This lies between the host machine (Windows OS)


and SQL Server
All the activities performed on database engine are
taken care of by SQL OS
It is a highly configurable operating system with
powerful API (application programming interface)
It enables automatic locality and advanced
parallelism
SQL OS provides various operating system services :
As mentioned in below :
SQL OS

Memory Management
Buffer Pool
Log Buffer
Deadlock detection using blocking and locking
structure.
Other Services. It includes following:
exception handling,
hosting for external components like Common
Language Runtime, CLR etc.
Partitioning
Allows tables and indexes to be split into a series of
ranges, with each range stored separately (most commonly
in separate file groups).
Each table or index can have up to 1000 partitions.
250 indexes x 1000 partitions x 3 allocation units = 750000
IAM chains.
Create Partition only on very large table.
Avoid it on small table/index
Physical design and Index Selection

Physical Dat abase


Design and Tuning
New Features of SQL Server 2012
T-SQL Features
 Table Value Parameters
 FileStream Object Storage
 Merge
 Variable initializers
 Row constructors with >1 row
 Compound operators (+=)
 Grouping sets (extension of Group By clause)
 Intellisense added
 New Collations
 CLR UDT 2GB capacity
 Integrated Full Text Search
 Sparse Columns (Indexing)
 Sequence
 Page Data
 Exception Handling
 Enhanced EXECUTE keyword
 Get Metadata
T-SQL Data Types
Geometery (for planar shapes, i.e. whse layout)
Geography (for GPS coordinates)
HierarchyID
date
time
datetime2
Datetimeoffset (timezone )
New Features In SQL serer 2012
New Data type Conversion
1. PARSE Conversion Function
2. TRY_PARSE Conversion Function
3. TRY_CONVERT Conversion Function
Uses Example:
SELECT StateProvinceID ,StateProvinceCode
,PARSE(StateProvinceCode AS INT) AS [Using PARSE
Function] FROM Person.StateProvince WHERE
CountryRegionCode IN ('FR') AND Name IN
('Vienne')
Date/Time Variables
SQL Server 2005:
Type Accuracy Range
Smalldatetime 1 min 1900-1-1 to 2079-6-6
Datetime 3.33 mS 1753-1-1 to 9999-12-31

SQL Server 2008:


Type Accuracy Range
Date 1 day 1-1-1 to 9999-12-31
time 100 nS 00:00:00 to 23:59.59.9999999
datetime2 100 nS 1-1-1 00:00:00 to
9999-12-31 23:59.59.9999999
datetimeoffset 100 nS 1-1-1 00:00:00 to
9999-12-31 23:59.59.9999999
Filestream
Filestream storage attribute on varbinary(max)
column
Includes transactional access through Win32 API
PathName()
Get_Filestream_Transaction_context()
OpenSqlFileStream()
Other Important Features
OVER Clause is enhanced with ROWS/RANGE
Clause to limit the rows
 Suppose, to calculate sum of last 5 yrs revenue for every row,
 Ex.ROWS BETWEEN 4 PRECEDING AND CURRENT ROW
 Suppose to calculate sum of all preceding years(Cumulative sum),
 Ex.ROWS UNBOUNDED PRECEDING
 SQL Server 2012 provides a function EOMONTH() to calculate end
date of a month.
 DECLARE @Currentdate DATETIME SET @Currentdate = '12/12/2010'
SELECT EOMONTH ( @Currentdate ) AS EndofMonth;
 /*Result: 2010-12-31*/
 FORCESEEK hint is extended to specify columns used to seek in the specified index
 SELECT CompanyID,CompanyName,Amount
 FROM COMPANIES
 WITH (FORCESEEK(Idx_Company(CompanyID)))
 WHERE CompanyID = 1
 OVER Clause is enhanced to apply aggregate functions while applying "Order By“
 SUM(Amount) OVER (PARTITION BY CompanyID ORDER BY Year)
 Ex. SELECT CompanyId,[Year],Amount,
 SUM(Amount) OVER (PARTITION BY CompanyID
 ORDER BY [Year]) AS CumulativeRevenue
 FROM @Companies
 LOG function has been enhanced to accept any base
 SELECT LOG(10) as Result -- Returns natural logarithm value of 10. Natural base is e. its
value 2.718
 SELECT LOG(9,3) as Result1-- Returns logarithm value of base 3.
Disaster recovery :
disasters include :
•A natural or a man-made disaster such as a fire,
•A technical disaster such as a two-disk failure in a Redundant Array of
Independent Disks (RAID) 5 array
•Recovery:
A process that you can use to help recover information systems and data

Before you decide on which disaster recovery solution is best for you

look at each of the suggested disaster recovery solutions in more detail.


Failover clustering:
•Microsoft SQL Server failover clustering is designed to failover automatically if a hardware failure or
a software failure occurs.

•failover clustering is designed for high server availability with almost no server downtime
•To implement failover clustering, you must install Microsoft SQL Server Enterprise Edition.

The following operating systems support failover clustering:

Microsoft Windows NT 4.0, Enterprise Edition


Microsoft Windows 2000 Advanced Server
Microsoft Windows 2000 Datacenter Server
Microsoft Windows Server 2003, Enterprise Edition
Microsoft Windows Server 2003, Datacenter Edition

Microsoft Cluster Service (MSCS): To implement failover clustering for SQL


Server, you must install MSCS from operating systems.
Database mirroring

• Solution for increasing database availability


• can only implement mirroring on a per-database basis
• Mirroring only works with databases that use the full recovery model
• Database mirroring works with any supported database compatibility level

Advantages
• Database mirroring increases data protection.
• Database mirroring increases availability of a database.
• Database mirroring improves the availability of the production database during upgrades.

Disadvantages

•The mirror database should be identical to the principal database. For example, all objects,
logins, and permissions should be identical.

•Database mirroring involves the transfer of information from one computer to another
computer over a network. Therefore, the security of the information that SQL Server transfers is
very important
Peer-to-peer transactional replication

• Peer-to-peer transactional replication is designed for applications that


might read or might modify the data in any database that participates
in replication
• if any servers that host the databases are unavailable, you can modify
the application to route traffic to the remaining servers. The remaining
servers contain identical copies of the data
Advantages:
•Read performance is improved because you can spread activity across all nodes.
•Aggregate update performance, insert performance, and delete performance for the topology
resembles the performance of a single node because all changes are propagated to all nodes.
Disadvantages:
•Peer-to-peer replication is available only in SQL Server 2005 Enterprise Edition.
•All participating databases must contain identical schemas and data.
•We recommend that each node use its own distribution database. This configuration eliminates the
potential for SQL Server 2005 to have a single point of failure.
•You cannot include tables and other objects in multiple peer-to-peer publications within a single
publication database.
•You must have a publication enabled for peer-to-peer replication before you create any subscriptions.
•You must initialize subscriptions by using a backup or by setting the value of the subscription
synchronization type to replication support only.
•Peer-to-peer transactional replication does not provide conflict detection or conflict resolution.
•We recommend that you do not use identity columns.
Configure Replication for Always On Availability Groups

1. Configure the database publications and subscriptions.


2. Configure the Always On availability group.
3. Insure that all secondary replica hosts are configured for replication.
4. Configure the secondary replica hosts as replication publishers.
5. Redirect the original publisher to the Availability Group Listener Name.
6. Run the validation stored procedure to verify the configuration.
7. Add the original publisher to Replication Monitor.

You might also like