Saturday, July 20, 2019

SQL server 2008 R2 Performance tuning


SQL Server 2008 R2 Performance Tuning

#1. Check fragmentation for indexing.

Check particular all index details based on selected database.

SELECT dbschemas.[name] AS 'Schema'
 ,dbtables.[name] AS 'Table'
 ,dbindexes.[name] AS 'Index'
 ,indexstats.avg_fragmentation_in_percent
 ,indexstats.page_count
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) AS indexstats
INNER JOIN sys.tables dbtables ON dbtables.[object_id] = indexstats.[object_id]
INNER JOIN sys.schemas dbschemas ON dbtables.[schema_id] = dbschemas.[schema_id]
INNER JOIN sys.indexes AS dbindexes ON dbindexes.[object_id] = indexstats.[object_id]
 AND indexstats.index_id = dbindexes.index_id
WHERE indexstats.database_id = DB_ID()
ORDER BY indexstats.avg_fragmentation_in_percent DESC

#2. Shrink Database log file.

     Shrinking database log file when SQL Server log file size increased.

DBCC SHRINKFILE (
  < DB LOG FILENAME >
  ,1
  )

BACKUP LOG < DB NAME >
WITH TRUNCATE_ONLY

DBCC SHRINKFILE (
  < DB LOG FILENAME >
  ,1
  )

#3. Check last backup details for particular database.

Check database specific backup details using this query.

USE MSDB;

DECLARE @DatabaseName SYSNAME

SET @DatabaseName = '<DB Name>'

SELECT DISTINCT d3.user_name
 ,d3.name AS backup_name
 ,d3.description
 ,(datediff(ss, d3.backup_start_date, d3.backup_finish_date)) / 60.0 AS duration
 ,d3.backup_start_date
 ,d3.backup_finish_date
 ,d3.type AS [type]
 ,CASE 
  WHEN (d3.backup_size / 1024.0) < 1024
   THEN (d3.backup_size / 1024.0)
  WHEN (d3.backup_size / 1048576.0) < 1024
   THEN (d3.backup_size / 1048576.0)
  ELSE (d3.backup_size / 1048576.0 / 1024.0)
  END AS backup_size
 ,CASE 
  WHEN (d3.backup_size / 1024.0) < 1024
   THEN 'KB'
  WHEN (d3.backup_size / 1048576.0) < 1024
   THEN 'MB'
  ELSE 'GB'
  END AS backup_size_unit
 ,d3.first_lsn
 ,d3.last_lsn
 ,CASE 
  WHEN d3.differential_base_lsn IS NULL
   THEN 'Not Applicable'
  ELSE convert(VARCHAR(100), d3.differential_base_lsn)
  END AS [differential_base_lsn]
 ,b6.physical_device_name
 ,b6.device_type AS [device_type]
 ,d3.recovery_model
 ,d3.backup_set_id
FROM sys.databases d1
INNER JOIN backupset d3 ON (d3.database_name = d1.name)
LEFT OUTER JOIN backupmediaset b5 ON (d3.media_set_id = b5.media_set_id)
LEFT OUTER JOIN backupmediafamily b6 ON (b6.media_set_id = b5.media_set_id)
WHERE (d1.name = @DatabaseName)
ORDER BY backup_start_date DESC
 ,d3.backup_set_id
 ,b6.physical_device_name


Wednesday, November 28, 2018

Windows command prompt tips


View command history  type this line
C:\doskey /history

You can also view history by pressing the F7 key on current command windows.

Copy doskey history in text file

C:\doskey /history >C:\commands.txt

Set parameter command prompt to not remember any command history

C:\doskey /listsize=0

Keyboard shortcut for clear command history   alt + F7
On current command windows.

Friday, November 23, 2018

Tomcat Error for Port number already in use

Exception :
org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:960) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) [tomcat-embed-core-9.0.12.jar:9.0.12]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:259) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:197) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) [spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.mkyong.springbootwebjsp.SpringBootWebJspApplication.main(SpringBootWebJspApplication.java:16) [classes/:na]
Caused by: java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_191]
at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_191]
at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_191]
at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) ~[na:1.8.0_191]
at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) ~[na:1.8.0_191]
at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:236) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1108) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:550) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:957) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
... 14 common frames omitted


Solution:
Use command prompt using Window + R then type CMD