SQL Server Production Issues

SQL Server Production Issues

Prod Problems and Solutions:

     Below are the common problems from production environment.

  •  SQL Server Log full alert 
  • SQL Server Blocking Alert
  • Low Disk Space/Disk Full
      Now here are the solutions for these issues…………….

 

 SQL Server Log full alert
________________________________________

Title

SQL Server log full

 Issue/Problem Description

Log is full on TempDB or a user database. This is most often caused by a process has run longer than expected, has hung or performed a rollback because there was insufficient space in the database to proceed.

Action/Resolution Information

For User Databases

1. Verify drive space is not causing the problem.
2. Check SQL Agent jobs to see is one is causing the problem.

3. Locate running process verify if:
a. Are still running
b. Have completed already.
c. Are rolling back or have rolled back.

4. Check DB settings for caps on the files.
a. If a max size is set, expand the max size by a small amount to allow the process to finish running. Make sure that other files on the drive are not impacted.
b. If a max is not set and the drive is running out of space notify the customer of the findings and have them consider the following:
** Expand to another location. (Make sure to cap the file as well before expanding to
another location to prevent the file from taking all of the disk space left.)
** Grow the drive if it is on Storage Utility
5. If the following hold true attempt to shrink the log:
a. The process has completed or rolled back
b. There is free space on the Disk
c. There is free space to be gained in the log

For TempDB

1. Identify if TempDB is setup with multiple files.

2. Verify DB settings.

a. If there is a maxcap on the tempdb file and there is adequate, disk space increase it up a small amount to allow the process to complete.

IMPORTANT – If this TempDB is set up with several TempDB files you need to add a little space to each file equally to maintain the correct algorithm.

b. If there’s no cap set on the database.

** Verify drive space If there is a lot of space available than the process may have

already rolled back.

** Identify process using tempdb and what is driving them.

** Locate alternate location to expand files

(Use extreme caution when expanding to another drive. It will affect the other databases on the server. Try to expand only long enough to get the process completed and only to a drive other than E-H.)

As a last resort and only when SQL is negatively impacted by the condition consider requesting permission from the customer to restart SQL.

 

Blocking Alert
________________________________________

Title

SQL Server Blocking

Issue/Problem Description

On occasion SQL server will throw alerts for blockage. A lot of times this blockage will pass on its own. In those cases let the customer know the blockage occurred and that it has passed. If it continues however this could indicate a larger problem.

Action/Resolution Information

Blocking often occurs because:

1. A SPID holds locks on a set of resources for an extended period of time before releasing them. This type of blocking resolves itself over time, but can cause performance degradation.(This type will often resolve itself however can cause a moving target of sorts as the blocking moves from one resource to another making this harder to troubleshoot overall)

2. A SPID holds locks on a set of resources and never releases them. This type of blocking does not resolve itself and prevents access to the affected resources indefinitely.(This type is fairly consistent and easy to troubleshoot normally)

Running SQLStat will verify blockage is still occurring after you receive the alert:

CONNECTING TO SQL SERVER:

SERVER_NAME 9.00.1355

TOTAL PROCESSES: 26

BLOCKED PROCESSES: 2

Once you have verified that the blockage is still occurring you need to identify the following:

1. The SPID causing the blocking.

2. The command being executed by the SPID.

3. If the SPID is still active.

4. What process is controlling the SPID.

 

You can either view things using Query Analyzer or Enterprise Manager. Since some tempDB blocking can prevent you from viewing the process’ through Enterprise Manager it is good to be aware of which query to run to get the same information.

 

 

From Query Analyzer you can run any of the following to get SPID information:

 

 

** SP_WHO2 – BlkBy column

** SP_LOCK – SPID Column

** SELECT * FROM MASTER..SYSPROCESSES

** SELECT * FROM MASTER..SYSLOCKINFO

** SELECT * FROM SYS.DM_TRAN_LOCKS – SQL 2005 only-

Use WHERE resource_database_id = clause for specific database.

 

 

A SPID value of -2 indicates an orphaned transaction.

 

 

Take these blockers and run the following to get the detail of what they are running:

 

 

DBCC INPUTBUFFER(spid)

 

 

