Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Tuesday, August 11, 2020

Microsoft SQL Server Version Details


Quick summary:

 RTM (no SP)SP1SP2SP3SP4
↓ SQL Server 201613.0.1601.513.0.4001.0
or 13.1.4001.0



↓ SQL Server 201412.0.2000.812.0.4100.1
or 12.1.4100.1
12.0.5000.0
or 12.2.5000.0
  
↓ SQL Server 2012
     codename Denali
11.0.2100.6011.0.3000.0
or 11.1.3000.0
11.0.5058.0
or 11.2.5058.0
11.0.6020.0
or 11.3.6020.0
 
↓ SQL Server 2008 R2
     codename Kilimanjaro
10.50.1600.110.50.2500.0
or 10.51.2500.0
10.50.4000.0
or 10.52.4000.0
10.50.6000.34
or 10.53.6000.34
 
↓ SQL Server 2008
     codename Katmai
10.0.1600.2210.0.2531.0
or 10.1.2531.0
10.0.4000.0
or 10.2.4000.0
10.0.5500.0
or 10.3.5500.0
10.0.6000.29
or 10.4.6000.29
↓ SQL Server 2005
     codename Yukon
9.0.1399.069.0.20479.0.30429.0.40359.0.5000
↓ SQL Server 2000
     codename Shiloh
8.0.1948.0.3848.0.5328.0.7608.0.2039
↓ SQL Server 7.0
     codename Sphinx
7.0.6237.0.6997.0.8427.0.9617.0.1063


Ref : https://sqlserverbuilds.blogspot.in/

Tuesday, August 9, 2016

Sql Server - Find the Size of Database File and Find the Size of Log File

use below script to find the size of the DB

SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, (size*8)/1024 SizeMB
FROM sys.master_files
WHERE DB_NAME(database_id) = '<<your database name>>'
GO

Wednesday, March 23, 2016

fix: sql server 2008 r2 cpu usage 100%

CPU usage can be caused by a lot of reasons like:

  • Bad execution plans caused by bad statistics
  • Locks and blocks
  • DBCC CHECKDB
  • Index rebuild
  • etc
I have faced cpu usage touch 90-100%  around 10 hour.  follow action taken but not able to fix it.

1. select * from sys.sysprocesses where blocked>=1 (kill unwanted spid) 

2. restarted sql services

3. Sp_who2 'active'

Referred following articles : 

http://www.sqlservercentral.com/Forums/Topic1411982-391-1.aspx

http://raaviblog.com/how-to-investigate-100-cpu-usage-problem-in-sql-server-2008/


 "after 8 hour search found link and offline dba support to arrive the lack of index. in maintenance activity sp_updatestats missing."

====================================================================
Query execution causing CPU spike:

Query execution  takes long times and spikes CPU commonly because of in-correct carnality estimates caused by outdated statistics, Lack of Index, Server configuration, Distributed queries, etc.

When the server is experiencing this problem run the query in below link to list all the queries which are executing in the server order by CPU time desc along with plan.
{
}
 It could be one query which is driving the majority CPU time or Multiple queries each driving the CPU. Look at the CPU time of the above query output.

If it is single query/Store procedure which is driving the majority of CPU.

1.        Update the stats of tables and indexes used by the query (If the stats are up to date Estimated rows and estimated execution will  be approximately
same in execution plan .If there is huge difference stats are out dated and requires update

=======.=====================================================


Thanks god found link and read first step and stick-out run the 

Solution: "sp_updatestats"



1) did you update ALL statistics with a FULL SCAN?

2) I would simply use profiler to capture rpc batch completed and tsql batch completed events and find the big hitters. Tune these. I would also consider running a trace to disk and using Qure from DBSophic to do aggregate trace analysis. The thing(s) you need to tune most are not necessarily the ones that run the longest or use the most resources individually...

3) it is possible that someone altered the schema in any way - i.e. dropped some indexes?

4) I also see this routinely at clients these days: did you perchance upgrade to a much better IO subsystem? Getting data into the CPUs faster can cause them to actually start earning their keep.

 



Wednesday, December 16, 2015

performance: msdb.dbo.sp_readrequest;1 – long running process

