您的位置:首页 > 数据库

Microsoft SQL SERVER interval summary Chapter 1

2019-10-02 20:38 671 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/u011868279/article/details/101938417

--- Chapter 1 SQL Server 2008 Architecture and Configuration.

1, This book, SQL Server 2008 Internals, covers the main features of the core database engine.

2, we can verify what edition we are running with the following query:

SELECT SERVERPROPERTY('Edition');

3, If you log in as a system administrator and select from the catalog view (discussed shortly) called sys.objects,

you can see the names of all the system tables.

4,In SQL Server 2008, there are three types of system metadata objects.One type is Dynamic Management Objects, which we'll talk about later in this chapter when we discuss SQL Server scheduling and memory management. These Dynamic Management objects don't really correspond to physical tables--- they contain information gathered from internal structrues to allow you to observer the current state of  your SQL Server instance. The other two types of system objects are actually views built on top of the system base tables.

5.(Compatibility View)For  SQL Server 2008 to retrieve all the information available in sysprocesses, you must access three Dynamic Management Objects:sys.dm_exec_connections,sys.dm_exec_sessions, and sys.dm_exec_requests.

6.Catalog view  

All the catalog views(as well as the Dynamic Management Objects and compatibility views) are in the sys schema, and you must reference the schema name when you access the objects. For example, there is a catalog view called objects in the sys schema, so to reference the view, the following can be executed:

Similarly, there are catalog views called sys.indexes and sys.databases. but the columns displayed for these catalog views are very different from the columns in the compatibility views.Because the output from these types of queries is too wide to reproduce, let me just suggest that you run these two queries yourself and observe the difference:

SELECT * FROM sys.databases;

SELECT * FROM sysdatabases;

If you want to know which databases are in simple recovery mode, you can run the following :

SELECT name FROM sys.databases WHERE recovery_model_desc = 'SIMPLE'

 

 

7. As views, these metadata objects are based on an underlying Transact-SQL (T-SQL) definition. The most straightforward way to see the definition of these views is by using the object_definition function.(you can also see the definition of these system views by using sp_helptext or by selecting from the catalog view sys.system_sql_modules.) So the definition of sys.tables, you can execute the following :

SELECT object_definition(object_id('sys.tables'));

8,Property functions give us individual values for many SQL Server objects and also for SQL Server databases and the SQL Server instance itself. The values returned by the property functions are scalar as opposed to tabular,so they can be used as values returned by select statements and as values to populate columns in tables.Here is the list of property functions available in SQL Server 2008:

SERVERPROPERTY

COLUMNPROPERTY

DATABASEPROPERTY

DATABASEPROPERTYEX

INDEXPROPERTY

INDEXKEY_PROPERTY

OBJECTPROPERTY

OBJECTPROPERTYEX

SQL_VARIANT_PROPERTY

FILEPROPERTY

FILEGROUPPROPERTY

TYPEPROPERTY

CONNECTIONPROPERTY

ASSEMBLYPROPERTY

9.The DATABASEPROPERTYEX function has a property call Recovery that returns the recovery model of a database. To view the recovery model of a single database, you can use the property function as follows:

SELECT DATABASEPROPERTYEX('msdb','Recovery');

10.To view the recovery models of all our databases, you can use the sys.databases view:

SELECT name, recovery_model,recovery_model_desc FROM sys.databases;

 


 11.In addition to the property functions, the system functions include functions that are merely shortcuts for catalog view access. For example, to fi nd out the database ID for the AdventureWorks2008 database, you can either query the sys.databases catalog view or use the DB_ID() function. Both of the following SELECT statements should return the same result:  
SELECT database_id FROM sys.databases WHERE name = 'AdventureWorks2008'; 
 
SELECT DB_ID('AdventureWorks2008');
 

12, System Stored Procedures

you cannot do it using the supplied stored procedure. Using the catalog views, these queries are straightforward:

SELECT name FROM sys.databases WHERE suser_sname(owner_sid) ='sue'; 

 

SELECT name FROM sys.databases WHERE compatibility_level < 90; 

13,Metadata Wrap-Up
 Figure 1-1 shows the multiple layers of metadata available in SQL Server 2008, with the  lowest layer being the system base tables (the actual catalog). Any interface that accesses the 
 information contained in the system base tables is subject to the metadata security policies. For SQL Server 2008, that means that no users can see any metadata that they don’t need to see or to which they haven’t specifi cally been granted permissions. (There are a few exceptions, but they are very minor.) The “other metadata” refers to system information not contained in system tables, such as the internal information provided by the Dynamic Management Objects. Remember that the preferred interfaces to the system metadata are the catalog views and 
 system functions. Although not all the compatibility views, INFORMATION_SCHEMA views, and system procedures are actually defi ned in terms of the catalog views, conceptually it is useful to think of them as another layer on top of the catalog view interface. 

 

 

