Showing posts with label yogesh ranade. Show all posts
Showing posts with label yogesh ranade. Show all posts

Monday, July 22, 2013

How to quickly create a large test file for SQLIO?

Easiest way is to use FSUTIL.EXE tool which comes with all versions of Windows.

Following command will create a 2TB file.

PS C:\> FSUTIL.EXE File CreateNew D:\TestFile.DAT (2TB)
File D:\TestFile.DAT is created

Please note that CREATENEW will take longer time since it actually initializes the block to the size you mentioned (2TB in example) so easier way is to use SETVALIDDATA. This just moves the end of file marker. 

!!!Be very careful while doing this as it will overwrite already existing data!!!

PS C:\> FSUTIL.EXE File SetValidData D:\TestFile.DAT (2TB)
Valid data length is changed

To use the file size in GB or TB you must run these commands thru PowerShell. Else you must give size in bytes

Thursday, July 18, 2013

IOPS Calculator and SQLIO

I was asked by my storage admins what is SQLIO and how does it calculate IOPS throughput. And here is the how (What is SQLIO is none of their business)

So this is how output of SQLIO looks like

C:\Program Files (x86)\SQLIO>sqlio -kR -t64 -s120 -o128 -frandom -b64 -BH -LS -Fparam.txt 
sqlio v1.5.SG
using system counter for latency timings, 14318180 counts per second
parameter file used: param.txt
file D:\testfile.dat with 2 threads (0-1) using mask 0x0 (0)
file E:\testfile.dat with 2 threads (2-3) using mask 0x0 (0)
file S:\testfile.dat with 2 threads (4-5) using mask 0x0 (0)
6 threads reading for 120 secs from files D:\testfile.dat, E:\testfile.dat and S:\testfile.dat
using 64KB random IOs
enabling multiple I/Os per thread with 128 outstanding
buffering set to use hardware disk cache (but not file cache)
using specified size: 100000 MB for file: D:\testfile.dat
using specified size: 100000 MB for file: E:\testfile.dat
using specified size: 90000 MB for file: S:\testfile.dat
initialization done
CUMULATIVE DATA:
throughput metrics:
IOs/sec: 10717.27
MBs/sec:   669.83
latency metrics:
Min_Latency(ms): 8
Avg_Latency(ms): 71
Max_Latency(ms): 122
histogram:
ms: 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24+
%:  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 100

And here is the formula used to calculate IOPS

IOPS = (MBps Throughput / KB per IO) * 1024

Based on above throughput of SQLIO will be

10717.27 = (669.83 * 64) / 1024

Tuesday, May 28, 2013

Secondary Replica of AlwaysOn Availability group is in "Resolving" state after fail over

While testing AlwaysOn Availability groups I failed over primary to secondary couple of times. However 3rd time when I failed over the secondary did not come up immediately and was in “Resolving” state.

Problem was with maximum failures threshold. By default it is set to 2 failures in 6 hours.


So since I failed over AG more than 2 times within an hour it tripped the maximum failures threshold for this clustered resource and came up with “Resolving” state.

Solution 1: wait for default period of 6 hours.
Solution 2: Change the threshold and fail back to original primary.

Default failback setting is set to immediate. I would also recommend setting it to Prevent Failback.

Here is how I have configured my availability group clustered resource


Following KB also has other scenarios

http://support.microsoft.com/kb/2833707?wa=wsignin1.0

Please note that I used these configurations only for testing. You may need to reconsider for your production setup depending your fail over needs



Friday, May 17, 2013

Error while adding Replica to SQL Server 2012 AlwaysOn Availability group


Problem: While adding secondary replica to AlwaysOn Availability group you get following error




TITLE: Connect to Server
------------------------------
Cannot connect to REPLICASERVER.
------------------------------
ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 5)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=5&LinkId=20476

Solution: Most likely Named Pipe provider for SQL is disabled on secondary instance


Open SQL Server Configuration Manager and click on Protocols for MSSQLSERVER under SQL Server Network Configuration

Enable Named Pipes provides


Restart SQL Services

Then try adding the replica again in New AlwaysOn Availability Group Wizard







Error when opening New AlwaysOn Availability Group Wizard in SSMS 2012


Problem: If you are setting up availability group using New AlwaysOn Availability Group Wizard and if you get following error message.


