Tuesday, February 14, 2017

MSSQL: CheckDB failed for large user database which is of 2 TB

On one of the weekend, I received call from our team member who was in support that CheckDB maintenance job got failed on a large user database whose size was around 2 TB.

We have identified the table 'Table_abc' on which there is consistency issue from the SQL Error log based on the object_id. Table which got corrupted is of 50 GB. We ran below command to see if it fixes the issue.

DBCC CHECKTABLE (<table_name>, REPAIR_REBUILD) WITH ALL_ERRORMSGS.
GO

To verify whether still consistency error exists, we ran below command.

DBCC CHECKTABLE ('dbo.Table_abc');    
GO

But it was of no use still there was consistency error.

We created a new table 'Table_abc_new' and imported data into it using Export and Import wizard (BCP option also can be used).

Later created indexes and constraints similar to the old table 'Table_abc' and ran DBCC CHECKTABLE on the newly created table and there was no consistency issue.

Renamed the table 'Table_abc' to 'Table_abc_Old' and also renamed Table_abc_new' to 'Table_abc'.

Post Application team confirmation and after appropriate cooling period, dropped 'Table_abc_old' from the database.

You may refer below links for more information about CHECKDB and Repair options:
1. https://www.sqlskills.com/blogs/paul/misconceptions-around-database-repair/
2. https://msdn.microsoft.com/en-us/library/ms176064.aspx

Saturday, February 11, 2017

Typical Issue with SQL server Agent-- Agent Jobs not starting internally

Today I faced a typical isue with SQL agent.

When I am invkoing a job (by right clicking on the job and selecting start) it is displaying as executing. But I cannot find any proces ID related to it in the sysprocesses.

When I click on the job history also, I cannot find the history for that job.

When checked in the SQL Agent log file foudn below messages.

![298] SQLServer Error: 87, SQL Server Network Interfaces: Connection string is not valid [87]. [SQLSTATE 08001]
! [165] ODBC Error: 0, Login timeout expired [SQLSTATE HYT00]
![298] SQLServer Error: 87, A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [SQLSTATE 08001]
! [382] Logon to server '' failed (ConnLogJobHistory)
! [298] SQLServer Error: 87, SQL Server Network Interfaces: Connection string is not valid [87]. [SQLSTATE 08001]
! [165] ODBC Error: 0, Login timeout expired [SQLSTATE HYT00]
! [298] SQLServer Error: 87, A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [SQLSTATE 08001]
! [382] Logon to server '' failed (ConnAttemptCachableOp)
! [298] SQLServer Error: 87, SQL Server Network Interfaces: Connection string is not valid [87]. [SQLSTATE 08001]
! [165] ODBC Error: 0, Login timeout expired [SQLSTATE HYT00]
! [298] SQLServer Error: 87, A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [SQLSTATE 08001]
! [382] Logon to server ''failed (ConnLogJobHistory)
! [298] SQLServer Error: 87, SQL Server Network Interfaces: Connection string is not valid [87]. [SQLSTATE 08001]
! [298] SQLServer Error: 87, SQL Server Network Interfaces: Connection string is not valid [87]. [SQLSTATE 08001] "

Based on the above error log checked the Aliases under SQL Ntive client cofiguration in configuration manager.

Alias was created giving wrong port number, so SQL was not able to connect to SQL instance.

After rectifying the alias, my jobs worked without any issues.