Troubleshooting Security Cache Growth In SQL Server (USERSTORE_TOKENPERM And TokenAndPermUserStore)

Erik Darling
28 Aug 202411:52

Summary

TLDRIn this video, Eric Darling from Darling Data discusses a common yet strange issue on SQL Server involving the security cache, which can lead to various problems such as CPU spikes and memory issues if left unchecked. He explains how to troubleshoot and resolve these issues, offering queries, scripts, and tools like the SP Pressure Detector. Eric also highlights ways to clear out the security cache and prevent it from growing excessively, and encourages users to engage with his channel, hire him for consulting, or attend his upcoming training sessions.

Takeaways

  • 💡 The video addresses a recurring issue with the security cache in SQL Server, which can cause various performance problems like CPU spikes, memory issues, and stack dumps.
  • 🔍 The security cache stores information about logins and other security details, but if it grows too large, it can negatively impact system performance.
  • ⚠️ A bloated security cache can lead to issues such as increased CPU usage, plan cache problems, and high memory consumption, which can disrupt server performance.
  • 🛠️ The presenter discusses using `DBCC FREE SYSTEM CACHE (TokenAndPermUserStore)` to manually clear out the security cache if it becomes too large.
  • 📊 There are specific queries and scripts that can help monitor and manage the size of the security cache. The `sp_pressure_detector` stored procedure is one example that provides insight into memory usage.
  • 🔧 Trace flags like 4610 and 4618 can be used to manage the security cache, but they need to be set as startup flags to be effective.
  • 📅 Automating the clearing of the security cache can be achieved by using an agent job that runs the necessary scripts regularly, such as every hour, to prevent the cache from growing too large.
  • 🔁 Application behaviors like frequent user impersonation or using `SET APP ROLE` excessively can inflate the security cache. It's important to identify and address these behaviors.
  • 📂 The presenter provides a GitHub repository with scripts for monitoring and managing the security cache size, including an automated procedure that can clear the cache when it exceeds a specified threshold.
  • 👍 The video also covers the importance of keeping the security cache under control to avoid compromising SQL Server performance, especially when it exceeds 2 GB in size.

Q & A

  • What is the main issue discussed in the video?

    -The main issue discussed is the growth of the security cache in SQL Server, which can lead to various performance problems like CPU spikes, memory issues, and plan cache bloating.

  • What is the security cache and why can it cause problems?

    -The security cache stores information related to user logins and permissions. If it grows unchecked, it can consume significant memory, leading to performance issues such as slowdowns, memory allocation problems, and erratic behavior.

  • What are some of the transient issues caused by an oversized security cache?

    -An oversized security cache can lead to CPU spikes, plan cache bloating, memory leaks, stack dumps, and other performance-related problems in SQL Server.

  • How does the speaker inflate the security cache for demonstration purposes?

    -The speaker inflates the security cache by running a loop using the 'set app role' command repeatedly, which artificially grows the security cache to demonstrate the issues it can cause.

  • What tool does the speaker recommend for checking memory usage by the security cache?

    -The speaker recommends using the 'sp_pressure_detector' stored procedure, which provides information on memory consumers in SQL Server, including the size of the user store token perm cache.

  • What SQL command is used to manually clear the security cache?

    -The SQL command used to clear the security cache is 'DBCC FREE_SYSTEM_CACHE('TokenAndPermUserStore')'. This command frees the memory used by the security cache.

  • What are the recommended trace flags to prevent security cache growth?

    -The recommended trace flags are 4610 and 4618. However, these must be startup trace flags to be effective in preventing security cache growth.

  • What should users do if they cannot restart SQL Server to apply trace flags?

    -If users cannot restart SQL Server, they can schedule a stored procedure to regularly monitor and clear the security cache. The speaker provides scripts that automatically clear the cache when it grows beyond a specified size.

  • At what size does the speaker suggest you start worrying about security cache growth?

    -The speaker suggests starting to monitor the security cache closely once it surpasses 2 GB. If it grows to 4, 8, or even 16 GB, it can lead to significant performance issues.

  • Where can users find additional resources and scripts related to this issue?

    -Users can find additional resources and scripts on the speaker's GitHub repository, which includes stored procedures, agent jobs, and diagnostic tools for monitoring and managing the security cache.

Outlines

00:00

🎤 Introduction to a Common Client-Side Issue

Eric introduces himself and the topic of the video, focusing on a strange issue encountered on client servers. This problem causes CPU spikes, plan cache anomalies, memory issues, and other transient problems. The root cause is identified as a growing security cache. He briefly promotes his channel, encouraging viewers to support by subscribing or becoming members. Eric also highlights his consulting services and training opportunities, humorously inviting viewers to interact with him at upcoming events.

