Create and Monitor Jobs

A job is an Oracle Cloud Infrastructure resource that enables you to create and asynchronously execute SQL jobs on a single Managed Database or all the Managed Databases in a Database Group.

Before you create a job and monitor its runs and executions, you must:

To go to the Jobs section:

  1. Sign in to the Oracle Cloud Infrastructure console.
  2. Open the navigation menu, click Observability & Management. Under Database Management, click Diagnostics & Management.
  3. Depending on whether you want to create a job for a single Managed Database or a Database Group, go to one of the following pages:
  4. In the left pane, expand Management and click Jobs.

The following tabs are displayed in the Jobs section:

  • Runs: On this tab, you can monitor job runs and executions.
  • Definitions: On this tab, you can create a job and view the jobs that are in the Active state and were created within the time period selected in the Time period applied filter.
  • Job templates: On this tab, you can view Oracle-defined and user-defined job templates, and create and manage user-defined job templates.

Create a Job

You can create a SQL job to perform administrative operations on a single Managed Database or a Database Group.

When creating a job, you can specify the SQL command or use an Oracle-defined or user-defined job template.

Note

To create a job from a job template, you must have permission to read the job template, in addition to the permissions required to create jobs. For information, see Database Management Permissions.

The information provided when creating a job is to enable the following components to connect and interact:

  • The single Managed Database or the Database Group on which the job will be executed.
  • If an Oracle Cloud Infrastructure Management Agent is used to configure network access to the database, it's used to execute the job.
  • The Oracle Cloud Infrastructure Object Storage bucket in which job results for a Query type job are stored.

To create a job:

  1. Go to the Managed database details page for the Managed Database or the Managed databases page for the Database Group, for which you want to create the job.
  2. In the left pane, click Jobs. For a Managed Database, first expand Management.
  3. In the Jobs section, click the Definitions tab and then click Create job.
  4. In the Create job panel:
    1. Select one of the following source options to specify how to create the job:
      • Create new: Select to create a job by specifying the SQL command and any bind variables.
      • Create from job template: Select to create a job using an Oracle-defined or user-defined job template. Select a template in the Job template drop-down list. If the compartment in which the job template resides is different from the compartment displayed, click Change compartment and select another compartment.
        Note

        When you select a job template, the job name, job description, SQL type, SQL command, and bind variable definitions are populated based on the selected template. You can edit the job name and description and provide values for the bind variables. You cannot change the SQL type, SQL command, or bind variable definitions.
    2. Provide the following information for the SQL job:
      1. Job name: Enter a unique name for the job.
      2. Job description: Optionally, enter a description for the job.
      3. SQL type: If you selected Create new as the source, select the SQL type. The available options are:
        • Query
        • DML
        • DDL
        • PL*SQL
      4. Choose compartment: Select the compartment in which you want to create the job. The compartment in which the Managed Database or Database Group resides is selected by default, however, you can opt to create the job in a different compartment.
      5. Timeout: Depending on the time the SQL job is likely to take, select one of the options in the drop-down list, and based on the selected option the job is prioritized.
    3. Provide schedule details for the job by selecting one of the following options:
      • One time (immediately): Select to execute the job once (immediately).
      • One time (later): Select to execute the job once (later) and specify the time when it should be executed.
      • Repeating: Select to execute a job multiple times at the specified frequency. If you want to specify an end date for the scheduled job, then select the Define end date check box.
    4. Select one of the available options in the Credential type drop-down list to specify database credentials to connect to the Managed Database. For information on credential types, see Use Credentials to Perform Diagnostics & Management Tasks.
      Note

      • If creating a job for a Database Group, you cannot use named credentials and you will have to select the New credential option in the Credential type drop-down list and specify the user name, user password secret, and role. Also, when creating a job for a Database Group, the database credentials must apply to all the databases in the Database Group.
      • When creating a scheduled job (to be executed once or multiple times), if A policy is required... message is displayed, click Add policy to view the resource principal policy that grants Managed Database resources the permission to access the secret, and automatically add it. The Oracle Cloud Infrastructure IAM service creates the policy and it's added to a collection of policies called DBMgmt_Resource_Policy in the IAM service.
    5. For a Query type job, select the Object Storage bucket in which the job results will be stored. The Oracle object storage for job results section with the Bucket name drop-down list is only displayed if you've selected the Query type job. The Object Storage bucket can be in the same compartment as the job or in another compartment, and you must have the required Object Storage service permissions to select the bucket.

      When creating a scheduled job (to be executed once or multiple times), if A policy is required... message is displayed, click Add policy to view the resource principal policy that grants Managed Database resources the permission to write the results of the scheduled job to an Object Storage bucket, and automatically add it. The IAM service creates the policy and it's added to a collection of policies called DBMgmt_Resource_Policy in the IAM service.

      For information on:

    6. If you selected Create new as the source, click Load SQL to load the SQL command or enter it in the SQL command field. If you're entering a SQL command, then do not add a trailing ; or /.

      If you selected Create from job template as the source, review the SQL command populated from the selected template. The SQL command cannot be edited.

    7. If you selected Create new as the source, optionally add bind variables for Query, DML, and PL*SQL type jobs in the Bind variables section. If bind variables are used as placeholders that must be replaced with valid values for the statement to execute successfully, then click Add bind variable and specify the following information:
      1. Position: Select the bind variable position.
      2. Type: Select the type to specify if the bind variable is an in-bind or out-bind variable.
      3. Data type: Select the relevant data type.
      4. Array type: Enter the array type for the Array of numbers and Array of strings data types. Note that this field is not displayed if you select Number, String, or CLOB in the Data type field.
      5. Value: Enter the bind variable value.

      To add more bind variables, click Add bind variable and provide the required information.

      If you selected Create from job template as the source, enter a value in the Value field for each input bind variable defined in the selected template. The bind variable definitions cannot be changed.

      For information on bind variables, see Bind Variables and Cursors in Oracle Database SQL Tuning Guide.

    8. Optionally, click Show advanced options to add free-form or defined tags to the job. If you have the permissions required to create a job, then you also have permissions to add free-form tags. To add a defined tag, you must have permissions to use the tag namespace.

      For information on:

    9. Click Create job.