TITLE: Microsoft SQL Server Management Studio
------------------------------
The local node is not part of quorum and is therefore unable to process this operation. This may be due to one of the following reasons:
•   The local node is not able to communicate with the WSFC cluster.
•   No quorum set across the WSFC cluster.
 For more information on recovering from quorum loss, refer to SQL Server Books Online.
(Microsoft.SqlServer.Management.HadrTasks)


Solution 1: Go to SQL Server Configuration Wizard and disable AlwaysOn High Availability 


Restart SQL.
After restart enable AlwaysOn High Availability again thru SQL Configuration Manager. 
Restart SQL Services
and try again to open the wizard

Solution 2: make sure all pre-requisites are setup properly. Refer to following link



Wednesday, April 10, 2013

How to rebuild system databases in SQL Server 2008

setup.exe /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=instance_name /SQLSYSADMINACCOUNTS= accounts [/SAPWD=password] [/SQLCOLLATION=collation_name]

Thursday, April 4, 2013

How to create FileTable in SQL Server 2012


1.  Create Windows file share and grant R/W permission to SQL Service account




2.  Enable FileStream for Instance: Open SQL Configuration Manager. Right click on SQL Server service. Go to FILESTREAM tab and enable by providing windows file share created in step 1







3.  Create FileStream enabled database

CREATE DATABASE FileStreamDB
ON
PRIMARY ( NAME = FileStreamDB_data,
    FILENAME = 'D:\MSSQL\Data\FileStreamDB.mdf'),
FILEGROUP FileStreamGroup1 CONTAINS FILESTREAM( NAME = FileStreamDB_FS_Data,
    FILENAME = 'D:\MSSQL\Data\FileStream')
LOG ON  ( NAME = FileStreamDB_log,
    FILENAME = 'E:\TransactionLogs\FileStreamDB.ldf')
GO
4.  Alter DB to provide filestream directory name

USE [master]
GO
ALTER DATABASE [FileStreamDB] SET FILESTREAM( DIRECTORY_NAME = N'FileStream' ) WITH NO_WAIT
GO

5.  Create filetable


USE FileStreamDB
GO
IF OBJECT_ID('dbo.testFileTable', 'U') IS NOT NULL
  DROP TABLE dbo.testFileTable
GO
CREATE TABLE dbo.testFileTable AS FILETABLE
  WITH
  (
    FILETABLE_DIRECTORY = 'FileTable',
    FILETABLE_COLLATE_FILENAME = database_default
  )
GO

6.  Verify filestream directory by right clicking on the table and selecting Explore FileTable directory


7.  We can copy files to the directory or load files into filetable we can use either bulk insert

INSERT INTO [dbo].testFileTable
([name],[file_stream])
SELECT
'Yogesh.JPG', * FROM OPENROWSET(BULK N'D:\MSSQL\Data\FileStream\Yogesh.JPG', SINGLE_BLOB) AS FileData
GO


8.  Same was you can delete files by manually deleting from folder or running DELETE statement

9.  Verify data

USE FILESTREAMDB
GO
SELECT [name]
,[file_type]
,CAST([file_stream] AS VARCHAR) FileContent
,[cached_file_size]
,[creation_time]
,[last_write_time]
,[last_access_time]
FROM [dbo].testFileTable
GO

Friday, March 8, 2013

Disk related counters not showing in PerfMon on Windows 2008 Server where SQL Server instance is running



Default counters like physical disk, logical disk are overridden by SQL server perfmon config files which are in *.INI files under following location

C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\

You will have to manually rebuild performance counter library values to include other non-SQL counters

Please refer to following link for rebuilding counter library

Here are the steps from the above link (In case link breaks in future)
Rebuild the base performance counters
Extensible counter information is stored in both of the following locations:
·         The following registry subkey:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\Current Version\Perflib\009
·         The %Systemroot%\System32\Perfc009.dat file and the %Systemroot%\System32\Perfh009.dat file
To rebuild the base performance counter libraries manually, follow these steps:
1.       Expand the Perfc009.dat file and the Perfh009.dat file. These files are located on the Windows Installation Disc. The compressed files are found at DriveLetter:\i386\perfc009.da_ and at DriveLetter:\i386\perfh009.da_. Replace the files that are in the %Systemroot%\System32 folder.
2.       Start Registry Editor, and then locate the following key in the registry:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Perflib
3.       In the registry, change the Last Counter value to 1846 (decimal), and change the Last Help value to 1847 (decimal).
4.       Locate the following registry key to search for services that have a Performancesubkey:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
5.       Remove the following values from the Performance subkey (if they exist):
o    First Counter
o    First Help
o    Last Counter
o    Last Help
You can also use the Exctrlst.exe tool to locate the performance counter dynamic-link library files (DLLs) that are installed, and then access the registry to remove the DWORD values. You now have a workable performance registry that contains only system base counters.