Identify I/O consumption on long running tasks to verify still active:

 

 

SELECT SPID, PHYSICAL_IO FROM MASTER..SYSPROCESSES

 

 

OR

 

 

Connect via Enterprise manager and view the following

1. Expand Group

2. Choose Server

3. Expand Management

For SQL 2000

** Expand Locks/Process ID

** Click Process Info

** Double Click the blocking Spid to capture the last command executed.

For SQL 2005

•Double click on Activity Monitor

** Scroll to the right and locate the “Blocked By” columns. These are your head

blockers.

** Double click on Process ID to make note of what activity is causing the blocking.

** Note Process ID number for the head of the blocking chain.

 

 

Once you have identified the running command and verified it is still active look at some of the following:

 

 

If a SQL Agent job is spawning the command to run.

 

 

1. If the job is running over, notify customer of situation and to check

2. If the job is not running over, notify customer and monitor till expected job end

3. If this is a daily occurrence you may suggest they choose a different time to run their job when the server is under fewer loads and it will not cause blocking.

 

 

Not a SQL job but ad-hoc query – Notify customer and person running query of the problem and request they

 

 

1. Break any large, complex queries into simpler queries

2. Run the query during off hours or on a separate computer

 

 

Remember that certain SPIDs should not be killed or cannot be killed.

 

 

**Your own process – Cannot be killed

 

 

Those labeled with the following should not be killed:

 

 

** AWAITING COMMAND

** CHECKPOINT SLEEP

** LAZY WRITER

** LOCK MONITOR

** SIGNAL HANDLER

 

 

If blocking is persistent and an attempt to kill the SPID has left it hung you may need to either:

1. Restart SQL

or

2. Reboot Server

 

 

Run the following from a Query Analyzer to get an idea of how long a SPID may take to rollback:

 

 

KILL spid WITH STATUSONLY

 

 

In order to clear the issue. Make sure and discuss this with the customer first.

 

 

 

 

Disk Space Alert

________________________________________

 

 

Title

 

 

Low Disk Space/Disk Full

 

 

Issue/Problem Description

 

 

Disk threshold alerts

 

 

There are two disk threshold alerts we are currently trapping:

1. Below 400mb (Sends email to MSE every 15 minutes)

2. Below 5% (Sends email to MSE every 15 minutes)

 

 

Drive Notations as Per  General Production Standards

 

 

C Drive – All OS Files present.

D Drive – All the System Database files (log & data files) present in D:\MSSQL\Data folder.

E Drive – All the Database Backup files (Full & Differential) present in E:\MSSQL\BAK folder.

F Drive – All the Transaction Log Backup files present in F:\MSSQL\TRAN folder.

T Drive – All the data files of Tempdb database present in T:\MSSQL\DATA

H Drive – All the database files (only Data) present in H:\MSSQL\DATA.

O Drive – All the Log files present in O:\MSSQL\DATA. .

 

 

Action/Resolution Information

 

 

Identify the server type

 

 

Since we monitor several different types of servers, each with its own SKU, it is important to identify the type of server throwing the error to make sure you understand what each drive’s purpose is.

 

 

Common:

 

 

** File servers

** SQL Servers

** IIS Servers

** Servers on SANs or SU’s

 

 

Common causes

 

 

** Look for the obvious files first:

1. *.tmp

2. *.dmp

3. *.log

** Look for failed jobs within SQL or Task Scheduler that may be causing the drive to fill.

** Check the Print Spooler if this server does a lot of printing. (A large print job that hung can cause the C$ drive to fill quickly. Commonly this folder is located

C:\$systemroot$\system32\spool\PRINTERS.)

** Check for SMS Cache that has grown large.
Actions you can consider

For C Drive alerts:

** Contact DCOps for resolution.

For other drives:

**Contact the customer and ask them to remove any unnecessary files/folders.

** Compressing old files and/or the folder.

** Special Tape archive and delete.

a. Create a share where the data is located.

b. Create a Change Request for the Backup team to backup the newly created share to

tape and send offsite.

c. Verify successful tape save with Backups.

d. Delete data off server.

** Shrinking the files if they are from a SQL database.

a. Identify if there is available space on the database to shrink it down a bit.