05:01

🛠️ Demonstration of the Security Cache Problem

Eric explains the security cache issue in more depth, showcasing how it grows excessively when certain operations like 'set app roll' are executed repeatedly. He walks viewers through a query example, noting how the cache grows over time. Though parsing the XML data isn't ideal due to duplicated lines, Eric emphasizes focusing on when spikes occur. He hints at using his own 'pressure detector' stored procedure to monitor the growth of the security cache.

10:02

🧰 Using Tools to Manage Security Cache Growth

Eric continues discussing the tools available to detect and manage security cache growth. He demonstrates how to clear the cache manually using DBCC commands. He explains how impersonation and switching users in queries contribute to the cache's growth. Eric also mentions trace flags (4610 and 4618) that can help manage the problem, but only if set as startup flags. If issues persist, he refers viewers to his GitHub repository for scripts and procedures to automate cache clearing.

💾 Long-Term Cache Management Strategies

Eric advises on more aggressive strategies for long-term management of the security cache, recommending setting limits to automatically clear it once it surpasses 1-2 GB. He reiterates that growing caches can lead to performance issues, as they consume memory that could otherwise be used for important functions like caching data pages. For those who can't restart SQL servers to set trace flags, Eric encourages using the provided scripts to regularly clear the cache and prevent server slowdowns.

Mindmap

Keywords

💡Security Cache

The security cache in SQL Server stores information related to logins and permissions. When this cache grows unchecked, it can lead to various system performance issues such as CPU spikes, memory problems, and stack dumps. In the video, the speaker explains that managing the security cache is crucial to avoiding these problems.

💡CPU Spikes

CPU spikes refer to sudden increases in CPU usage that can affect system performance. The speaker identifies CPU spikes as one of the main symptoms of an unchecked security cache, which can cause the system to perform inefficiently. Monitoring and managing cache size can help mitigate these issues.

💡Plan Cache

The plan cache stores execution plans in SQL Server for reuse, which can speed up query execution. However, if the security cache grows too large, it can negatively impact the plan cache by using up valuable memory that could otherwise be allocated for storing these execution plans, leading to slower queries.

💡Memory Management

Memory management refers to how resources are allocated and utilized in a system. In the video, the speaker emphasizes how the unchecked growth of the security cache can consume memory that would otherwise be used for other essential functions like query execution or caching data pages. Effective memory management involves clearing caches and adjusting settings to optimize performance.

💡DBCC Commands

DBCC (Database Console Commands) are a set of SQL Server commands used for database management and maintenance. The speaker mentions the command 'DBCC FREE SYSTEM CACHE' as a way to manually clear the security cache when it grows too large. This helps free up memory and maintain system performance.

💡Trace Flags

Trace flags are used in SQL Server to enable or disable specific database behaviors for troubleshooting. The video discusses two trace flags, 4610 and 4618, which can help prevent the security cache from growing too large by managing memory usage. These flags must be set as startup trace flags to be effective.

💡SP Pressure Detector

SP Pressure Detector is a stored procedure mentioned by the speaker that helps detect memory pressure on SQL Server. It provides insights into how much memory is being consumed by different components, such as the security cache. The speaker uses this tool to monitor whether the security cache is growing too large.

💡User Store Token Perm

User Store Token Perm refers to a specific type of memory cache in SQL Server that stores user permissions and tokens. The video describes how this cache can grow excessively due to certain operations, such as user impersonation or switching between users in queries, leading to performance degradation.

💡Application Impersonation

Application impersonation occurs when a system or query switches between different user accounts to perform tasks that require varying permissions. The speaker mentions that this practice can significantly inflate the security cache, contributing to system inefficiencies if not managed properly.

💡Performance Tuning

Performance tuning refers to optimizing a system to improve its efficiency and speed. In the context of the video, the speaker offers training on SQL Server performance tuning, focusing on identifying and mitigating issues like an overgrown security cache. Proper tuning can enhance server stability and performance.

Highlights

Introduction to a recurring, unusual problem with security cache on client servers leading to issues like CPU spikes and memory problems.

Explanation of how the security cache is meant to cache security information about logins but can cause problems when it grows too large.

Security cache issues can cause memory dumps, plan cache problems, and unpredictable performance in SQL Server.

A demonstration of inflating the security cache using repeated loops of the 'set app roll' command.

