AWS AmazonRDS: Use cron.schedule_in_database to avoid jobs running in wrong database
Summary
Replaces the two-step workflow (schedule in postgres, then UPDATE cron.job SET database) with the single-step cron.schedule_in_database function, and removes the note about jobs unintentionally running in the default postgres database before being reassigned.
Security assessment
The change documents a new pg_cron API that prevents a scheduled job from executing in the default database before reassignment. It is primarily a correctness/operational improvement, though it reduces unintended job execution; no specific vulnerability, privilege escalation, or incident is referenced.
Evidence
+Use the `cron.schedule_in_database` function to schedule a job that runs in another database within your PostgreSQL DB instance in a single step. This avoids the metadata database running the job before you reassign it. This function is available in `pg_cron` 1.4.0 and higher.
Diff
diff --git a/AmazonRDS/latest/AuroraUserGuide/PostgreSQL_pg_cron.md b/AmazonRDS/latest/AuroraUserGuide/PostgreSQL_pg_cron.md index 1e81072..1de3d74 100644 --- a//AmazonRDS/latest/AuroraUserGuide/PostgreSQL_pg_cron.md +++ b//AmazonRDS/latest/AuroraUserGuide/PostgreSQL_pg_cron.md @@ -158 +158 @@ Only users with `rds_superuser` role or `rds_superuser` privileges can list all - 1. In the cron database, schedule the job as you normally do using the cron.schedule. +Use the `cron.schedule_in_database` function to schedule a job that runs in another database within your PostgreSQL DB instance in a single step. This avoids the metadata database running the job before you reassign it. This function is available in `pg_cron` 1.4.0 and higher. @@ -160 +160 @@ Only users with `rds_superuser` role or `rds_superuser` privileges can list all - postgres=> SELECT cron.schedule('database1 manual vacuum', '29 03 * * *', 'vacuum freeze test_table'); + 1. If you have the `rds_superuser` role, schedule the job directly in the target database by passing the database name as the final argument to `cron.schedule_in_database`. @@ -162 +162 @@ Only users with `rds_superuser` role or `rds_superuser` privileges can list all - 2. As a user with the `rds_superuser` role, update the database column for the job that you just created so that it runs in another database within your PostgreSQL DB instance. + postgres=> SELECT cron.schedule_in_database('database1 manual vacuum', '29 03 * * *', 'vacuum freeze test_table', 'database1'); @@ -164,3 +164 @@ Only users with `rds_superuser` role or `rds_superuser` privileges can list all - postgres=> UPDATE cron.job SET database = 'database1' WHERE jobid = 106; - - 3. Verify by querying the `cron.job` table. + 2. Verify by querying the `cron.job` table. @@ -178,4 +175,0 @@ Only users with `rds_superuser` role or `rds_superuser` privileges can list all -###### Note - -In some situations, you might add a cron job that you intend to run on a different database. In such cases, the job might try to run in the default database (`postgres`) before you update the correct database column. If the user name has permissions, the job successfully runs in the default database. -