Managing scheduled jobs v9

You can create a PEM scheduled job to perform a set of steps you define in a specified sequence. These steps can contain SQL code or a batch/shell script that you can run on a server that's bound with the agent. You can schedule these jobs to suit your business requirements. For example, you can create a job for taking a backup of a particular database server and schedule it to run on a specific date and time of every month.

To create or manage a PEM scheduled job, use the PEM tree to browse to the PEM agent for which you want to create the job. The tree displays a Jobs node, under which currently defined jobs are listed. To add a job, right-click the Jobs node and select Create Job from the context menu.

Use the tabs on the Create - Agent Job dialog box to define the steps and schedule that make up a PEM scheduled job, as described in the following sections.

Provide general information about the job

Use the General tab to provide general information about a job:

  • Provide a name for the job in the Name field.
  • Set the Enabled switch to Yes to enable a job. Set it to No to disable a job.
  • Use the Comment field to store notes about the job.

Define the job steps

Use the Steps tab to define and manage the steps that the job performs. Select Add (+) to add a step. Then, select the compose icon, located at the left side of the header, to open the Step Definition dialog box.

Use the Step Definition dialog box to define the step:

  • Provide a name for the step in the Name field. Steps are performed in alphanumeric order by name.

  • Use the Enabled switch to include the step when executing the job (True) or to disable the step (False).

  • Use the Kind switch to indicate if the job step invokes SQL code (SQL) or a batch script (Batch).

    • If you select SQL, use the Code tab to provide SQL code for the step.
    • If you select Batch, use the Code tab to provide the batch script to execute during the step.
  • Use the On error list to specify the behavior of pgAgent if it encounters an error while executing the step. Select from:

    • Fail Stop the job if you encounter an error while processing this step.
    • Success Mark the step as completing successfully and continue.
    • Ignore Ignore the error and continue.
  • If you selected SQL as your input for the Kind switch:

    • Use the Server field to specify the server that's bound with the agent for which you are creating the PEM scheduled job.
    • Use the Database field to specify the database that's associated with the server that you selected.
  • Use the Comment field to provide a comment about the step.

  • Use the context-sensitive field on the Step Definition dialog box Code tab to provide the SQL code or batch script to execute during the step:

    • If the step invokes SQL code, provide one or more SQL statements in the SQL query field.

    • If the step invokes a batch script, provide the script in the Code field. If you're running on a Windows server, use standard batch file syntax. On a Linux server, you can use any shell script, provided that you specify a suitable interpreter on the first line (such as #!/bin/sh). Along with the defined inline code, you can also provide the path of any batch script, shell script, or SQL file on the filesystem.

      • To invoke a script on a Linux system, you must modify the entry for the batch_script_user parameter in the agent.cfg file and specify the user who runs the script. You can specify either a nonroot user or root for this parameter. If you don't specify a user or the specified user doesn't exist, then the script doesn't execute. Restart the agent after modifying the file.

      • To invoke a script on a Windows system, set the registry entry for AllowBatchJobSteps to true and restart the PEM agent. PEM registry entries are located in HKEY_LOCAL_MACHINE\Software\EnterpriseDB\PEM\agent.

After providing all the information required by the step, select Save.

Define the job schedule

Select Add (+) to add each step, or select the Schedules tab to define the job schedule.

On the Schedules tab, select Add (+) to add a schedule for the job. Then select the compose icon located at the left side of the header to open the Schedule Definition dialog box.

Use the Schedules definition tab to specify the days and times for the job to execute.

  • Provide a name for the schedule in the Name field.
  • Use the Enabled switch to indicate for pgAgent to use the schedule (Yes) or to disable the schedule (No).
  • Use the calendar selector in the Start field to specify the starting date and time for the schedule.
  • Use the calendar selector in the End field to specify the ending date and time for the schedule.
  • Use the Comment field to provide a comment about the schedule.

Select the Repeat tab to define the days when the schedule executes in a cron-style format. The job executes on each date or time element selected on the Repeat tab.

In each field, select a value to add it to the list of selected values for the field. To clear the values from a field, select the X located at the right-side of the field.

  • Use the fields in the Days box to specify the days when the job executes:
    • Use the Week Days field to select the days when the job executes.
    • Use the Month Days field to select the numeric days when the job executes. Select Last Day to perform the job on the last day of the month, regardless of the date.
    • Use the Months field to select the months when the job executes.
  • Use the fields in the Times box to specify the times when the job executes in hours and minutes.

Select the Exceptions tab to specify any days when you don't want the schedule to execute. For example, you might not want to run jobs on holidays.

Select Add (+) to add a row to the exception table. Then:

  • In the Date column, open a calendar selector and select a date when you don't want the job to execute. Specify **<Any>** to indicate that you don't want the job to execute on any day at the time selected.
  • In the Time column, open a time selector and specify a time when you don't want the job to execute. Specify **<Any>** to indicate that you don't want the job to execute at any time on the day selected.

Configure the email notifications

Select the Notifications tab to configure the email notification settings on job level:

  • Use the Send the notifications field to specify when you want to send the email notifications.
  • Use the Email group field to specify the email group to send the email notification to.

When you finish defining the schedule, you can use the SQL tab to review the code that creates or modifies your job.

Select Save to save the job definition.

After you save a job, the job is listed under the Jobs node of the PEM tree of the server on which it was defined. The Properties tab in the PEM console displays a high-level overview of the selected job, and the Statistics tab shows the details of each run of the job. To modify an existing job or to review detailed information about a job, right-click a job name, and select Properties from the context menu.