Skip to main content

Dropping (deleting) a production database…


Deleting a production database is not an easy task to accomplish. Well technically it may be easy but as a guardian of database, you need to make sure that you do not any one adversely by deleting a production database abruptly.

Hence I prefer to use below steps as a standard guideline to delete a production database:

  1. After you get approval of database’s deletion from database owner, announce to the users of the server that you intent to take the database offline (and eventually delete). Inform a date and time (I prefer to give them at least 5 working day’s notice or follow the company’s police)
  2. Make the database read-only on the day of taking it offline and then take a full backup. Make sure this backup is moved to tape and archived for maximum duration to ensure that the data will not be lost for ever after you drop it from server. (Some financial database needs to be archived as per Government mandate which may be much larger duration than standard company retention policy. So always make sure that you got a written confirmation from database owner agreeing with the retention policy of the database backup after it is offline/deleted)
  3. Take the database offline. At this stage, advice users when the database will be permanently deleted from the server. (I prefer to wait for at least 5 working days unless company has a different policy). Also make sure to disable all jobs using this database, edit maintenances and monitoring plans as needed to ensure that no one gets pages at night for unnecessary alerts from this “offline” database.
  4. On the day of final deletion, bring the database online and delete it. Also I prefer to delete all the backup/restore history information of the database while I delete the database.

Example code I use to delete the database:

EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'[Database Name]'
GO
USE [master]
GO
DROP DATABASE [Database Name]
GO

Note:

a.      Although it is not expected, you may need to kill all the connections to this database while deleting it. However in this case advice the SPID owner about the database’s deletion after you killed his/her connection. (He/she may missed the information about the database’s deletion and started a application/query pointing to the database coincidentally when you bough it online for deletion)
b.      Deleting backup/restore history may take a while depending on the volume of data present at msdb about this database. So delete may take longer time in this case. (This situation is often common for a database which was in production for a long time which has long backup/restore history)

  1. After database is deleted, inform every one about the deletion.

Following this step will ensure that this deletion is well coordinated and did not created any outage on any application. Also having a defined retention period of last backup of the deleted database will guarantee that you can recover the database or data in case of some unforeseen issue later.

Comments

Popular posts from this blog

How to kill a negative SPID (like SPID -2) in SQL Server?

Rarely this scenario will arise when most likely you see this negative SPID (most likely SPID -2) is blocking other transaction causing issues. If you try to kill it using normal KILL command, it will fail reporting below error: Msg 6101, Level 16, State 1, Line 1 Process ID <SPID Number> is not a valid process ID. Choose a number between 1 and 2048 This is because of an orphaned distributed transaction ID.  Please follow below steps to kill it: Step 1: -- Find the UOW Number select req_transactionUOW from master..syslockinfo where req_spid = <SPID Number> --  <SPID Number>  is -2 most likely. Step 2: -- Copy the UOW number from Step one KILL ‘<UOW Number>’ This will kill the negative SPID resolving the issue.  However please note following points: 1. For SPID -2, you may find multiple UOW numbers. Please start killing them one by one. Typically killing first UOW will resolve the issues. (ie. will kill all UOW and release

DMV/TSQL to find out basic hardware information of the SQL Server including when SQL Server started.

Please use below code: However, please be advised that it can not tell correct information around virtualization.  For example, it will show Hypervisor even if SQL runs on a physical OS where Hyper-V is on. So use this query only when you do not have sufficient access on underlying Windows Operating system to get these information directly. -- Basic hardware information for SQL Server (sys.dm_os_sys_info) /* This query is courtesy of https://sqlserverperformance.wordpress.com/. All credits goes to original author. */ SELECT cpu_count AS [Logical CPU Count] , scheduler_count , hyperthread_ratio AS [Hyperthread Ratio] , cpu_count / hyperthread_ratio AS [Physical CPU Count] , physical_memory_kb / 1024 AS [Physical Memory (MB)] , committed_kb / 1024 AS [Committed Memory (MB)] , committed_target_kb / 1024 AS [Committed Target Memory (MB)] , max_workers_count AS [Max Workers Count] , affinity_type_desc AS [Affinity Type] , sqlserver_start_time AS [

‘Trace Skipped Records’ – What is this and how to resolve it while using SQL Server Profiles?

In some very rare case, you may experience a very weired message in profiler’s output as ‘Trace Skipped Records’ while you trace something on SQL Server. Screenshot of similer situation is as below: This is not an error but it comes by design of SQL Server (I believe so). When you are using SQL profiler and return data is too big to fit in the GUI (for me, it is an enormous xml), SQL Server simply prints this message and proceed to next step. Mostlikely this is to save server’s memory and performance. Although not suggested and guranteed, you can try to run a server side trace and dump data in a file which should capture all the data. However, it is strongly not recommended to run a trace on your production server from server side. Microsoft will probally document this limitation in future. More details may be found at https://connect.microsoft.com/SQLServer/feedback/details/304225/msft-edw-profiler-displays-trace-skipped-records-for-large-530kb-batch