44
Sql Server For The Experienced Oracle DBA Aaron Shilo CEO@DBcs [email protected] www.dbcs.co.il About me Maried+ 3 Was CTO @ johnryceisrael Currently Owner and CEO @ DBcsltd Certified as ocpand mcp 1

About me - mscom.co.ilmscom.co.il/Downloads/SQLPresentations/11065.pdf · About me • Maried+ 3 ... Checkpoint Archive r Log Writer SQL Server Background Processes ... Undo Tablespace

Embed Size (px)

Citation preview

Sql Server

For The

Experienced

Oracle DBA

Aaron Shilo

CEO@DBcs

[email protected]

www.dbcs.co.il

About me

• Maried + 3

• Was CTO @ johnryce israel

• Currently Owner and CEO @ DBcs ltd

• Certified as ocp and mcp

1

DBcs Ltd

• Provide Premium DataBase Services.

• Specialize in :

– Design : logical , physical

– Integration , migration , upgrade in and between

Sql Server and Oracle dbms.

– Database management and development using

latest techniques and technologies.

– Great troubleshooting skills

Among our customers

2

Agenda

• Understand the underlying architecture of SQL Server– Services

– Instance Structure

• Manage the SQL Server system, databases, and users– Database Structure

– Database Option/Parameters

– Users & Roles

– Security Concepts

– Advanced Security Overview

• Database backup & recovery– Recovery Model Options

– Backup Options

– Restore Options

– Advanced High Availability Overview

• Define and implement monitoring and tuning solutions for the SQL Server system– Resource Governor

– Profiler

– Database Tuning Advisor

Instance Architecture

3

Concept of Database and Instance

• Database Management System (DBMS) encompasses database and instance

• A Database is a set of physical files that store application and system data

• An instance consists of the hardware resources of the system (primarily memory and CPU utilization) that facilitates data access for the end-user

Database and Instance Implementations

4

Database and Instance Implementations

Database and Instance Implementations

5

Database and Instance Implementations

Database and Instance Implementations

6

Client Interaction with Database and Instance

• Key components in the interaction of the user (client) with the database environment

Application

Layer

-------------

SQL Server

Network

Interface

protocol

layer

-------------

SNAC

network

libraries

ClientPerson

ClientSystem

Database ServerEngine

TDS Endpoint

(defined by

listener.ora

may implement

TNSnames.ora)

Relational

Engine

--------------

Tabular Data

Stream (TDS)

Packet

------------

SQL Server

Network

Interface (SNI)

Layer

StorageSystem

Data Storage

Application

Layer

-------------

Oracle Net

Foundation

Layer

-------------

Oracle

Protocol

Support

Layer

ClientPerson

ClientSystem

Database Server

Listener

