A cron-based job scheduler that runs as a PostgreSQL extension for running periodic jobs directly inside the database.
pg_cron is a PostgreSQL extension that provides a cron-based job scheduler running inside the database. It allows users to schedule periodic SQL commands, stored procedures, and maintenance tasks directly within PostgreSQL, eliminating the need for external cron services. The extension uses standard cron syntax with extensions like seconds-based intervals and runs as a background worker within the PostgreSQL cluster.
PostgreSQL database administrators and developers who need to automate periodic database tasks like data cleanup, rollups, maintenance, or stored procedure execution. It's particularly useful for teams managing PostgreSQL instances who want to keep job scheduling integrated with their database infrastructure.
Developers choose pg_cron because it runs entirely inside PostgreSQL, leveraging the database's security, reliability, and existing infrastructure without external dependencies. Unlike external cron services, it provides native SQL functions for job management, Row-Level Security for job isolation, and detailed execution logging within the database.
Run periodic jobs in PostgreSQL
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Runs entirely as a PostgreSQL extension, leveraging built-in security, reliability, and infrastructure without external cron services, as evidenced by its use of background workers and RLS policies.
Uses familiar cron syntax with extensions like seconds-based intervals and last-day-of-month indicators, making it easy for users to schedule jobs with precision, as shown in the README examples.
Supports scheduling and running jobs across multiple databases within the same PostgreSQL cluster using functions like cron.schedule_in_database, enabling centralized management.
Implements Row-Level Security so users can only see and modify their own jobs unless superuser, providing built-in access control without additional configuration.
Requires modifying postgresql.conf (e.g., shared_preload_libraries) and potentially pg_hba.conf for authentication, necessitating server restarts and careful configuration.
Default maximum of 32 concurrently running jobs (cron.max_running_jobs), which can be restrictive for high-frequency tasks or large-scale deployments.
Job execution details accumulate in cron.job_run_details without automatic cleanup, forcing users to schedule additional jobs for pruning or manage storage manually.