SQL server connection and blocking finding script -- For SQL 2000 select db_name(dbid),* from master.dbo.sysprocesses where spid> 51 and status <>'sleeping' -- and blocked <>0 -- To find the spid and connections which are all running select db_name (r.database_id),r.command,r.wait_resource,s.status,s.session_id, r.blocking_session_id,r.last_wait_type,r.open_transaction_count,sql_handle, * from sys.dm_exec_sessions s join sys.dm_exec_requests r on s.session_id =r.session_id --where s.status <>'sleeping' and s.session_id >=51 and s.session_id <>@@SPID -- exclude your session -- to find the blockings select db_name (r.database_id),r.command,r.wait_resource,s.status,s.session_id, r.blocking_session_id,r.last_wait_type,r.open_transaction_count, * from sys.dm_exec_sessions s join sys.dm_exec_requests r on s.session_id =r.session_id where r.blocking_session_id<>0 -- list blocking select * FROM sys.dm_exec_requests -- to find the code which is run by spid connections SELECT T.TEXT As Query, R.session_id, R.status, R.command…
-
-
Error: 17300, Severity: 16, State: 1. (Params:). The error is printed in terse mode because there was error during formatting. Tracing, ETW, notifications etc are skipped. There is insufficient system memory in resource pool ‘internal’ to run this query.
Today my colleague had issue that SQL server instance is not starting on. It is a SQL 2016 and had seven instances with 24 GB of total OS RAM. Same again, one of the SQL instance memory configured incorrectly. It is a alwaysON secondary replica. We know where we have to look, when we cannot start SQL service. Run — Eventvwr — Windows logs –Application and system. One more: Open SQL server errorlog file in notepad and review as well. You can get the error log location in the configuration manger — startup parameters. 2019-01-30 04:43:14.73 spid6s Error: 701, Severity: 17, State: 123. 2019-01-30 04:43:14.73 spid6s There…
-
Move database between drives
SQL server Move user database steps and scripts: Check you have a free space on the moving drive and make sure the SQL service account has read and write permission. (You can check the account name in configuration manager) Move TempDB database --========================= for tempdb -- note the existing details with logical name --Step 1 USE TempDB GO EXEC sp_helpfile tempdev 1 C:\Program Files\Microsoft SQL Server\MSSQL11.PROD\MSSQL\DATA\tempdb.mdf templog 2 C:\Program Files\Microsoft SQL Server\MSSQL11.PROD\MSSQL\DATA\templog.ldf --Step 2 -- alter to new location USE master GO ALTER DATABASE TempDB MODIFY FILE (NAME = tempdev, FILENAME = 'T:\SQL_TEMPDB\tempdb.mdf') GO ALTER DATABASE TempDB MODIFY FILE (NAME = templog, FILENAME = 'T:\SQL_TEMPDB\templog.ldf') GO --Step 3 -- restart…
-
Msg 8909, Level 16, State 1, Line 1 Table error: Object ID index ID partition ID
Being a DBA , you will see database corruptions in your environments. I got four or five and not affected much of the data. Most of the time logical corruption and memory errors. The bellow one I got sometimes back and the worst part is backup also corrupted database. What we can do when we got a corruption errors or tickets. Analysis the error from the error log, if you have good entries or run CheckDB and get the messages. (Don’t go and detach the database, restart SQL or run repair_allow_data_loss) dbcc checkdb ('DB') with no_infomsgs,all_errormsgs I take a help of http://www.sqlservercentral.com/articles/Corruption/65804/ Gail shaw’s article to start with it.…
-
SQL server change single user mode or backup or recovery model of all database sql script
Following is the DBA script which generally used for most cases the action needed for all the databases like migration, upgrade etc. Change the database recovery model and set to single_user mode. Backup of all databases. -- Dynamic SQL select 'alter database ['+name+'] set single_user with rollback immediate' , * from sys.databases where database_id not in (1,2,3,4)-- exclude system DBs select 'alter database ['+name+'] set multi_usere' , * from sys.databases where database_id not in (1,2,3,4)-- exclude system DBs select 'alter database ['+name+'] set recovery simple' , * from sys.databases where database_id not in (1,2,3,4)-- exclude system DBs select 'backup database ['+name+'] to disk = ''B:\SQL_backup\'+name+'_full.bak''' , * from sys.databases where…