When monitoring the new installed version of SQL 2008 R2 SP1, I have encountered that Database mail leaves a hung process few minutes. This doesn’t do any blockages or other trouble to your SQL installation, either that it is anoying to see over and over again this long running process. In order to get rid off it, just check the system parameter value for “DatabaseMailExeMinimumLifeTime” running the following query:
Use msdb
GO
exec sysmail_help_configure_sp 'DatabaseMailExeMinimumLifeTime'
GO
The default setting will be 600. You need to change it to a lower period.
Use msdb
GO
exec sysmail_configure_sp 'DatabaseMailExeMinimumLifeTime', 30
GO

=================================================================

Anyone get a solution to this one?  I'm getting the same hung process today after an upgrade to 2005 SP3

Had a look at the mail logs - the process runs for 10minutes.  Which is coincidentally the same as the setting for 'Database Mail Executable Minimum Lifetime (seconds)'

When I adjusted 'Database Mail Executable Minimum Lifetime (seconds)' down from the 10 minutes default to 10 seconds everything went back to normal.  Much happiness for me. 
I am troubleshooting a similar issue, whereby the Performance Dashboard Reports (the Query Duration Component) show that a stored procedure used by Database Mail is the most costly query. It appears to be a service broker wait request, i.e. the database mail queue is waiting for further requests to process.

Based on your comments this seem like a plausable solutiuon. I have adjusted the very same Database Mail property to see if it clears this issue.

Wednesday, October 14, 2015

Find text in Stored Procedures View Trigger and Function and Troubleshoot Replication Ambiguous Column

Today I'm faced Challenge in replication when added all tables, Sps,VIEWs and user defined functions.

Error : Its return "Ambiguous Column"

Tried and found below query to identified the root cause of issue.


DECLARE @SEARCHSTRING VARCHAR(255), @notcontain Varchar(255)

SELECT @SEARCHSTRING = 'foobar', @notcontain = 'comments'

SELECT DISTINCT sysobjects.name AS [Object Name] ,
case when sysobjects.xtype = 'P' then 'Stored Proc'
when sysobjects.xtype = 'TF' then 'Function'
when sysobjects.xtype = 'TR' then 'Trigger'
when sysobjects.xtype = 'V' then 'View'
end as [Object Type]
FROM sysobjects,syscomments
WHERE sysobjects.id = syscomments.id
AND sysobjects.type in ('P','TF','TR','V')
AND sysobjects.category = 0
AND CHARINDEX(@SEARCHSTRING,syscomments.text)>0
AND ((CHARINDEX(@notcontain,syscomments.text)=0
or CHARINDEX(@notcontain,syscomments.text)<>0)) 



Tuesday, July 22, 2014

Transactions waiting to be replicated to Subscription Database (Transactional Replication)

While troubleshooting Replication issues it’s always a question till what point transaction has been replicated to subscription and from which point transaction are in distribution database waiting to be replicated to subscription database.
Replication Architecture

Let’s say distributor agent failed to replicate transaction from distributor to subscriber due to some reason and now after restarting the distributor agent it’s still not replicating the transactions.
There could be n number of reason due to which distributor agent may fail.
In this post we will focus on how to get last transaction replicated to subscriber database and what all transaction are waiting in the distributor database to be replicated.
Every time distributor agent replicates the transaction from distributor to subscriber, it does an entry in a system table dbo.MSreplication_subscriptions which exists in subscriber database.
The MSreplication_subscriptions table contains one row of replication information for each Distribution Agent.
Code: SELECT publisher,publisher_db,publication,transaction_timestamp 
FROM dbo.MSreplication_subscriptions

Transaction_timestamp value is same as xact_seqno and till this sequence number all the transaction are replicated to subscription database.
In case u does not have access to the subscription database and to find out the last replicated xact_seqno to subscriber database from distributor database
sp_MSget_last_transaction Publicationid,Publication_database
sp_MSget_last_transaction 2,TestDB
Connect to the Distributor
Code: select * from MSrepl_commands Where xact_seqno>Transaction_timestamp value
This will give you those records which are in distributor and not been replicated to subscriber database after the last replicated xact_seqno 
in subscriber database (dbo.MSreplication_subscriptions)
sp_browsereplcmds : @xact_seqno_start, @xact_seqno_end
The stored procedure will use to view pending commands in the distributor database.|
It will display the commands in the readable format.


