How to Create a sScheduler Job in PostgreSql using PgAgent

Nayeem Mansoori picture Nayeem Mansoori · Nov 21, 2017 · Viewed 7.8k times · Source

I'm new in PostgreSQL, and I want to create a scheduled job which is run every day.

Firstly I'm creating a function for this. my function is working fine.

And now I want to create jobs and use this function inside the jobs, so it runs every day.

But I don't know how do this. I've been googling but didn't find any reference.

Please help

enter image description here

Answer

tinkal patel picture tinkal patel · Dec 26, 2017

Kindly follow the below steps:

Step 1: install pgAgent using application stack builder of postgres

Step 2:execute schema pgagent.sql in maintainance DB.follow this https://www.pgadmin.org/docs/pgadmin4/dev/pgagent_install.html link.

Step 3:Execute Following Command to pgAgent bin directory.

   pgAgent REMOVE pgAgent

   pgAgent INSTALL pgAgent -u system_username -p system_password 
    hostaddr=127.0.0.1 dbname=xyz 
    user=postgres_password=password_for_database

Step 4: Create job. follow this https://www.pgadmin.org/docs/pgadmin4/dev/pgagent_jobs.html link. in the sql You have to write select your_func_name();.

Step 5: Start job service using below command

    net start pgAgent