Quantcast
Channel: SQL Server Database Engine forum
Viewing all 12963 articles
Browse latest View live

Wait Events in SQL

$
0
0

Hi,

I am getting many Wait Events in SQL Server 2012. Please let me know how can I resolve these wait events.

ASYNC_IO_COMPLETION

WRITELOG

IO_COMPLETION

PAGELATCH_EX

PAGELATCH_SH

SOS_SCHEDULER_YIELD

LCK_M_X

LCK_M_U

Regards

 





SQL Query issue

$
0
0

HI - I have one peculiar issue with sql query.   Below query is not returning any rows.  The issue lies with store_code(st.store_code = 'MAUR') filter

select st.store_code, s.source_title,c.*from rpt.Combined c
join dim.store st 
on c.store_key = st.store_key  
join dim.source s
on c.source_key = s.source_key
where c.event_date_key = 20140406
and source_title = 'ADROIT'
and  st.store_code = 'MAUR'

However, if i use LTRIM(st.store_code)= 'MAUR' in the above query its returning the desired results.  I dont have any leading and trialing spaces for st.store_code in dim.store table.  To prove that i have executed the below query which is returning the results

select * from dim.store st where
 st.store_code = 'MAUR'

Can someone help in identifying the root cause for this issue.

thanks

Problems with backing up to HP 3par disks

$
0
0

Hi,

We have a SQL2012 SP1 build 3412 availability group cluster that recently moved the backend SAN to HP 3par. Since the move we have had the disk array setting changed to high performance for 3par but we still get the errors

The operating system returned the error '59(An unexpected network error occurred.)' while attempting 'SetEndOfFile' and

The operating system returned the error '59(An unexpected network error occurred.)' while attempting 'FlushFileBuffers'.

I have seen http://dirkhondong.wordpress.com/2012/01/27/the-specified-network-name-is-no-longer-available-sql-backup-problem-solved/ as we are using Ola's backup solution. Is changing the registry by creating a DWORD with name ‘Sesstimeout’ and value 360 in HKLM\SYSTEM\CurrentControlSet\Services\lanmanworkstation\parameters the right approach?

Anybody else using HP 3par and having backup troubles?

Thanks

Chris

How to execute the job in multithread

$
0
0

 Hi ,

  Can I execute a job parallel. I have A procedure that I want to execute on user request even the job is already running, I want to execute as different threads(in another SPID). Is it possible. The problem I am facing is if the procedure is taking some around 10 minutes the another user has to wait till previous is completed.

 In other case I have a ETL package that called in job , and this job is executing on user demand, the problem here is if a user hit the job and start executing , other user has to wait till completion. can we run the same package parallel

Thanks in advance..


Regards Vikas Pathak

NO NEED FOR THIS

backup history all servers

$
0
0

I'd like to write a report with backup history for all sql servers. I can manually easily get it by using registered servers and running a single query on all of them (I have the query, I just don't know how to gather a single resultset for multiple servers).

I wanted to avoid openquery or linked servers. Is there any best way of getting this done? SSIS package seems involved. Is there a magic powershell? thanks!


Paula

TempDB size on creation

$
0
0

I've googled this topic to see if TempDB is created based on the model database and get mixed opinions.
Also when I look at model I see the default size is 3MB yet the TempDB initial size is 8MB

My thinking is that 8MB with 10% autogrowth sounds very inefficient and am wanting to increase the file size for tempDB when it is created (after each restart).

Are my feelings warranted? And if so, is it as simple as increasing the size of the model DB?

Loading IO stalls and wait type counters into table

$
0
0

Hi,

I ran into strange issue on our sql server 2008r2 server. While running analysis of how fast our SAN is, I put together stored procedure that captures IO stalls and wait types counters (and some others as well), and I included it at the beginning and the end of some of our intensive processes (to measure performance). Basically this proc loads counter values into WaitTypes, and  IO_Stalls user tables (see section of the code below).

Here is interesting part: when I run this proc manually, it loads both tables. When proc runs within the process (other stored procedures), second statement never loads any data (IO stalls).

How is this possible, any ideas?

--1. Load waits:
;with Waits as(
	select wait_type, wait_time_ms/1000. as wait_time_s, 100. * wait_time_ms/sum(wait_time_ms) over() as pct,
	ROW_NUMBER() over(order by wait_time_ms desc) as rn
	from sys.dm_os_wait_stats
	where wait_type not in (N'CLR_SEMAPHORE',N'LAZYWRITER_SLEEP',N'RESOURCE_QUEUE',N'SLEEP_TASK',
		N'SLEEP_SYSTEMTASK',N'SQLTRACE_BUFFER_FLUSH',N'WAITFOR', N'LOGMGR_QUEUE',N'CHECKPOINT_QUEUE',
		N'REQUEST_FOR_DEADLOCK_SEARCH',N'XE_TIMER_EVENT',N'BROKER_TO_FLUSH',N'BROKER_TASK_STOP',N'CLR_MANUAL_EVENT',
		N'CLR_AUTO_EVENT',N'DISPATCHER_QUEUE_SEMAPHORE', N'FT_IFTS_SCHEDULER_IDLE_WAIT',
		N'XE_DISPATCHER_WAIT', N'XE_DISPATCHER_JOIN', N'SQLTRACE_INCREMENTAL_FLUSH_SLEEP',
		N'ONDEMAND_TASK_QUEUE', N'BROKER_EVENTHANDLER', N'SLEEP_BPOOL_FLUSH')) --etc
