r/SQLServer • • 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

30 comments sorted by

View all comments

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/TheSmashingChamp Aug 16 '26

My applications are all Python based. Front end with react. I believe the issue is the connector. I have monitored tempeh usage when running the application locally and found no issues. The temp always clears on it own or doesn’t fill at all (less than 1 MB). On the azure platform a users sessions holds forever regardless of where they access a query. I am at a loss here

1

u/jwk6 Aug 17 '26

It has to be an issue with your backend Python code, or possibly a driver configuration problem.

Are you using Connection Pooling and not explicitly calling close() on each connection, or using With, to close and return the connections to the pool?

1

u/Lost_Term_8080 Aug 17 '26

I've seen the same thing in python apps with a default to implicit transactions without auto commit.

1

u/jwk6 Aug 16 '26

Great advice!

I'll also add sp_whoisactive.

https://github.com/amachanic/sp_whoisactive/releases

If you run sp_whoisactive while the culprit queries are executing (before the failure occurs) , then you will see the current tempdb usage for each session also, the status, and how long each query has been running, etc.