pgcron-railway
Open-source cron-based job scheduler for PostgreSQL
pgcron-railway
niarde/postgres-extensions:latest
Just deployed
/var/lib/postgresql/data
Deploy and Host pgcron-railway on Railway
pg_cron is a simple cron-based job scheduler for PostgreSQL (10 or higher) that runs inside the database as an extension. It uses the same syntax as regular cron, but it allows you to schedule PostgreSQL commands directly from the database. You can also use '[1-59] seconds' to schedule a job based on an interval. It is fully compatible with Railway Postgres Data.
About Hosting pgcron-railway
Hosting pgcron-railway involves enabling the pg_cron extension in your Railway PostgreSQL database, configuring the postgresql.conf settings (like shared_preload_libraries), and using SQL commands to define and manage scheduled tasks. Since Railway supports the pg_cron extension natively, no manual server setup is required. You can manage jobs using standard SQL within your existing application.
Common Use Cases
- Standard cron jobs checks for expired rows
- Periodic data cleanup (e.g. deleting stale records)
- Routine maintenance (e.g. VACUUM or ANALYZE)
- Scheduled analytics or rollup jobs
- Invoking stored procedures regularly
- Automated reports or notifications
Dependencies for pgcron-railway
- Knowledge on how to use pg-cron
- Available volume storage of 5GB atleast
Deployment Dependencies
Implementation Details
To enable pg_cron, run:
CREATE EXTENSION IF NOT EXISTS pg_cron;
To schedule a job:
SELECT cron.schedule('nightly-vacuum', '0 3 * * *', 'VACUUM');
To view job run details:
SELECT * FROM cron.job_run_details ORDER BY start_time DESC LIMIT 10;
To clean up old job logs:
SELECT cron.schedule('cleanup-cron-logs', '0 12 * * *', $$DELETE FROM cron.job_run_details WHERE end_time < now() - interval '7 days'$$);
To clean up a share from shares table that is expired, every 5 minutes:
SELECT cron.schedule('shares_cleanup', '*/5 * * * *', 'DELETE FROM shares WHERE expires_at < NOW();');
Why Deploy pgcron-railway on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying pgcron-railway on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
pgcron-railway
niarde/postgres-extensions:latest