pgAgent is a tool used for scheduling jobs for PostgreSQL databases. Each job consists of steps and schedules.
Creating a pgAgent job
To create or manage a job, use the pgAdmin object explorer to browse to the server on which the pgAgent database objects were created. The object explorer will display a pgAgent Jobs node, under which currently defined jobs are displayed. To add a new job, right click on the pgAgent Jobs node, and select Create pgAgent Job… from the context menu.
Once you click the option the pgAgent dialog opens; use the tabs on pgAgent job dialog to define steps and schedules.
Inside the general tab provides basic information like job name, class etc.
Defining steps
Use the steps tab to define and manage the steps that the job will perform. Click on the add icon (+) to add a new step, then click on the edit icon (located on the left side) to open the step definition dialog.
- Fill in all the details and click on the code tab. If you have selected kind as SQL, provide one or more SQL queries that need to be executed. If it is a batch step then provide a batch script that will be executed during the step. If you have selected batch then you can not provide connection type and database.
- Use the On error drop-down to specify the behaviour 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.
In the code tab provide the query/batch script as per your requirement (in this example we are executing a query which copies data from a table to a CSV file).
Defining schedule
Click on the schedule tab to define the schedule for running the job.