Showing posts with label time. Show all posts
Showing posts with label time. Show all posts

Wednesday, March 21, 2012

Quoted-Identifyer

Hi
Since short time I am experiencing the following problem when testing a
stored procedure.
Error on Insert since the following set options are not set properly:
QUOTED_IDENTIFYER
Sorry, that I do not have an exact error message, since I am working on
a german server, and I only translated the message by myself.
The error occured without changing the procedure or the data. It
suddenly appeared, then disappeared and then appeared again...
regards
StephanzDo any of your statements use "" around column names or aliases or values?
If a column name has spaces or is a reserved word, use [brackets] as opposed
to "double quotes" -- and strings should be delimited using 'single quotes'
rather than "double quotes".
"Stephan Zaubzer" <stephan.zaubzer@.schendl.at> wrote in message
news:uStQuCoyFHA.3588@.tk2msftngp13.phx.gbl...
> Hi
> Since short time I am experiencing the following problem when testing a
> stored procedure.
> Error on Insert since the following set options are not set properly:
> QUOTED_IDENTIFYER
> Sorry, that I do not have an exact error message, since I am working on a
> german server, and I only translated the message by myself.
> The error occured without changing the procedure or the data. It suddenly
> appeared, then disappeared and then appeared again...
> regards
> Stephanz|||In all my Procedures there is no " (Double Quote).
I already checked this. No column name has any space or uses reserved
words... and all my strings are sourrounded with single quotes. That's
why I contacted this news group, because this behaviour seems to be kind
of strange.
Last w the procedure worked fine! This w, suddenly I got the error
and I put a "SET QUOTED_IDENTIFYER ON" right above the insert statement.
Then it worked. Today it stopped working and I moved the "SET
QUOTED_IDENTIFYER ON" statement right to the beginning of the stored
procedure and then it worked again. But I didn't change any column names
in the database nor did I change the stored procedure. That all
sometimes makes me even believe that software can be indeterministic
allthough I know that it isn't...
regards
Stephan
Aaron Bertrand [SQL Server MVP] wrote:
> Do any of your statements use "" around column names or aliases or values?
> If a column name has spaces or is a reserved word, use [brackets] as opposed
> to "double quotes" -- and strings should be delimited using 'single quotes
'
> rather than "double quotes".
>
>
> "Stephan Zaubzer" <stephan.zaubzer@.schendl.at> wrote in message
> news:uStQuCoyFHA.3588@.tk2msftngp13.phx.gbl...
>
>
>|||debug the procedure with print statments and the profiler,
I always put this at the beginning an end of my sProcs
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
...do stuff
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET NOCOUNT OFF
GO
"Aaron Bertrand [SQL Server MVP]" wrote:

> Do any of your statements use "" around column names or aliases or values?
> If a column name has spaces or is a reserved word, use [brackets] as opposed
> to "double quotes" -- and strings should be delimited using 'single quotes
'
> rather than "double quotes".
>
>
> "Stephan Zaubzer" <stephan.zaubzer@.schendl.at> wrote in message
> news:uStQuCoyFHA.3588@.tk2msftngp13.phx.gbl...
>
>|||I traced down the problem a little bit:
The problem first arised when changing to a new developement server
which is hosted on a virtual test machine rather than on my old crappy
laptop ;-)
When creating tables, stored procedures and so on I never cared about
the QUOTED-IDENTIFYER options and I now had a look in the old version of
the database on my laptop and there for each stored procedure the
QUOTED-IDENTIFYER option was set to ON. Now (with exactly the same
create scripts for the stored procedures) for each procedure the server
sets this option to OFF. This is my problem now. How does the server
determine wheter to set or unset the QUOTED-IDENTIFYER option when
creating stored procedures.
btw... The error on the insert statement happened even though I did not
have any double quotes or similar constructs. SQL server requires that
when performing inserts, deletes, updates and creates on tables with
indexed views QUOTED-IDENTIFYERS must be set to ON. Otherwise those
opererations will fail...
Stephan Zaubzer wrote:
> In all my Procedures there is no " (Double Quote).
> I already checked this. No column name has any space or uses reserved
> words... and all my strings are sourrounded with single quotes. That's
> why I contacted this news group, because this behaviour seems to be kind
> of strange.
> Last w the procedure worked fine! This w, suddenly I got the error
> and I put a "SET QUOTED_IDENTIFYER ON" right above the insert statement.
> Then it worked. Today it stopped working and I moved the "SET
> QUOTED_IDENTIFYER ON" statement right to the beginning of the stored
> procedure and then it worked again. But I didn't change any column names
> in the database nor did I change the stored procedure. That all
> sometimes makes me even believe that software can be indeterministic
> allthough I know that it isn't...
> regards
> Stephan
> Aaron Bertrand [SQL Server MVP] wrote:
>|||> sets this option to OFF. This is my problem now. How does the server
> determine wheter to set or unset the QUOTED-IDENTIFYER option when
> creating stored procedures.
The server doesn't. The connection settings in effect for the dbms
connection used to edit the procedure are used (and saved). You determine
these settings by the method (or application) you use to edit the procedure.
You should read the information in BOL under the topic of "create
procedure". There is a detailed explanation of the settings that are
relevant to procedure creation and execution - very important information!

