How to get sql server performance counters using query?
Hai i want to see my sql server performance counters like, Full Scans/sec, Buffer
Cache Hit Ratio, Database Transactions/sec, User
Connections, Average Latch Wait Time (ms), Lock
Waits/sec, Lock Timeouts/sec, Number
of Deadlocks/sec, Total Server Memory, SQL
Re-Compilations/sec, User Settable Query. If any one know how to get it by using query means, please help me.
Thanks in advance
Hello,
Below is query created by Jonathan Kehayias for measuring Perfom counters using DMV sys.dm_os_performance_counter.
You can download book from below link
https://www.simple-talk.com/books/sql-books/troubleshooting-sql-server-a-guide-for-the-accidental-dba/
DECLARE @CounterPrefix NVARCHAR(30)
SET @CounterPrefix = CASE WHEN @@SERVICENAME = 'MSSQLSERVER'
THEN 'SQLServer:'
ELSE 'MSSQL$' + @@SERVICENAME + ':'
END ;
-- Capture the first counter set
SELECT CAST(1 AS INT) AS collection_instance ,
[OBJECT_NAME] ,
counter_name ,
instance_name ,
cntr_value ,
cntr_type ,
CURRENT_TIMESTAMP AS collection_time
INTO #perf_counters_init
FROM sys.dm_os_performance_counters
WHERE ( OBJECT_NAME = @CounterPrefix + 'Access Methods'
AND counter_name = 'Full Scans/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Access Methods'
AND counter_name = 'Index Searches/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Buffer Manager'
AND counter_name = 'Lazy Writes/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Buffer Manager'
AND counter_name = 'Page life expectancy'
OR ( OBJECT_NAME = @CounterPrefix + 'General Statistics'
AND counter_name = 'Processes Blocked'
OR ( OBJECT_NAME = @CounterPrefix + 'General Statistics'
AND counter_name = 'User Connections'
OR ( OBJECT_NAME = @CounterPrefix + 'Locks'
AND counter_name = 'Lock Waits/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Locks'
AND counter_name = 'Lock Wait Time (ms)'
OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
AND counter_name = 'SQL Re-Compilations/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Memory Manager'
AND counter_name = 'Memory Grants Pending'
OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
AND counter_name = 'Batch Requests/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
AND counter_name = 'SQL Compilations/sec'
-- Wait on Second between data collection
WAITFOR DELAY '00:00:01'
-- Capture the second counter set
SELECT CAST(2 AS INT) AS collection_instance ,
OBJECT_NAME ,
counter_name ,
instance_name ,
cntr_value ,
cntr_type ,
CURRENT_TIMESTAMP AS collection_time
INTO #perf_counters_second
FROM sys.dm_os_performance_counters
WHERE ( OBJECT_NAME = @CounterPrefix + 'Access Methods'
AND counter_name = 'Full Scans/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Access Methods'
AND counter_name = 'Index Searches/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Buffer Manager'
AND counter_name = 'Lazy Writes/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Buffer Manager'
AND counter_name = 'Page life expectancy'
OR ( OBJECT_NAME = @CounterPrefix + 'General Statistics'
AND counter_name = 'Processes Blocked'
OR ( OBJECT_NAME = @CounterPrefix + 'General Statistics'
AND counter_name = 'User Connections'
OR ( OBJECT_NAME = @CounterPrefix + 'Locks'
AND counter_name = 'Lock Waits/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Locks'
AND counter_name = 'Lock Wait Time (ms)'
OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
AND counter_name = 'SQL Re-Compilations/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'Memory Manager'
AND counter_name = 'Memory Grants Pending'
OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
AND counter_name = 'Batch Requests/sec'
OR ( OBJECT_NAME = @CounterPrefix + 'SQL Statistics'
AND counter_name = 'SQL Compilations/sec'
-- Calculate the cumulative counter values
SELECT i.OBJECT_NAME ,
i.counter_name ,
i.instance_name ,
CASE WHEN i.cntr_type = 272696576
THEN s.cntr_value - i.cntr_value
WHEN i.cntr_type = 65792 THEN s.cntr_value
END AS cntr_value
FROM #perf_counters_init AS i
JOIN #perf_counters_second AS s
ON i.collection_instance + 1 = s.collection_instance
AND i.OBJECT_NAME = s.OBJECT_NAME
AND i.counter_name = s.counter_name
AND i.instance_name = s.instance_name
ORDER BY OBJECT_NAME
-- Cleanup tables
DROP TABLE #perf_counters_init
DROP TABLE #perf_counters_second
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
Similar Messages
-
How to get SQL server IP ?
Hi ALL ,
I am using this script to get the SQL server IP address but it is working on one of the servers and generating an error on the other
SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS') [Machine Name]
,SERVERPROPERTY('InstanceName') AS [Instance Name]
,LOCAL_NET_ADDRESS AS [IP Address Of SQL Server]
,CLIENT_NET_ADDRESS AS [IP Address Of Client]
FROM SYS.DM_EXEC_CONNECTIONS
WHERE SESSION_ID = @@SPID
there error I am getting is
Invalid object name 'SYS.DM_EXEC_CONNECTIONS'.
Any ideas how to get it to work ?Do you have
VIEW SERVER STATE permission?
Can you execute below SQL and post us the output?
SELECT HAS_PERMS_BY_NAME(null, null, 'VIEW SERVER STATE');
Also, Can you check the existence of the DMV under master database -> views->system views of the server?
--Prashanth -
Hello,
I use Entity Framework code first approach.
My project is working fine with SQL Server. But, I want to access Oracle too. I want to switch SQL Server and Oracle in run time.
I am able to access Oracle using "Oracle.ManagedDataAccess.EntityFramework.dl" in a new project.
But, Is this possible to access SQL Server and Oracle in the same project.
Thanks,
MuruganThis should be possible with a Code-First workflow. In Code-First the database mapping layer is generated at runtime.
David
David http://blogs.msdn.com/b/dbrowne/ -
How to get current server node information uses webdynpro?
Hi,everybody!
Can I use webdynpro to get the current logined on sever node informaition,such as server node id,server node number.This problem is resolved.
-
How to compare 2 dates in SQL Server 2000 DB using Java?
How do you compare 2 dates in SQL Server 2000 DB using Java?
Let's say we have two fields: Date Reported and Target Finish Date.
Date Reported is 09-10-2004 09:55:55: PM
Target Finish Date is 09-12-2004 11:59:59: PM
What i want to happen is i want to convert both dates to days and get the difference of the two.
can SQL Server 2000 DB do this?it doesnt wrk.
ok here's what i did:
iv tested a simple code for this case.
I created a table name tblDate which has 3 columns namely date_ID, date_From (datatype datetime), date_To (datatype datetime).
I inserted 1 row: date_ID has the value 1, date_From has the value 10/22/2004, and date_To has the value 10/24/2004.
i run the java code below:
int days = 0;
String query = "SELECT date_From, date_To cast(date_From-date_To AS int) AS Diff FROM tblZoo WHERE date_ID = '1'";
try
DBConnect db = new DBConnect();
db.openCon();
ResultSet rs = db.execute(query);
while(rs.next())
days = rs.getInt("Diff");
db.closeCon();
catch (Exception ex)
System.out.println("Error on Execution: " + ex);
return days;___________
an error occurred: Error on Execution: java.lang.nullpointerexception -
How much memory sql server is using
Hi Experts,
I want to know how much of RAM is currently used by sql server.
is there a query for the same?
we are using sql server 2008 R2 SP2 on windows server 2008 R2 with a RAM of 48 GB. min memory as 40, max memory as 43GB.
thanks in advance.
Cheers, Vinod MalloluHi Shanky
Thanks for the info. Perhaps you can clarify something for me on it.
If I run this on one of my production servers:
SELECT object_name, cntr_value MemoryUsageKB, cntr_value/1024 MemoryUsageMB,cntr_value/1024/1024 MemoryUsageGB
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Total Server Memory (KB)';
select physical_memory_in_use_kb,
(physical_memory_in_use_kb/1024) as Phy_mem_MB,
(virtual_address_space_committed_kb/1024) as Total_mem_MB--memory pagefile+physical memory
from sys.dm_os_process_memory
I get this:
object_name
MemoryUsageKB
MemoryUsageMB
MemoryUsageGB
SQLServer:Memory Manager
118488256
115711
112
physical_memory_in_use_kb
Phy_mem_MB
Total_mem_MB
118363564
115589
231792
As I have LPIM enabled I'm surprised at the Total_mem_MB result, page file usage is at 0.09%. Any idea why it would be reported like that?
I'm also surprised that the DMV is reporting a lower number for physical memory usage than the perfmon counter, but I guess they're not measuring the exact same thing.
Edit: Version is SQL 2012 SP2 CU2....should have included that :) -
How much memory does SQL Server 2008R2 Standard use on Windows Server 2008 R2 64-bit?
Hi,
can anyone tell me how much RAM will really be used by SQL Server?
72 GB are currently installed. As Windows is only able to use 32 GB is SQL Server able to use the other 40GB + the unused part of the first 32 GB?
Thank you very much!
BR MatthiasSorry, I don´t understand your post ?!
Maybe the question is if SQL Server is able to allocate more memory than the installed Windows Version is able to?
Since your OS is Windows Standard edition(X64) it cannot use or a process running cannot use more than 32 G of memory.
Now SQL server can use as much memory possible but it is now limited by Windows as your OS can only see 32 G.So it would be good part from your side to go to sp_configure and set 25 G for SQL server and can leave rest for OS( it just a figure not a actual
value i have given,actual you have to calculate by yourself or refer to below link) .
http://mssqlwiki.com/2013/04/22/max-server-memory-do-i-need-to-configure/
As Andrew said after 32 G what ever memory you put it is waste.
Hope this helps
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers -
How to connect SQL server using JRun
I am relatively dumb into Java. I am running JRun server in Unix box, and I need to connect to the SQL server (full marks for guesssing that SQL server is on the Win2K box).
Now I want to connect to the SQL server from Jrun using JSPs.
Question:
1. Is JDBC:ODBC only way to connect to the SQL server, if yes -
2. Do I have to create a DSN on the server for the JDBC:ODBC bridge to work
3. Can I write my own database connection package,
Appreciate if any body can help me with this problem, and if you have written a package to connect to the database, then would be nice if you would let me try the same.
If you have any responses, please email me at [email protected]
Thanks in Advance for the anticipated help.
Viviar PrasadHi Prasad,
There is two ways(what I have done) to connect to sql server in jRun..
1) using your jdbc - odbc connectivity using your type one jdbc driver..
2) using type 4 driver.. (type 2 and 3 are not available right now for sql server)
in 1 you have to create an dsn and use it directly in program bypassing jrun management console(I mean u don't have to configure for that)
in 2 case you need to use jrun proprietery driver for the jdbc... there is a problem here..
this driver is available in Jrun 3.0 enterprise edition only and still has got some problem so you need to apply service pack-2 to your Jrun installation and need to download the driver.. jdbc driver from following link
ftp://ftp.allaire.com/kbftp/jrun/all/jrun_drivers.jar.zip
this will suply a html doc along with the driver . which will explain you how to apply..
you can download jdbc driver specilly for sql server from this link http://www.j-netdirect.com/jsqlconnect2_26.zip
but it will expire in a month..
any way once you have obtain any of the above driver, follow these step to configure jdbc in jrun.. you need to put the driver in the classpath..
1 - open your management console
2- select the webapplication for which you want to configure from left frame of mc(management console)
3- select jdbc data source click the add button and follow the wizard..
for more info ref to jrun quick start configuring jdbc settings that came with your JRun..
or you can directly click the link there and type
the name of the
first
datasource(you have supply any name you will be using that to access db in your java prog)
second name of the the jdbc driver
for Jrun it's
allire.jrun.jdbc.JRunDriver
for net direct
com.jnetdirect.jsql.JSQLDriver
third
url for jrun driver
jdbc:jrun:sqlserver://hostname:portno/databasename = dbname; USER = uname; Password = password
where dbname is your database name
uname is your sql server user name e.g sa
password is your password for the corresponding user name
where hostname is the name of the computer where your sqlserver is running it could be an ip e.g 10.0.0.32:1433
1433 is the default port no for the sqlserver if you are using tcp protocol to connect to the sql server
url for net direct
jdbc:JSQLConnect//hostname:port/databasename=dbname; USER =uname; Password = password
for any more information on this you can mail me in this id
[email protected]
All the best..
regards
Bishwa -
How to connect Sql Server 2000 using JDBC ODBC Driver
How to connect Sql Server 2000 using JDBC ODBC Driver ?
plz Send Syntax.
thanksIn SQL Server 2000 the driver class is com.microsoft.jdbc.sqlserver.SQLServerDriver
The connection URL for the default SQL Server 2000 database is jdbc:sqlserver://localhost:1433
Class.forName(
"com.microsoft.sqlserver.jdbc.
SQLServerDriver");
String url =
"jdbc:sqlserver://localhost:1433";
Connection conn = DriverManager.
getConnection(
url, "sa", "sqlserver"); -
How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?
I tried using DROP Tables, Truncate Database, Delete and many more but it is not working. I want to delete all tables using Query Analyzer, i.e. through SQL Query.
Please help me out in this concern.
Nishith ShahInformative thread indeed. Wish I saw it early enough. Managed to come up with the code below before I saw this thread.
declare @TTName Table
(TableSchemaTableName
varchar
(500),
[status] int
default 0);
with AvailableTables
(TableSchemaTableName)
as
(select
QUOTENAME(TABLE_SCHEMA)
+
+
QUOTENAME(TABLE_NAME)
from
INFORMATION_SCHEMA.TABLES)
insert into @TTName
(TableSchemaTableName)
select *
from AvailableTables
declare @TableSchemaTableName varchar
(500)
declare @sqlstatement nvarchar
(1000)
while 1=1
begin
set @sqlstatement
=
'DROP TABLE '
+ @TableSchemaTableName
exec
sp_executeSQL
@sqlstatement
print
'Dropped Table : '
+ @TableSchemaTableName
update @TTName
set [status]
= 1
where TableSchemaTableName
= @TableSchemaTableName
if
(select
count([Status])
from @TTName
where [Status]
= 0)
= 0
break
end -
How to access database in Sql Server 7.0 using Java
I am trying to access a database in SQL Server 7.0 using JDBC.But it is giving me errors.I have used following statements to connect the database
private String URL = "jdbc:odbc:DatabaseName";
private String userName="user";
private String passWord="password";
Class.forName( "sun.jdbc.odbc.SQLServerDriver" );
connection = DriverManager.getConnection( URL,userName,"passWord" );
where "username" and "password" are user Name and password respectively to access the database in SQL Server 7.0.I am sorry but I have written like;
private String URL = "jdbc:odbc:DatabaseName";
private String userName="user";
private String passWord="password";
Class.forName( "sun.jdbc.odbc.jdbcOdbcDriver" );
connection = DriverManager.getConnection( URL,userName,"passWord" );
where "username" and "password" are user Name and password respectively to access the database in SQL Server 7.0. And I have used the same name in "ODBC data source" as that of the database.I am trying some examples from book and these examples just work fine with MS Access( I created those databases in Access and tried the examples) but not with SQL Server 7.0. Do I need a separate driver or something? -
How to restore SQL Server 2008 database to SQL Server Express 2012
How to restore SQL Server 2008 database to SQL Server Express 2012.
I BACKED UP a SQL Server 2008 database from work, which runs the enterprise version of 2008, and I tried to RESTORE it to my new 64-Bit home PC which is running the new SQL Server Express 2012 64-Bit (Advanced Edition).
But if fails. I get the following message text.
Can anyone help me please. I thought restoring a 2008 database to the later version 2012 would be possible.
Here is the error message. Thanks.
TITLE: Microsoft SQL Server Management Studio
Restore of database failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The database was backed up on a server running version 8.00.2039. That version is incompatible with this server, which is running version 11.00.3128. Either restore the database on a server that supports the backup, or use a
backup that is compatible with this server. (Microsoft.SqlServer.SmoExtended)ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The database was backed up on a server running version 8.00.2039. That version is incompatible with this server, which is running version 11.00.3128. Either restore the database on a server that supports the
backup, or use a backup that is compatible with this server. (Microsoft.SqlServer.SmoExtended)
Are you sure your database is SQL server 2008 from error message it seems your SQL server version is 2000.I guess you have multiple versions of SQL server.
AFAIK you cannot restore backup of SQL server 2000 to 2012 directly .Restore it first to SQL 2008/2008R2 or 2005 then take backup again of new database created and then you would be able to restore it on 2012.Its kind of intermediate way
Also make sure your DB size is less than 10 G as max DB size supported by Express edition is 10 G and if your DB size is more than 10 G restore will fail.
You are also trying to restore enterprise DB backup on express edition so you will loose enterprise features on express edition
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers -
Getting SQL Server Agent running
I am trying to get my SQL Server Agent running, and no conventional means thus far have worked.
I set it to run automatically in the Services window of the Control Panel. Attempting to run it from there yields the error "The SQL Server Agent (BENTLEYECAD) service on Local Computer started then stopped. Some services stop automatically if they
are not in use by services or programs"
Attempting to start the Server agent in the Server configuration manager yields the error "The request failed or the service did not respond in a timely fashion. Consult the event log or other applicable error logs for details"
The resulting error log in SQLAGENT.OUT is
2015-02-19 15:58:44 - ? [100] Microsoft SQLServerAgent version 10.50.1600.1 (x86 unicode retail build) : Process ID 6064
2015-02-19 15:58:44 - ? [101] SQL Server HFC-RND-104-D\BENTLEYECAD version 10.50.1600 (0 connection limit)
2015-02-19 15:58:44 - ? [102] SQL Server ODBC driver version 10.50.1600
2015-02-19 15:58:44 - ? [103] NetLib being used by driver is DBNETLIB.DLL; Local host server is HFC-RND-104-D\BENTLEYECAD
2015-02-19 15:58:44 - ? [310] 4 processor(s) and 4096 MB RAM detected
2015-02-19 15:58:44 - ? [339] Local computer is HFC-RND-104-D running Windows NT 6.1 (7601) Service Pack 1
2015-02-19 15:58:44 - ! [000] This installation of SQL Server Agent is disabled. The edition of SQL Server that installed this service does not support SQL Server Agent.
2015-02-19 15:58:44 - ? [098] SQLServerAgent terminated (normally)
I have installed this version of SQL alongside Promise V8i (M). Any advice on how to get this server agent running is welcome
-EugeneI see.
I'm not sure if it's Express or not, how can I tell? The start-up for the server management studio just says "Microsoft SQL Server 2008 R2"
If this is the case, will any other version of SQL besides Express work? or is it only specific ones?
Thanks,
Eugene O'Donnell -
Hi All,
I want to know how to get the health , performance information and about the services run on devices that have connected to the system center to my c# application. Also I need to know about the information of databases that have connected to system center.
I will appreciate your feedback
Thank youHi,
You can configure service monitor for the required service on the server
refer below link for how to configure service monitoring
http://www.bictt.com/blogs/bictt.php/2011/03/17/scom-monitoring-a-service-part3
You can use SCOM SDK to connect to the scom server using c# and get required information
http://msdn.microsoft.com/en-us/library/hh329086.aspx
you can find the database in below registry path on management server
HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\DatabaseName
Regards
sridhar v -
We are getting this below alert message, while using SCOM 2012 R2. Anybody have any idea how to resolve this on the SQL box ?
Thx...
SQL Server cannot authenticate using Kerberos because the Service Principal Name (SPN) is missing, misplaced, or duplicated.
Service Account: NT Service\MSSQL$SQLEXPRESS
Missing SPNs:
Misplaced SPNs: MSSQLSvc/mysqlbox.com:SQLEXPRESS - sqldbadmin
Duplicate SPNs:To Fix this issue, You can check below links
http://support.microsoft.com/kb/2443457/EN-US
http://www.scomgod.com/?p=155
Please remember, if you see a post that helped you please click "Vote As Helpful" and if it answered your question, please click "Mark As Answer"Mai Ali | My blog:
Technical | Twitter:
Mai Ali
Maybe you are looking for
-
Role design issue in regarding SU01 and UserGroups
Hi Experts, I got a requirement to set up a custom role in regarding SU01 access and User groups. Create a role that allows users with this role to go to SU01 but only is allowed to lock/unlock account or reset password. Also should be able to do onl
-
Updating .rpd file in oracle Fusion middleware control 11G
Hi people, I've a problem. I tried to upload my .rpd file by loggin in oracle Fusion middleware control 11G, doing this steps: correaplications-> implantation-> repository -> block editconfiguration-> search repository in folder -> insert password->
-
Acrobat XI Pro transformed to a trial edition
My daughter's Acrobat XI Pro was installed a year ago and worked just fine. Now we get a splash screen saying it's a trial version. When I try enter the serial number it's not accepted (only numeric characters are accepted, serial contains alphabetic
-
Images in Premiere = blurry
Hey, So I've made a video in premiere, I get to the finish line and then I get hung up by the credits. I made some images in Photoshop to create the credits/logo, but when I import those into premiere they are blurry. This isn't so noticible with a p
-
Can I turn off automatic playing of next podcast on nano 6?
On previous models when the end of a podcast was reached the ipod would stop. This was good. Now it advances automatically to the next episode and unsets the "unplayed" flag for that episode. If I don't want to listen to the next one right away then