Database Forensics Flashcards
SQL Server Data Storage has three components
Primary Data Files (MDF)
Secondary Data Files (NDF)
Transactional LOG Data Files (LDF)
Primary Data File (MDF)
The primary data file contains the startup information for the database and points to the other files in the database. User data and objects can be stored in this file or in secondary data files. Every database has one primary data file. The recommended file name extension for primary data files is .mdf
Secondary Data Files (NDF)
Secondary data files are optional, are user-defined, and store user data. Secondary files can be used to spread data across multiple disks by putting each file on a different disk drive. The recommended file name extension for secondary data files is .ndf
Transaction LOG Data Files (LDF)
The transaction log files hold the log information that is used to recover the database. There must be at least one log file for each database. The recommended file name extension for transaction logs is .ldf
SQL Database File Locations
Database & logs files:
\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA*.MDF | *.LDF
Trace files:
\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\LOG\LOG_#.TRC
SQL Server error logs:
\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\LOG\ERRORLOG
What command will help in collecting the active transaction log?
sp_helpdb
What function allows you to retrieve the active portion of the transaction log file
The fn_dblog() function
fn_dblog () function filters transactions by:
Target database object
Specific columns
SPID and/or date/time range
What is the Database Consistancy Checker (DBCC)?
The DBCC LOG command allows you to view and retrieve the active transaction log files for a specific database. Following are the other DBCC commands that allow you to obtain additional information related to the specified database.
DBCC DBTABLE: Returns the structure of the selected database table
DBCC DBINFO: Returns information related to the database metadata
DBCC PROCBUF: Returns the contents of the SQL Server Procedure Buffer.
DBCC BUFFER:
Returns the buffer headers and pages from SQL Server’s buffer cache, where SQL Server stores results.
DBCC SHOWFILESTATS:
Returns information related to the space occupied by the data files in the active database.
DBCC PAGE:
Returns the data page structure of the selected database
To collect the database plan cache, the following query is used in SSMS:
select * from sys.dm_exec_cached_plans cross apply sys.dm_exec_sql_text(plan_handle)
Issuing sys.dm_exec_cached_plans
returns a row for each query plan that the SQL server had cached to speed up query execution. This dynamic management view will help users to find cached query plans, cached query text, the amount of memory taken by cached plans, and the reuse count of the cached plans.
To collect the trace files (.trc) navigate to:
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\LOG