Replication monitor will also give the xact_seqno at which distributor agent failed


You can also check the error on browsing MSrepl_errors table in distribution database.
select
*
From MSrepl_errors

In this case error is :”The row was not found at the Subscriber when applying the replicated command:
To resolve the same I have xact_seqno and command id , I simple deleted the record from the MSrepl_commands at the distributor.Once done distributor agent will start replicating pending transaction to subscriber.
DELETE from MSrepl_commands where command_id=1295 and xact_seqno=0x000260AD000000100021

Replication Architecture

Replication Architecture

Replication Troubleshooting

Basics of Replication Troubleshooting

There are many scenarios where you have been alerted for the replication failure and you have to troubleshoot the issue. In this article I will guide you what should be your approach to get the detailed error message and transaction details in replication.
First check the replication monitor and click on the failed publisher. Next step is double click on the failed subscriber from All Subscriptions list.
Now next step is click on the error and check its description.
Error :
Command attempted:
if @@trancount > 0 rollback tran
(Transaction sequence number: 0x0000044100002D93000100000000, Command ID: 1)
From the above error message we have to identify which command is failed to execute on the subscriber.
To get the exact command, find out the distributer server and distribution database for the failed publisher.
Once you get the distribution database server, execute the below query against the distribution DB.
1
2
3
4
5
use distribution
go
SELECT * FROM msrepl_commands
WHERE xact_seqno = 0x0000044100002D93000100000000
AND command_id = 1
Once you execute the above query against the distribution database, you will get the more information about the error, for example Publisher database ID, Article ID and much more…
We have to use the above details, to get the exact command using eitherSP_BROWSEREPLCMDS (If CLR is enabled) or you can cast the command column inmsrepl_commands table.
We will check both the alternatives.
Using SP_BROWSEREPLCMDS 
Please note CLR must be enabled for to use this procedure.
1
2
3
4
5
6
EXEC SP_BROWSEREPLCMDS
@xact_seqno_start = '0x0000044100002D930001',
@xact_seqno_end = '0x0000044100002D930001',
@publisher_database_id = 1033,
@article_id = 12,
@command_id= 1
By casting command column in msrepl_commands table
Please note if you want to see the better output use the Result to Text as output in SSMS (CTRL + T)
1
2
3
4
SELECT CAST(SUBSTRING(command, 7, 8000) AS NVARCHAR(MAX))
FROM msrepl_commands
WHERE xact_seqno = 0x0000044100002D930001
AND command_id = 1
Now you got the exact SQL Command. As a next step check the objects from both the publisher and the subscriber to see the violation of the keys or do the data comparisons etc.
=================================================================================

Row Not Found at the Subscriber - Replication Issue

 
When you find an issue in replication with the error “The row was not found at the Subscriber when applying the replicated command.”, first we have to get the Transaction sequence number and Command ID from the error.
This can be found at Distributer to Subscriber history in replication monitor.

Once we get the Transaction Sequence Number and Command ID we can easily drill down to the command which is causing the issue by using sp_browsereplcmds. Before to this, we have to also find out publisher_database_id.

For finding publisher_database_id, we need to make use of Transaction Sequence Number and Command ID.
Query to find publisher_database_id using Transaction Sequence Number and Command ID
select * from msrepl_commands
where xact_seqno = 0x000BF8FB0003411E000400000000 and command_id=6


Once we get the publisher_database_id from the above query, then we need to execute the below query to get the command which is causing the error.
Query to find the command which is causing error
exec sp_browsereplcmds @xact_seqno_start = '0x000BF8FB0003411E000400000000',
@xact_seqno_end = '0x000BF8FB0003411E000400000000', @Command_id=6,@publisher_database_id=60


Once we get the command, we can manually sync the missing data from publisher to subscriber to make the replication work fine as before.

Note: All these commands have to be run on distribution database.

This article is also available in pdf format for downloading.
Please Click here to get your copy.
=======================================================