Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
41 views
36 pages
Chapter 17 SQL Metadata
Uploaded by
Đoan Trang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Chapter 17 SQL Metadata For Later
Download
Save
Save Chapter 17 SQL Metadata For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
41 views
36 pages
Chapter 17 SQL Metadata
Uploaded by
Đoan Trang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Chapter 17 SQL Metadata For Later
Carousel Previous
Carousel Next
Download
Save
Save Chapter 17 SQL Metadata For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 36
Search
Fullscreen
PART IV Performance and MaintenanceCHAPTER 17 SQL Server Metadata Metadata is data that describes other data, SQL Server exposes a vast array of metadata including structural metadata, which describes every object, and descriptive metadata, which describes the data itself. Metadata is exposed through a series of + Catalog views + Information schema views + Dynamic management views and functions + System functions + System stored procedures In this chapter, we will discuss how metadata can be used to perform actions at the instance level, such as expose registry values, examine how metadata can assist in capacity planning, and discuss how metadata can be used for troubleshooting and performance tuning. Finally, we will see how metadata can be used to drive automated maintenance. Tip Metadata is a high topic worthy of a book in its own right. | therefore encourage you to play with other metadata objects, which may not be covered in this chapter. Introducing Metadata Objects Catalog views reside in the sys schema. There are many catalog views, some of the most useful of which, such as sys.master_files, are explored in this chapter. Listing 17-1 shows an example of how to use a catalog view to produce a list of databases that are in FULL recovery model. 623 © Pewer A. Carter 2018 P.A. Carter, Pro SQL Server 2019 Administration, https: /doi.org/10.1007/978-1-4842-5089-1_17CHAPTER 17 SQL SERVER METADATA Listing 17-1. Using Catalog Views SELECT name FROM sys.databases WHERE recovery model_desc = 'FULL' ; Information schema views reside in the INFORMATION_SCHEMA schema. They return less detail than catalog views but are based on the ISO standards. This means that you can port your queries between RDBMS (Relational Database Management Systems). Listing 17-2 shows an example of using information schema views to produce a list of principals that have been granted SELECT access to the Chapter10. dbo. SensitiveData table. Listing 17-2. Using Information Schema Views USE Chapterzo co SELECT GRANTEE, PRIVILEGE_TYPE FROM INFORMATION SCHEMA. TABLE_PRIVILEGES WHERE TABLE_SCHEMA = ‘dbo’ AND TABLE_NAME = 'SensitiveData’ AND PRIVILEGE TYPE = ‘SELECT’ ; Many dynamic management views and functions are available in SQL Server. Collectively, they are known as DMVs and they provide information about the current state of the instance, which you can use for troubleshooting and tuning performance. The following categories of DMV are exposed in SQL Server 2019: + AlwaysOn Availability Groups + Change data capture + Change tracking + Common language runtime (CLR) + Database mirroring + Databases + Execution 624CHAPTER 17 SQL SERVER METADATA + Extended events + FILESTREAM and FileTable + Full-text search and semantic search + Geo-Replication + Indexes + Vo + Memory-optimized tables + Objects + Query notifications + Replication + Resource Governor * Security + Server + Service broker + Spatial + SQL Data Warehouse and POW * SQLServer operating system + Stretch Databases + Transactions ‘We demonstrate and discuss how to use DMVs many times throughout this chapter. DMVs always begin with a dm_prefix, followed by two to four characters that describe the category of the object—for example, os_for operating system, db_for database, and exec_for execution. This is followed by the name of the object. In Listing 17-3, you can see two things: an example of how to use a dynamic management view to find allist of logins that are currently connected to the Chapter16 database and a dynamic management function you can use to produce details of the pages that store the data relating to the Chapter16 .dbo. Customers table 625CHAPTER 17 SQL SERVER METADATA Listing 17-3. Using Dynamic Management Views and Functions USE Chapter16 -This database will exist if you followed the examples in Chapteri6 of this book co --Find logins connected to the Chapter16 database SELECT login_name FROM sys.dm_exec_sessions WHERE database _id = DB_ID(‘Chapter16") ; --Return details of the data pages storing the Chapter16.dbo.Customers table SELECT * FROM sys.dm_db_database_page_allocations(DB_ID('Chapter16"), OBJECT_1D(‘ dbo. Customers"), NULL, NULL, “DETAILED') ; SQL Server also offers many metadata-related system functions, such as DB_ID() and OBJECT_ID(), which we used in Listing 17-3. Another example of a metadata-related system function is DATALENGTH, which we use in Listing 17-4 to return the length of each value in the LastName column of the Chapter16..dbo. Customers table. Listing 17-4. Using System Functions USE Chapter16 co SELECT DATALENGTH(LastName) FROM dbo.Customers ; Server-Level and Instance-Level Metadata Many forms of metadata are available for the server and instance. Server-level metadata can be very useful for DBAs who need to find configuration information or troubleshoot an issue when they do not have access to the underlying operating system. For example, the dn_server category of DMVs offers views that allow you to check the status of server 626CHAPTER 17 SQL SERVER METADATA audits, view SQL Server's Registry keys, find the location of memory dump files, and find details of the instance's services. In the following sections, we discuss how to view the Registry keys associated with the instance, expose details of SQL Server's services, and view the contents of the buffer cache. Exposing Registry Values The sys.dn_server_registry DMV exposes key registry entries pertaining to the instance. The view returns three columns, which are detailed in Table 17-1 Table 17-1. sys.dm_server_registry Columns Column Description Registry key The name of the Registry key Value_name The name of the key’s value Value_data The data contained within the value Avery useful piece of information that you can find in the sys.dn_server_registry DMVis the port number on which SQL Server is currently listening. The query in Listing 17-5 uses the sys. dn_server_registry DMV to return the port on which the instance is listening, assuming the instance is configured to listen on all IP addresses. Listing 17-5. Finding the Port Number SELECT * FROM ( SELECT CASE WHEN value_name = ‘tcport' AND value_data <> ‘' THEN value_data WHEN value_name = 'tcpport' AND value_data = "' THEN ( SELECT value_data FROM sys.dm_server_registry WHERE registry key LIKE ‘%ipall' AND value_name = 'tepdynamicports’ ) 627CHAPTER 17 SQL SERVER METADATA END PortNumber FROM sys.dm_server_registry WHERE registry key LIKE '%IPALI' ) a WHERE a.PortNumber IS NOT NULL ; Another useful feature of this DMV is its ability to return the startup parameters of the SQL Server service. This is particularly useful if you want to find out if switches such as -E have been configured for the instance. The -E switch increases the number of extents that are allocated to each file in the round-robin algorithm. The query in Listing 17-6 displays the startup parameters configured for the instance. Listing 17-6. Finding Startup Parameters SELECT + FROM sys.dm_server_registry WHERE value_name LIKE "SQLArg®’ ; Exposing Service Details Another useful DMV within the dn_server category is sys.dn_server_services, which exposes details of the services the instance is using. Table 17-2 describes the columns returned. Table 17-2. sys.dm_server_services Columns Column Description Servicename The name of the service. Startup_type An integer representing the startup type of the service, Startup_desc A textual description of the startup type of the service Status An integer representing the current status of the service. Status_desc A textual description of the current service state Process_id The process ID of the service. Last_startup_time The date and time that the service last started, Service_account The account used to run the service. (continued) 628CHAPTER 17 SQL SERVER METADATA Table 17-2. (continued) Column Description Filename The file name of the service, including the full file path Is_clustered 1 indicates that the service is clustered; 0 indicates that it is stand-alone. Clusternodename Ifthe service is clustered, this column indicates the name of the node on Which the service is running, The query in Listing 17-7 returns the name of each service, its startup type, its current status, and the name of the service account that runs the service. Listing 17-7. Exposing Service Details SELECT servicename »startup_type_desc ,status_desc ,service_account FROM sys.dm_server_services ; Analyzing Buffer Cache Usage The dn_os category of DMV exposes 41 objects that contain information about the current status of SQLOS, although only 31 of these are documented. A particularly useful DMV in the dm_os category, which exposes the contents of the buffer cache, is sys.dn_os_buffer_descriptors. When queried, this object returns the columns detailed in Table 17-3. Table 17-3. sys.dm_os_buffer_descriptors Columns Column Description Database_id The ID of the database that the page is from File_id The ID of the file that the page is from Page_id The ID of the page Page_level The index level of the page (continued) 629
You might also like
Oracle DBA Queries
PDF
100% (1)
Oracle DBA Queries
27 pages
Database Administration (SQL Server)
PDF
100% (2)
Database Administration (SQL Server)
43 pages
Data Dictionary
PDF
No ratings yet
Data Dictionary
4 pages
DBA Cheat Sheet
PDF
No ratings yet
DBA Cheat Sheet
13 pages
Oracle Data Dictionary Tables
PDF
No ratings yet
Oracle Data Dictionary Tables
28 pages
Data Dictionary and Performance Views for DBA 1746874758
PDF
No ratings yet
Data Dictionary and Performance Views for DBA 1746874758
4 pages
Dynamic Management Views
PDF
No ratings yet
Dynamic Management Views
2 pages
Dynamic Management Views
PDF
No ratings yet
Dynamic Management Views
11 pages
Querying Metadata, XML, and Full-Text Indexes
PDF
No ratings yet
Querying Metadata, XML, and Full-Text Indexes
41 pages
08-System Databases in SQL Server 2005 PDF
PDF
No ratings yet
08-System Databases in SQL Server 2005 PDF
4 pages
SQL Server 2000 System Tables and Their Equivalent DMV in SQL Server 2005 MSSQLFUN
PDF
No ratings yet
SQL Server 2000 System Tables and Their Equivalent DMV in SQL Server 2005 MSSQLFUN
3 pages
08 - Retrieving SQL Metadata and Improving SQL Performance
PDF
No ratings yet
08 - Retrieving SQL Metadata and Improving SQL Performance
35 pages
Performance Diagnosis Using DMV's & DMF's in SQL 2005 & 2008
PDF
100% (1)
Performance Diagnosis Using DMV's & DMF's in SQL 2005 & 2008
37 pages
SQL Server Documentation
PDF
No ratings yet
SQL Server Documentation
477 pages
SQL Server Basics
PDF
No ratings yet
SQL Server Basics
50 pages
The History of SQL Server and Relational Databases
PDF
No ratings yet
The History of SQL Server and Relational Databases
5 pages
4 8 SQL Server Basics Material
PDF
No ratings yet
4 8 SQL Server Basics Material
6 pages
Cat Tables
PDF
No ratings yet
Cat Tables
12 pages
DMVS and DBCCS
PDF
No ratings yet
DMVS and DBCCS
18 pages
SQL Server
PDF
No ratings yet
SQL Server
20 pages
Csc Advanced Db Features1
PDF
No ratings yet
Csc Advanced Db Features1
49 pages
Home-Work 2 DATABASE Administration Submitted To: MR Sarbhjeet KUMAR
PDF
No ratings yet
Home-Work 2 DATABASE Administration Submitted To: MR Sarbhjeet KUMAR
21 pages
8 Most Useful Dynamic Management Views and Functions I Often Use
PDF
No ratings yet
8 Most Useful Dynamic Management Views and Functions I Often Use
18 pages
CAP414: Database Administration: Homework 2
PDF
No ratings yet
CAP414: Database Administration: Homework 2
22 pages
DBCC DMV Commands
PDF
No ratings yet
DBCC DMV Commands
6 pages
Oracle Metadata: Data Dictionary vs. Dynamic Performance Views
PDF
No ratings yet
Oracle Metadata: Data Dictionary vs. Dynamic Performance Views
1 page
Total Database Information at Your Fingertips Part I
PDF
No ratings yet
Total Database Information at Your Fingertips Part I
13 pages
Look It Up! - Oracle Data Dictionary
PDF
No ratings yet
Look It Up! - Oracle Data Dictionary
5 pages
CSC Advanced DB Features1
PDF
No ratings yet
CSC Advanced DB Features1
49 pages
Adl SQL Cheatsheet
PDF
100% (1)
Adl SQL Cheatsheet
3 pages
Monitoring and Tuning The Database
PDF
No ratings yet
Monitoring and Tuning The Database
16 pages
DW - Chap 6
PDF
No ratings yet
DW - Chap 6
2 pages
Oracle DBA Pocket Guide 8i
PDF
No ratings yet
Oracle DBA Pocket Guide 8i
2 pages
Advanced Database Chapter One: Introduction To Oracle RDBMS
PDF
No ratings yet
Advanced Database Chapter One: Introduction To Oracle RDBMS
17 pages
DB 2 Are 951
PDF
No ratings yet
DB 2 Are 951
841 pages
SQL Server Materials
PDF
No ratings yet
SQL Server Materials
102 pages
Discovery Wizard SQL Storage Schema
PDF
No ratings yet
Discovery Wizard SQL Storage Schema
8 pages
12.data Dictionary
PDF
No ratings yet
12.data Dictionary
16 pages
SQL Server Monitoring and Performance
PDF
No ratings yet
SQL Server Monitoring and Performance
148 pages
Microsoft SQL Server Administration For SAP
PDF
No ratings yet
Microsoft SQL Server Administration For SAP
35 pages
Oracle Data Dictionary: - Tables, - Columns, - Users, - Data Files Etc. Metadata
PDF
No ratings yet
Oracle Data Dictionary: - Tables, - Columns, - Users, - Data Files Etc. Metadata
9 pages
week 3
PDF
No ratings yet
week 3
28 pages
sql-server-storage-internals-101
PDF
No ratings yet
sql-server-storage-internals-101
20 pages
DBMS all units
PDF
No ratings yet
DBMS all units
52 pages
Views We Query in Database
PDF
No ratings yet
Views We Query in Database
3 pages
SQL Server Handy Notes VishwanathReddy
PDF
No ratings yet
SQL Server Handy Notes VishwanathReddy
28 pages
Information Schema
PDF
No ratings yet
Information Schema
8 pages
Tuning Area View Description
PDF
No ratings yet
Tuning Area View Description
6 pages
SQL
PDF
No ratings yet
SQL
11 pages
ORACLE9 I DBAPOCKETGUIDE
PDF
No ratings yet
ORACLE9 I DBAPOCKETGUIDE
2 pages
Dbms Notes
PDF
No ratings yet
Dbms Notes
28 pages
Oracle DB Data Dictionary and Views
PDF
No ratings yet
Oracle DB Data Dictionary and Views
6 pages
Oracle SQL Metadata or System Tables
PDF
No ratings yet
Oracle SQL Metadata or System Tables
2 pages