Showing posts with label separate. Show all posts
Showing posts with label separate. Show all posts

Monday, March 19, 2012

Got an expensive server, SQL is very slow on writes

Hi,

i am experiencing SQl write performance problems on a very shiny server. Got data files on a Raid 1+0, log files on a separate drive, all SCSI, Win2003 server, 6G RAM, 2 Xeon processors. I've created a small benchmarking program and run it on my desktop pc and this 'big' server. Here are the results:

Desktop: SQL server inserts: 78 Seconds, Direct writes to the harddisk(Just write a string to the file 10000 times): 13 seconds

SQLServer: SQL server inserts: 422 Seconds, Direct writes to the harddisk: 16 seconds

So, for some reason, my 'shiny' machine is 6 times slower on writes than my desktop. When i tried comparing the select performance, my shiny server is 10 times faster than my desktop.

Initially i had Raid5 on my server and it had poorer direct write performance but now, direct writes seem to be ok, so, i recon this is a problem related to SQL server.

What can i do to improve the insert performance?

Thanks in advanceYour performance should double by placing the database file and transaction log file on different drives.

HTH|||As i mentioned previously, i already have my data and log files in different physical drives but it it does not make a difference.
Playing around with Raid configurations i managed to significally improve the speed of direct writes to hardisk (not within SQL) but sql write speed still stayed the same. I have a feeling that this is either Win2003 server or sql server matter. Cannot find any info about it.

Had someone come accross the same problem?|||Maybe check if your RAID-controller has its writecache disabled. How did you test? Within Queryanalyzer or custom Tool.?|||I wrote a small c# utility to do the test. Tool does 2 types of test:

1. It runs 10,000 insert quieries against a simple table

2. It writes a string into the flat file using direct file access 10,000 times.

I thought that writecache might be an issue but my direct writes (test 2) perform very well (equal to my desktop pc, whereas test 1 is 6 times slower than on my desktop) so i think that bottleneck is not in disk/raid configuration but somewhere else.

Not sure where though:( Same thing happens with SQL7.

Currently trying to install Win2k server op.|||For anyone having the same kind of a problem, issue was resolved by by installing a battery backed write cache on the SCSI controller. Achieved 24 times speed boost at once.|||... though enabling write cache is not a good idea anyways since it can lead to data corruption, even during normal operation.|||I've paid £250 for this write cache chip, it's backup onboard battery will last for 72 hours. I am pretty confident that my cached data will be save. Besides that, apparently write caching with battery backup is microsoft's recommendation. (Q230785)|||It's not a matter of how long your battery lasts. I read that the datapages can get out of sync with write caching enabled which leads to corrupt data files. But not 100% sure could be an issue of SQL 7 only.

... maybe one of our friendly MVP-SQL-Gurus here can confirm or disproof that hardware write caching can be a problem? :)

- Moon

Sunday, February 26, 2012

GO statement in SQL scripts

I have inherited a large script which uses DateFrom and DateTo parameters in 4 separate places in the script. I would like to DECLARE these parameters and put them into 2 variables to use in the 4 instances (instead of having to alter the script every time I run it). My problem is that the GO statement ends a batch of commands and the script loses the value of my variables.

Can anyone tell me exactly what the significance of the GO statement is in a SQL script, what it does and under what circumstances it is really necessary.

Thanks for your help.

itsmarkdavies@.hotmail.combasically you need a go any time you issue a:

CREATE DEFAULT, CREATE FUNCTION, CREATE PROCEDURE, CREATE RULE, CREATE TRIGGER, or CREATE VIEW statment. Also a table can not be altered and then referenced in the same batch.

Check out Books On Line, on the index tab type in the keyword "GO". BOL has a very goo explination of the use of "GO" and batches in general.|||So Paul it sounds like 'GO' is like 'commit' when you create new objects in your script ?|||Not quite, transactions are used to group operations into a logical work unit which you commit or rollback based on some test. A "go" is syntacticaly required to execute some TSQL statments. Consider the following:

Code:
----------------------------
begin transaction
create procedure test_getstuff as select db_name(), user_id()
exec test_getstuff
rollback transaction
if object_id('test_getstuff') is not null
print 'test_getstuff exists'
else
print 'test_getstuff does not exist'
----------------------------
will generate an error, however

Code:
----------------------------
begin transaction
go
create procedure test_getstuff as select db_name(), user_id()
exec test_getstuff
rollback transaction
if object_id('test_getstuff') is not null
print 'test_getstuff exists'
else
print 'test_getstuff does not exist'
go
sp_helptext test_getstuff
go
----------------------------
will work because TSQL requires a create procedure to be the first command in a batch. Notice, however, that the stored procedure does a little more than expected. Lastly:

Code:
----------------------------
begin transaction
go
create procedure test_getstuff as select db_name(), user_id()
go
exec test_getstuff
sp_helptext test_getstuff
rollback transaction
if object_id('test_getstuff') is not null
print 'test_getstuff exists'
else
print 'test_getstuff does not exist'
go
----------------------------
The 2nd go is used to terminate the batch. Now the sp looks correct.

Notice that in all of this I destroyed all my work by wrapping everything in a transaction. I could just ahve easily saved all my work by using a commit.|||Hi,

Use the "GO" statement if you want to end the SQL Statements and want SQL Server to execute till that.

Mr. Paul and Mr.Youngman has explained in a nice way.

You can add these below basic info also along with that.

Basically SQL Server must understand where Your SQL script ends.
So, Microsoft uses "GO" to terminate/end SQL Statements. Oracle uses ";" to terminate/end SQL Statements.

As soon as SQL Server sees "Go" statement it understands that SQL Statement is ended and it can start executing the SQL Statements till that point.

I can put in this way, like a man looking for pebbles. as soon as he finds a pebble, he picks and puts in a bag and looks nearby whether there are some more and keep going. Similarly SQL Server looks for "Go" and as soon as it sees "GO" it thinks, Ok I found a "go" and I have to end there and pick all the SQL Statements I come across and start executing.

Thats it.

Have Fun :)
Varad01

Friday, February 24, 2012

Global prefixes available?

Our business system consists of 4 separate database. One of these is a
Reference database that stores common look up tables, such as Countries,
Provinces, States, etc. When we want to access this information from
another database, we always prefix the table with the db name, then the
owner, as in:
select * from Reference.dbo.Country
Since there is no Country table in any of the other databases, I was
wondering if there was a way to 'instruct' SQL to always look in the
Reference database for a table called 'Country'. This would make coding
the stored procedures (and working in Query Analyzer) a bit less verbose,
but I do NOT want to sacrifice performance. Plus, I don't even know if this
possible. One of the developers here mentioned that Oracle has global
prefixes, or constants or something like that, that allows you to define
this. So far, the only thing I've come up with is to create a view in each
of the other databases with the same name as the tables in Reference, where
the view is something like:
Create View Country As Select * from Reference.dbo.Country
Any thoughts?On Sun, 3 Apr 2005 21:19:55 -0600, Dave Slinn wrote:
(snip)
> select * from Reference.dbo.Country
>Since there is no Country table in any of the other databases, I was
>wondering if there was a way to 'instruct' SQL to always look in the
>Reference database for a table called 'Country'.
Hi Dave,
No, there is no such option in SQL Server.
Sidenote - even if there was, I'd probably recommend against using it,
since it would slow things down. Consider the well documented
performance difference between "SELECT somecol FROM sometable" and
"SELECT somecol FROM dbo.sometable". The first will check first for a
table called sometable owned by the current user before going to the
sometable table owned by dbo; the second will skip the first step.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)