SQL DBA PDF (20 files merged)
SQL DBA PDF (20 files merged)
Hai iam satish , i have total 3 years of experiance in sql dba and
currently working with infosys and we have different servers which
were deployed into staging,testing,developement,DR,pre production.
As a daily bases,i have logon to the system and i will check mails,and
tickets assign for my team we will work on those tickets.
Logshipping
Some times high cpu and high memory causes low perfomance.
so
High memory
Even though performance is slow i will run DTA and profiler performer
and i have basic idea on execution plan.
Software requirements
.netframe work
powershell 2.0
Hardawrae requirements:
preinsatllation steps:
we need to ask about componets what kind of componets they need we will install those
components
2)reporting service
3)anlysis service
4)integration service
we need to ask about authentication whether they need windows or mixed mode(sql+windows)
we will ask about collation setting we will install required one
========================================================================
Interview questions:
sql_latin1_general_cp1_CI_AS
it is used to connect the the nameinsatnce(sql server name) in the sql serverlevel.
configartion manger we can enable at 'sql services' right click and 'startup parameters' .we can add
'-t1222' in 'specify a startup parameters'.
we will get setup files in one test server we have access to the test server(repository)
what are the issue do you faced while insatllation?
1.permission issue:
i do not have proper accessing permistion on drive so we need to inform to windows team they will
provide the access on that drive.
2.Restart error:
3.if we are not uninstallation properly we will get new installtion issue so we need to unistall properly
any sql unisatlltions request came
we need need to inform to windows team they can re-configure the .netframe work
Service packs
--->> what is the importance of service pack OR what is the use of sp(service
pack)???
1.performance
2.security
2012------->sp1,sp2,sp3------ latest(sp3)
2008R2----->sp1,sp2,sp3----- latest(sp3)
change order :
1.implementation plan
2.verification plan
3.backout plan
---->Every change order has perticular starting time and ending time(windows
time).
(or)
what are the pre & post installation steps for sp??
Ans: pre-installation:-
select @@vertion
sp_configure
select @@vertion
issues for service packs:
Q)what are the challenges do you face while apply the service pack?
(or)
2.permissin issue:
3.space issue:
1.Master
2.Model
3.Msdb
4.Tempdb
5.Resouce Database
7.Distributor Database
MASTER:
Master database is a critical database it contains all logins
information,linked server information,end point information and
other system database,user files information.
MODEL:
Model database is Template for all user databases.
And all user databases inherit all the properties from model database.
MSDB:
It can stores are backup information and restoration information and
logshipping related jobs information.
TEMPDB:
Tempdb is used for temporary operations.All index related operations
can be happening on tempdb.
RESOURCE:
Resource is a hidden database whenever any service packs
upgradations are happening that can be updated in resource
database.
Note:
it can allow into the sql server so we can restore with available
backup.
If you dont have a backup for master what will you do??
sp_configure, 'Agentxp','0'
reconfigure
sp_configure,'Agentxp','1'
'atach-deatach'.
RECOVERY MODEL
Recovery model can specify how much data we can recover whenever something
happens to the database.
(OR)
As per WAL(write ahead logging) concept every transaction can logged into the
logfile and bufferpool.
Data File
---->>At regular intervals of time check point will raise and data flush from
bufferpool to datafile.
whenever any bulk operations are happening they can keep bulk recovery model.
----->>Except the bulk operations bulk logged recovery model behaves like fully
recovery model.
Minimally logged: when compared to full recovery model bulk logged recovery
---->>Every transaction logged into the logfile and at the same time buffer pool
at regular intervals of time check point will be raise it will be
truncate(delete) the data(recors).
----->>By using simple recovery model we can saves the space in disk.
Backups
Backups can maintain the same copy of the database.
1.full backup
2.differential backup
7.mirror backup
8.partial backup
Full backup:
Differential backup:
whatever the modifications after the full backup those all transactions come
under differential backup.
it will trigger the log file backup and it can gernerate the LSN(log sequence
number) .if miss the LSN ,point intime is missed.
without effection the LSN ,we can take copy only full backup
if database corrupted we can apply the tail log backup to get the active
transactions in the logfile.
we can use split backup whenever any space constaints and using split backup we
can make backup is much as fast.
Mirror backup:
mirror backup means it can maintain the same copy of the database
By using file and file group backup we can take file level or file group bakups.
F&FG backups are helpful to devise backup strategies for Very Large DBs.
Individual Files and Filegroups are backed up using this method, also tables can be
placed in FG and can be backed up individually.
Command:
Command:
1) NOINIT/INIT:
2) NOFORMAT/FORMAT:
FORMAT will create a new media set and overwrites all the contents in the file.
3) NOSKIP/SKIP:
NOSKIP instructs the BACKUP statement to check the expiration date of all backup
sets on the media before allowing them to be overwritten. This is the default
behavior.
4) BLOCKSIZE
Specifies the physical block size, in bytes. The supported sizes are 512, 1024,
2048, 4096, 8192, 16384, 32768, and 65536 (64 KB) bytes. The default is 65536
for tape devices and 512 otherwise.
STATS [ =percentage ]
1.with_recovery mode
3.standby mode
With_recovery mode:
In this mode databases are in online state and users can able to connect the
database.
Standby mode:
It is read-only mode and we can just report the database.
The background process of backup is copying the data files into the backup file
by using check point operation and there are 2 phases
Roll forward: All the committed transactions comes under the roll forward or
redo.
Roll backward: All the uncommitted transactions comes under the roll backward
or undo.
How can we see the how much percentage of process completed and estimated
time for the backups&restorations??
1.percent_time:
2.estimated_completion_time:
The background process of restoration is first files will be creating into drives
and after data will be copy and finally there will be 2 other phases also.
sp_helpdb databasename
by using "backup media family" table we can able to see the backupfiles path in
our system.
How can we check when was the last backup happend for the databases???
copy the backup file from server1 to server2 and restoring that file into server2 at
that time we can modify the .mdf and .ldf files
Tell me have you faced any issues while performing backups and restores??
Backups issues:
1.whenever any space issue, backup got fail so we need to remove old backup
files or we will raise INCIDENT to windows team and they will provide the space.
1.user is inuse:
we need to inform the application team about the using current session
according to their approvers we can kill the session or user and they can restore
2.space issue:
There is no sufficient space in the drive ,restoration got fail and they can inform
to the windows team.
3.permission issue:
we can inform to the windows team and they can provide the accessing
permission to us.
some times while performing the restore operations often raise one error like
"restore database terminated abonarmally".at that time we can performing the
following commands.
go
restoring commands______________
go
what is LSN???
1.windows authentication
windows authentication:
It can be created at windows level and it can be provide more security when
compared to sql server authentication.In windows authentication we wont
provide the user name and password.
For third party vendors(DB2 tool,oracle,my sql) we can provide sql authentication.
In sql server there are 3 types of security levels.Those are in the following way.
1.Server-level security
2.Database-level security
1.DB creator
2.Bulk admin
3.Disk admin
4.process admin
5.Security admin
6.Server admin
7.Setup admin
8.Public
9.Sys admin
DB creator:
Login whoever having the DB creator role,he can able to do create the database.
Bulk admin:
Login whoever having the bulk admin login ,he can able to do bulk
operations.those are
insert into
Disk admin:
Login whoever having the Disk admin role,he can able to manage the disk level
files.
Process admin:
Login whoever having the process admin role,he can able to see the process
information and kill the session.
Security admin:
Login whoever having the security admin role,he can able create the new
logins,and at the same time he can able to do reset or change the passwords.
Server admin:
Login whoever having the server admin role,he can able to change the server level
settings and he can able to restart or shutdown the sql server.
i.e,memory settings.
Setup admin:
Login whoever having the setup admin role,he can able to configure the linked
server and he can remove the linked server.
Public:
Login whoever having the public role,he can able to see the sql server.
Sys admin:
Login whoever having the Sys admin role,he can able to do anything in the sql
server.
Note:we can provide temporary sys admin access also if anybody wants and we
can revoke it after 15 days.
what are the DB level roles in sql server???
1.DB_reader
2.DB_writer
3.DB_Denyreader
4.DB_Denywriter
5.DB_owner
6.DB_Backup operator
7.DB_Acess admin
8.DB_Security admin
9.DB_public
10.DDL admin
DB_Reader:
user whoever having DB_reader acess,he can able to read the data for perticular
database.
DB_writer:
user whoever having DB_writer acess,he can able to write the data for
perticular database.
DB_Deny reader:
user whoever having deny reader,he cant able to read the data.
DB_Denywriter:
user whoever having DB_Deny writer access he cant able to write the data.
DB_owner:
user whoever having the DB_owner access ,he can able to do anything in the
database.
Backup operators:
user whoever having the Backup_operator ,he can able to take the backup of
perticular database.
DB_Acess admin:
user whoever having the 'Access admin' access,he can able to add or remove
access to the database.
DDL admin:
user whoever having the DDL access,he can access the DDL
operations(grant,revoke)
Security admin:
user whoever having the security admin access,he can able to create the new
user and remove the user for the perticular database.
Public:
user whoever having the DB_public access,he can able to see the database.
JOBS
JOB is the automatic process it can run according to the schedule
time.we can configure backup jobs
1.fully
2.differential
3.T-log
4.Rebuild
5.Reorganize
1.Full backup
2.differential backup
3.T-log backup
4.Rebuild index
5.Reorganize index
6.update statistic
9.shrink database
10.cleanup history
pages
Extends
Files
Filegroups
Database
page header(96bytes)
Row data
RowOffSet
Page header contains actual data and rowoffset and size of the page header is 96 bytes.
Actual data(8096 bytes) is the actual information of the user.
Rowoffset can point to the actual data.
Types of pages:
1) Data page
2) Index page
3) Page free space
4) GAM(global allocation map)
5) SGAM(shared global allocation map)
6) IAM(index allocation map)
7) DCM(differential change map)
8) BCM(bulk change map)
9) Text page
Extends:
Extends is a collection of pages and size of the extends is 64 kb.
I. uniform extends
II. mixed extends
8 continuous same type of pages is called uniform extends
8 continuous different type of pages is called mixed extends.
Files:
Log file
Data file or primary file or master file
secondary file
Data file:data files are perminent storage .we can read any
data from the data files directly .we cant do any modification
into the data file.
Extension for datafile is .mdf
File groups:
Disastor recovery:
The disastor recovery it can maintain the same copy of the data
maintain at different data servers.
Log shipping:
Log shipping is one of the database level high availability concept.
Log backups
alert job
monitor server
log bakups are transfer from primary server to secondary server.
i. primary server
ii. secondary server
iii. monitor server
secondary server: it can maintain the same copy of the primary server
we should provide same name for the severs like primary server and
secondary server.
In primary server we should use backup share only,and the backup
share requires read/write permission .
In secondary server we should use copy share only,and the copy share
requires only read permission.
To initalize the log shipping for primary and secondary server by using
the backup and restore technique,and then we can configure the log
shipping .
1.backup copy
2.copy job
3.restore job
4.alert job
The tuf file created into the secondary server while restoring mode is stand-by.
Logshipping scenarios
FAILOVER:
The 'failover' means the primary database is corrupted , we need to bring the
secondary server is in online.
3.we need to compare the backup share and copy share if any backup files we
need copy to the copy share then do it.And run the copy job and restore job.
NOTE:
we can findout the when was the last log backups are happend in the log-
shipping by using on the msdb
we can findout when was the last copy backup and restore backups are
happend by using on msdb
4.And we need to restore the tail log backup with recovery in secondary server.
6.we need inform to application team ,they need to re-configure the log
shipping.
Switch over (or) DR test (or) DR drill (or) Roll swapping:
we need to do primary server as secondary server and secondary
server as primary server.
1.we need to disable the backup job ,copy job and restore job.
2.we need to compare backup share ,copy share if any backup files
copy to copy share.
ADD FILE:
How to add 'file' in log-shipping??
2.we need to add the file into the primary server database.
3.we need to take the log backup of the database for the primary
server.
Backup log dbname to disk='path'
4.we need to restore log backups by using 'with move ' option in the second
server.
space issue:
we dont have a sufficient space on a primary server or secondary
server we will remove the old backup files and to claim the space.
Add file:
once we have faced 'restore job failure issue' because one of the team
member added file without disable the jobs.
so we have reslove the issue before add the file we should disable all
the jobs and we have taken log backups in primary server and
restored in secondary server by using 'with move' option.
Network issue:
we have faced network issue in primary server ,then backup job
getting fail so we need to inform to network team and they will
resolve the issue from their side.
Access issue:
if we dont have sufficient accessing permissions on backup share and
copy share we will face backup,copy,restore jobs are getting fail.
TOO RECENTLY TO APPLY THE LOG BACKUP :
we have faced too recently to apply the log backup issue .
LOGIN ISSUE:
6.we should create same login for the database in secondary user by
using
7.we should maintain physical server and sql server name as same.
8.i have faced login issue in the secondary server whenever we are
using switchover primary to secondary ,in the secondary server user
not able to connect the application ,so i have trouble shooted the
issue .
WHAT IS MIRRORING???
log records transfer from principle server to mirror server this process
is called mirroring.
witness
principle server
mirror server
4.we should use same version and same addition of the both servers.
Synchronous:
Asynchronous:
mirror server----5023
witness server----5024
mirroring configuration:
ADD FILE:
I have faced add file issue one of my team member did added the file
manually without breaking the mirroring ,so he has faced issue.
LOGIN ISSUE:
we have faced login issue whenever they are doing DR DRILL they are
unable to connect the application once we have verified from our end
we can identify the issue,login was not created in mirror server,so we
have create the new login in mirror server with the same sid of
principle server.
END POINT:
what is 'unsetlog'???
it means how much data need to move from principle server to the
mirror server.
it means how much data need to write the data into the disk of the
mirror server.
ADD FILE:
Before adding the file(log file or secondary) we need to break
the mirroring and we can add the file into the principle server
database and we can take the log backup in principle server
and it can restore by using with move option in secondary
server
What is Listener:
1.windows team
2.network team
3.SAN team
high availability.
In active-active setup both the nodes having sql server setups.and sql
server services are running in the both nodes.
sql sql
services servies
NODE1(active) NODE2(active)
what is 'active-passive' setup??
In active-passive setup active node having sql server setup and sql
server services are running in the node1(active) node and
node2(passive) is waiting for the failover.
sql
failover
services
NODE1(active) NODE2(passive)
what is QUORUM??
it is used for odd number of nodes i.e,more than half of the nodes
must be up otherwise cluster wont be work .
Node&disk majority:
it is used for even number of the nodes i.e, more than half of the
nodes and disk must be in online otherwise cluster wont be work.
it is used for even number of the nodes i.e,half of the nodes and disk
must be in online otherwise cluster wont be work.
in this cluster can work without node,if disk fail cluster wont be work.
look alive is a basic check for every 5 seconds it will veriffy all the sql
services(sql main ,agent,disk,network services) are running or not.
Is alive:
ls alive is a complete check for every 1 minute and it will verify all the
sql server services(sql main ,agent,disk,network services) are running
or not.
if sql server services are not running ,services will be bring online into
the another node.
2-public
2-private
1-windows ip
msdtc[optional]
EX1: active-passive:
in this above situation we need 1-sql server public ip.
EX2: 2active-2passive:
in this above situation we need 2-sql server public ip's.
public ip:
it is used to connect the servers.The servers are either physical
or virtual.
private ip:
it is used to internal communication between nodes.
what is failover??
failover is the process of move the sql server services from one
node(node1) to another node(node2).
sql server
services
MOVE SERVICES
(AFTER FAILOVER)
NODE1 NODE2
what is failback??
fail back is the process of move the sql server services from node2 to
node1.
Roles
And then right click on 'services' and we can see 'move services' from
one node to another node.we can click where we want to move.
What is preffered owner or selected owner??
network name
network ip
3.once done with node1 ,we can go to the node2,and copy the same
setup file and we can just click on 'add node' and everything will be
replicated to node2.
How to apply service pack for clustering??
first i can apply service pack on passive node,once done with passive
node and reboot the server .i can go to the active node,i can failover
services from active node to passive node and again apply service
pack and reboot the server and again back from passive to active and
reboot the server.
pre-migration steps:
1.we need to take the backup which database we want to migrate.
sp_helprevlogin
we can change the build number from lower version to higher version
by using "compatability level" option.
DATABASE UPGRADATION
upgradation means we are moving all databases from lower versions to higher version(side by side)
(or)
1.we need to download the upgrade advisor and it will analyze whether all applications will be suitable
for higher version and it will analyze
components like
post-upgradation steps:
all the points are same in migration.
DATABASE REFRESH
issues:
1.we used to get orphan user issue ,so we can find orphan users by
using
sp_change_users_login report
2.user in use:
3.space issue:
LOCKS:
LOCKS can provided the consistecy.it can be hold the table or
object.There are different types of locking mechanisms in sql server.
2.update lock
4.intent lock
shared lock:
shared lock is used for all the 'read operations' such as 'select'
command that do not change or update the data.
update lock:
Exclusive lock:
sp_lock
(or)
Intent lock:
Example:
By using below command we can findout the script for the perticular
user according to the session id.
DBCC inputbuffer(sessionid)
DBCC inputbuffer(55)
BLOCKING (OR) BLOCKS:
user1 user2
resource or
table
SP_WHO2
DEADLOCKS:
one user is having a lock on one resource, and another user is having a
lock on another resource ,first user trying to put a lock on second
resource and second user trying to put a lock on first resource .this
situation is called dead lock .
user1 user2
Resource1 Resource2
By default dead lock information cant be trace into the ERROR LOG.
what is '-t1222'???
1222 is the trace flag to find the dead lock information into the xml
format and it can specify resource information and dead lock victim.
In sql server there are different ways to findout the deadlock .Those
are
2.session wise:
The script contain lot of joins and inner joins .iam not a part of
developement ,so i can remember few DMV's .Those are
sys.dm_tran_locks
sys.dm_execute_sql_text
sys.dm_db_connections
By using the following link ,it can detailed described about force the
deadlock.
https://ajitananthram.wordpress.com/2014/02/23/scripts-to-force-a-
deadlock-in-sql-server/
INDEXES:
An index is a disk structure associated with table or view that speads
retrival of the data in the form of 'B-TREE' structure.
cluster index:
cluster index sort and store the data rows in the table based on the
key value.actual data can be stored in leaf-level.
There is only one cluster index for table because the data rows(actual
data) themselves can be sorted in only one order.
Non-cluster index:
in the non cluster index ,leaf level pointers will be there and pointers
will located to actual data that may be again heap or cluster index
what is heap???
FRAGMENTATION:
whenever any DML operations like insert,update,delete we can see
fragmentation.
1.internal fragmentation
2.External fragmentation
Internal fragmentation:
The logical order of the page is not match with physical order of the
page is called internal fragmentation.
External fragmentation:
The logical order of extend is not match with physical order of the
extend is called external fragmentation.
How to identify fragmentation??
we have a DMV
sys.dm_db_physical_index_stats
If values are
MISSING INDEXES:
sys.dm_db_missing_index_details
UNUSED INDEXES:
we can find unused index by using
sys.dm_db_index_usage_stats
if 'user seek' and 'user-scan' are '0' ,so indexes are using.
if 'user seek' and 'user-scan' are other than '0' ,so indexes are unused.
UPDATE STATISTICS:
whenever any dml operations on the table 'stats' are not upto date,so
we need to update the stats by using
DBCC updatestats -----> all tables in the database
sys.dm_os_wait_stats
There are differrent types of wait types we can commanly see.Those
are
1. Async_network_io:
This can be occurs on network when the task is blocked behind the
network.
2. Async_io_completion:
3. Backup:
4.CX packet
4.Latch_Ex:
This is related to lock wait type.this wait type is we can see when
aquiring lock on table.
6.Resource_cemaphore:
HIGH CPU:
Whenever any cpu issue first we need to go to 'TASK MANAGER' and
we can verify for 'SQL.EXE'.
SP_WHO2
4.wheneve any rebuild ,and reorganize jobs are running cpu goes to
high once done it will comes to normal stage.
HIGH MEMORY:
Whenever any memory issue first we need to go to 'TASK MANAGER'
and we can verify for 'SQL.EXE'.
SP_WHO2
4.wheneve any rebuild ,and reorganize jobs are running memory goes
to high once done it will comes to normal stage.
DTA(DATABASE ENGINE TOOLING ADVISOR):
DTA is the one of the inbuild tool .it is identify the missing index and
stats.it will recommended us missing indexes if any indexes are miss,it
will recommend to create those indexes.
PROFILER:
PROFILER is also one of the inbuild tool,it is used to identify the
problem in the sql server.it is used to analyze the issue.
1.LOCKS
3.SP COMPLILATION
4.SP RECOMPILATION
5.DEADLOCK GRAPHS
PERFORMANCE MONITOR TOOL OR PERFMON:
This is also inbuild tool it is used to identify the issue related to sql
and os level . i.e,memory,cpu,network
1.processor time:
1.privilized time:
12) How we can take the split backup by using below cmd
Backup database dbname to disk='path' disk='path'
13) How we can check the size&logical name,physical path of
database by using below cmd
sp_helpdb databasename
14) How we can check the where backupfiles are taking in
server(defalult path of backupfiles)
select *from [dbo].[backup media family]
15) How we can check when was the last backup happend
select *from [dbo].[backupset]
16) How we can see the how much process completed
&estimated time for the process either backup or restore
select *from sys.dm_exec_request
17) How we can take the database from restoring mode to
online mode by using below command
restore database databasename with recovery
18) How we can restore the database with full backup
restore database dbname to disk='path'
19) How we can findout when was the last backup happend for
the log backup by using on msdb
select *from log_shipping_primary_databases
20) How we can findout when was the last backup happend for
the copy and restore job by using on msdb
select *from log_shipping_monitor_secondary
21) How to identify how many files in the backupfile
restore filelistonly from disk='path'
22) How we can verify backup file is valid(corrupted) or not
restore verifyonly from disk='path'
23) How we can findout LSN number by using below cmd
restore headeronly from disk='path'
24) How we can set the single user & multi user for the db
25) How we can set the database from offline and online state
40) If you want to create a new login id and password for this user, fix it by
doing:
sp_change_users_login 'Auto_Fix', 'user', 'login',
'password'
41) How to check the locks in the sql server
sp_who2
43) How to create the clusterindex for table in the sql server
create clusterindex indexname on table [column1,column2...]
44) How to create the nonclusterindex for table in the sql server
create non-clusterindex indexname on table
[column1,column2...]
45) How to create the nonclusterindex for table in the sql server
create compositeindex indexname on table
[column1,column2...]
45) How to identify the fragmentation in the sql server
sys.dm_db_physical_index_stats
53) How to find the long running queries in the sql server
DBCC opentran
Realtime questions
(or)
i start my day with checking mails and shift handover whether any
incidents from previous shift is handed to me for followup or any
action need to be taken.
we have 'CA service desk ' ticketing tool,where we get incident to our
queue.shift coordinator assign them to us on rotation bases and
sometimes we can proactively pick them and start working on them
by acknowledging in on our name.
Blocking checking
Deadlocks checking
checking job(rebuild,reorganize,backup) failuers.
Log file full alerts
Tempdb full alerts
Backups
script executions
Deployements(script execution)
password missuse
Login issue
8)what are the most common issues do you have faced ???
i have faced
Dbcc opentran
(or)
12)what will you do ,if you get two 'p1' ticket at a time ???
1.cpu
2.services offline
13)If your are only one person in the shift,you are unable to resolve
the issue,what will you do ???
If iam the person in the shift,i can assign ticket on my name,and i start
working on that ticket ,i iam unable to resolve immediately i can make
a call to my 'on-call' DBA. And i can inform him about the issue where
i have struck and i can explain him findings on issue and i can resolve
issue with help of 'on-call' DBA.
most popular 3rd party tool is 'Quest Light speed' and it can
compress the backup file almost 75-80%.
L2----->3
L3------>2
Team lead------>1
My project is hsbc ,it has huge inventory there are above 500
servers among those 60% on PRODUCTION servers and remaining are
UAT and DEV and DR servers.
Host name
Listener
Log shipping
25)How can monitor servers (or) How can you get alerts???
Incident:---->>
1.user-raised:
2.system-raised:
This can be configuring with the help of monitoring team into the
monitoring team.
1.implementation plan:
2.verification plan:
we need to verify action is performed or not.
3.Backout plan:
(or)
I have faced
sp_resetstats
And then i have put the database into single user mode by
using 'alter' command.
DBCC checkDB
30)If you dont habe a backup then how can you resove the issue???
DBCC checkdb(dbname,Repair_allow_dataloss)
DBCC CheckAlloc
DBCC CheckTable
DBCC CheckCatLog
Actually i have 1 month notice period but i can able to manage for 20
to 25 days.
How is it possible??
i have some leaves i can claim them and i can discuss with my
manager.
yes.