Note
 Removing the values from the Performance subkey in the registry may cause any installed .NET Framework applications not to work the next time that they are started. If this occurs, use the lodctr /R command in the "Re-add the extensible counters" section to rebuild the Performance counters. If you continue to have problems when you start a .NET Framework application, see the "Reinstall any custom .NET Framework assembly performance counters" section in this article.

Tuesday, January 15, 2013

How to change SQL Server collation after installation?


Once SQL Server is installed the selected collation setting applies to all system databases. For user databases collation can be changed after database is created but for all system databases it remains the same as the one selected during SQL Server installation. There are two ways to do it. First is to reinstall and second is to rebuild system databases

Following command can be used to rebuild

Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=TESTSERVER\administrator /SAPWD=SA_password /SQLCOLLATION=Latin1_General_CI_AS

Monday, December 17, 2012

How to move MSDTC from one SAN storage to other


Note: Please take backup of MSDTC folder .

From the current host server(the node where quorum drive visible) ,open the Failover Cluster Management. In the left pane expand the Services and Application group and select the MS-DTC resource. From the summary window note down the Server network name and IP address to use in our later steps.

The next step is to get  the new SAN disk in the cluster. To add the disk to the cluster follow the steps given below:

Ø  Open the windows disk manager.
Ø  Right click the new disk  in Windows Disk Management and select online.
Ø  Right click again and select initialize.
Ø  Finally format it by right clicking the disk and selecting New Simple Volume.
Ø  This will open Simple Volume Wizard. Provide the new drive letter and label for the disk.
Ø  In the Cluster Manager ,select the storage in the  left pane.
Ø  Select the Add Disk in the Action pane and select the proposed new disk.

Now we can see this disk under the available storage group.
Everything is ready to make the move.
Unfortunately we can't move existing MSDTC to the new disk directly. The only option is delete the existing one and add new MSDTC.

Follow the below steps to delete and add new MSDTC resource:

Ø  In the cluster manager ,expand the services and applications
Ø  Right click  the MSDTC  group and select Delete.
Ø  Now the existing MSDTC  disk (call it  X drive) will be available under the available storage.
Ø  Select the old disk  under the storage and click on change drive letter option available in the activity pane
Ø  Select None as new drive letter and click Ok button
Ø  Select the new disk  under the storage  and click on change drive letter option available in the activity pane
Ø  Select X as new drive letter and click Ok button

The last four steps are done to keep the drive letter for new disk as same as the old one. These four steps are not mandatory to perform.

Ø  Right click on the Services and Application and select Configure Services or Application option
Ø  This will open the high availability wizard screen.
Ø  Select next which will list Services or application that can be configured for the high availability. Select the Distributed Transaction Coordinator(DTC)
Ø  Select Next which will open the client access point configuration screen as given below. Enter the network name and IP address which we have noted down in the first step.
Ø  Select Next, which will open the storage configuration screen. This will list all the disk available under the available storage group. Select the appropriate disk and click Next
On clicking Next, it will directed into the confirmation screen and click again on Next will complete configuration. Now the MSDTC is configured in the SAN disk and can be verified by opening the disk in the windows explorer. Now we should be able to see the MSDTC  folder inside the new drive which confirms the movement.

Bring this service online. Set the preferred owner through the properties window and test the failover.


Monday, November 26, 2012

How to open a program in Windows 2008 and above using a different Windows account?


Before Windows Server 2008 there used to be an option to open a program like SQL Server Management Studio using different Windows account. You can open any program and say “Run as”.

This was helpful when you have domain accounts running SQL Services.

But in Windows 2008 and above "Run as" option has been removed.

So to open SSMS as some other domain account you can use following command in command prompt

runas /netonly /user:domain\user "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"

Change domain\user and program file exe file

Saturday, October 27, 2012

Find last time when transaction log backup


Find last time when transaction log backup

b.type = 'L' means transaction log
b.type = 'D' means full
b.type = 'I' means differential

SELECT   d.name,
         MAX(b.backup_finish_date) AS backup_finish_date
FROM     master.sys.sysdatabases d WITH(NOLOCK)
         LEFT OUTER JOIN msdb..backupset b WITH(NOLOCK)
         ON       b.database_name = d.name
         AND      b.type          = 'L'
