Thursday, June 25, 2009

Troubleshoot Suspect Database Issue

Problem

How to troubleshoot suspect database problem? How to bring it back online? What are the do you need to perform once the database is online?



Solution

Step 1: Bring the database online using below script

USE Master

GO

 

-- Determine the original database status

SELECT [Name], DBID, Status

FROM master.dbo.sysdatabases

GO

 

-- Enable system changes

sp_configure 'allow updates',1

GO

RECONFIGURE WITH OVERRIDE

GO

 

-- Update the database status

UPDATE master.dbo.sysdatabases

SET Status = 24

WHERE [Name] = 'SuspectedDatabaseName'

GO

 

-- Disable system changes

sp_configure 'allow updates',0

GO

RECONFIGURE WITH OVERRIDE

GO

 

-- Determine the final database status

SELECT [Name], DBID, Status

FROM master.dbo.sysdatabases

GO

Step 2: Check for database corruption. This is very important step please execute it.

  • DBCC CHECKDB - Validate the overall database integrity

  • DBCC CHECKCATALOG - Validate the system catalog integrity

  • DBCC CHECKTABLE - Validate the integrity for a single table


Step 3: To resolve the corruption issue, please execute below commands

  • Drop and Recreate Index(es)

  • Move the recoverable data from an existing table to a new table

  • Update statistics

  • DBCC UPDATEUSAGE

  • sp_recompile


Step 4: Repeat Step 2 to validate all the corruption occurred

Tuesday, June 23, 2009

DRBD, Heartbeat and MySQL

The easiest solution to implement clustering in MySQL is DRBD and Heartbeat.

DRBD: The Distributed Replicated Block Device (DRBD) is a software-based, shared-nothing, replicated storage solution mirroring the content of block devices (hard disks, partitions, logical volumes etc.) between servers.

DRBD mirrors data

  • In real time. Replication occurs continuously, while applications modify the data on the device.

  • Transparently. The applications that store their data on the mirrored device are oblivious of the fact that the data is in fact stored on several computers.

  • Synchronously or asynchronously. With synchronous mirroring, a writing application is notified of write completion only after the write has been carried out on both computer systems. Asynchronous mirroring means the writing application is notified of write completion when the write has completed locally, but before the write has propagated to the peer system


You can download DRDB from below site

http://www.drbd.org/download/packages/

Memcached & MySQL

memcached (pronunciation: mem-cash-dee.) is a general-purpose distributed memory caching system that was originally developed by Danga Interactive for LiveJournal, but is now used by many other sites. It is often used to speed up dynamic database-driven websites by caching data and objects in memory to reduce the number of times an external data source (such as a database or API) must be read. Memcached is distributed under a permissive free software license. Memcached lacks authentication and security features, meaning it should only be used on servers with a firewall set up appropriately. By default, memcached uses the port 11211. Among other technologies, it uses libevent. Memcached's APIs provides a giant hash table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order. Applications using memcached typically layer memcached requests and additions into core before falling back on a slower backing store, such as a database. You can download memcached API from http://www.danga.com/memcached/


 

Tuesday, April 28, 2009

How to search error from SQL Server error log or SQL Server Agent Log?

How to search error from SQL Server error log or SQL Server Agent Log?


We can find the particular error or information from error log by passing below parameters to XP_ReadErrorLog extended procedure.




EXEC 
sys.xp_readerrorlog @p1,@p2,@p3,@p4

@P1 = Value of error log file you want to read: 0 = current, 1 = Archive #1, 2 = Archive #2, etc...


@P2 = Log file type: 1 or NULL = error log, 2 = SQL Agent log


@P3 = Search string 1: String one you want to search for


@P4 = Search string 2: String two you want to search for to further refine the results


Please note all the parameters are optional.

Thursday, April 23, 2009

Error 18456, Severity 14: Login Failed States









































































Error 18456, Severity 14: Login Failed States 
Login Failed states summary
StateDescription
1Only state returned in SQL 2000. Server is in Single-User Mode (2005).
2 and 5Invalid User Id
6Attempt to use a windows login name with SQL Authentication
7Login disabled and password mismatch
8Password mismatch
9Invalid Password
10Read Ref Link #2
11 and 12Valid login but server access failure; Default Database access failure. Or Initial database connection failure in connection string.
13SQL Server service paused
16User doesn't have permission to target database
18Change password required
23Server in process of shutting down, and user attempted to login.
27Initial database could not be determined for session
38Initial database could not be determined for session (SQL 2008)
40Default database could not be accessed (SQL 2008)

Wednesday, March 25, 2009

How to Alter a SQL Server Database as Single User Mode and as Multi User Mode

You can use the SQL Server Enterprise Manager for SQL Server 2000 to set a database to a single user mode or to multi user mode. Similarly, SQL Server Management Studio can be used for SQL Server 2005 for changing a database to single user mode or to multi user mode. Also you can alter the database access mode by using sql commands like ALTER DATABASE and sp_dboption.


 


ALTER DATABASE [MyDBName] SET MULTI_USER WITH NO_WAIT


ALTER DATABASE [MyDBName] SET SINGLE_USER WITH NO_WAIT


or


EXEC sp_dboption 'MyDBName', 'single user', 'false'


EXEC sp_dboption 'MyDBName', 'single user', 'true'

Thursday, January 15, 2009

Find the SQL Server Service Startup Time

Find the SQL Server Service Startup Time


 


Many times for collecting or analyzing performance counter from the different DMV we need to collect the data of many days, so at that it is necessary to find the SQL Server Service startup time. We can find it as below.


 


1)       Every time when SQL Server restarts, It creates the “TempDB” so from the TempDB creation time you can find SQL Server startup time.


SELECT CREAT_DATE FROM SYS.DATABASES WHERE NAME = ‘TEMPDB’


2)       If you error log is not flushed you can use the XP_ReadErrorlog and from there you can find the SQL Server startup time


3)       We can also find it using sys.dm_exec_requests  DMV for startup time


4)       We can also find it from Master..SysProcesses system table by analyzing the login time for the System Processes (for i.e. LAZYWRITER)

Wednesday, January 14, 2009

Execute As in SQL Server 2005

When an EXECUTE AS statement is run, the execution context of the session is switched to the specified login or user name. This will help database administrator to check the different user permissions. `Execute As` is also very helpful when a user wants to execute a stored procedure in the context of another user.

Syntax
Execute as user = 'SQL_JShah'
select * from CompanyProducts.Products