CHAPTER 21 Automating Jobs. Introduction to Automating Jobs DBAs rely heavily on automating jobs. DBAs cannot be effective without automation. Listed.

Slides:



Advertisements
Similar presentations
CHAPTER 4 Tablespaces and Datafiles. Introduction After installing the binaries, creating a database, and configuring your environment, the next logical.
Advertisements

Week 6: Chapter 6 Agenda Automation of SQL Server tasks using: SQL Server Agent Scheduling Scripting Technologies.
18 Copyright © 2005, Oracle. All rights reserved. Moving Data.
Self-Managing Database: Easy Upgrade Tom Graves Consulting Member of Technical Staff Oracle Corporation Session id:
1 Chapter 17 Troubleshooting RMAN. 2 Background Authors thought this topic was often glazed over or not covered well Knew that every topic can’t be covered,
A Guide to Unix Using Linux Fourth Edition
Linux+ Guide to Linux Certification, Second Edition
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 12: Managing and Implementing Backups and Disaster Recovery.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment Chapter 9: Implementing and Using Group Policy.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Linux+ Guide to Linux Certification, Second Edition
RMAN Restore and Recovery
9 Copyright © Oracle Corporation, All rights reserved. Oracle Recovery Manager Overview and Configuration.
Backup Concepts. Introduction Backup and recovery procedures protect your database against data loss and reconstruct the data, should loss occur. The.
CHAPTER 18 RMAN Backups and Reporting. Introduction to RMAN Backups and Reporting The focus of this chapter is backups of: Datafiles Control files Archived.
Agenda  Overview  Configuring the database for basic Backup and Recovery  Backing up your database  Restore and Recovery Operations  Managing your.
Introduction to Oracle Backup and Recovery
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 12: Managing and Implementing Backups and Disaster Recovery.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
17 Copyright © 2004, Oracle. All rights reserved. Automating Tasks with the Scheduler.
PPOUG, 05-OCT-01 Agenda RMAN Architecture Why Use RMAN? Implementation Decisions RMAN Oracle9i New Features.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Linux Operations and Administration
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 9: Implementing and Using Group Policy.
Using Group Policy to Manage User Environments. Overview Introduction to Managing User Environments Introduction to Administrative Templates Assigning.
SUSE Linux Enterprise Server Administration (Course 3037) Chapter 4 Manage Software for SUSE Linux Enterprise Server.
Oracle10g RAC Service Architecture Overview of Real Application Cluster Ready Services, Nodeapps, and User Defined Services.
Guide to Linux Installation and Administration, 2e1 Chapter 8 Basic Administration Tasks.
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 12: Managing and Implementing Backups and Disaster Recovery.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Chapter 9 Scripting RMAN. Background Authors felt that scripting was a topic not covered well Authors wanted to cover both Unix/Linux and Windows environments.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Linux Operations and Administration
Linux+ Guide to Linux Certification, Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 10 Managing System Resources.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
IT 456 Seminar 5 Dr Jeffrey A Robinson. Overview of Course Week 1 – Introduction Week 2 – Installation of SQL and management Tools Week 3 - Creating and.
Linux Operations and Administration
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
SUSE Linux Enterprise Desktop Administration Chapter 6 Manage Software.
Oracle 10g Database Administrator: Implementation and Administration Chapter 2 Tools and Architecture.
17 Copyright © Oracle Corporation, All rights reserved. Recovery Catalog Creation and Maintenance.
Linux+ Guide to Linux Certification, Second Edition Chapter 10 Managing Linux Processes.
Chapter 10 Chapter 10: Managing the Distributed File System, Disk Quotas, and Software Installation.
Guide to Linux Installation and Administration, 2e1 Chapter 11 Using Advanced Administration Techniques.
1 Chapter Overview Defining Operators Creating Jobs Configuring Alerts Creating a Database Maintenance Plan Creating Multiserver Jobs.
Linux+ Guide to Linux Certification Chapter Eleven Managing Linux Processes.
14 Copyright © 2005, Oracle. All rights reserved. Backup and Recovery Concepts.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Operations and Administration
SPI NIGHTLIES Alex Hodgkins. SPI nightlies  Build and test various software projects each night  Provide a nightlies summary page that displays all.
2 Copyright © 2007, Oracle. All rights reserved. Configuring for Recoverability.
Hyperion Artifact Life Cycle Management Agenda  Overview  Demo  Tips & Tricks  Takeaways  Queries.
CHAPTER 1 Installing the Oracle Binaries. Introduction to Managing and Safeguarding Your Organization’s Data Efficiently installing Oracle software Create.
Linux+ Guide to Linux Certification, Second Edition
14 Copyright © 2005, Oracle. All rights reserved. Backup and Recovery Concepts.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Introduction to Utilities for New DBAs Session #332 4/19/2008 Erik Hobbs Introduction to Utilities for New DBAs.
Linux Administration Working with the BASH Shell.
SQL Database Management
Chapter 2: System Structures
Using SQL*Plus.
Chapter Four UNIX File Processing.
Periodic Processes Chapter 9.
DBMS_SCHEDULER: The How, What and Why
Presentation transcript:

