Category: SQL Server
-
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…
-
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…
-
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…