WHERE b.backup_finish_date IS NOT NULL        
GROUP BY d.name
ORDER BY backup_finish_date ASC

Monday, September 17, 2012

Uninstalling SQL Server Service Pack


Starting form SQL Server 2008 SP1, you will be able to uninstall service packs from Add/remove Programs and Features. Uninstall wizard will launch through this.

For all versions of SQL before SQL Server 2008 SP1 please refer to following link

Tuesday, August 21, 2012

SQL Server 2012 Failover cluster error (Windows Event ID 1119)


Recently I installed SQL Server 2012 RTM on a Windows failover cluster. After installation when I tried to fail over SQL server resources from N1 to N2 I got following error
Cluster network name resource 'SQL Network Name (MyServer)' failed to register DNS name 'MyServer.' over adapter 'Local Area Connection*' for the following reason:  'DNS server failure.'

I found the event ID and resolution on technet

But it was nothing to do with the solution mentioned on technet article.

My problem was SQL server service account was not part of the Local Administrators group. (Which I should have done before installing…dumb!!)
So here is how you add SQL service account to local
1)      Go to Start à Administrative Tools à Server Manager
2)      Expand Configuration
3)      Expand Local Users and Groups
4)      Select Groups
5)      Double click on Administrators
6)      Click on Add button
7)      Enter SQL Service account (Account under which SQL services are running)
8)      Click OK
After doing this I was able to failover SQL Server to passive node

Friday, August 17, 2012

Microsoft Security Bulletin MS12-060 – Critical


On Aug 14th 2012 Microsoft released security bulletin which includes an update for SQL Server. Please read the details in below link