** Delete completely. (Mostly refers to C$)

a. Old dump files from Windows and DrWatson.

b. Old Install bits from updates and upgrades.

** Move Print Spool to another drive.

** If this is on a Storage Utility, you may consider adding more drive space.

 

 

!! Always confirm!!

 

 

Always confirm with the customer before moving, removing or altering ANY of their data from a server.

 

Will be back with More probs and Sols…………………..!!!!!.

Posted in SQL Server DBA | Tagged , , , , , , , , , , | 3 Comments

Static and Dynamic port in sql server

Static and Dynamic port in sql server


STATIC PORT ALLOCATION

If you configure an instance of SQL Server to use a static port, and you restart the instance of SQL Server, the instance of SQL Server listens only on the specified static port. The SQL Server clients must send all the requests only to the static port where the instance of SQL Server is listening.

However, if an instance of SQL Server is configured to listen on a static port, and another program that is running on the computer is already using the specified static port when SQL Server is started, SQL Server does not listen on the specified static port.

By default, the default instance of SQL Server listens for requests from SQL Server clients on static port 1433. Therefore, the client network libraries assume that either port 1433 or the global default port that is defined for that client computer is used to connect to the default instance of SQL Server.

The default instance of SQL Server does not support dynamic port allocation. However, the named instances of SQL Server support allocation of both static and dynamic ports. By default, a named instance of SQL Server listens on a dynamic port.

DYNAMIC PORT ALLOCATION

Only named instances of SQL Server can use the dynamic port allocation process. In the dynamic port allocation process, when you start the instance of SQL Server for the first time, the port is set to zero (0). Therefore, SQL Server requests a free port number from the operating system. As soon as a port number is allocated to SQL Server, SQL Server starts listening on the allocated port.

The allocated port number is written to the Windows registry. Every time that you start that named instance of SQL Server, it uses that allocated port number. However, in the unlikely case that another program that is already running on the computer is using that previously allocated (but not static) port number when you start SQL Server, SQL Server chooses another port.

When an instance of SQL Server uses dynamic port allocation, the connection string that is built at the SQL Server client does not specify the destination TCP/IP port unless the user or the programmer explicitly specifies the port. Therefore, the SQL Server client library queries the server on UDP port 1434 to collect the information about the destination instance of SQL Server. When SQL Server returns the information, the SQL Server client library sends the data to the appropriate instance of SQL Server.

If UDP port 1434 is disabled, the SQL Server client cannot dynamically determine the port of the named instance of SQL Server. Therefore, the SQL Server client may be unable to connect to the named instance of SQL Server. In this situation, the SQL Server client must specify the dynamically allocated port where the named instance of SQL Server 2000, SQL Server 2005, or SQL Server 2008 is listening.

DETERMINE THE TCP/IP PORT NUMBER OF THE INSTANCE OF SQL SERVER.

SQL SERVER 2005

1. Open SQL Server Configuration Manager, and then expand SQL Server 2005 Network

Configuration.

2. Click Protocols for InstanceName, and then double-click TCP/IP in the right panel.

3. On the Protocol tab, notice the value of the Listen All item.

4. Click the IP Addresses tab:

• If the value of Listen All is yes, the TCP/IP port number for this instance of SQL Server 2005 is the value of the TCP Dynamic Ports item under IPAll.

• If the value of Listen All is no, the TCP/IP port number for this instance of SQL Server 2005 is the value of the TCP Dynamic Ports item for a specific IP address.

TROUBLESHOOTING

If the SQL Server clients cannot access an instance of SQL Server after you have configured, the following causes may exist:

A firewall may be blocking the specified TCP/IP port.

If the port that the SQL Server instance is currently listening on is blocked by your firewall, the connections will fail.

Another program may already be using the specified TCP/IP port.

If another program is already using the specified TCP/IP port, the port is not available to the instance of SQL Server and SQL Server clients may be unable to connect to the instance of SQL Server.

This problem is specific to an instance of SQL Server that is configured to use a static TCP/IP port. This problem does not occur for an instance of SQL Server that is configured to use dynamic port allocation. In dynamic port allocation, if another program is already using the specified TCP/IP port when you start the instance of SQL Server, the instance of SQL Server selects a new port.