The problem becomes noticeable when security cache size exceeds 2-3 gigabytes, leading to performance issues.

Use of queries to track the growth of the security cache and detailed XML results for troubleshooting.

The free stored procedure 'SP Pressure Detector' can help identify the size of memory-consuming user token permissions.

Recommendation to manually clear out the security cache using 'DBCC Free System Cache' if it grows too large.

In cases of regular cache growth, startup Trace Flags 4610 and 4618 may help prevent the problem.

For persistent issues, automated scripts from GitHub can monitor and clear the security cache periodically.

Discussion of when security cache size typically becomes a problem, usually around the 2GB mark and upwards.

The risk of letting the security cache grow unchecked includes losing valuable memory resources for other server functions.

Importance of managing memory efficiently to prevent performance degradation in SQL Server.

Detailed guidance on using SP Pressure Detector and other diagnostic tools to track and resolve memory consumption.

Closing remarks on the broader impact of memory-related issues and the benefits of using automated solutions to manage performance.

Transcripts

play00:01

Eric darling here with darling data and

play00:04

I I remember to turn my microphone on so

play00:06

we're off to a great start here uh in

play00:08

today's video we're going to talk about

play00:10

a very weird problem that uh I've seen

play00:12

crop up on client servers a number of

play00:15

times now and lead to all sorts of weird

play00:18

transient issues um CPU spikes plan cach

play00:23

stuff just weird memory things stack

play00:26

dumps uh you name it I've seen this

play00:29

thing be the root cause of all sorts of

play00:30

weird problems and of course that weird

play00:33

thing is the security cache uh it sounds

play00:37

like this like you know nebulous little

play00:40

little doohickey that you know uh is

play00:42

supposed to make life easier uh you know

play00:45

by cashing Securities information about

play00:47

logins and whatnot but uh if it grows

play00:50

grows unchecked uh it can cause some

play00:53

real big problems before we get into all

play00:56

that of course we need to talk a little

play00:58

bit about you and me uh and and and

play01:00

things that things that I like about you

play01:03

uh I like when people sign up for

play01:04

memberships and contribute just a little

play01:07

bit to uh making sure that this channel

play01:09

stays uh free and open source for

play01:11

everyone to use uh it it it it's it's

play01:14

like four bucks a month if if on on the

play01:17

at the low end uh if you don't have four

play01:19

bucks a month I totally understand um

play01:22

you know there are things that I'd

play01:24

probably rather spend four bucks a month

play01:25

on to um but if you if you if you don't

play01:28

want to do that uh liking subscribing

play01:31

commenting all that good stuff is just

play01:33

another way to make my little heart go

play01:34

all a flutter shut up Intel drivers uh

play01:37

if you're in need of SQL Server

play01:39

Consulting that's my job apparently uh I

play01:42

do all this stuff and more and my rates

play01:44

are reasonable so you can you can hire

play01:46

me to to do what I'm going to show you

play01:48

today for you it it's fun it's it's

play01:51

really great

play01:53

fulfilling uh really just you know life

play01:58

affirming work um

play02:00

if you need training in in the SQL

play02:02

Server Performance Tuning space you can

play02:04

get about 24 hours of it for about $150

play02:07

us when you use the discount code spring

play02:10

cleaning uh if you look in the the the

play02:13

the show the the video description I I I

play02:16

hesitate to call this a show um if you

play02:19

look in the video description there's a

play02:21

link with spring cleaning baked right

play02:23

into it and you can you can you can use

play02:25

that it's it's amazing technology uh the

play02:28

the advanced URL technology here at

play02:31

darling data uh if you want to see me

play02:34

live in in

play02:35

person and who wouldn't I'm even better

play02:37

in person cuz you can throw things at me

play02:40

and and I don't know G get give real

play02:44

likes and

play02:46

comments you can comment in real life in

play02:48

real time I think that's called a

play02:51

conversation weird uh I'll be in Dallas

play02:55

uh Friday September the 6th doing a full

play02:57

day training session and November 4th

play02:59

and 5th I will be at past data Summit in

play03:01

Seattle with Kendra little doing 2 days

play03:04

of SQL Server performance precons so you

play03:06

should come see us at those and you

play03:09

should come see me in Dallas if if you

play03:10

happen to be in the neighborhood so now

play03:13

let's get on and talk a little bit

play03:18

about how we can troubleshoot security

play03:20

caches

play03:22

now uh my my good and dear friend Josh

play03:26

Darnell um who is who is an application

play03:28

developer uh was able to figure out this

play03:31

this part of the demo I don't take a lot

play03:33

of credit here aside from doing some

