Skip to main content

Database last used

For a DBA its a routine issue to keep watch on the tables and database usage. Hence, it should be possible for any DBA to track the changes made to either a database or a table and be able to take necessary action according to the situation. Consider, if there is a database which is never used in a server but still there in the server. The metadata of the idle database will be stored in the system databases as this is connected to the server and if the database is very big with many objects, its obvious that a huge data should be stored in the system databases related to that database. Hence to counter the problem we can check the server databases which are critical in respect to its usage and if we found some databases never being used, we can take them offline. We can check the database, when it was last used or updated by running a query as shown below.

select distinct DB_NAME(database_id), object_name(object_id),  last_user_seek,last_user_scan, last_user_lookup, last_user_update
from
sys.dm_db_index_usage_stats

Note: This is valid only till the SQL Server session is open. If the server is once restarted, the table sys.dm_db_index_usage_stats looks empty.

To counter the above drawback, I am still working and update the same in the near future. I also wanted to know the number of times a database of a server is being used for a specified period, say a month. If someone have any suggestion please be kind enough to put on a comment.

Comments

Popular posts from this blog

Deferred prepare could not be completed

This is usually an error that is encountered while querying a remote database on a different server instance which says OLEDB provider "SQLNCLI" for linked server "ABCD" returned message "Deffered prepare could not be completed" Msg 8180, Level 16, State 1, Line 1 Statement(s) could not be prepared. This is the way I could rectify, though this is not the lone mistake that gives this error every time. Just set the default to the database that is being querying to the user through which the Linked server is connecting to the database.

Script level upgrade for database 'master' failed because upgrade step 'sqlagent100_msdb_upgrade.sql'

As huge a database grows, that tedious are regular DBA activities become. Besides, a warehouse database, can grow with no bounds to challenge.  There was a patching on one of our databases, SP3 for SQL Server 2008 R2, which was failing due to the error below. As the error says, MASTER the heart of SQL Server  “Script level upgrade for database 'master' failed because upgrade step 'sqlagent100_msdb_upgrade.sql' encountered error 2627, state 1, severity 14. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion. Cannot recover the master database. SQL Server is unable to run. Restore master from a full

Incorrect SET Options with Filtered Indexes

Rebuild Index|Create Index|DML on a Table with Filtered Index fails with the error: The following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations. [SQLSTATE 42000] (Error 1934).  The step failed. The Operation above might succeed when its through SSMS. But, would fail when the operation is from a SQL Agent Job. This is because, SQL Agent by default, do not have the SET Options enabled (ON). They are OFF. Reason: The following are the SET Options that are needed while operation on a table with a filtered index. Required SET Options for Filtered Indexes The SET options in the Required Value column are required whenever any of the following conditions occur: Create a filtered index. INSERT, UPDATE, DELETE, or MERGE operation modifies the data in a