The new job is listed on the Definitions tab in the Jobs section of the Managed Database or Database Group. The status of the job is Active if it's being executed and Inactive if it's already executed.

You can click the Actions icon (Actions) for the job and perform the following tasks:

  • View details: Click to go to the Job details page and view the details of the job, job runs and executions, the associated Managed Databases on which the job is executed, and perform tag-related tasks. For more information, see Monitor Job Runs and Executions.
  • Clone job: Click to clone the job.
  • Edit job: Click to edit the details of scheduled repeating jobs in Active state.
  • Move job: Click to move the job from the current compartment to another compartment.
  • Delete job: Click to delete the job.

On the Runs tab in the Jobs section, you can view the associated job runs and executions. The job runs for the time period selected in the Time period applied filter are displayed along with an overview of the status of the job executions: Succeeded, Failed, and In progress. You can click the execution status links to filter the executions by status.

Note

Job executions for Oracle Cloud Databases have a time limit of 50 minutes. If the job execution exceeds this limit, it fails and an error is displayed.

You can build metric queries and create alarms on the job execution status in the Oracle Cloud Infrastructure Monitoring service using the dbmgmtJobExecutionsCount metric. For more information, see Diagnostics & Management Metrics for Oracle Databases.

Here's an example of a query that you can use to create a "failed job" alarm:

dbmgmtJobExecutionsCount[1m]{managedDbId = "<OCID of the Oracle Database>", status = "Failed"}.mean()

In the query, the managedDbId dimension is used to notify you of any failed jobs for the Managed Database whose OCID is mentioned in the query. Similarly, you can use the following dimensions:

  • managedDbGroupId: To be notified of failed jobs for all the Managed Databases in a Database Group.
  • jobId: To be notified if a particular job fails.

For more information on how to create an alarm, see Creating a Basic Alarm.

Monitor Job Runs and Executions

You can monitor the runs and executions of a submitted job for a Managed Database or Database Group. A job execution is created for each of the Managed Databases associated with the job, and a job run is the sum of executions of a specific job that ran on a scheduled date.

