Friday, March 9, 2012

How to move TempDB in SQLServer?

If the TempDB grows fast and does not have have enough space to grow then the best option is move the TempDB to another physical drive, which will help to improve database performance.

You will receive below error messages, if tempdb is full

Event ID: 17052
Description: The log file for database 'tempdb' is full.
Back up the transaction log for the database to free up some log space

Server: Msg 1101, Level 17, State 10, Line 1
Could not allocate new page for database 'TEMPDB'. There are no more pages available in filegroup DEFAULT. Space can be created by dropping objects, adding additional files, or allowing file growth.

Follow the below steps to move the tempdb to new location.

Step 1: Open a “New Query” Window and run the below command to get the path and names of the TempDB.

EXEC sp_helpfile


SELECT name, physical_name FROM sys.master_files
WHERE database_id = DB_ID('TempDB');

Step 2: In the following query Replace “NewPath” with new drive path and run the command to change the LDF and MDF file path.

USE master;
MODIFY FILE (NAME = tempdev, FILENAME = '\tempdb.mdf');
MODIFY FILE (NAME = templog, FILENAME = '}\templog.ldf');

The tempDB definition has been changed, but no changes are made to until you restart SQLServer. Please stop and restart SQL Server and

Step 3: Stop and Start the SQLServer

Control Panel -- > Administrative Tools --> Services --> Right click on SQLServer (MSSQLSERVER) --> Restart


SQL Server Configuration Manager --> SQLServer 2008 Services --> Right Click on SQLServer (MSSQLSERVER) --> Restart

Now TempDB files created in new drive.

Step 4: Check the TempDB new file location patch

SELECT name, physical_name FROM sys.master_files
WHERE database_id = DB_ID('TempDB');

Satishbabu Gunukula

Authentication Modes in Microsoft SQLServer

Microsoft SQLServer has two authentication modes
1. SQLServer authentication – The logins are created in SQLServer which are not available at Windows level.
2. Windows authentication – The windows user accounts validated by SQLServer at the time of log using Windows Active Directory.

The sa account connects by using SQL Server Authentication. For SQLServer accounts, three option password policies available.
• User must change password at next login
• Enforce password expiration
• Enforce password policy

Users will receive below errors, if only Windows authentication mode enabled.

2012-03-09 15:41:06.44 Logon Login failed for user 'App_user'. Reason: An attempt to login using SQL authentication failed. Server is configured for Windows authentication only. [CLIENT:]

To change the authentication mode follow the below steps.
1. Launch SQLServer Management Studio, right click on Server and select properties
2. Go to Security page, Under “Server Authentication” select the authentication mode
3. Restart the SQLServer

To enable the SA Login execute the following command.


Satishbabu Gunukula

Monday, March 5, 2012

Whats new in SQLServer 2012?

There are many new features introduced in SQLServer 2012, but 5 of them or most important.

1.Great Availability
2.Rapid Data Exploration
3.Blazing-Fast Performance
4.Optimized Productivity
5.Credible, consistent Data

SQLServer 2012 Licensing
From SQL Server 2012, a new licensing model introduced i.e. core-based licensing. Only enterprise and Standard will be available under this licensing. To license a physical server, you must license all the cores in the server, with a minimum of 4 core for each processor in the server.

Please refer below link for SQLServer 2012 Licensing Overview

SQLServer 2012 Editions
SQLServer introduced new edition called “Business Intelligence”. Please see the below link for Editions and SQLServer 2012 capabilities.

SQLServer 2012 enable mission-critical environment with maximum uptime and data availability. You can achieve greater availability using Synchronous or Asynchronous data movement. Please check below link for detailed info.

SQLServer 2012 Overview
SQLServer 2012 is a cloud ready platform and you can quickly build solution based up on your organization needs. Please see the blow link for overview.

Download SQLServer 2012
SQLServer 2012 RC0 is here and you can download using below link.

Satishbabu Gunukula

Thursday, March 1, 2012

How to Shrink Tempdb in SQLServer

Once in a while DBA’s will come across the situation that tempdb is full and no longer able to expand. You can avoid this situation by proactively monitoring the system with notification system setup for particular threshold.

To avoid this situation proactive monitoring is the best solution and it is always recommend to setup alerts for particular threshold.

It's highly recommended to disable "Autogrow" option for better performance. By default this option is enabled and it grows by 10% of its initial size. While performing auto growth, it will lock all applications and internal operations. This will also lead to fragmentation in the tempdb database.

Each time the SQL Server service starts, the tempdb is newly created by copying from the model database and inheriting some database configurations from it. The default size of tempdb is 8MB

You can try below solutions to shrink the databases.

Method 1: Shrink database using DBCC SHRINKDATABASE.

For ex:-

This command shrinks the tempdb database as a whole with specified percentage.

Method 2: Shrink the tempdb data file or log file

Use tempdb
--shrink the data file
DBCC shrinkfile (tempdb_data,’< target_size_in_MB’>)
--shrink the log file
DBCC shrinkfile (tempdb_log, ’)

DBCC shrinkfile (tempdb_data, 5000);

Method 3: shrink the tempdb data file or log file using T-SQL Command

-- Shrink the data file
ALTER DATABASE tempdb MODIFY FILE (NAME = 'temp_data', SIZE = target_size_in_MB)

-- Shrink the log file
ALTER DATABASE tempdb MODIFY FILE (NAME = 'temp_log', SIZE = target_size_in_MB)

Where target_size_in_MB= Desired target size for the data/log file

Errors while shrinking tempdb
If you have any active transactions in tempdb then you may receive below consistency errors.

1. Server: Msg 2501, Level 16, State 1, Line 1 Could not find table named '1525580473'. Check sysobjects.

This error may not be an indicative of any corruption, but it causes the shrink operation to fail.

2. Server: Msg 8909, Level 16, State 1, Line 0 Table Corrupt: Object ID 1, index ID 0, page ID %S_PGID. The PageId in the page header = %S_PGID.

This 8909 error indicates tempdb corruption. You can clean up the consistency errors by restarting the SQL Server. If you still see any errors then restore the database from valid backup.

3. DBCC SHRINKFILE: Page 1:456120 could not be moved because it is a work file page.

This error indicates that Page could not be moved because it is a work file page. You can release the cached objects by running “DBCC FREEPROCCACHE”. Now try shrink tempdb once again to release the free space.

Satishbabu Gunukula