insert into StatsDB.dbo.WaitTypes(date_id, date_time, wait_type, wait_time_s, pct, running_pct)
select @Date_id,
	getdate() as date_time, 
	W1.wait_type,
	cast(W1.wait_time_s as decimal(12,2)) as wait_time_s,
	cast(W1.pct as decimal(12,2)) as pct,
	cast(sum(W2.pct) as decimal(12,2)) as running_pct
from Waits W1
join Waits W2 on W2.rn <= W1.rn
group by W1.rn, W1.wait_type, W1.wait_time_s, W1.pct
having sum(W2.pct) - W1.pct < 99; --percentage threshold

--2. Load IO stalls:
insert into StatsDB.dbo.IO_Stalls(date_id, date_time, database_name, physical_name, io_stall_read_ms, num_of_reads, avg_read_stall_ms, io_stall_write_ms, num_of_writes, avg_write_stall_ms, io_stalls, total_io, avg_io_stall_ms)
select @Date_id,
	getdate() as date_time,
	db_name(fs.database_id) as database_name,
	mf.physical_name, io_stall_read_ms, num_of_reads,
	cast(io_stall_read_ms/(1.0 + num_of_reads) as numeric(10,1)) as [avg_read_stall_ms],
	io_stall_write_ms, num_of_writes,
	cast(io_stall_write_ms/(1.0 + num_of_writes) as numeric(10,1)) as [avg_write_stall_ms],
	io_stall_read_ms + io_stall_write_ms as [io_stalls], num_of_reads + num_of_writes as [total_io],
	cast((io_stall_read_ms + io_stall_write_ms)/(1.0 + num_of_writes + num_of_reads) as numeric(10,1)) as [avg_io_stall_ms]
from sys.dm_io_virtual_file_stats(null,null) as fs
join sys.master_files mf on mf.database_id = fs.database_id and fs.file_id = mf.file_id
order by avg_io_stall_ms desc;




Pedja


Watch out: change for line numbers in SSMS 2014

$
0
0

There is a change in SSMS 2014 how line numbers are displayed in error
messages. Instead of displaying the raw line number from SQL Server, SSMS
2014 adds the offset where the current batch starts to the error message. So if the query window reads:

PRINT'This is the first batch'
goPRINT'This is the second batch'
goPRINT'This is a the third batch''and it has a syntax error'

The output message in SSMS 2014 is:

This is the first batch
This is the second batch
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'and it has a syntax error'.

SSMS 2012 reports the error to be on line 1. You could argue that this is midly useful. However, there is a very nasty side effect. Consider:

CREATETABLE PoorLittleNemo (a tinyintNOTNULL)
goCREATEPROCEDURE ScenesFromANightsDream @a intASINSERT PoorLittleNemo(a) VALUES (@a)
goEXEC ScenesFromANightsDream 800
goDROPTABLE PoorLittleNemoDROPPROCEDURE ScenesFromANightsDream

The output in SSMS 2014 is:

Msg 220, Level 16, State 2, Procedure ScenesFromANightsDream, Line 7
Arithmetic overflow error for data type tinyint, value = 800.
The statement has been terminated.

There are not seven lines in that stored procedure!

I find this extremely unhelpful, If I get an error from a stored procedure
that I run from my query window (which often is a scratchpad of various ad
hoc statements), I need to find where the current batch starts (Typically I
only select a single statement) to compute the correct line number. And if I
get the message from a co-worker, I have no idea how his query window looked
like.

I have submitted a Connect item on
https://connect.microsoft.com/SQLServer/feedback/details/857794/ssms-
reports-incorrect-line-number-for-error-that-occurs-in-stored-procedures

If you feel the same as me, vote up!
If you think this is a great improvement, vote down!
If you don't care - don't vote at all.


Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

attach database with norecover

$
0
0

Hi everyone,

If I attached the database from a detached database files, can I put it no-recovery mode and restore tlog backup?

Thanks,

SkyRiver


SkyRiver

sp_who2 shows blocking by spid that isnt listed

$
0
0

Using sp_who2

I was noticing some blocking going on in one of my DB's and after a few minutes it cleared up except for one row that listed the status as "SUSPENDED" and the Blkby = 200, but there was no SPID of 200 in the list, so where would I see info about that spid (200)?

Powershell to connect to SQL 2012 problem

$
0
0

Hi~ I am writing a powershell script to connect to an SQL 2012 to run a query. but seems it cant connect:

Add-Type -Path 'C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Smo\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Smo.dll'
$today=(Get-Date).ToString('MM-dd-yyyy')

