Category: SQL Server Toolbox
-
Recover a database with a DAMAGED and/or LOST log file
In this procedure we’ll manage one of the worst situation a DBA has to manage: corrupted files and data loss. When this heppen usually the common way is restoring but we’ll use sql server features to reduce stop time (avoiding a complete restore) and data loss. Possible starting problems: Corrupted logfile Corrupted logfile during a…
-
Monitoring Wait Events of a single Session or Query in SQL Server
Using sys.dm_os_wait_stat is not useful for deep troubleshooting because this view contains wait events for ALL processes/queries running on your instance since last restart. Using command “DBCC SQLPERF (‘sys.dm_os_wait_stats’, CLEAR)” we can reset this view with no restart but on big and stressed instances with many processes and applications running this isn’t a real good…
-
Massive SQL Server Database Moving Using Detach – Attach: The Complete Procedure
This is a complete configurable metascript, prepared to create detach statements, file move statement and re-attach statements for every database in your instance. You have only to configure the final destination for datafiles and the database list you want to migrate. The final generated script for every database selected will be something like this (remembar…
-
Anayze SQL default trace to investigate instance events
Quering default trace is the best way to investigate unusual or critical events heppened in SQL server and not logged in errorlog files. It’s not difficult to find useful informations there but the trace is full of codes to translate to make it more readable and useful. This is my query, based on sys.fn_trace_gettable function…
-
SQL Jobs Monitoring: check last run datetime and duration
A simple query to check rapidly your job’s status and duration. Useful for fast monitoring on many instances. No more thing s to say: this is the code based on msdb..sysjobs and msdb..sysjobhistory. It’s easy if necessary filtering a single job id or jobs durations too long. select job_id, job_name, run_datetime, SUBSTRING(run_duration, 1, 2) +…
-
How to make your databases smaller and faster: find unused indexes
It’s a boring job but sometimes a good DBA has to do it. Applications change and you have to understand what become unuseful in your databases: we are talking about unused indexes. In any SQL server database indexes take up a lot of space and have to be updated every time an application runs an…
-
Analyze SQL Server database historical growth: MONTLY size changes
The most simple way to analyze database historical growth is quering database backup catalog. SQL Server catalog stores informations about every single database backup in msdb..backupset. If you don’t have other instruments to collect historical database size this is a good point to start for a capacity planning This time we take the max size…
-
Analyze SQL Server database historical growth: DAILY size changes
The most simple way to analyze database historical growth is quering database backup catalog. SQL Server catalog stores informations about every single database backup in msdb..backupset. If you don’t have other instruments to collect historical database size this is a good point to start for a capacity planning. Remembar only this: – msdb..backupset stores historical…
-
Queries to see rapidly what your SQL Server is doing NOW
1) Blocked And Blocking queries. If this query returns no rows you have no blocked queries in this moment. Run it more then once to see any few-seconds blocking queries. NOTE: This exclude ONLY problems with long-locking running queries. Cumulative short-term locking contentions need other kinds of debug (see point 2) SELECT ‘BLOCKING STATUS’ as…
-
Massive Database Migration between SQL Server instances: the complete procedure v.2.0 *UPDATED*
(05/04/2014) Procedure Upgrades : – Added compresson to reduce bandwith,space necessary and transfer time – Reduced stat value for very large database – Added backup type parameter to choose from FULL,FULL_COPYONLY or DIFFERENTIAL backup (for bigger database migration) – Added Maxtransfersize and Buffercount parameters to improve backup performance (warning – this needs more memory!) –…