> btw... The error on the insert statement happened even though I did not
> have any double quotes or similar constructs. SQL server requires that
> when performing inserts, deletes, updates and creates on tables with
> indexed views QUOTED-IDENTIFYERS must be set to ON. Otherwise those
> opererations will fail...
Yes - this is (relatively) common knowledge. It helps to provide complete
information when posting in the newsgroups. Had you mentioned that an
indexed view was involved, someone might have identified the actual problem
a bit quicker. As a side note, you should also verify that any triggers
that may be participating in these actions are not contributing to the
problem.sql

Monday, March 12, 2012

Quick SQL Server 2000 Locking question

We are running a 3rd party ETL tool to populate a denormailized version of a production database for reports. Everything works fine 95% of the time. However there is a semi-rare occurence of the ETL tool hanging up. The norm is for the tool to take about 5 times longer than usual, but it still works. Over the weekend however it through an error saying:

The SQL Server cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users or ask the system administrator to check the SQL Server lock and memory configuration.

The reports are run through Crystal using stored procs and are all basically select statements

So my question(s) are the following:
1. What kind of lock would a report put on a table (select statement)
2. Would it make sense to change stored procs to use WITH NOLOCK?
3. Or is something else going on?

Your thoughts would be greatly appreciated.1) Select statements put shared locks on tables. These allow other readers, but block writers to the locked portions of the tables. Shared locks are blocked by existing Exclusive locks.

2) If you like partial results, using (nolock) is perfectly fine. I wouldn't suggest it to an accountant, though.

3) Could be, but you would need to monitor the process as it is running to be certain.|||Here is response I received from 3rd party ETL tool:
Tables/rows seem to be locked by another application or process. We have seen users do this with DBArtisan or Query Analyzer. They lock the table and can't figure out why DT/Engine appears to hang for hours. When they close whichever application that is locking the tables, DT/Engine finishes up what it was doing and everything goes back to normal. You may have a DBA tool like Query Analyzer open looking at either the source or target data as it moves which would result in a hang as the engine waits for the release.|||The ETL tool does update some Flag fields just to keep track of what's being moved around. My concern is that the reports run lighting fast with none taking more than 1 second.
The slow down (when it occurs) happens on the same task over and over. You could call it a main enitity table, but its not the largest table. However, most of the reports use it. But we are talking about a 3 hour hang-up on the ETL side. There's no way it wouldn't be able to obtain a lock in that time, right?

Just having query analyzer open is not causing this.

Next steps??
1. Keep a trace going with duration set to more than 10 minutes?
2. Try to track down who's doing what on this server (located across the globe)?|||First step is to prove who is blocking and whether there is blocking at all. A three hour block sounds suspiciously like a maintenance job. A three hour slowdown could be SQL Server got starved for memory by some currently unknown process.

Personally, I would spend a night with this thing, to see if I can spot the reason for the slowdown/stoppage. OK, first thing I would do is write scripts to capture the interesting information (the sysprocesses table is a nice place to start. Pay attention to the blocked, waittype, waitresource, and open_tran columns). But then, I am lazy like that.|||Never used sysprocesses table before. Looking at it for first time I notice a few suspect entries. Is this just a current snapshot or does it keep archive info. It only had 3 pertinent rows out of 22.

Friday, March 9, 2012

quick SELECT statement question

Hello all!
I have a date/time column on my table. How can I write a select statement
to pick only items from todays date? I looked, but can't find an answer.
SELECT * User FROM TABLE WHERE datecolumn = "todays date"
Thanks!
RudySELECT
*
FROM
Table
WHERE
CONVERT(CHAR(8), datecolumn, 112) = CONVERT(CHAR(8),
GETDATE(), 112)
Due to the time that is stored in a datatime datatype, you need to strip the
time out as above.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Rudy" <Rudy@.discussions.microsoft.com> wrote in message
news:5E70E4E8-EB91-4DBF-8489-5F9E3A5A204C@.microsoft.com...
> Hello all!
> I have a date/time column on my table. How can I write a select statement
> to pick only items from todays date? I looked, but can't find an answer.
> SELECT * User FROM TABLE WHERE datecolumn = "todays date"
> Thanks!
> Rudy|||Hi Mike!
WOW!! I wouild have never figured that out. Thanks!!
Rudy
"Mike Epprecht (SQL MVP)" wrote:

> SELECT
> *
> FROM
> Table
> WHERE
> CONVERT(CHAR(8), datecolumn, 112) = CONVERT(CHAR(8),
> GETDATE(), 112)
> Due to the time that is stored in a datatime datatype, you need to strip t
he
> time out as above.
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "Rudy" <Rudy@.discussions.microsoft.com> wrote in message
> news:5E70E4E8-EB91-4DBF-8489-5F9E3A5A204C@.microsoft.com...
>
>|||Hi
Or
SELECT
*
FROM
Table
WHERE
datecolumn >= (CONVERT(CHAR(8), GETDATE(), 112) + '
00:00:00.000'
AND datecolumn <= (CONVERT(CHAR(8), GETDATE(), 112) + '
23:59:59.997'
The 1st one can not use an index if that is the only predicate in the where
clause as each row needs to be evaluated.
The 2nd one could use an index, but make sure that you use ' 23:59:59.997'
and not ' 23:59:59.999' as .999 can not be represented in datetime, so it
rounds itself to 00:00:00.000, the next day
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Rudy" <Rudy@.discussions.microsoft.com> wrote in message
news:2202B61C-5A3A-4FEB-B0E4-6FC0480FB1EA@.microsoft.com...
> Hi Mike!
> WOW!! I wouild have never figured that out. Thanks!!
> Rudy
> "Mike Epprecht (SQL MVP)" wrote:
>|||In addition to Mike's comments, you might want to red more about the subject
at:
http://www.karaszi.com/SQLServer/info_datetime.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Rudy" <Rudy@.discussions.microsoft.com> wrote in message
news:5E70E4E8-EB91-4DBF-8489-5F9E3A5A204C@.microsoft.com...
> Hello all!
> I have a date/time column on my table. How can I write a select statement
> to pick only items from todays date? I looked, but can't find an answer.
> SELECT * User FROM TABLE WHERE datecolumn = "todays date"
> Thanks!
> Rudy

Quick question about Server copying

Ok guys, it's my first day on a job, I need a quick answer, and I'm not a
full time DBA. Refresh my memory.
I have a SQL Server 2000 (SP3) server with multiple databases of uncertain
size (probably a few gig at least.) I need to duplicate this entire server
(all databases, users, permissions, everything) to a second server on a
nightly basis. Any changes to the second servers's data are irrelevant.
They are to be wiped out and replaced by the first.
What's the fastest way to do this? (At the moment, everyone else in the
office is leaning towards a backup-restore solution. Anything better that I
might be forgettting?)
Normally I'd be suggesting log-shipping, but in your case you want to take a
copy of the master database as well, which can't be log-shipped. So, you
could use backup and restore for the entire databases, assuming the second
server can maintain the same name. Coordination of the backups might become
crucial here if the databases are related eg logical FKs across databases.
This will also apply to replication where the coordination of distribution
backup and publisher backup will be required. Also, you'll need to consider
peripheral areas eg FTIs which will need rebuilding (taken care of in SQL
2005). You might be better off looking at a server-mirroring solution eg
DoubleTake for your requirements.
Rgds,
Paul Ibison
"B. Chernick" wrote:

> Ok guys, it's my first day on a job, I need a quick answer, and I'm not a
> full time DBA. Refresh my memory.
> I have a SQL Server 2000 (SP3) server with multiple databases of uncertain
> size (probably a few gig at least.) I need to duplicate this entire server
> (all databases, users, permissions, everything) to a second server on a
> nightly basis. Any changes to the second servers's data are irrelevant.
> They are to be wiped out and replaced by the first.
> What's the fastest way to do this? (At the moment, everyone else in the
> office is leaning towards a backup-restore solution. Anything better that I
> might be forgettting?)
|||On Apr 16, 2:58 pm, B. Chernick <BChern...@.discussions.microsoft.com>
wrote:
> Ok guys, it's my first day on a job, I need a quick answer, and I'm not a
> full time DBA. Refresh my memory.
> I have a SQL Server 2000 (SP3) server with multiple databases of uncertain
> size (probably a few gig at least.) I need to duplicate this entire server
> (all databases, users, permissions, everything) to a second server on a
> nightly basis. Any changes to the second servers's data are irrelevant.
> They are to be wiped out and replaced by the first.
> What's the fastest way to do this? (At the moment, everyone else in the
> office is leaning towards a backup-restore solution. Anything better that I
> might be forgettting?)
This solution will keep a realtime copy of all your databases as well
as Master, System, etc. You can also schedule it to just do periodic
snapshots, so that should meet your needs for a nightly copy on a
secondary server.
http://www.steeleye.com/pdf/literature/lifekeeper_for_sql_server.pdf
David A. Bermingham, MCSE, MCSA:Messaging
Director of Product Management
www.steeleye.com
|||Thanks. Unfortunately, my boss has told me in no uncertain terms that this
project does not warrant the expense of 3rd party software so we're going the
batch file route (which I've mostly gotten working.)
"daveberm" wrote:

> On Apr 16, 2:58 pm, B. Chernick <BChern...@.discussions.microsoft.com>
> wrote:
> This solution will keep a realtime copy of all your databases as well
> as Master, System, etc. You can also schedule it to just do periodic
> snapshots, so that should meet your needs for a nightly copy on a
> secondary server.
> http://www.steeleye.com/pdf/literature/lifekeeper_for_sql_server.pdf
> David A. Bermingham, MCSE, MCSA:Messaging
> Director of Product Management
> www.steeleye.com
>
>

Monday, February 20, 2012

Queue DELETE time

Hello!

In running some performance tests on a Queue using a message size of ~5KB, we found that we can process (SEND and RECEIVE) on the order of 600 - 800 messages / second. However, we have found that INSERTs of new messages to the Queue appear to take great precedence over DELETEs of received messages from the queue. In particular, we found that during heavy use the total size of the Queue (as determined using the sp_spaceused procedure) equals about the number of total messages processed, not the number of messages on the queue.

When we stop sending messages, the overall size of the Queue table appears to decrease slowly, so there is a background process that is obviously doing some work there to clean up the received messages from the Queue. What I would like to know is if we can affect that background process in any way so that the messages are cleared out more quickly. The performance has been determined to suffer appreciably once the Queue size grows to greater than about 3GB in size. We also notice timeouts on the RECEIVE statements when the Queue size is that large.

Thanks for any help --

Robert

There is no background deletion from queues.
If retention is OFF, the RECEIVE is a DELETE WITH OUTPUT and messages are deleted immedeately.
If retention is ON, RECEIVE is an UPDATE WITH OUTPUT and the messages are deleted when the END CONVERSATION is run.

HTH,
~ Remus

|||

Remus --

Thanks for the reply. What we have noticed is that if we SEND a lot of messages in a short period of time, the overall size of the Queue will grow regardless of the actual number of messages on the Queue. Maybe what it is is actually a background shrinking of the TABLE; I don't know. I did find that if the throughput was ~300 messages / sec or less, the shrinking kept up with the INSERTs and the size of the Queue did not increase.

Is there no way, then, to affect the shrinking of the Queue?

Thanks --

Robert

|||

Doesn't this means that your sending faster than the attached procedure can process? I have a blog on how to process faster at http://blogs.msdn.com/remusrusanu/archive/2006/10/14/writing-service-broker-procedures.aspx , but as a general rule, you will always be able to send faster than the service can process. You must tune your system to be able to process as many messages as you need as average over some period of time. You do not need to be able to keep up with spikes of messages, they can queue up and be processed later, but you need to be able to keep up with the incomming rate over time.

|||

Remus Rusanu wrote:

Doesn't this means that your sending faster than the attached procedure can process?

I don't know if I would call this SENDing faster than being able to process the messages. As a general rule, the number of items on the Queue (as told by the ROWS column from sp_spaceused) doesn't appear to grow that large.

Here is an example: we would SEND 5KB messages at a rate of ~600 - 800 / sec. We were able to process the messages at about the same rate, give or take a little. Over the course of half an hour, the ROWS column said that there were maybe 10000 items on the Queue, but the RESERVED column would show a TABLE size of ~5GB. Obviously, the size of 10000 5KB messages is not 5GB, but the total number of items processed (~1.1 million) * 5KB is ~5GB.

What that indicates to me is that either the process that DELETEs the rows from the TABLE or the process that shrinks the TABLE after items are DELETEd operates more slowly or less frequently than the process that INSERTs the rows into the TABLE. If I throttle the SEND process down to ~300 messages / sec, it appears that the two processes -- growing to add the new messages and shrinking after delivering the received messages -- are close to equilibrium.

In talking through this, I guess we've more or less answered the question, which was whether I could make the TABLE shrink occur any more quickly -- and the answer is no, we need to tune the system for the greatest throughput. Thanks very much for your time!

Robert

|||

Use this query to get the number of rows in the queue:

select p.rows

from sys.objects as o

join sys.partitions as p on p.object_id = o.object_id

join sys.objects as q on o.parent_object_id = q.object_id

where q.name = '<queuename>'

and p.index_id = 1

What you see is probably the ghost writer cleanning up pages in the database, has no relation with SSB per say, is the normal process you would see with any table that has a large number of inserts (message enqueues) followed by a large number of deleted (message dequeues). sys.dm_db_index_physical_stats (http://msdn2.microsoft.com/en-us/library/ms188917.aspx) shows the actual number of ghosted records and you may correlate this with your observations.

HTH,

~ Remus