To view the job runs and executions:

  1. Go to the Managed database details or the Database Group Managed databases page.
  2. In the left pane, expand Management and click Jobs.
  3. In the Jobs section, click the Definitions tab.

    Ensure that the compartment in which the job was created is selected in the Compartment applied filter.

  4. Click the name of the job. Alternatively, you can also click the corresponding Actions icon (Actions) and click View details.

The Job runs page is displayed and it provides the details of the job, job runs and executions, and the associated Managed Databases on which the job is executed. On this page, you can perform tasks such as editing, moving, and deleting the job and using tags. In addition, you can also monitor each job execution and its status. To do so:

  1. Expand a job run, and click a job execution link.

    The job execution link is in the following format:

    <Name of job>_<Name of Managed Database>_YYYY-MM-DD'T'HH:MM:SS.SSS
  2. On the Job execution output page, click Job execution details and review the details such as the job execution status, the SQL associated with the execution, and the duration of the job execution. Note that the duration is the time taken for the entire job execution workflow to complete and not just the time taken for the SQL to execute on the database.
  3. For a Query type job, click Download output to download the job execution output to a .txt file.
    Note

    The Download output option is only available for Query type jobs and you can use this option only if you have the required Oracle Cloud Infrastructure Object Storage service permissions. For more information, see Additional Permissions Required to Use Diagnostics & Management.

Create and Manage Job Templates

You can create and manage reusable job templates to create SQL jobs for Managed Databases or Database Groups.

A job template contains a SQL command and bind variable definitions. You can use job templates to create jobs without entering the SQL command and defining bind variables each time.

The following types of job templates are available:

  • Oracle-defined: Predefined job templates for common database tasks. You cannot edit or delete Oracle-defined templates, but you can clone them to create user-defined templates.
  • User-defined: Job templates that you create or clone from existing templates. You can edit and delete user-defined templates.

To create and manage job templates, you must have the required Database Management permissions. For information, see Database Management Permissions.

To create a job template:

  1. Go to the Managed database details page for a Managed Database or the Managed databases page for a Database Group.
  2. In the left pane, click Jobs. For a Managed Database, first expand Management.
  3. In the Jobs section, click the Job templates tab and then click Create job template.
  4. In the Create job template panel:
    1. Provide the following information for the job template:
      1. Enter a name for the job template.
      2. Optionally, enter a description for the job template.
      3. Select the SQL type.
      4. Select the compartment in which you want to create the job template.
    2. Click Load SQL to load the SQL command or enter it in the SQL command field.
    3. If the SQL command uses bind variables, add the corresponding definitions in the Bind variables section. Click Add bind variable and specify the following information:
      1. Position: Select the bind variable position.
      2. Type: The available option is IN, which specifies an input bind variable.
      3. Data type: Select the relevant data type.
      4. Array type: Enter the array type for the Array of numbers and Array of strings data types. Note that this field is not displayed if you select Number, String, or CLOB in the Data type field.
      5. Default value: Enter a default value for the bind variable.

      To add more bind variables, click Add bind variable and provide the required information.

      You can specify default values for input bind variables in the template and provide or update their values when creating a job from the template.

      For information on bind variables, see Bind Variables and Cursors in Oracle Database SQL Tuning Guide.

    4. Optionally, click Show advanced options to add free-form or defined tags to the job template. If you have the permissions required to create a job template, then you also have permissions to add free-form tags. To add a defined tag, you must have permissions to use the tag namespace.

      For information on:

    5. Click Create job template.

The new job template is listed on the Job templates tab in the Jobs section.

You can click the Actions icon (Actions) for a job template and perform the following tasks:

  • View details: Click to view the basic information, SQL command, and bind variable definitions of the job template.
  • Associated jobs: Click to view the jobs associated with the job template.
  • Clone template: Click to clone the job template.
  • Edit template: Click to edit a user-defined job template.
  • Change compartment: Click to move a user-defined job template from the current compartment to another compartment.
  • Delete template: Click to delete a user-defined job template.

To create a job using a template, select Create from job template in the Create job panel. For information, see Create a Job.