Professional Documents
Culture Documents
MOnitoring and Admin Database - 1
MOnitoring and Admin Database - 1
MONITORING AND
ADMINISTERING
DATABASE
03/18/2021 BY: SAMUEL S 2
LO -1:
START UP A DATABASE
03/18/2021 BY: SAMUEL S 3
Cont..
• A database is an organized collection of related information.
Cont..
• When you start up a database, you create an instance of that
database and you determine the state of the database.
Cont..
Here are few ways we penned down here which are used
for standalone instance of SQL Server.
• These are our Top 5 most commonly used methods:
1. Object Explorer in SSMS (SQL server Management Studio)
2. Windows Services.
3. Net Start Command.
4. Using executable Sqlservr.exe
5. SSCM - SQL Server Configuration Manager.
• In case of failover cluster instances we should be failover
cluster manager to stop and start service by taking resource
offline and online respectively.
03/18/2021 BY: SAMUEL S 7
1.
• The object explorer in SSMS can also start both local and
remote servers as long as the remote server is connected and we
have remote-service rights.
• Right Click and select the required action – Start, Pause,
Resume, Stop. If we are not already connected, we can’t start a
stopped instance.
03/18/2021 BY: SAMUEL S 8
2. Windows Services
• This is one of the most common way used by all DBAs. Top
open services applet,
we can either go to start > Run and
type services.msc or
by using the Windows Start, Programs,
Administrative Tools, Services menu.
Then, double-click (or right click)
the MSSQLServer service, and
right-click the required action.
• If we want to start a SQL Server named instance, look for the service called
SQL Server (Instance Name).
• Let’s say our machine has named instance called SQL2014 then we would see
SQL Server (SQL2014), as shown below:
03/18/2021 BY: SAMUEL S 9
Cont..
03/18/2021 BY: SAMUEL S 10
• Methods so far are the one to use User Interface, but we can
also use the Net Start command.
• Type net start mssqlserver at the command prompt.
Cont..
03/18/2021 BY: SAMUEL S 13
•This is the best way to control the services because we are using the tool which
•Once we click on SQL Server Services on left, we can see all services on right
pane.
•Then we can right-click SQL Server (MSSQLServer), and then choose required
action.
•A green icon next to the server name and indicates that the service is running.
03/18/2021 BY: SAMUEL S 14
Cont..
03/18/2021 BY: SAMUEL S 15
03/18/2021 BY: SAMUEL S 16
General Knowledge of
Structured Query Language (SQL)
• Structured Query Language (SQL) is a programming
language that is typically used in relational database or data
stream management systems.
Cont..
• SQL, structured query language, is the standard language for
creating and maintaining relational databases.
• Key metrics such as CPU and memory usage can give you important
insights into your database’s performance.
• Monitoring system and SQL Server databases shows the metrics that
indicate server performance.
The activities are queried only when the specific pane is expanded “Activity
Monitor runs queries on the monitored instance to obtain information for the
Activity Monitor display panes.
03/18/2021 BY: SAMUEL S 21
Cont..
The Overview pane
• The Overview pane contains the graphs for the most
important SQL Server instance information.
• The context menu contains the Refresh interval option that
can be set to a predefined value from 1 second to 1 hour
03/18/2021 BY: SAMUEL S 22
Cont…
• Session ID – is a unique value assigned by Database Engine to
every user connection. This is the spid value returned by the
sp_who procedure
• User Process – 1 for user processes, 0 for system processes.
The default filter is set to 1, so only user processes are shown
• Login – the SQL Server login that runs the session
• Database – the database name on which the process is running
• Task State – the task state, blank for tasks in the runnable and
sleeping state.
• The value can also be obtained using the sys.dm_os_tasks view,
as the task_state column. The states returned can be:
• PENDING: Waiting for a worker thread.
03/18/2021 BY: SAMUEL S 26
Cont..
• RUNNABLE: Runnable, but waiting to receive a quantum.
• DONE: Completed.
• Command – the current command type. The value can also be obtained using the
sys.dm_exec_requests view, as the command column
• Wait Time (ms) – how long in milliseconds the task is waiting for a resource. The value can
also be obtained using the sys.dm_os_waiting_tasks view, as the wait_duration_ms column.
03/18/2021 BY: SAMUEL S 27
CONT..
• Wait Type – the last/current wait type. The value can also be obtained
using the sys.dm_os_waiting_tasks view, as the wait_type column. The
waits can be resource, queue and external waits
• Wait Resource – the resource the connection is waiting for. The value
can also be obtained using the sys.dm_os_waiting_tasks view, as the
resource_description column
• Blocked By – the ID of the session that is blocking the task. The value
can also be obtained using the sys.dm_os_waiting_tasks view, as the
blocking_session_id column
• Head Blocker – the session that causes the first blocking condition in
a blocking chain
03/18/2021 BY: SAMUEL S 28
CONT..
• Memory Use (KB) – the memory used by the task. The value
can also be obtained using the sys.dm_exec_sessions view, as the
memory_usage column.
• Recent Wait Time (ms/sec) – the average time all waiting tasks are waiting for
one or more resources
• Average Waiter Count – is calculated for a typical point in time in the last sample
interval and represents the number of tasks waiting for one or more resources
• Cumulative Wait Time (sec) – the total time waiting tasks have waited for one or
more resources since the last SQL Server restart, or DBCC SQLPERF last execution
• The Data File I/O pane - Shows information about the database files on the SQL
Server instance. For each database, all database files are listed – MDF, LDF and
NDF, their paths, and names
03/18/2021 BY: SAMUEL S 31
MB/sec Read – shows recent read activity for the database file
MB/sec Written – shows recent write activity for the database file
Response Time (ms) – average response time for recent read-and-write
activity
03/18/2021 BY: SAMUEL S 32
Cont..
• The Recent Expensive Queries pane - Expensive queries are
the queries that use much resources – memory, disk, network.
• The pane shows expensive queries executed in the last 30
seconds.
CONT..
• Query – the SQL query statement monitored
• Executions /min – the number of executions per minute, since
the last recompilation. The value can also be obtained using the
sys.dm_exec_query_stats view, as the execution_count column
• CPU (ms/sec) – the CPU rate used, since the last recompilation.
The value can also be obtained using the
sys.dm_exec_query_stats view, as the total_worker_time column
• Physical Reads/sec, Logical Writes/sec, and Logical
Reads/sec – the rate of physical reads/logical writes/logical
reads per second. The value can also be obtained using the
sys.dm_exec_query_stats view, as the
total_physical_reads/total_logical_writes/total_logical_reads
columns.
03/18/2021 BY: SAMUEL S 35
CONT..
Average Duration (ms) – average time that the query runs.
Calculated based on the total_elapsed_time and execution_count
columns in the sys.dm_exec_query_stats view
Plan Count – the number of duplicate query plans. A large number
requires investigation and potential explicit query parameterization
Requirements to use Activity Monitor
• The permission necessary to view Activity Monitor is VIEW
SERVER STATE
• To view the Data File I/O pane, besides VIEW SERVER STATE, the
login must be granted CREATE DATABASE, ALTER ANY DATABASE,
or VIEW ANY DEFINITION permissions
• To kill a process, it’s necessary to be a member of the sysadmin
role.
03/18/2021 BY: SAMUEL S 36
On the next SQL Server Management Studio start up, Object Explorer will be shown on the
left and Activity Monitor on the right
Activity Monitor is a SQL Server Management Studio feature that tracks some
It shows the metrics in real time, without the out-of-the-box solution to save
Due to its limited set of features and monitored metrics, it’s not recommended
File and Log File) can be defined by us, with the Autogrowth
and MAXSIZE parameter.
Cont..d
03/18/2021 BY: SAMUEL S 40
Cont...d
At the beginning, size of the database can be set up using the
How fast a database file can reach its maximum space can be
Cont..d
Cont..
03/18/2021 BY: SAMUEL S 43
Cont.
SQL Server can not commit any transaction to disk storage in the situation where disk
is full so it’s always good to define the MAXSIZE parameter beforehand to avoid
such situation.
UNLIMITED would fill up the disk storage but before that, it makes several spaces
Even this has a very hazardous impact on the operating system as well if it doesn’t
We also need to take into consideration the size of multiple databases before defining
Get a list of databases file with size and free space for a database in SQL Server:
Cont..
03/18/2021 BY: SAMUEL S 47
Cont..
Now, free space for the file in the above query result set will be
362 = 238).
03/18/2021 BY: SAMUEL S 48
Cont..
•There are cases where in the Deep Security Manager database is occupying
Cont..
03/18/2021 BY: SAMUEL S 50
CONt..
CONT..
We can further modify above query to also include database name in the query as:-
LO 3: MANAGE DATABASE
ACCESS
03/18/2021 BY: SAMUEL S 55
Cont..
Some of the common performance issues:
High I/O during peak or maintenance times
Memory pressure slowing down queries
CPU pressure slowing down database server
Concurrency issue from locking/blocking
03/18/2021 BY: SAMUEL S 57
Cont..
• High input/output represents disk subsystems doing too much
work.
• Particularly during peak or maintenance times.
• Input/output bottlenecks can be the hardest to troubleshoot
because they are usually manifested from memory or CPU issues.
• Furthermore, they can be also manifested from poorly written
queries and not having a good indexing strategy.
• Bear in mind that proper indexing and query tuning can have a
significant impact on all areas of SQL Server performance.
• All these factors are a good reason why it’s a good idea to look at
I/O last, even though it first in the list, just to rule out any other
things that can cause I/O problems.
03/18/2021 BY: SAMUEL S 58
Cont..
• All these factors are a good reason why it’s a good idea to look
at I/O last, even though it first in the list, just to rule out any
other things that can cause I/O problems.
• Memory pressure can simply become an issue when the system
doesn’t have enough RAM of SQL Server cannot allocate
enough memory or more commonly poor database and query
design.
• Lack of memory can also be caused by high I/O. Yeah right, it
goes both ways.
• This is, again, why it can get tricky when troubleshooting SQL
Server performance.
03/18/2021 BY: SAMUEL S 59
Cont…
This command helps to get the Dynamic Management Views
for performance monitoring.
Cont..
03/18/2021 BY: SAMUEL S 61
Cont..
• There is also a public role.
• The public role is a special database role to which each database
user belongs.
• The public role contains default access permissions for any user
who can access the database.
• This database role cannot be dropped, but it is strongly
recommended not to grant superfluous permissions to the public
role, because each databases user has the public role's
permissions.
03/18/2021 BY: SAMUEL S 63
Cont..
• SQL Server 2000 provides the GRANT, DENY, and REVOKE
statements to give or take away permissions from a user or role.
Permissions Types
• To perform any activity in a database, user must have the
appropriate permissions. These permissions fall into three
categories, which we call permissions types:
• Permissions to work with data and execute procedures (object
permissions).
• Permissions to create a database or an item in the database
(statement permissions).
• Permissions to utilize permissions granted to predefined roles
(implied permissions).
03/18/2021 BY: SAMUEL S 64
1. Object Permissions
The object permissions are the permissions to act on the database objects (such as tables,
stored procedures and views).
2. Statement Permissions
o These are the permissions to create a database or an object in the database. These
permissions are applied to the statement itself, rather than to a specific object defined
in the database.
called a default.
03/18/2021 BY: SAMUEL S 66
3. Managing Permissions
• You can use the GRANT, DENY, and REVOKE statements to
give or take away permission from a user or role.
• The GRANT statement is used to give permissions to a user or
role.
• By using the GRANT statement, it is possible to assign
permissions to both statements as well as objects.
• You can use the GRANT statement with the WITH GRANT
OPTION clause to permit the user or role receiving the
permission to further grant/revoke access to other accounts.
03/18/2021 BY: SAMUEL S 67
Cont..
• This example grants the SELECT permission on the authors
table to Alex
Cont..
• The REVOKE statement is used to remove a previously granted
or denied permission from a user in the current database.
• You can use the REVOKE statement to remove both statements
and objects permissions.
REVOKE SELECT ON authors TO Alex
03/18/2021 BY: SAMUEL S 69
Cont..
In the next screen, Enter
1. Login Name
3. Enter Password
4. Click Ok
03/18/2021 BY: SAMUEL S 70
The End!