CHAPTER 21 Automating Jobs

Introduction to Automating Jobs DBAs rely heavily on automating jobs. DBAs cannot be effective without automation. Listed next are a sample of tasks DBAs typically automate: Shutdown and startup of databases and listeners Backups Validating the integrity of backups Checking for errors Removing old trace or log files Checking for errant processes Checking for abnormal conditions

Utilities to Automate Oracle Scheduler The Linux/Unix cron utility Others?

Creating and Scheduling a Job Using Oracle Scheduler Use the CREATE_JOB procedure of the DBMS_SCHEDULER package to create a job. Run the following as SYS (from the SQL*Plus): BEGIN DBMS_SCHEDULER.CREATE_JOB( job_name => 'RMAN_BACKUP', job_type => 'EXECUTABLE', job_action => '/orahome/oracle/bin/rmanback.bsh', repeat_interval => 'FREQ=DAILY;BYHOUR=14;BYMINUTE=11', start_date => to_date('21-OCT-10'), job_class => '"DEFAULT_JOB_CLASS"', auto_drop => FALSE, comments => 'RMAN backup job', enabled => TRUE); END; /

Viewing Job Details To view details about how a job is configured query the DBA_SCHEDULER_JOBS view. This example selects information for the RMAN_BACKUP job: SELECT job_name,last_start_date,last_run_duration,next_run_date,repeat_interval FROM dba_scheduler_jobs WHERE job_name='RMAN_BACKUP';

Modifying Job Logging History By default Oracle Scheduler keeps 30 days worth of log history. You can modify the default retention period via the SET_SCHEDULER_ATTRIBUTE procedure. For example, this changes the default number of days to 15: SQL> exec dbms_scheduler.set_scheduler_attribute('log_history',15); To completely remove the contents of the log history, use the PURGE_LOG procedure: SQL> exec dbms_scheduler.purge_log();

Modifying a Job You can modify various attributes of a job via the SET_ATTRIBUTE procedure. This example modifies the RMAN_BACKUP job to run weekly on Monday: BEGIN dbms_scheduler.set_attribute( name=>'RMAN_BACKUP',attribute=>'repeat_interval',value=>'freq=weekly; byday=mon'); END; /

Stopping a Job If you have a job that has been running for an abnormally long time, you may want to abort it. Use the STOP_JOB procedure to stop a currently running job. This example stops the RMAN_BACKUP job while it is running: SQL> exec dbms_scheduler.stop_job(job_name=>'RMAN_BACKUP');

Disabling a Job You may want to temporarily disable a job because it's not running correctly or you may want to stop a job while performing an upgrade or maintenance activity and so on. Use the DISABLE procedure to disable a job: SQL> exec dbms_scheduler.disable('RMAN_BACKUP');

Enabling a Job You can enable a previously disabled job via the ENABLE procedure of the DBMS_SCHEDULER package. This example re-enables the RMAN_BACKUP job: SQL> exec dbms_scheduler.enable(name=>'RMAN_BACKUP');

Copying a Job If you have a current job that you want to clone, you can use the COPY_JOB procedure to accomplish this. This procedure takes two arguments: the old job name and the new job name. Here's an example of copying a job where RMAN_BACKUP is a previously created job and RMAN_NEW_BACK is the new job that will be created: begin dbms_scheduler.copy_job('RMAN_BACKUP','RMAN_NEW _BACK'); end; /

Running a Job Manually You can manually run a job outside of its regular schedule. You might want to do this to test the job to ensure that it's working correctly. Use the RUN_JOB procedure to manually initiate a job. This example manually runs the previously created RMAN_BACKUP job: BEGIN DBMS_SCHEDULER.RUN_JOB( JOB_NAME => 'RMAN_BACKUP', USE_CURRENT_SESSION => FALSE); END; /

