Use pgAgent create a scheduled task

Use Postgresql comes pgAgent, you can easily create a scheduled task. Now online data are relatively old, Postgresql version updates faster, resulting in a number of online tutorials are not combined, and now I write to share their own experiences.

Postgresql version is 9.X

1. Install pgAgent. pgAgent before the old version is pgAdmin own, but the new version of pgAgent is required by Postgresql built-in Application Stack Builder software to install. Specific process is as follows:

* Here to fill in the username and password postgres Postgresql, or operate with user account postgres database permissions. Because pgAgent need to create the corresponding table in the postgres database inside, so there must fill out a user needs to have the authority to operate postgres database, where it postgres user with maximum privileges.

* Here is the implementation of pgAgent Zhi wrote a windows user account, if it is a domain user, please fill in the full domain user name and password. Because pgAgent adds a service called the windows inside "PostgreSQL Scheduling Agent - pgAgent" service, and after the service need to log in to run, so here fill in the account must be a current account widnows be logged.

Here, it means pgAgent has been successfully installed. Can go to the windows service inside look at the service did not add pgAgent, is running:

2. Create Job. When successfully installed pgAgent, and pgAgent already in the running, the next task is to create a scheduled task. Timing task concept Postgresql divided into two parts: Schedule and Step. Schedule a timer, configure the Job executes. The Step is content to perform tasks. By combination of these two parts, you can configure this Job did what when. Schedule a Job can have more and more Step, they are superimposed role.

Specific operation is as follows:

Create a Job, named Job1, as set Job Class Routine Maintenance, and in front of the check Enabled.

Add to job1 Schedule, named schedule1, check Enabled, and then set the start and end time. If the end time is not filled, it means that Job will continue to run indefinitely. Then in Times this section Minutes Tab, check the 00 and 30, represented here this job1 will be executed every hour of the whole point (00), and the slightest (30). Is performed once every 30 minutes. If only the check 30, it means that 30 minutes of every hour executed, for example, 4: 30,5: 30, which is performed every time an hour. Other Hours, Week Days, Month Days, Months concept is the same.

Exceptions Tab is another exception, that is, when this situation will not execute the Job.

Then add the content is executed as job1. Now add a Step, named step1. Check Enabled. Then select the database you need to perform this job. Also note Kind On Error section and section. Kind is part of this job is specified to perform SQL or batch type. In addition to job running SQL, you can also run the windows batch command. In this example, we use SQL. On Error In part, expressed while performing the job of error, is to stop (Fail), normal (Succeed), or ignore (Ignore). This example now choose Fail, says that when the contents of an execution error, stop running, quit.

Now you need to do is to define job1 SQL, SQL write these general recommendations in a transaction, so even if job1 fail, will not affect the data.

At this point, job1 basically create complete.

Now you want to monitor the status of job1, by pgAdmin, in job1 the Properties Tab, you can see the time job1 next run, last run time, the result, is currently running. Can also Statistics Tab, Views job1 run.

 

Well, here's how to create a scheduled task would be finished by pgAgent presentation. Later a more in-depth discussion, give you about

Guess you like

Origin www.cnblogs.com/telwanggs/p/11599386.html