play03:35

nice formatting on it even though there

play03:37

are a couple things that could do some

play03:38

work apparently you know it's hard to

play03:41

hard to find good help these days uh and

play03:43

what the the whole point of this thing

play03:46

is to inflate our security

play03:48

cache so uh that's what I've done I have

play03:51

inflated the security cache uh by using

play03:55

uh set app roll over and over and over

play03:57

and over again in a loop uh I actually

play04:00

had this Loop run I actually the the

play04:02

first run of it got me to about like a

play04:05

gig so I ran this a few times to get it

play04:07

up a little bit higher uh just cuz it

play04:10

made things a little bit more

play04:11

interesting for me not because it's you

play04:12

know really all that fun or interesting

play04:15

or cool for you uh but that that's what

play04:18

I did so

play04:20

um what we've got here are a couple

play04:23

queries that will help you look at

play04:25

security cache stuff if you look at this

play04:28

one you will see that things were

play04:30

cruising along going just fine for a

play04:32

while and then at some point the

play04:34

security cach grew uh so that's about

play04:37

2.3 gigs plus about another gig from the

play04:40

ACR cach store so that'll be about 3.2

play04:43

gigs total uh from uh from

play04:48

there this is a tough query to remember

play04:50

it's not very portable it's not very

play04:52

interesting uh I mean it's kind of

play04:54

interesting uh actually know if you if

play04:56

you look at it uh and you actually click

play04:58

on the XML column uh you can get a lot

play05:00

more information out uh I don't like

play05:02

parsing this stuff out in the actual XM

play05:05

from the XML uh to show in the tabular

play05:07

result because it makes a lot of like

play05:10

duplicate lines that are just kind of

play05:11

messy I generally just zoom into where

play05:14

like things grew or when things grew or

play05:17

like if they you know Spike up from what

play05:19

like a lower number to a higher number

play05:21

or a high number to another higher

play05:22

number uh and then I sort of just dig

play05:24

around in here because you can see all

play05:25

sorts of interesting stuff about you

play05:27

know entries getting put in and but not

play05:30

removed and the size of things and uh

play05:33

it's it is you know mildly interesting

play05:35

if you have the this particular fetish

play05:38

if you want an easy

play05:40

way excuse me an easy

play05:42

way of uh of of figuring out if your

play05:46

system cache if your token and perm user

play05:48

store is growing a lot you can use my

play05:51

free store procedure as pressure

play05:52

detector uh I've get it set up here to

play05:54

only look at memory and to skip some

play05:56

other stuff that's not really per

play05:57

pertinent to us but if you run that

play06:00

right at the very

play06:01

top you will have uh this section here

play06:05

and you will see user store token perm

play06:08

is about 3.2 gigs total which I believe

play06:11

is about what we talked about it being

play06:14

from the the the the XML when we did the

play06:17

XML query it was like you know 2.3 plus

play06:20

0.9 something gigs so that's the size of

play06:23

the token perm store there now you can

play06:26

clear this out manually by running

play06:30

this dbcc free system cach token and

play06:34

perm user store um so but the thing is

play06:37

if this is a something that happens

play06:39

regularly because of your application

play06:41

either using set app roll or like doing

play06:44

impersonation stuff like I think execute

play06:46

as is another thing that can really pump

play06:47

this up uh switching users back and

play06:50

forth and queries for different reasons

play06:52

um I've seen a bunch of applications

play06:53

that you know log in as one user switch

play06:55

to another user to do something switch

play06:57

to another user to do a different thing

play06:58

like they have different per missions

play07:00

and schemas and stuff uh all those

play07:03

things that will inflate the the

play07:05

security caches so you can totally run

play07:08

this to to to clear that out um if this

play07:11

is a big long-term problem for you there

play07:13

are a couple Trace flags that can help

play07:15

the thing is they don't help if you just

play07:17

do this these have to be startup Trace

play07:20

flags for them to really make a

play07:21

difference uh so if you want to look

play07:23

into what 4610 and 4618 do if you're

play07:26

having this problem go crazy they're

play07:29

pretty use useful if you're having the

play07:30

issue but only is startup Trace Flags

play07:32

they don't fix a problem if you just

play07:33

enable them

play07:35

globally if this is a problem that

play07:37

you're having a lot and the trace Flags

play07:40

don't help and your security cach is

play07:42

still growing over in my GitHub repo

play07:45

which I'll have a link to in the the

play07:47

video description I've got a few scripts

play07:49

in there that can

play07:50

help uh one of them is a store procedure

play07:53

