Creating a PEM Scheduled Job¶
You can create a PEM scheduled job to perform a set of custom-defined steps in the specified sequence. These steps may contain SQL code or a batch/shell script that you may run on a server that is 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 control to browse to the PEM agent for which you want to create the job. The tree control will display a Jobs node, under which currently defined jobs are displayed. To add a new job, right click on the Jobs node, and select Create Job… from the context menu.
When the Create Agent Job dialog opens, use the tabs on the Create - Agent Job dialog to define the steps and schedule that make up a PEM scheduled job.
Use the fields on the General tab to provide general information about a job:
- Provide a name for the job in the Name field.
- Move the Enabled switch to the Yes position to enable a job, or No to disable a job.
- Use the Comment field to store notes about the job.
Use the Steps tab to define and manage the steps that the job will perform. Click the Add icon (+) to add a new step; then click the compose icon (located at the left side of the header) to open the step definition dialog:
Use fields on the step definition dialog to define the step:
- Provide a name for the step in the Name field; please note that steps will be 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 that will be executed during the step.
Use the On error drop-down 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 have selected SQL as your input for Kind switch, provide the following additional information: * Use the Server field to specify the server that is bound with the agent for which you are creating the PEM scheduled job. * Use the Database field to specify the database that is associated with the server that you have selected.
- Use the Comment field to provide a comment about the step.
Use the context-sensitive field on the step definition dialog’s Code tab to provide the SQL code or batch script that will be executed 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 are running on a Windows server, standard batch file syntax must be used. When running on a Linux server, any shell script may be used, provided that a suitable interpreter is specified on the first line (e.g. #!/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 batch_script_user parameter of agent.cfg file and specify the user that should be used to run the script. You can either specify a non-root user or root for this parameter. If you do not specify a user, or the specified user does not exist, then the script will not be executed. Restart the agent after modifying the file. If pemagent is being run by a non-root user then the value of batch_script_user will be ignored and the script will be executed by the same non-root user that is being used for running the pemagent.
To invoke a script on a Windows system, set the registry entry for AllowBatchJobSteps as true and restart the PEM agent. PEM registry entries are located in HKEY_LOCAL_MACHINE\Software\Wow6432Node\EnterpriseDB\PEM\agent.
After providing all the information required by the step, click the Save button to save and close the step definition dialog.
Click the add icon (+) to add each additional step, or select the Schedules tab to define the job schedule.
Click the Add icon (+) to add a schedule for the job; then click the compose icon (located at the left side of the header) to open the schedule definition dialog:
Use the fields on the Schedules definition tab to specify the days and times at which the job will execute.
- Provide a name for the schedule in the Name field.
- Use the Enabled switch to indicate that pgAgent should 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 on which the schedule will execute.
Use the fields on the Repeat tab to specify the details about the schedule in a cron-style format. The job will execute on each date or time element selected on the Repeat tab.
Click within a field to open a list of valid values for that field; click on a specific value to add that value to the list of selected values for the field. To clear the values from a field, click the X located at the right-side of the field.
Use the fields within the Days box to specify the days on which the job will execute:
- Use the Week Days field to select the days on which the job will execute.
- Use the Month Days field to select the numeric days on which the job will execute. Specify the Last Day to indicate that the job should be performed on the last day of the month, irregardless of the date.
- Use the Months field to select the months in which the job will execute.
Use the fields within the Times box to specify the times at which the job will execute:
- Use the Hours field to select the hour at which the job will execute.
- Use the Minutes field to select the minute at which the job will execute.
Select the Exceptions tab to specify any days on which the schedule will not execute.
Use the fields on the Exceptions tab to specify days on which you wish the job to not execute; for example, you may wish for jobs to not execute on national holidays.
Click the Add icon (+) to add a row to the exception table, then:
- Click within the Date column to open a calendar selector, and select a date on which the job will not execute. Specify <Any> in the Date column to indicate that the job should not execute on any day at the time selected.
- Click within the Time column to open a time selector, and specify a time on which the job will not execute. Specify <Any> in the Time column to indicate that the job should not execute at any time on the day selected.
Select the Notifications tab to configure the email notification settings on job level:
Use the fields on the Notifications tab to configure the email notification settings for a job:
- Use the Send the notifications field to specify when you want the email notifications to be sent.
- Use the Email group field to specify the email group that should receive the email notification.
When you’ve finished defining the schedule, you can use the SQL tab to review the code that will create or modify your job.
Click the Save button to save the job definition, or Cancel to exit the job without saving. Use the Reset button to remove your unsaved entries from the dialog.
After saving a job, the job will be listed under the Jobs node of the PEM tree control of the server on which it was defined. The Properties tab in the PEM console will display a high-level overview of the selected job, and the Statistics tab will show the details of each run of the job. To modify an existing job or to review detailed information about a job, right-click on a job name, and select Properties from the context menu.