(defined by

listener.orga

may implement

TNSnames.ora

Oracle

Instance

--------------

Oracle Net

Foundation

Layer

------------

Oracle

Protocol

Support

Layer

StorageSystem

Data Storage

Oracle

Connections

SQL Server

Connections

Configuration of a Server

• Using Configuration Parameters to Allocate

and Manage Resources

• Oracle Configuration• Use of initialization parameters (init.ora or spfile)

• ALTER SYSTEM, ALTER DATABASE

• SQL Server Configuration• Setting server properties using SQL Server Management Studio (SSMS)

• The role of sp_configure system stored procedure

7

Memory Address Space – Oracle

• Components of Oracle in Me

Application components

RDBMS components

SYSTEM GLOBAL AREA

JAVA POOL

LARGEPOOL

STREAMSPOOL

SHAREDPOOL

REDOBUFFER

BUFFERCACHE

OracleProcess

Server Process

Server Process

Server Process

BackgroundProcess

PGA PGA PGA

PGA PGA

Automatic Shared MemoryManagement

Managed by SGA_Target

Automatically sizes

SQL Server’s Memory Pool and Oracle’s SGA

Oracle System Global Area (SGA)

Buffer Cache Shared Pool

Large

Pool

Java

Pool

Redo

BuffersFixed

SGA

Streams

Pool

SQL Server Memory Pool

Buffer Cache Procedure Cache

Connection

ContextLog Cache System

Structures

CLR Hosting

Layer

8

SQL Server Architecture (SQLOS)

• Components of SQL Server Architecture

• Non-Preemptive Scheduling

• Memory Management

Hosting Subsystems

Memory Management Non-Preemptive

Scheduling

SQLOS

Memory Nodes

Memory Clerks

Caches

Pools

Memory Objects

Scheduling Nodes

Schedulers

Tasks

Worker Threads

System Threads

Exception Handling Resource Monitoring

Memory Address Space – Comparison (Cont.)

• Memory Allocation in SQL ServerDynamic at

higher level (memory pool, etc.)

lower level (buffer cache, procedure cache, etc.)

Few configurable parameters

• Memory Address Range32-bit (x86)

Address WindowingExtensions (AWE)

/3GB

64-bit (x64 and xIA64)

2TB

9

Process and Thread-Based Architecture

• Process - memory space to protect applications

• Threads –

Execute code

Allocated time on CPU

Managed by Operating System

• Fibers are light-weight threads

reduce context switching overhead

• Oracle uses processes in Unix and threads in Windows

• Both Oracle and SQL Server use threads and optionally fibers.

• Allocate thread assignment with CPU affinity

Resource Governor = Greater Control

Resource Governor

• Performance

• Availability

• Security

Key Components

• Resource Pools

• Workload Groups

• Classification

10

Oracle Client–Database Interaction

• Oracle’s two modes of interaction are:• Dedicated Server – uses a dedicated server process per client

session• Shared Server – uses dispatchers and shared server processes

DATABASE Data Files

USERS

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

Client

Client

Client

Request

Queue

Database

Buffer

Cache

Response

Queue

Dispatche

r

Shared

Server

Dedicated

Server

INSTANCE

SGA1

5

6

7

2

3

4

8

SQL Server Client–Database Interaction

• SQL Server uses the shared server mode• Functionality of the dispatcher is facilitated by the networker thread

• Functionality of the shared server processes by the worker threads

Users

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

Client

Client

ClientDatabase

Buffer

Cache

Data Files

Relationa

l

Engine

OLE

DBStorage

Engine

Open

Data

Services

Worker

Thread

Worker

Thread

Worker

Thread

Memory

Pools

11

Oracle Background Processes

USERS

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

Client

Client

Client

INSTANCE

DATABASE

Automatic Storage Management

Process

Monitor

System

Monitor

Queue

Monitor

Job

Queue

Event

Monitor

Recoverer

Trace

Writer

Dispatcher

Shared

Server

Request

Queue

Response

Queue

SGA

Redo

Log

Buffer

Data FilesArchive Log

Files

Control

Files

Redo Log

Files

Database

Buffer

Cache

Dedicated

Server

Databas

e

WriterCheckpoint

Archive

r

Log

Writer

SQL Server Background Processes

Users

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

User

Process

Client

Client

Client

Relational

Engine

OLE

DB

Storage

Engine

Data Files

Log

Files

Database

Buffer

Cache

Log

Cache

Database

Cleanup

Worker

Thread

Log Writer

Lazy

Writer

Worker

Thread

Database

Shrinking

Open

Data

Services

Memory

Pool

12

Comparing Background Processes

Oracle

Process

Oracle

Identifier

SQL Server

Equivalent

Required

Process Monitor PMON SQLOS Mandatory

System Monitor SMON Database

Cleanup/Shrinking

Mandatory

Database Writers DBWn Lazywriter Mandatory

Checkpoint Process CKPT Database Checkpoint Mandatory

Recoverer RECO MS DTC Optional

Log Writer LGWR Log Writer Mandatory

Archive Processes ARCn N/A N/A

Job Queue Processes Jnnn SQL Agent Optional

Job Queue Coordinators CJQn SQL Agent Optional

Queue Monitor Processes QMNn SQL Agent Optional

Parallel Query Slave

Processes

Pnnn Worker Threads Mandatory

Dispatcher Dnnn Networker Thread Mandatory

Shared Servers Snnn Worker Threads Mandatory

Database Architecture

13

Database Capacities

• A brief look at Oracle and SQL Server 2008 maximum capacity specifications

Database Capacities on Windows

Server 2003 (x86, x64, or IA64)

Oracle 10g SQL Server 2008

Minimum data block size 2 KB 8 KB

Maximum data block size 16 KB 8 KB

Maximum file size 64 GB 16 TB

Maximum number of files 65,536 32,767

Maximum database size 4 PB

(65,536 * 64 GB)

524 PB

Maximum control file size 20,000 data blocks N/A

Instances per server Limited by host resources 50 – Standard and

Enterprise Edition

16 or less on other

editions

Maximum database extent 4GB 64 KB

Maximum number of tablespaces 65,536 32,767 (filegroups – see

Module 2)

Maximum log file size 64 GB 2 TB

Schema and Data Structures (Objects)

• Schema – a collection of objects owned by a database user

• Schemas in SQL Server provide logical separation of objects,

similar to Oracle’s schema

Oracle SQL Server

Table Table

Index Index

View View

Synonym Synonym

Sequence Identity Columns

Procedure Stored Procedure

Function Function

Package N/A

Queue in Streams Advanced Queuing Service Broker Queue

Object Type Type

XML DB XML Schema Collection

Comparison of Core Schema and Data Structures (Objects)

14

Storage Architecture

• Database storage architecture includes physical and logical structures

• Physical structures are data files, log files, and operating system blocks

• Logical structures are subdivisions of data files used to manage storage space

Data File Data File Data File Data File Data File Data File

Temporary Tablespace Groups

Tablespace

ExtentExtent

FilegroupTablespace

Segment Segment

ExtentExtent

Filegroup

Heap/Index Heap/Index

ExtentExtent Extent

BlocksBlocksBlocks Blocks Pages Pages Pages

Data Blocks, Extents, and Segments

Structure Oracle SQL Server 2008

Smallest unit of logical storage

Block Page

Block size Variable 8 KB fixed

Storage allocationPerformed in multiple blocks; are ‘extents’

Performed in multiple pages; are ‘extents’

Extent size Variable 64 KB fixed

SegmentAny logical structure that is allocated

storageNo equivalent structure

15

Storage Allocation

Fundamental difference in storage allocation between Oracle and SQL Server

Managing Extents and Pages

• In Oracle, each extent is dedicated to an allocated object. In SQL Server, the equivalent is a uniform extent.

• SQL Server uses mixed extents: pages are allocated to objects with less than 8 blocks of data

• Similar to the Oracle bitmap functionality used to manage free space and extent allocation, SQL Server uses the Global Allocation Map (GAM) and Shared Global Allocation Map (SGAM)

• Oracle keeps track of extents using extent allocation maps

16

Managing Extents and Pages (Continued)

Current Use of ExtentGAM Bit

Setting

SGAM Bit

Setting

Free, not being used 1 0

Uniform extent, or full

mixed extent0 0

Mixed extent with free

pages0 1

File Header Extent

Extents in

SQL Server

GAMs and SGAMs

Tablespaces and Datafiles

• Oracle and SQL Server store data in datafiles

• The largest logical storage structure in Oracle is a tablespace

• The largest logical storage structure in SQL Server is a filegroup

• Tablespaces/filegroups are used to group application objects

• Tablespaces/filegroups optimize administration of datafiles

17

SQL Server Data Files

Three file types supported by SQL Server:

• Primary Data Files

• Secondary Data Files

• Log Data Files

Mapping of Tablespaces and Filegroups

System Tablespace

SysAux Tablespace

Temporary Tablespace

BigFile Tablespace

User Data Tablespace

User Index Tablespace

Undo Tablespace

Redo Log Files

Master DB

Resource DB

TempDB

Model DB

MSDB

User DB

Data FG

Index FG

Log File(s)

Oracle Database Instance SQL Server Instance

Data file

Data fileData file

Data fileData file

Tablespace Group

Data fileData file

Data fileData file

Data fileData file

Data fileData file

Data fileData file

Redo LogRedo Log

Redo Log

Log fileData file

Log fileData file

Log fileData file

Log fileData file

User Database

Data fileData file

Data fileData file

Log file

Log fileData file

18

Logging Model

• Oracle uses online redo logs to record changes made to the database by transactions and undo segments to capture the ‘before image’ of data

• SQL Server implements both of these functions using transaction logs. Each transaction record contains the undo and redo image of the transaction.

Data Dictionary

• In Oracle the data dictionary is stored under the SYS schema in the

SYSTEM tablespace

• In SQL Server the data dictionary consists of:

– Catalog View—the best way to access system metadata

– Backward Compatibility Views—All system tables from previous

releases are provided as backward compatibility views

– Dynamic Management Views—to view the current state of the SQL

Server system. Provide real-time snapshots of internal memory

structures indicating the server state.

– INFORMATION_SCHEMA views—SQL-99 method to view system

metadata

• The SQL Server Resource database contains the metadata for system

stored procedures

19

Basic Administration

Installing SQL Server 2008

Stages in SQL Server 2008 installation• Planning—software edition, file locations, naming

conventions, installation options (SQL Server Versions, OFA recommendations: file locations)

• Resource procurement—hardware, operating system, utilities

• Installing software and components

• Network configuration—choice of protocols, load balancing, etc., using SQL Server Configuration Manager

• Client connectivity and configuration—choice of protocols, server details using SQL Server Configuration Manager

20

Database System

• Creating instances – Initial and subsequent instances can be named; one default, unnamed instance

• Configuration – Database System configuration parameters can be set using sp_configure or Management Studio

• Configuration parameters can be basic or advanced – Certain parameters are self-configuring and can also be manually set

SQL Server Databases

• Database name — constrained by the same

rules as identifiers

• Database/Schema owner — user that owns

database and objects

21

Database Configuration

• Database configuration option set using ALTER DATABASE and sp_dboptions can be classified as:

• Auto options – auto_close, auto_shrink, …

• Cursor options – address cursor restrictions and scope

• Recovery options – recovery full | bulk_logged | simple

• SQL options – ansi_padding, …

• State options – offline | online, single user, …

Database Maintenance

• Information on the database can be obtained using sp_helpdb

• Database maintenance operations in SQL Server and their Oracle

equivalent are:

• Shrinking database – equivalent to shrinking all the files in a

tablespace

• Changing default filegroup – same as changing default tablespace but

set for the database rather than the user login

• Attaching & detaching databases – similar to transporting tablespaces

• Changing database name – similar in function to Oracle’s tablespace

renaming feature

• Changing database owner – not found in Oracle

22

Data Dictionary

• SQL Server term for data dictionary is system catalog

• System catalog is decentralized with instance system objects in the Master and Resource databases and database-specific objects in individual databases

• INFORMATION_SCHEMA views provide an interface to schema related system tables

• SQL Server provides system catalog views to obtain metadata – equivalent to Oracle’s DBA_ / ALL_ / USER_ views

System Stored Procedures

System Stored Procedure categories include:

• Active Directory • Catalog • Cursor• Database Engine• Database Mail

and SQL Mail• Distributed Queries• Full-Text Search• Log Shipping• Automation

Notification Services

Replication

Security

SQL Server Profiler

SQL Server Agent

Web Task

XML

General Extended

23

Data Objects

Schema Objects – Table

• Tables are the primary objects that store data in rows and columns

• Each DBMS offers different types of tables to support different access needs with optimal performance and extended functionality as the goals

Oracle SQL Server

Heap-Organized Table

Heap

Clustered Table -

Partitioned Table Partitioned Table

Nested Table XML datatype

Temporary Table Temporary Table

External Table Linked Server

Object Table Table Types

Index-organized Table

Clustered Index

Table Types in Oracle and SQL Server

24

Putting Data in the Table

• Heap is the default form of data organization in a table, where data is stored in an unordered manner

• Allocation units can extend beyond themselves

• Oracle’s index organized tables store data in a B-tree structure in primary key order

• Oracle and SQL Server offer local and global temporary tables to store transient application data

• Compression is necessary

SQL Server Table Structures

Clustered Index Structure in SQL ServerSysindexes

Root

node

Intermediat

e level

Leaf node /

data pages

A-Z

W-ZA-D E-H …

Debr

a

Andy Charlie

25

Indexes

Index Structures in Oracle and SQL Server

Index scheme Oracle SQL Server

B-tree Unique Yes Yes

B-tree Non-unique Yes Yes

B-tree Composite Yes (32 cols) Yes (16 cols)

B-tree Ascending Yes Yes

B-tree Descending Yes Yes

B-tree Cluster Yes Yes

B-tree Reverse key Yes No

B-tree Key compressed Yes No

B-tree Function-based Yes No

B-tree Index organized table Yes Yes (clustered)

B-tree Partitioned Yes No

Bitmap Yes (30 cols) No1

Bitmap Join Yes No1

Constraints

• Constraints are data integrity rules defined on columns of a table to enforce certain business rules

Oracle SQL Server

NOT NULL NOT NULL

UNIQUE UNIQUE

PRIMARY KEY PRIMARY KEY

FOREIGN KEY FOREIGN KEY

DEFAULT DEFAULT

CHECK CHECK

Constraints in Oracle and

SQL Server

26

Triggers

Trigger Types Compared

Feature Oracle SQL Server

DML – INSERT Yes Yes

DML – UPDATE Column/Row Row

DML – DELETE Yes Yes

Timing – BEFORE Yes Yes (INSTEAD OF)

Timing – AFTER Yes Yes

Level Row/Statement Row

Views – INSTEAD OF Yes Yes

Multiple triggers per action Yes Yes (first/last specified)

DDL Triggers No Yes

Single trigger for multiple actions Yes Yes

Views

• Both Oracle and SQL Server offer views based on simple queries involving a single table and complex queries based on multiple tables

• Indexed views in SQL Server is the only type of view which actually stores data

• Oracle and SQL Server offer updatable views with INSTEAD OF triggers and WITH CHECK OPTION constraint

View Type Oracle SQL Server

Simple views Yes Yes

Join views Yes Yes

Partitioned views Yes Yes

Updatable views Yes Yes

Inline views Yes Yes

Object views Yes No

Indexed views No Yes

View Types in Oracle and SQL Server

27

Number Generation and New Names

• CREATE SEQUENCE SomeNewNumbers

• START WITH 0 INCREMENT BY 1

ORACLE: Sequence ( 0, 1, 2, 3, 4, ……….

• CREATE TABLE ASchema.ATable

• ( Id int IDENTITY(0,1),

• Information nvarchar(12) )

SQL Server: Identity (0, 1, 2, 3, 4, ………..

• CREATE TABLE dbo.Globally_Unique_Data

• (guid uniqueidentifier CONSTRAINT Guid_Default DEFAULT NEWSEQUENTIALID() ROWGUIDCOL,

• Employee_Name varchar(60)

• CONSTRAINT Guid_PK PRIMARY KEY (guid) );

SQL Server: Global Unique Identifiers( B2794358-DA6A-DD11-829F-

001E685F0BC5…

• CREATE SYNONYM MyProductFOR TheSchema.TheProduct;

Either: Synonyms

Character-Based Data Types

Character-based data types in Oracle and SQL Server

Oracle SQL ServerData Type Size (bytes) Data Type Number of

CharsSize in bytes

Char 1 to 2000 Char 1 to 8000 1 to 8000 fixed

NChar 1 to 2000 (fewer chars) NChar 1 to 4000 2 to 8000 fixed

Varchar 1 to 4000 Varchar

Varchar(max)

1 to 8000

1 to 231-1

0 to 8000

0 to 2 GB

NVarchar 1 to 4000 (fewer chars) NVarchar

NVarchar(max)

1 to 8000

1 to 230-1

0 to 4000

0 to 2 GB

Varchar2 1 to 4000

NVarchar2 1 to 4000 (fewer chars)

LONG 1 to 231 Text, Varchar(max)

1 to 231-1 0 to 2 GB

CLOB 1 to 232 Text, Varchar(max)

1 to 231-1 0 to 2 GB

NCLOB 1 to 232 Ntext, Nvarchar(max)

1 to 230-1 0 to 2 GB

28

Numeric Data Types

Numeric data types in Oracle and SQL ServerOracle SQL Server

Number(19,0) BigInt

Int or Number(10,0) Int

SmallInt or Number(6,0) SmallInt

Number(3,0) TinyInt

Number(p,0) Decimal(p,s)

Number(p,0) Numeric(p,s)

Float or DoublePrecision or Number(38)

Float

Number(1) Bit

Number(19,4) Money

Number(10,4) SmallMoney

Date and Time Types

Oracle SQL Server

Data Type Values Data Type Values

Date Date and time to seconds SmallDateTime Date and time to seconds

DateTimeDate and time with fractional seconds

to 1/300 or 3.33 milliseconds

Calendar01/01/1753 AD – 01/06/9999 AD

(DMY)

Timestamp (TS)Date and time with fractional seconds

(9 digits)DateTime2 (DT2)

Date and time with fractional seconds (7 digits)

Timestamp with time zone (TSTZ)

Like TS with zones

Timestamp with local time zone

(TSLTZ)

Like TS with relative zones to users

DateTimeOffset Like DT2 with time zone offsets

Calendar – Julian01/01/4712 BCE -

12/31/4712 CECalendar –Gregorian

01/01/0001 AD – 31/12/9999 AD (DMY)

Daylight Savings Time Support

YesDaylight Savings

Time SupportNo

DATE Date only – Gregorian

TIME Time only with fractional seconds(7 digits)

29

Binary Data Types

Oracle SQL Server

BLOB Image, Varbinary(max)

Raw Image, Varbinary(max)

Long Raw Image, Varbinary(max)

BFile Similar to

Varbinary(max) Filestream

BLOB/Raw(n) Binary(n)

BLOB/Raw(n) Varbinary(n), Varbinary(max)

Binary data types in Oracle and SQL Server

Database Security

30

Managing Users

• In Oracle, a username is database system wide, SQL Server uses login accounts to access the instance and user accounts for the individual databases

• Oracle usernames and SQL Server logins can be operating system authenticated or database authenticated. In addition, SQL Server logins could be authenticated by the network domain.

• In SQL Server, a user account has to be created in every database that a login needs access to and can be named differently from the login name

Managing Privileges

• Oracle and SQL Server control access and activity within the database using system and object privileges

• ALTER DATABASE and GRANT are examples of system privileges while object privileges can be SELECT, INSERT, UPDATE, DELETE.

• Oracle and SQL Server use the GRANT statement to give privileges and REVOKE statement to remove privileges. In addition SQL Server has the DENY statement to suspend privileges.

• Use the system catalog view sys.database_permissionsand function fn_builtin_permissions to list permissions on objects and statements in SQL Server

31

Managing Roles

• Oracle and SQL Server provide system roles with predefined privileges and user defined roles

• The SQL Server system defined roles are of two categories:1. Fixed server roles which are defined for the database instance

2. Fixed database roles whose scope is limited to a database

• Sysadmin fixed server role is equivalent to Oracle’s DBA role

• In Oracle, there is a single DBA role that has database instance wide privileges spanning all schemas

• In SQL Server, administrative privileges can be limited to individual databases by the use of fixed database roles

Backup and Recovery

32

Database Errors

The most common database errors include:

• Statement failure—when a program encounters a failure in the handling

of a statement

• Process failure—when a background process, user process, or server

process encounters an abnormal disconnection or process termination

• Instance failure—when an instance ceases to run due to a hardware or

software failure

• User or application error—when objects are dropped or data is deleted

accidentally

• Media failure—when reading from or writing to a database file fails

• Network failure—when a network segment fails or a phone connection

aborts

Backup Methods

Two Types: Logical and Physical Backups • Logical backups facilitate recovery at the

individual schema object level• In SQL Server, you can use SSIS, bcp, and other

data transport tools

• Physical backups are copies of physical database files. These include:• Online (or inconsistent) backups

• Offline (or consistent) backups

• Incremental backups

• Archive log backups

33

SQL Server Recovery Models

• Available recovery models include:

• Full

• Bulk Logged

• Simple

• Recovery models determine the amount of logging at the database or command level

• Recovery models provide much needed control over logging and speed up bulk operations while providing recoverability to transaction-heavy systems

Factors Affecting Backup Strategy

Decisions

• Transaction rate and rate of data change

• Availability requirements of databases

• Value and degree of mission critical nature of data

• Nature of data access

• File system storage space available for backups

• Backup media space available

• Cost of other hardware and software resources

• Performance load requirements

34

Recovering From Database Errors

• Statement failure—Oracle and SQL Server automatically recover and

return control

• Process failure—PMON in Oracle and SQLOS in SQL Server automatically

roll back the current transaction and release held resources

• Instance failure—Oracle and SQL Server recover on instance startup

• User or application error—Oracle and SQL Server offer point in time

recovery options

• Media failure—Oracle and SQL Server offer file-level recovery

• Network failure

• PMON in Oracle and SQLOS in SQL Server recover aborted transactions

• RECO in Oracle and MSDTC in SQL Server recover from failures during

two-phase commit of distributed transactions

Backup and Recovery Tools

• Oracle Recovery Manager (RMAN)—part of Oracle, used to back up and recover database files.

• SQL Server backup and restore components—in conjunction with SQL Server Agent, you can set up, schedule, automate backups and perform recovery.

• BACKUP and RESTORE commands can be used in applications, T-SQL scripts, stored procedures, and triggers.

• Backup history is maintained in the RMAN recovery catalog. The equivalent system catalog tables are in the msdb database in SQL Server.

• Consider Encryption/Compression – Both tools provide it in some approach.

35

Third-Party Backup and Recovery

Solutions

• EMC, Compaq, Hitachi, Quest, Idera, and other third party vendors offer SQL Server backup and restore tools

• Third-party backup and recover tools interface RDBMS native backup and restore components with media management. Some examples include:• BMC’s Recovery Manager

• EMC’s Datamanager

• Symantec’s NetBackup

• HP’s Data Protector

• Red Gate’s SQL Backup

• Quest’s LightSpeed

• Idera’s SQLsafe

Scalability and High Availability

36

High Availability

• High availability — ensuring database and data are accessible for the maximum amount of time

• Initialization parameters or configuration options in Oracle and SQL Server

• Logical (add, remove, rename columns) and physical (rebuild, move, change storage parameters) structure of tables

• Indexes

• SQL Server partitioning option

Clustering

• Both Oracle and SQL Server offer Active/Passive (single instance) and Active/Active (multi-instance failover clustering) options in clustering. In Oracle, it is called Failsafe and Real Application Clusters (RAC); SQL Server refers to it as Failover Clustering

• For Active/Passive clustering, Failsafe and Failover clustering are both based on Microsoft Cluster Services (MSCS) containing a single set of non-shared disks

• For Active/Active clustering, Failsafe and Failover clustering utilize a multi-node configuration where each node has its own instance connecting to shared disks. However, the database can be opened by only one node at a time

• Oracle’s RAC can also provide Active/Active clustering in a shared-everything architecture where multiple instances can simultaneously access data from the same database

37

Standby Database

• Both offer standby database which can be used for availability and disaster recovery• In Oracle, Data Guard

• In SQL Server, Database Mirroring and Log Shipping

• Standby databases are updated using archive logs in Oracle and transaction logs in SQL Server

• Shipping of logs to a standby server and their application can be controlled to provide scope for recovery from user errors in the primary

• Snapshots of mirrored database in SQL Server and logical standby database in Oracle can be used for read-only purposes such as reporting, analysis, DSS

Replication – Objects

• Replication is a specialization of the distributed database concept where

copies of an object can be kept in multiple databases

• Unlike clustering and standby databases, replication encourages sharing

and distribution of individual objects rather than entire databases

• Both Oracle and SQL Server provide multiple types of replication based on

whether the replicas are read-only or updatable

• Replicas are refreshed in full or updated using discrete transactions either

synchronously (multi-master) or asynchronously (all others)

• Oracle Streams offers replication in three forms:

• Multi-master replication — multiple peer-to-peer updatable replicas

• Materialized views — each replica has a master site with various policies on updating the replicas

• Hybrids of replication and materialized views

38

Replication – Types

• SQL Server offers the following types of replication:

• Snapshot replication — used mostly as read-only copies which are

completely refreshed periodically

• Transactional replication — kept up-to-date with immediate or

deferred updates from the master site. Copies are used mostly as

read-only and occasionally updated. Updatable subscribers

(immediate and queued), and peer-to-peer transactional replication

support updates at subscribers.

• Merge replication — similar to Oracle’s multi-master replication where

the autonomous sites are synchronized at regular intervals

• Oracle and SQL Server offer sophisticated algorithms for conflict resolution

among updatable replicas

Database Mirroring

• Software solution for increasing the availability of a specific database

• Consists of principal server, a mirror server, and optionally a witness server

• Witness server enables automatic failover

• Can operate in either Synchronous or Asynchronous mode

• Use views such as sys.database_mirroring, sys.dm_db_mirroring_connections to monitor database mirroring

39

Scalability

• Scalability is the ability to support very large databases (VLDB) and/or large volume OLTP

• Memory areas in Oracle and SQL Server are dynamically resized without restarting. The process is performed either automatically or by the DBA in Oracle, where it is automatically performed by the DBMS in SQL Server.

• Oracle and SQL Server, respectively, use parallel query and worker threads to provide interoperation and intra-operation parallelism in the execution of DML and DDL. Both optimizers are parallel-aware.

• Oracle and SQL Server scale well in the handling of user connections through the use of shared server processes

• Oracle and SQL Server offer many types and features for speedy access to large volumes of data. Examples are many types of indexes, advanced I/O techniques and caching.

• SQL Server 2008 supports NUMA and Hot Add CPU

Scalability and HA in Backup and

Recovery

• MTTR targets can be set for instance recovery by controlling the checkpoint process in Oracle using FAST_START MTTR_TARGET and in SQL Server using ‘recovery interval’ option

• The RMAN features available in SQL Server backup and restore utilities are:• Parallelism in backup and recovery operations• Incremental backups• Multiple granularities in backup and restore to reduce the

amount of recovery needed• Point in time recovery• Choice of backup media and devices• Duplicating or cloning databases

• Moving of data in logical units of tablespaces using transportable tablespaces across multiple platforms in Oracle is found in SQL Server through the attach and detach features for databases

40

Performance Tuning

Tuning Methodologies — Tuning While

Building

• The Tuning While Building methodology offers

a proactive approach to performance tuning

• These are the steps:

1. Tune the business rules

2. Tune the data design

3. Tune the application

4. Tune the instance

5. Tune the underlying platform

41

Tuning Methodologies — Performance

Tuning

• Performance tuning is an ongoing, interactive process

• Performance Improvement Method offers steps in improving performance of a system in production:

• Define the problem

• Examine the host system and the Oracle statistics

• Examine documentation to help identify the problem

• Generate a prognosis based on captured data

• Propose a course of action and implement the changes

• Evaluate the causes of the changes

• If unsuccessful, repeat previous two steps

Application Tuning

• Tune Application Design — Leverage RDBMS features

• Example: Perform calculations and summaries on the database before fetching the results so as to leverage database resources as well as to reduce network traffic

• Tune Logical Structure of Database — Leverage supporting schema objects

• Example: choose appropriate indexes

• Tune Database Operations

• Find statements that consume most resources — Use statistics available in system catalog, such as parses, CPU time, physical reads

• Tune the statements to use fewer resources — Use coding standards and tools to analyze and tune SQL

• Tune Access Paths — Aid Optimizer in finding optimal access path, creating indexes, clustered indexes, and providing optimizer hints

42

• Tune Memory Allocation

• Proper configuration and use of the caches that make

up the SGA (Oracle) and memory pool (SQL Server)

• Tune I/O and Physical Structures

• Separation of files based on access

• Distribution of I/O load across files and devices

• Tune Resource Contention

• Reduce and/or eliminate contention for locks, latches,

block (page) headers, and queues

Instance Tuning

SQL Server Performance Tuning Tools

• Profiler — records detailed information on activity on the database server, including I/O statistics, CPU statistics, index and table scans, execution plans and several other statistics to aid in tuning SQL and T-SQL

• Performance Data Collector — fully integrated tool that collects a variety of performance metrics on one or more SQL Servers and stores the data in a central datawarehouse

• Build custom reports showing trends

• Query Editor in SSMS — graphical tool used to execute and debug queries to resolve performance issues

• Database Engine Tuning Advisor — database physical design tool to optimize indexes and partitioning

• Replaces Index Tuning Wizard from previous SQL Server releases

• Performance Monitor —Windows tool that records counters at hardware, operating system, database, and application levels

• Task Manager — used for initial review of high-level counters on the system, including utilization at a process level

43

44