$log='C:\'+$today+'.log'
$filepath='C:\'+$today+'.csv'
$filepath2='C:\'+$today+'.xls'
$finalDataSet = New-Object System.Data.Datatable

get-content 'C:\SLDATA\Serverlist.txt'  | foreach-object {

$SQLServer=$_
$SQLDBName = "master"
$SqlQuery = "select @@version"

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = SSPI"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
trap
{
"Cannot connect to $SQLServer" | Out-file $log
continue
}
$SqlConnection.open()
if ($SqlConnection.state -eq 'Open')
{
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
#$DataSet = New-Object System.Data.DataSet
$Datatable = New-object System.Data.Datatable
$SqlAdapter.Fill($datatable)
$SqlConnection.Close()
$finalDataSet.Merge($datatable)
clear
#$DataSet.Tables[0] | select name
#$finaldataset.Tables.add($datatable)
#$finaldataset
}
}

$finalDataSet | sort-object FileSizeMB -descending | export-csv $filepath -force -notypeinformation

I am wondering if that's my SMO is too old to connect to SQL 2012.  Connect   to SQL 2005 and 2008 are ok.

Database Ownership Chaining Across Servers

$
0
0

Server 1 - SQL Server 2005 Standard on Windows 2003

Server 2 - SQL Server 2012 Standard on Windows 2008 R2

There are three databases (A, B and C) that have a Database Ownership Chain set up on Server 1. However, database C is explored to be moved to Server 2.

1. If, database C is moved to Server 2, can a database ownership chain be set up across databases A, B and C, even though database C is on another Server?

2. If 1. above is possible, is it accomplished by having a Linked Server?

Thank you. 

-Jeelani



My SQL Server instance suddenly stopped

$
0
0

It has been running for a few months but recently it suddenly stopped.

Would like to know how to find the cause why it stopped, and any remedy to prevent it from stopping in the future.

Current sql version: SQL Server 2008 R2

OS:Windows server 2008 R2

SQL Server wants to open properties of wrong database and cannot restore logs of different databases at the same time

$
0
0
We have implemented our own way of logshipping by backing up the transaction logs of all our non-system databases every hour. Then we transfer the backups (before SQL Server 2008 R2 with additional zip and unzip steps) to the second environment where we restore them only during the night on databases in standby-state (Like this, our developers can access the databases without disturbing the productive system and we can restore the t-logs during night, so not shutting out the developers during the day).

Now since we replaced our hardware in the productive environment, we replaced the hardware in the second environment with the servers from previous productive environment. Same SQL Server 2008 R2, same Service Pack (SP2), same installation procedure. But since then the SQL Server in the second environment behaves different:

- When the logs of some database "A" are restored, I cannot access the properties of any database, i.e. database "B", I only get the error message "Cannot show requested dialog. (SqlMgmt) Database 'A' cannot be opened. It is in the middle of a restore. (Microsoft SQL Server, Error: 927)"

- Our logshipping runs multiple instance at the same time, so restoring multiple databases' logs. But since the change, two of the instances fail restoring of datatbases, i.e. "B" and "C" with the error message "Database 'A' cannot be opened. It is in the middle of a restore.". The jobs guarantee to restore only logs of the database they need to restore, they have strictly separated sets of target databases and only try to restore the databases of their sets.

Before the new installations, we did not have these strange behaviours. But as said, it is the same SQL Server version, the same service pack, and we followed the same installation document but maybe with the small changes in settings. The user the jobs are running under is a domain admin, the login they use has dbcreator, processadmin, db_owner and db_backupoperator roles. My login on the SQL Server has sysadmin rights and as described similar problems.

Is this problem known or does somebody have an idea where to go looking for?

Thanks, Chris



Problem to create database after Drop

$
0
0

Hi,

I need to create automatically a lot of databases but sometimes I get errors. So, I drop the database and try to recreate them but, when I try to recreate them, SQL Server says : "impossible, database already exist, change the name".

So after 5 tries with a 100ms pause in between each, I use DBCC FREEPROCCACHE and it's ok.

But, using FREEPROCCACCHE beeing very violent I trying to find how to manage that in a better way.

Is it possible to do something else ?

Thanks


SQL 2000 Log and data file free space

$
0
0
HI ~ In SQL 2000, are there any tsql I can get the free space of the mdf and ldf file ?

SQL Server Performance

$
0
0

What is the best approach if we got performance issues in SQL Server

Need step by step process of Root cause analyses for performance issues.

 

Kamal

Remove Log Primary Log File

$
0
0

Dears,

how can i remove the primary log file, or reduce its size, it is becoming around 60 GB.

best regards,

Bilal Abdallah

SQL Embedded, In-memory or whatever its called

$
0
0

I am a developer who uses different databases, but SQL Server is my favorite. I have a couple of small portable apps that I have been using a MS Access database to store information. I am interested in using the feature that allows you to embed a SQL database/engine in your .NET app. I saw it first in 2012, and now in 2014, but still a shortage of info, even in MSDN. Is this fringe tech to be avoided? Maybe I should stick with access as it has a front-end for design purposes?


Lee


Viewing all 12963 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>