Posted in SQL Server DBA | Tagged , , , , , , | 2 Comments

Migrate Log shipping from SQL 2005 to 2008

Migrate Log shipping from SQL 2005 to 2008

This post helps us to Migrate Log shipping from SQL 2005 to 2008.

LET’S upgrade the Log shipping from SQL SERVER 2005 TO SQL SERVER 2008

We have 3 different cases as follows:

1. One Primary, One Secondary

2. One Primary, One Secondary and a Monitor

3. One Primary and More Secondary Servers

Case1:

à Upgrade the Secondary

à Upgrade the Primary

Ø Set database in offline and Upgrade

Ø Failover to the secondary and Upgrade

Ø Switch back the Log shipping (Optional)

Case2:

à Upgrade the Monitor

à Upgrade the Secondary

à Upgrade the Primary

Ø Set database in offline and Upgrade

Ø Failover to the secondary and Upgrade

Ø Switch back the Log shipping (Optional)

Case3:

à Upgrade all the secondary servers

à Upgrade the Primary

Ø Set database in offline and Upgrade

Ø Failover to one of the secondary server and Upgrade. Here remaining secondary servers

are in offline till the primary server is being enabled log shipping.

Ø Switch back the Log shipping

Protect Your Data Before the Upgrade

To protect your data

1. Perform a full database backup on every primary database

2. Run the DBCC CHECKDB command on every primary database.

Upgrading the Monitor Server Instance

The monitor server instance, if any, can be upgraded at any time.

While the monitor server is being upgraded, the log shipping configuration continues to work, but its status is not recorded in the tables on the monitor. Any alerts that have been configured will not be triggered while the monitor server is being upgraded. After the upgrade, you can update the information in the monitor tables by executing the sp_refresh_log_shipping_monitor (Transact-SQL) system stored procedure.

The Upgrade Process for Configurations with a Single Secondary Server

The upgrade process described in this section assumes a configuration consisting of the primary server and only one secondary server. This configuration is represented in the following illustration, which shows a primary server instance, A, and a single secondary server instance, B.

Upgrading the Secondary server instance

The upgrade process involves upgrading the secondary server instances of a SQL Server 2005 log shipping configuration to SQL Server 2008 before upgrading the primary server instance. Always upgrade the secondary server instance first. If the primary server were upgraded before a secondary server, log shipping would fail because a backup created on a newer version of SQL Server cannot be restored on an older version of SQL Server.

Log shipping continues throughout the upgrade process because the upgraded secondary servers continue to restore the log backups from the SQL Server 2005 primary server. While the secondary server instance is being upgraded, the log shipping copy and restore jobs do not run, so unrestored transaction log backups will accumulate. The amount of accumulation depends on the frequency of scheduled backup on the primary server. Also, if a separate monitor server has been configured; alerts might be raised indicating restores have not been performed for longer than the configured interval.

Once the secondary server has been upgraded, the log shipping agents jobs resume and continue to copy and restore log backups from the primary server instance, server A. The amount of time required for the secondary server to bring the secondary database up to date varies, depending on the time taken to upgrade the secondary server and the frequency of the backups on the primary server.

Note:
During the server upgrade, the secondary database is not upgraded to a SQL Server 2008 database. It will get upgraded only if it is brought online.

Upgrading the Primary server instance

When planning an upgrade, a significant consideration is the amount of time that your database will be unavailable. The simplest upgrade scenario involves the database being unavailable while you upgrade the primary server (scenario 1, below).

At the cost of a more complicated upgrade process, you can maximize your database availability by failing over the SQL Server 2005 primary server to a SQL Server 2008 secondary server before upgrading the original primary server (scenario 2, below). There are two variants of the failover scenario. You can switch back to the original primary server and keep the original log shipping configuration. Alternatively, you can remove the original log shipping configuration before upgrading the original primary server and later create a new configuration using the new primary server. This topic describes each of these scenarios.

Scenario 1: Upgrade Primary Server Instance Without Failover

