I want to create a stored procedure/ Job that will monitor all the SQL server Agent job. When any of the SQL Server Agent's jobs fail it will send and email with the job name to the admin.
What is the best way to create such a job that will monitor all jobs.
You can approach this issue in several ways. From top of my head you can use either a SSRS report scheduled for auto delivery. Or a SQL agent job that run periodically.
In both cases the an underlying stored procedure needs to be built that queries sysjobs and related tables in MSDB.
Related
I have a Job in SQL server which is scheduled to 'Start automatically when SQL Server Agent starts', however, this is creating some issues in our environment. The issue is not SQL specific but because of it we need to delay the execution of this particular job. I cannot schedule this as a recurring job and assign a particular time of a day, it needs to run every time when the SQL Server starts. Is there a way in which I can schedule the job that runs after 15 mins after SQL Server Agent starts?
Sure, just make the first step:
WAITFOR DELAY '00:15:00';
(Or, probably better, you could try to resolve whatever "some issues" are.)
However, note that someone can restart the Agent service without restarting SQL Server; or, they could set SQL Server Agent to not automatically start at startup, so that the next time the SQL Server service is restarted, your procedure will not run.
If you want to tie some startup activity to SQL Server starting, you could probably look into startup procedures, but if you need it to wait 15 minutes, the first thing in the procedure would be the above WAITFOR. Also startup procedures can't have input parameters (or output parameters, but that is less likely to be an issue for a stored procedure you're calling from a job).
Finally, SQL Server 2008 R2? That was barely still in support at the beginning of the last decade.
I have Oracle source and SQL Server. Every day at 12.00 AM Oracle data populate for oracle database tables, after that sql server agent jobs run manually by me after Oracle Data Extraction completed. for SQL Server databases, I want to automate this process. when oracle data population completed i need to run sql server agent jobs automatically, how can i do this.
You write a little program that will monitor the oracle process and when it "sees" that is has completed (probably successfully - you skipped that part) it starts the sql server job. Now - how do you do that? How do you know that the process both completed and successfully? Go figure it out based on what functionality Oracle offers and (perhaps) the characteristics of the output that signify success.
Perhaps you can vastly simplify things and schedule some sort of "do it" job that will look for "good" output. Schedule it for a time that is more than sufficient for the oracle process to complete. Do some checking and if things look good, start the other job.
I have read this great Remus Rusanu's article
http://rusanu.com/2009/08/05/asynchronous-procedure-execution/
How to implement this idea:
I have a big main table, user can mark 'as delete' records there (set field to 1)
I cannot use SQL Jobs because customers can use SQLExpress.
The idea is: when user 'delete' or 'undelete' records in big table need to send message to a queue.
An activation proc 'fire and forget' proc to execute real Delete statement for marked records in the main table - all or parts, it depends.
But need maximally to avoid blocking.... That's why the question:
How to execute real deletion when SQL Server has a lowest loading? or when database has a lowest activity?
How to detect these 'Low database loading' moments in the async proc?
There is no way to lync Service Broker activation directly to workload and only activate during 'low activity'.
I cannot use SQL Jobs because customers can use SQLExpress
While is true that SQL Server Express Edition lacks SQL Agent scheduling, there are work arounds using Service Broker conversation timers. See Scheduling Jobs in SQL Server Express (and part 2).
We have a transactional replication setup using 3 SQL Servers, 1st as publisher, 2nd as distributor, and 3rd as subscriber.
We have an activity to change the location of the replicated DB (subscriber) using de-attach and attach method. During this activity, I will need to stop the SQL server and hence all replicated transactions will fail.
What's the proper way to pause the replication during this activity, so when I attach the DB again and start the SQL service, replication will resume normally.
Thanks
Please see the following link for details of how to accomplish this:
Start and Stop a Replication Agent
The above article doesn't appear to give information on stopping the distribution agent, this can be achieved by using the stored procs detailed in the link below:
Start/Stop SQL Server Replication Agent using TSQL
SQL Server Agent allows you to create Notifications at the moment a Job succeeds or fails, but I'd like to create a regular notification that sends a summary of the events for those who are one step removed from server maintenance.
Is there a way to setup summary notifications that spell out which jobs failed over the last 24 hours?
There are several system stored procedures that you might be able to use or you could query directly against the system tables. If you have SSRS available then put together a report using those queries and you can have it on-demand or scheduled to be emailed to the necessary people at whatever time is right for you.
Specifically, check out sp_help_jobhistory and sp_help_jobhistory_full in msdb.
I'd be surprised if you couldn't use Google to find a demo of setting this up.