MS SQL Server Architecture M A Srinivas 9036916045 sqlservertraining@outlook.com For Training and Consultancy visit https://sqlserverprofessional.wordpress.com SERVER CLIENT ARCHITECTURE 2 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 Storage Engine • Storage Engine is responsible for the following: • Storage of data • Retrieval of data What is SQLOS ? • SQLOS is an engine that provides a service for multi-threaded worker pool based scheduling of tasks, memory management, monitoring, hosting, tracing and debugging. SQLOS is powered by the Windows API’s • The key objective of SQLOS is to essentially have an operating system for SQL server and to localize resource management and consumption • SQLOS is not a service or a single dedicated thread. SQLOS is an API for developers and an interface to the operating system of SQL Server. SQLOS is also NUMA aware as it was since its inception in SQL 2005. SQL OS – 1 • 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 : SQLOS – 2 • To take care of massive workloads SQLOS is introduced as a thin layer between windows and SQL Server . SQLOS functions are • Managing system resources (CPU,RAM,IO) • Adapting to ever changing hardware platforms • How SQL server integrates into Windows Operating Systems • Scalability SQL OS - 3 • 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. What is NUMA? • Non-Uniform Memory Architecture is a motherboard design Improves scalability by removing memory controller bottlenecks • Physical memory becomes either local or remote to a specific physical processor • Accessing remote memory is slower than local memory • Each node (or CPU) has its own memory bank • Memory access management is distributed • Local Access Minimum latency (100-200 CPU cycles) • Remote Access Increased latency (1-4x local access) SQL Server’s NUMA objectives • Align the motherboard and SQLOS architectures • Reduce remote memory access • Create memory objects in a task’s NUMA node • E.g. Buffer pool pages, locks and schedulers etc • sys.dm_os_nodes, sys.dm_os_schedulers SQL OS Hierarchy Scheduling • Pre-emptive scheduling : When a thread can be pre-empted by another thread on the same CPU • Non-Pre-emptive scheduling / Cooperative multitasking : A thread can execute until it decides to allow another thread to execute or until it is finished processing • SQL Server uses Non-Pre-emptive scheduling • A SQLOS scheduler is a logical “CPU” for SQLOS. It provides a method to allow “threads” to be assigned to a CPU. A SQLOS scheduler allows nonpre-emptive scalable scheduling and also provides a mechanism for affinity to NUMA and CPU’s. Life Cycle of task • User connects to SQL server Engine -- Session • User executes SQL statement(s) • Statement is divided into one or more tasks, if parallelism is required -- Tasks • Each task is assigned to a worker • SQLOS Scheduler schedules worker • Worker executes in RUNNING, RUNNABLE or SUSPENDED state(s) • Task is completed Execution Model • When an execution request is made within a session, SQL Server divides the work into one or more tasks and then associates a worker thread to each task for its duration. Each thread can be in one of • ➤ Running — A processor can only execute one thing at a time and the thread currently executing on a processor will have a state of running. • ➤ Suspended — SQL Server has a co-operative scheduler so running threads will yield the processor and become suspended while they wait for a resource. This is called a wait in SQL Server. • ➤ Runnable — When a thread has finished waiting, it becomes runnable which means that it’s ready to execute again. This is known as a signal wait 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 Recovery Model 19 Recovery Model Description Work Loss Exposure Recover to point in time? Simple No log backups Changes since the most recent Can recover only to backup are unprotected the end of a backup Full Requires log backups Normally none Can recover to a specific point in time Bulk logged Requires log backups If the log is damaged or bulklogged operations occurred since the most recent log backup, changes since the last backup must be redone Point in time is not supported 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