This is the simpler scenario, but it causes more downtime than using failover. The primary server instance is simply upgraded and the database is unavailable during this upgrade.
Once the server is upgraded, the database is automatically brought back online, which causes it to be upgraded. After the database is upgraded, the log shipping jobs resume.

Scenario 2: Upgrade Primary Server Instance with Failover
This scenario maximizes availability and minimizes downtime. It utilizes a controlled failover to the secondary server instance, which keeps the database available while the original primary server instance is upgraded. Downtime is limited to the relatively short time required to fail over, rather than the time required to upgrade the primary server instance.
Upgrading the primary server instance with failover involves three general procedures:

1. Performing a controlled failover to the secondary server,
2. Upgrading the original primary server instance to SQL Server 2008,
3. Setting up log shipping on a SQL Server 2008 primary server instance.

Important:
If you plan to have the secondary server instance as the new primary server instance, you need to remove the log shipping configuration. Log shipping will need to be reconfigured from the new primary to the new secondary, after the original primary server instance has been upgraded. For more information, see Removing Log Shipping.

Procedure 1. Perform a controlled failover to the secondary server

Controlled failover to the secondary server:
1. Manually perform a tail-log backup of the transaction log on the primary database specifying WITH NORECOVERY. This log backup captures any log records that have not been backed up yet and takes the database offline. Note that while the database is offline, the log shipping backup job will fail. The following example creates a tail log backup of the AdventureWorks database on the primary server. The backup file is named Failover_AW_20080315.trn:2.

BACKUP LOG AdventureWorks

TO DISK=N’\\FileServer\LogShipping\AdventureWorks\Failover_AW_20080315.trn’

WITH NORECOVERY; GO

We recommend that you use a distinct file naming convention to differentiate the manually-created backup file from the backup files created by the log shipping backup job.

3. On the secondary server:
a. Ensure that all backups taken automatically by the log shipping backup jobs have been applied. To check which backup jobs have been applied, use the sp_help_log_shipping_monitor (Transact-SQL) system stored procedure on the monitor server or on the primary and secondary servers. The same file should be listed in the last_backup_file, last_copied_file, and last_restored_file columns. If any of the backup files have not been copied and restored, manually invoke the agent copy and restore jobs for the log shipping configuration. For more information, see How to: Start a Job (SQL Server Management Studio) or sp_start_job (Transact-SQL).

b. Copy your the final log backup file that you created in step 1 from the file share to the local location that is used by log shipping on the secondary server.

c. Restore the final log backup specifying WITH RECOVERY to bring the database online. As part of being brought online, the database will upgraded to SQL Server 2008. The following example restores the tail log backup of the AdventureWorks database on the secondary database. The example uses the WITH RECOVERY option, which brings the database online: d.

RESTORE LOG AdventureWorks

FROM DISK = N’c:\logshipping\Failover_AW_20080315.trn’

WITH RECOVERY;GO

d. Fail over the database by redirecting clients from the original primary server (server A) to the online secondary server (server B).

e. Take care that the transaction log of the secondary database does not fill while the database is online. To prevent the transaction log from filling, you might need to back it up. If so, we recommend that you back it up to a shared location, a backup share, to make the backups available for restoring on the other server instance.

Procedure 2. Upgrade the Original Primary Server Instance to SQL Server 2008

After you upgrade the original primary server instance to SQL Server 2008, the database will still be offline and in the SQL Server 2005 format.

Procedure 3. Set Up Log Shipping on SQL Server 2008

The rest of the upgrade process depends on whether log shipping is still configured, as follows:
If you have kept the SQL Server 2005 log shipping configuration, switch back to the original primary server instance. For more information, see “To switch back to the original primary server instance,” later in this section.

If you removed the log shipping configuration before failing over, create a new log shipping configuration in which the original secondary server instance is the new primary server instance. For more information, see “To keep the old secondary server instance as the new primary server instance,” later in this section.

To switch back to the original primary server instance

1. On the interim primary server (server B), back up the tail of the log using WITH NORECOVERY to create a tail-log backup and take the database offline. The tail log backup is named Switchback_AW_20080315.trn.For example:2. BACKUP LOG AdventureWorks 3. TO DISK = N’\\FileServer\LogShipping\AdventureWorks\Switchback_AW_20080315.trn’4. WITH NORECOVERY;GO