Deleting a Job If you no longer require a job, you should delete it from the scheduler. Use the DROP_JOB procedure to permanently remove a job. This example removes the RMAN_BACKUP job: BEGIN dbms_scheduler.drop_job(job_name=>'RMAN_BACKUP'); END; /

Oracle Scheduler Advantages over cron Can make the execution of a job dependent on the completion of another job Robust resource balancing and flexible scheduling features Can run jobs based on a database event The Oracle Scheduler DBMS_SCHEDULER PL/SQL package syntax works the same regardless of the operating system Can run status reports using the data dictionary If working in clustered environment, no need to worry about synchronizing multiple cron tables for each node in the cluster Can be maintained and monitored via Enterprise Manager

cron Advantages over Scheduler Easy to use, simple, tried and true; only takes seconds to create and/or modify jobs Almost universally available on all Linux/Unix boxes; for the most part, runs nearly identically regardless of the Linux/Unix platform (yes, there are minor differences) Database agnostic; operates independently of the database and works the same regardless of the database vendor or database version Works whether the database is available or not

How cron Works When your Linux/Unix server boots up, a cron background process is automatically started that manages all cron jobs on the system. The cron background process is also known as the cron daemon. This process is started on system startup by the /etc/init.d/crond script. You can check to see whether the cron daemon process is running with the ps command: $ ps -ef | grep crond | grep -v grep root Aug02 ? 00:00:00 crond

Enabling Access to cron To verify whether you have access to access cron type in the following: $ crontab -e If you receive the following error message, then you do not have access: You (oracle) are not allowed to use this program (crontab) To enable cron access, as the root user, add oracle to the /etc/cron.allow file with the echo command: # echo oracle >> /etc/cron.allow

Understanding cron Table Entries Your cron table is a list of numbers and commands that the cron background process (cron daemon) will run at a specified time and schedule. The crontab utility expects entries to follow a well-defined format. You can add a comment line at the beginning of your crontab file that documents the required format: # min(0-59) hr(0-23) dayMonth(1-31) monthYear(1-12) dayWeek(0/7-6) commandOrScript 0, * * 1-5 echo "wake up" | mailx -s "wake up"

Editing the cron Table Directly You can edit your cron table directly with the -e (editor) option of the crontab command: $ crontab -e

Loading the cron Table from a File The other way to modify your cron table is to load it directly with a file name using the following syntax: $ crontab

Redirecting cron Output Whenever you run a Linux shell command by default the standard output (of the command) will be displayed on your screen. Also if any error messages are generated they will by default be displayed on your terminal. You can use either > or 1> (they are synonymous) to redirect any standard output to an operating system file. Additionally you can use 2> redirect any error messages to a file. The notation of 2>&1 instructs the shell to send any error messages to the same location as standard output.

Troubleshooting cron 1. Copy your cron entry, paste it to the operating system command line, and manually run the command. Often a slight typo in a directory or file name can be the source of the problem. 2. If the script runs Oracle utilities, ensure that you source (set) the required operating system variables within the script such as ORACLE_HOME and ORACLE_SID. Oftentimes these variables are set by startup scripts (like HOME/.bashrc) when you log on. Since cron doesn’t run a user’s startup scripts, any required variables must be set explicitly within the script. 3. Ensure that the first line of any shell scripts invoked from cron specifies the name of the program that will be used to interpret the commands within the script. For example, #!/bin/bash should be the first entry in a Bash shell script. Since cron doesn’t run a user’s startup scripts (like HOME/.bashrc), you can’t assume that your operating system user’s default shell will be used to run a command or script evoked from cron. 4. Ensure that the cron background process is running.

Examples of Automated DBA Jobs Starting and Stopping Database and Listener Checking for Archive Redo Destination Fullness Truncating Large Log Files Checking for Locked Production Accounts Checking for Files over a Certain Age Checking for Too Many Processes Verifying Integrity of RMAN Backups This can be a long list...

Summary In order to manage and maintain an environment with any sort of complexity, DBAs must be proficient with automating various jobs. Oracle’s Job Scheduler and the Linux/Unix cron utility are two tools that DBAs commonly use to automate jobs. If you work in Linux/Unix environments, you should become familiar with cron, it’s widely used.