As stated updates included in KB2598041 which was part of security bulletin MS12-027 (http://www.microsoft.com/en-us/download/details.aspx?id=29372) are replaced with KB2687441 (http://support.microsoft.com/kb/2687441)

So important question is do you need to install this security update?

If you look under the replacement update KB2687441 then the it applies only to the host machines which have Microsoft Office installed on it. Specifically
2007 Microsoft Office Suite Service Pack 3
2007 Microsoft Office Suite Service Pack 2
Usually it is not a standard practice to install MS Office on database servers so most likely you do not need this security update.
In case you do have Microsoft Office installed on one of you database servers and have one of the following versions of SQL Server installed then you need to install this security update
Microsoft SQL Server 2000 Service Pack 4
Microsoft SQL Server 2000 Analysis Services Service Pack 4
Microsoft SQL Server 2005 Express Edition with Advanced Services Service Pack 4
Microsoft SQL Server 2005 for 32-bit Systems Service Pack 4
Microsoft SQL Server 2005 for x64-based Systems Service Pack 4
Microsoft SQL Server 2005 for Itanium-based Systems Service Pack 4
Microsoft SQL Server 2008 for 32-bit Systems Service Pack 2
Microsoft SQL Server 2008 for 32-bit Systems Service Pack 3
Microsoft SQL Server 2008 for x64-based Systems Service Pack 2
Microsoft SQL Server 2008 for x64-based Systems Service Pack 3
Microsoft SQL Server 2008 for Itanium-based Systems Service Pack 2
Microsoft SQL Server 2008 for Itanium-based Systems Service Pack 3
Microsoft SQL Server 2008 R2 for 32-bit Systems
Microsoft SQL Server 2008 R2 for 32-bit Systems Service Pack 1
Microsoft SQL Server 2008 R2 for 32-bit Systems Service Pack 2
Microsoft SQL Server 2008 R2 for x64-based Systems
Microsoft SQL Server 2008 R2 for x64-based Systems Service Pack 1
Microsoft SQL Server 2008 R2 for x64-based Systems Service Pack 2
Microsoft SQL Server 2008 R2 for Itanium-based Systems
Microsoft SQL Server 2008 R2 for Itanium-based Systems Service Pack 1
Microsoft SQL Server 2008 R2 for Itanium-based Systems Service Pack 2

Wednesday, July 11, 2012

How to find all tables and views used in a SQL Server Analysis services cube?


Someone asked me today if there is an easy way to find all tables, views used in a SSAS cube. You can always see XMLA file to find the tables or check the data source view in the cube definition. But we have some cube databases which have more than 100 tables and going through XMLA or DSV is time consuming.

Good thing is Microsoft provides DMVs explore metadata of a cube database. Here is a sample query to get meta data for a cube

  1. Connect to the SSAS instance via SSMS.
  2. Open new MDX query
  3. Copy paste the query below
    SELECT * FROM $SYSTEM.MDSCHEMA_DIMENSIONS
    WHERE CUBE_NAME = 'cube_name'AND DIMENSION_NAME <> 'Measures'
  1. Change the cube name and execute the query

Tuesday, July 10, 2012

SQL Server Integration Services name for clustered SQL Server installation or named instance of SQL



After you install SQL Server on an Active/passive cluster you need to provide cluster name for SQL Server Integration Services instance. Same is case for named instance of SQL server where you have to provide

Lets assume for a cluster with 2 nodes Server1N1 and Server1N2; the cluster name is Server1. Here is how your MsDtsSrvr.ini.xml should look like.

<?xml version="1.0" encoding="utf-8"?>
<DtsServiceConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <StopExecutingPackagesOnShutdown>true</StopExecutingPackagesOnShutdown>
  <TopLevelFolders>
    <Folder xsi:type="SqlServerFolder">
      <Name>MSDB</Name>
      <ServerName>Server1</ServerName>
    </Folder>
    <Folder xsi:type="FileSystemFolder">
      <Name>File System</Name>
      <StorePath>..\Packages</StorePath>
    </Folder>
  </TopLevelFolders>
</DtsServiceConfiguration>

For a named instance is should be

<?xml version="1.0" encoding="utf-8"?>
<DtsServiceConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <StopExecutingPackagesOnShutdown>true</StopExecutingPackagesOnShutdown>
  <TopLevelFolders>
    <Folder xsi:type="SqlServerFolder">
      <Name>MSDB</Name>
      <ServerName>Server1\InstanceName</ServerName>
    </Folder>
    <Folder xsi:type="FileSystemFolder">
      <Name>File System</Name>
      <StorePath>..\Packages</StorePath>
    </Folder>
  </TopLevelFolders>
</DtsServiceConfiguration>

MsDtsSrvr.ini.xml can be found under SQL server installation directory

C:\Program Files\Microsoft SQL Server\100\DTS\Binn

Once INI file is changed you need to restart SSIS service to it to take effect 

Wednesday, June 27, 2012

How to connect to SQL Express 2005/2008/2008 R2 using SA account?


By default Microsoft will disable SA account and only Windows Authentication Mode is enabled. So when you try to connect to SQL Express instance using sa account it will not work. Also by default SA account is disabled in SQL Express instance

There are 2 things which we need to do to gain access using SA account

  1. Enable SA account
  2. Change authentication mode from Windows only to Mixed mode


And there are 2 ways to achieve this

  1. GUI
    1. Enable SA account
                                                               i.      Download SSMS Express for SQL Server Express (http://www.microsoft.com/downloads/)
                                                             ii.      Connect to SQL Express instance MACHINE\INSTANCE
                                                            iii.      Expand Security tab
                                                            iv.      Double click on SA account
                                                              v.      Under General page type in new password
                                                            vi.      Confirm the password
                                                           vii.      On Status page Enable the account
                                                         viii.      Click OK
    1. Change authentication mode
                                                               i.      Right click on instance name in SSMS
                                                             ii.      Select Security page
                                                            iii.      Under Server authentication select “SQL Server and Windows Authentication mode”
                                                            iv.      Click OK
                                                              v.      Go to services.msc and restart SQL Express service
    1. Connect using SA by SQLCMD or OSAL
                                                               i.      SQLCMD -S MACHINE\INSTANCE -U sa -P password
                                                             ii.      Osql –S MACHINE\INSTANCE –U sa –P password
  1. Programmatically
    1. Connect to SQL Express instance using NT authentication
                                                          i.      On command prompt use SQLCMD -S MACHINE\INSTANCE –E
    1. Enable SA account
                                                          i.      Run following to change password and enable SA account
USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD=N'P@s$w0rd'
GO
ALTER LOGIN [sa] ENABLE
GO
    1. Change authentication mode to mixed
                                                          i.      Using SQLCMD

USE [master]
GO
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2
GO
    1. Restart services for SQL express instance
    2. Connect to SQL express using SA
                                                               i.      SQLCMD -S MACHINE\INSTANCE -U sa -P password
                                                             ii.      Osql –S MACHINE\INSTANCE –U sa –P password

As a security practice Microsoft disabled SA and hope you find this article helpful in enabling and using it.