5. If any transaction log backups were taken on the interim primary database, other than the tail backup that you created in step 1, restore those log backups using WITH NORECOVERY to the offline database on the original primary server (server A). The database is upgraded to SQL Server 2008 format when the first log backup is restored.

6. Restore the tail-log backup, Switchback_AW_20080315.trn, on the original primary database (on server A) using WITH RECOVERY to bring the database online.

7. Fail over back to the original primary database (on server A) by redirecting clients to the online secondary server from the original primary server.
After the database comes online, the original log shipping configuration will resume.
To keep the old secondary server instance as the new primary server instance
Establish a new log shipping configuration using the old secondary server instance, B, as the primary server and the old primary server instance, A, as the new secondary server, as follows:

Important:

The old log shipping configuration should have been removed from the original primary server at the start of the process before taking the manual transaction log backup that took the database offline.
1. To avoid performing a complete backup and restore of the database on the new secondary server (server A), apply the log backups from the new primary database to the new secondary database. In the example configuration, this involves restoring the log backups taken on server B to the database on server A.
2. Back up the log from the new primary database (on server B).
3. Restore the log backups to the new secondary server instance (server A) using WITH NORECOVERY. The first restore operation updates the database to SQL Server 2008.
4. Configure log shipping with the former secondary server (server B) as the primary server instance.

Important:
If you use SQL Server Management Studio, specify that the secondary database is already initialized.

5. To configure log shipping
o How to: Enable Log Shipping (SQL Server Management Studio)
o How to: Enable Log Shipping (Transact-SQL)

6. Fail over the database by redirecting clients from the original primary server (server A) to the online secondary server (server B).

Important:

When you failover to a new primary database, you should ensure that its metadata is consistent with the metadata of the original primary database. For more information, see Managing Metadata When Making a Database Available on Another Server Instance.

Considerations for Upgrading Multiple Secondary server instances

This configuration is represented in the following illustration, which shows a primary server instance, A, and two secondary server instances, B and C.
Always upgrade all the secondary server instances before you upgrade the primary server.

Upgrading With Failover and Switching Back to the Original Primary Server

When upgrading the primary instance with failover the process is more complex when there are multiple secondary server instances. In the following procedure, after all the secondary servers are upgraded, the primary server is failed over to one of the upgraded secondary databases. The original primary server is upgraded, and log shipping is failed over back to it.

1. Upgrade all the secondary server instances (server B and server C).
2. Obtain the tail of the transaction log of the primary database (on server A), and take the database offline, by backing up the transaction log using WITH NORECOVERY.
3. On the secondary server to which you plan to fail over (server B), bring the secondary database online, by restoring the log backup using WITH RECOVERY.
4. On every other secondary server (server C), leave the secondary database offline by restoring the log backup using WITH NORECOVERY.

Note:

The log shipping copy and restore jobs will run on the secondary servers, but the jobs will do nothing because new log-backup files will not be placed on the backup share.

5. Fail over the database by redirecting clients from the original primary server (server A) to the online secondary server (server B). The online database becomes an interim primary server, keeping the database available while the original primary server is offline (server A).

6. Upgrade the original primary server (server A).

7. On the database to which you failed over—the interim primary database (on server B), manually back up the transaction log using WITH NORECOVERY. This takes the database offline.

8. Restore all transaction log backups that you created on the interim primary database (on server B) to every other secondary database (on server C) using WITH NORECOVERY. This allows log shipping to continue from the original primary database after its upgrade, without requiring a full database restore on each secondary database.

9. Restore the transaction log from the interim primary server (server B) to the original primary database (on server A) using WITH RECOVERY.

Redeploying Log Shipping

If you do not want to migrate your log shipping configuration using one of the procedures shown above, you can redeploy log shipping from scratch by reinitializing your secondary database with a full backup and restore of the primary database. This may be a desirable option if you have a small database or if high availability is not crucial during the upgrade procedure.
For information about enabling log shipping using SQL Server Management Studio, see How to: Enable Log Shipping (SQL Server Management Studio).

Posted in High Availability, SQL Server DBA | Tagged , , , , | Leave a comment