

To enable the pg_cron extension, modify the database parameter group and add the value pg_cron to the shared_preload_libraries parameter, then restart the database.Because pg_cron is an extension that is created in the Postgres database, you must be connected to the database to create and manage the cron jobs.Have an EC2 instance to access the database instance with PostgreSQL installed and configured.For instructions on provisioning an instance, see Create and Connect to a PostgreSQL Database with Amazon RDS. Have an RDS for PostgreSQL instance (version 12.5 or higher) or an Aurora PostgreSQL instance (version 12.6 or higher).Create or have access to an AWS account.Prerequisitesīefore you get started, complete the following prerequisites:
CRON SCHEDULE CREATOR HOW TO
In this post, we demonstrate how to use pg_cron along with some use cases of pg_cron with examples to show how to automate routine maintenance tasks. Logs are stored within the database in the table cron.job_run_details Runs within the database, no additional authentication needed but requires permissions from rds_superuser to manage jobs No separate instance is needed to schedule the jobs Serverless no separate instance needed to schedule cron jobs Instance should be provisioned all the time where cron jobs are scheduled The following table compares scheduling jobs on EC2 instances, Lambda, or pg_cron: You have a variety of ways to schedule jobs on AWS. The pg_cron extension is also supported with Amazon Aurora PostgreSQL-Compatible Edition databases with versions 12.6 and higher. Starting with PostgreSQL version 12.5 and higher, Amazon RDS for PostgreSQL now supports the extension pg_cron, a simple cron-based job scheduler for PostgreSQL that runs inside the database. However, you may want to work with pg_cron because this is an extension for this specific use case. You can use services such as Amazon Elastic Compute Cloud (Amazon EC2), AWS Lambda, AWS Batch, Amazon CloudWatch, and Amazon EventBridge to schedule the maintenance tasks. When you migrate your databases to Amazon Relational Database Service (Amazon RDS) or Amazon Aurora, you lose the ability to log in to the host and schedule cron jobs.

On a traditional on-premises database, you can schedule database maintenance jobs on the operating system where the database runs.

Scheduling jobs is an important part of every database environment.
