r/SQLServer • u/TheSmashingChamp • Aug 16 '26
Solved Temp Cache endlessly expanding until server failure/slowdown
I am working on a consultant's azure gov cloud portal where I put applications on. There is a consistent issue with queries running forever even after being finished executing. Do anyone have experience with this? The temp cache endlessly expands until our DB fails.
I believe the issue is the connector, but it may be the queries? I dont know.
Solved: it was the connector
7
Upvotes
•
u/AutoModerator Aug 28 '26
After your question has been solved /u/TheSmashingChamp, please reply to the helpful user's comment with the phrase "Solution verified".
This will not only award a point to the contributor for their assistance but also update the post's flair to "Solved".
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/VladDBA Microsoft MVP Aug 16 '26 edited Aug 16 '26
Use sp_QuickieStore with
@sort_order = 'tempdb'to get a list of top 10 queries by tempdb usage or@sort_order = 'avg duration'for the longest running queries.If they're not in the query store you can use Brent Ozar's sp_BlitzCache to try and get them from the plan cache.
Note: "queries running forever even after being finished executing" is an oxymoron. But I'm suspecting that you might be seeing sessions whose requests have completed but still have uncommitted transactions (this tends to happen quite often with JDBC and Java based apps because of JDBC setting IMPLICIT_TRANSACTIONS to on and occasionally "forgetting" to issue a commit).
In this case you catch those in the act by running Brent Ozar's sp_BlitzWho and said sessions will show up as sleeping but with one or more opened transactions.
1
u/dlevy-msft Microsoft Employee Aug 17 '26
Any chance your code calls
sp_xml_preparedocument?1
u/dbrownems Microsoft Employee Aug 17 '26
What exactly are the symptoms? What specific diagnostics have you captured?
1
u/Better-Credit6701 Aug 16 '26
One of the things that we monitor is virtual log files. If we see the number growing, we do a full backup and shrink the log. Same solution on local SQL servers or Azure
1
u/FishBones83 Aug 16 '26
what about reviewing wait stats to see if something is holding the query up? check the transaction log to make sure the queries are actually committing. To me it sounds like either a performance issue (blocking or resource bottleneck) or an issue with query logic. finding the query in query store might help too.
1
u/CanProfessional766 Aug 17 '26
If the queries are actually finishing but the temp space keeps growing, something may not be getting cleaned up open connections, transactions, result sets, etc. I’d try running the same queries directly against the DB and compare. If the problem only happens through the portal/connector,that would point pretty strongly to the connector rather than the queries themselves
0
u/Dry_Author8849 Aug 16 '26
If you have slow queries, the queries will continue executing until the query returns the first row. Even if the session is disconnected, sql server won't end the query immediately.
Query options, like language, arith abort, ansi nulls, make the query plan different. Usually when you run the query from SSMS the default query options are different than when you connect to sql server from python or other programs.
It's very common to tune a query from SSMS that is instant, and then when run from your program, behave slow.
So, your problem is likely caused by those two things. Your query runs with different query options and becomes slow when run from python. Your users refresh and execute the query again and again and the queries pile up until each return the first row.
The first thing is to set your query options exactly as SSMS (sql server management studio) does. You can look at them with the sql profiler or check the commands to read them from SSMS.
The other thing you need to do is to program your backend to cancel the queries when an http connection is closed. It varies according your platform and programming language, but that will ensure the query is stopped immediatly if the user/client has stopped waiting for results.
Cheers!