that will run look at the size of your

play07:55

security cache and if it and there's a

play07:58

parameter that you pass into to say how

play07:59

big of a security cach you care about uh

play08:02

if it grows beyond a certain size it'll

play08:04

run that dbcc free system Cash Call and

play08:07

clear it out for you I've also got an

play08:10

agent job to set that up to run uh the

play08:13

schedule I think is baked in for like

play08:14

every hour or something if that's not

play08:17

often enough you can of course adjust

play08:18

the schedule but all of this stuff you

play08:20

can just hit F5 on and of course if you

play08:22

want to um inflate your security cach

play08:25

for some reason uh or you just want the

play08:27

the Standalone analysis scripts here

play08:29

here you can use that also in my GitHub

play08:31

repo is sp pressure detector right down

play08:34

here which you can also get totally for

play08:37

free you you don't have to like or

play08:39

subscribe or comment on that uh but you

play08:41

can get that and also view the biggest

play08:43

memory consumers on your server and if

play08:45

that user store token perm stuff is up

play08:48

there you might want to think about you

play08:50

know running the dbcc dbcc command to

play08:52

clear it out maybe enabling the trace

play08:55

flags and maybe using this code to set

play08:57

up a job to clear it out on a regular

play08:59

basis because you might be having all

play09:01

sorts of weird performance issues uh and

play09:04

and reliability issues because this

play09:06

thing grows out of control um as for

play09:09

like how big it it has to be before I

play09:11

worry about it um you know

play09:16

generally once it gets past the two gig

play09:18

Mark is when I see things I see signs of

play09:21

trouble if it gets up past like 4 8 16

play09:25

20 gig somewhere in there then you're

play09:27

just about guaranteed to have some

play09:29

issues

play09:30

so I usually I'm usually pretty

play09:32

aggressive on this and I usually set

play09:33

that to be about around like one one to

play09:35

two gigs uh to clear out uh for the uh

play09:38

store procedure there because like

play09:40

really anything beyond that you're just

play09:42

kind of asking for trouble in the long

play09:43

term

play09:45

so uh I hope that this this is not a

play09:48

problem that you have I hope that you

play09:50

don't have applications that that blow

play09:52

out your server security cash because

play09:54

memory is precious right and if you have

play09:57

you know 8 16 24 gigs of of security

play10:01

cache that's that's memory that your

play10:03

server can't use for other stuff like

play10:05

caching data Pages or query memory

play10:07

grants or having a plan cache or other

play10:10

things like that so it's it's a bad

play10:12

problem to have uh if you are having

play10:14

that problem you've got some Trace flags

play10:16

that you can you can look into you've

play10:17

got some scripts that you can run to

play10:18

clear it out um if you you know I

play10:21

honestly like you know I say try the

play10:24

trace Flags but a lot of people can't

play10:26

just restart SQL server with new startup

play10:28

Trace Flags in place it might be safer

play10:30

for you to just use the scripts there

play10:33

excuse me

play10:35

so look at your SQL server with SP

play10:38

pressure detector if you see high user

play10:41

store token perm anything like over like

play10:43

the 2 gig or so Mark you might want to

play10:46

think about you know clearing that out

play10:48

see if the problem comes back if it

play10:49

keeps coming back I've got you on the

play10:52

scheduled stuff with the store procedure

play10:53

right there uh the store procedure also

play10:55

does some logging so you can see like

play10:57

you know which runs cleared stuff out um

play10:59

how big the security cache was when the

play11:01

when the Run cleared so there's some

play11:03

diagnostic data in there too that's

play11:04

pretty helpful so

play11:06

anyway thank you for watching I hope you

play11:08

enjoyed yourselves I hope you learned

play11:10

something uh I hope that uh every all

play11:14

your dreams come true um I hope that you

play11:18

just get everything you want from life

play11:20

it's it's a short Endeavor and and

play11:23

feeling like you are are missing out on

play11:28

stuff is never a good feeling so I hope

play11:30

I hope you've got no fomo I hope hope

play11:33

that you get everything that your heart

play11:34

desires

play11:36

including this video coming to an end

play11:39

that's what I desire right now because I

play11:41

feel like I'm sticking the landing a

play11:43

little bit here anyway uh uh thank you

play11:46

for watching I'm going to upload this

play11:48

and figure out what to do with my life

play11:49

next all right cool thank you

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
SQL Serversecurity cacheperformance tuningCPU spikesmemory managementdatabase optimizationtroubleshootingserver performanceSQL consultingtrace flags
¿Necesitas un resumen en inglés?