14, Components of the SQL Server Engine

The SQLOS layer handles activities that are normally considered to be operating system responsibilities,such as thread management(scheduling),synchronization primitives,deadlock detection, and memory management ,including the buffer pool.

 

15.Observing Engine Behavior 

The main categories we'll address are the following :

dm_exec_*

Contains information directly or indirectly related to the execution of user code and associated connections. For example,sys.dm_exec_sessions returns one row per authenticated session on SQL Server. This object contains much of the same information that sysprocesses contains but has even more information about the operatiing enviroment of each session.

dm_os_*

Contains low-level system information such as memory, locking, and scheduling. For example. sys.dm_os_scheduler is a DMV that returns one row per scheduler. It is primarily used to monitor the condition of a scheduler or to identify runaway tasks.

dm_tran_*

Contains details about current transactions. For example,sys.dm_tran_locks returns information about currently active lock resources. Each row represents a currently active request to the lock management component for a lock that has been granted or is waiting to be granted.

dm_io_*

Keeps track of I/O activity on networks and disks. For example, the function sys.dm_io_virtual_file_stats returns I/O statistics for data and log files.

dm_db_*

Contains details about databases and database objects such as indexes. For example, sys.dm_db_index_physical_stats is a function that returns size and fragmentation information for the data and indexes of the specified table or view.

16,Protocols

When an application communicates with the Database Engine, the application programming interfaces(APIs) exposed by the protocol layer formats the communication using a Microsoft-defined format called a tabular data stream(TDS) packet. The SQL Server Network Interface(SNI) protocol layer on both the server and client computers encapsulates the TDS packet inside a standard communication protocol.such as TCP/IP or Named Pipes. On the server side of the communication, the network libraries are part of the Database Engine. On the client side, the network libraries are part of the SQL Native Client. The configuration of the client and the instance of SQL Server determine which protocol is used . SQL Server can be configurated to support multiple protocols simultaneously,coming from different clients.Each client connects to SQL Server with a single protocol.If the client program does not know which protocols SQL Server is listening on, you can configure the client to attempt multiple protocols sequentially. The following protocols are available:

Shared Memory 

The simplest protocol to use, with no configurable settings.Clients using the Shared Memory protocol can connect only to a SQL Server instance running on the same computer,so this protocol id not useful for most database activity.  

Named Pipes

A protocol developed for local area networks(LANs).A portion of memory is used by one process to pass information to another process, so that the output of one is the input of the other.The second process can be local(on the same computer as the first) or remote(on a networked computer).

TCP/IP 

The most widely used protocol over the internet. TCP/IP can communicate across interconnected networks of computers with diverse and operating systems.

Virtual Interface Adapter(VIA) A protocol that work with VIA hardware. This is a speciallized protocol; configuration details are available from your hardware vendor.

17.SQL Server uses 13 types of disk pages. The ones we'll be discussing in this book are data pages,two types of LOB pages,row-overflow pages,index pages,Page Free Space(PFS) pages,Global Allocation Map and Shared Global Allocation Map(GAM and SGAM) pages,Index Allocation Map(IAM) pages,Bulk Changed Map(BCM) pages, and Differential Changed Map(DCM) pages.

All user darta is stored on data or LOB pages, and all index rows are stored on index pages. PFS pages keep track of which pages in a database are available to hold new data.Allocation pages (GAMs,SGAMs, and IAMs) keep track of the other pages.They contain no database rows and used only internally. BCM and DCM pages are used to make backup and recovery more efficient. We'll explain these types of pages in Chapter 3 and 4,"Logging and Recovery"

18, You can see the hidden schedulers in sys.dm_os_schedulers. Each Resource Monitor has its own SPID, which you can see by querying the sys.dm_exec_requests and sys.dm_os_workers DMVs, as shown here:

SELECT session_id,        CONVERT (varchar(10), t1.status) AS status,        CONVERT (varchar(20), t1.command) AS command,       CONVERT (varchar(15), t2.state) AS worker_state  FROM sys.dm_exec_requests AS t1 JOIN sys.dm_os_workers AS t2  ON  t2.task_address = t1.task_address WHERE command = 'RESOURCE MONITOR';

19.Observing Scheduler Internals

SQL Server 2008 has several Dynamic Management Objects that provide information about schedulers, workers, and tasks.

These Dynamic Management Objects are as follows:

sys.dm_os_schedulers

this view returns one row per scheduler in SQL Server. Each scheduler is mapped to an individual processor in SQL Server.

you can use this view to monitor the condition of a scheduler or to identify runaway task.

sys.dm_os_tasks 

This view returns one row for each task that is active in the instance of SQL Server.

sys.dm_os_waiting_tasks 

This view returns information about the queue of tasks that are waiting on some resource. 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