Re: limit sql agent job resource with resource governor



Another thing I'll mention (and it's part of the best practices section of
the forthcoming whitepaper) is that you should try to avoid standalone IF
conditions that assign workload group names. This makes it too easy to meet
one, and then meet another one further down, which you might not anticipate.

I would much rather see:

SELECT @workload_group_name = CASE
WHEN ... THEN ...
WHEN ... THEN ...
ELSE 'default'
END

This way, no matter how many of your conditions are met, only the first one
is ever used - and you can rank them in priority. So imagine you have one
condition that says, all users running Management Studio go into group A.
Before that, you have one that says

IF USER_NAME() = 'ceo'
SET @workload_group_name = 'group A';

IF APP_NAME() LIKE '%studio'
SET @workload_group_name = 'group B';

Now your CEO happens to be using Management Studio, he/she will end up in
group B, which could get you fired if it is not what you expected. If you
had used CASE then the second test would never have been attempted. This is
obviously better for debugging and logic purposes, but also helps
performance slightly. Optimizing the performance of this function is
critical and anything you can do to prevent unnecessary work will be better
for you in the long run.

A



On 5/28/09 11:40 AM, in article #olegq63JHA.3860@xxxxxxxxxxxxxxxxxxxx,
"James" <kush@xxxxxxxxxxx> wrote:

Still doesn't make sense because I could see that the username is correct
throughout the time the job is running. I run the DMV query multiple times
during the job run and still see the same login.
If the job were to connect with one user in the begining and change after it
starts executing, then, I should see different user from the DMV query in
the middle or end of job run right? Well, I am not seeing that behaiour, the
username stays the same throughout the job run.

Anyway, As you guys suggested, I will explore different options like
app_name() etc. If you have a sample classifier function code that uses
app_name() specifically for sql agent job, I will appreciate it if you share
that info. Once again thanks a bunch for your time.

"Aaron Bertrand [SQL Server MVP]" <ten.xoc@xxxxxxxxxxxxxx> wrote in message
news:C64402BE.2C7E9%ten.xoc@xxxxxxxxxxxxxxxxx
Definitely, the resource governor classification happens long before the
user/session can execute any commands. It goes:

Authentication -> logon triggers -> classification -> ok now let the
session
do its work (including "execute as")...

As I suggested before, you should use some other way to identify the job
in
the classifier function. Hint: look at APP_NAME(); it has a unique
job_id.

A





On 5/28/09 1:45 AM, in article #EVeUe13JHA.1416@xxxxxxxxxxxxxxxxxxxx,
"Tibor
Karaszi" <tibor_please.no.email_karaszi@xxxxxxxxxxxxxxxxxx> wrote:

I think what is happening is that the classifier function is executed
before Agent executes the EXECUTE AS command. And not until later to
you run your query to see the login name. Again, I doubt you can use
the login name for this scenario - since Agent uses its own login and
not until *later* impersonates the selected login.




.



Relevant Pages

  • Re: limit sql agent job resource with resource governor
    ... Still doesn't make sense because I could see that the username is correct ... I run the DMV query multiple times ... during the job run and still see the same login. ... do its work (including "execute as")... ...
    (microsoft.public.sqlserver.server)
  • Re: limit sql agent job resource with resource governor
    ... during the job run and still see the same login. ... If you have a sample classifier function code that uses ... do its work (including "execute as")... ... before Agent executes the EXECUTE AS command. ...
    (microsoft.public.sqlserver.server)
  • Re: SQL Server and Agent Accounts
    ... authority\Network service" isn't a member of SQL server sysadmin. ... Distributor, the user need to be a member of the sysadmin fixed server ... Replication implements login security by requiring a user to have a valid ... On the Microsoft Windows 98 operating system, SQL Server Agent and the ...
    (microsoft.public.sqlserver.replication)
  • Re: SQL Server 2000 Replication Agents Credentials
    ... the snapshot agent IS using sql login to connect to the ... The pull distribution agent IS using sql ... Do you know where SQL Server 2000 saves the sql ...
    (microsoft.public.sqlserver.replication)
  • RE: SQL Server Errorlog login Failure
    ... the login error. ... If your replication agents are proper, ... agent startup account etc to resolve it. ... ||I have an Windows account that runs all my SQL Server ...
    (microsoft.public.sqlserver.replication)

Quantcast