You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+42-20Lines changed: 42 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,8 +35,10 @@ CREATE EXTENSION
35
35
36
36
## Configuring pg_cron
37
37
38
+
To fully use the extension, you must grant read/write rights to the user who will be running the `pg_cron` functions to manage jobs on the database.
39
+
38
40
<Messagetype="note">
39
-
To fully use the extension, you must grant read/write rights to the user who will be running the `pg_cron` functions to manage jobs on the database. Refer to the [How to add users to a PostgreSQL or MySQL Database Instance](/managed-databases-for-postgresql-and-mysql/how-to/add-users) documentation for more information.
41
+
Refer to the [How to add users to a PostgreSQL or MySQL Database Instance](/managed-databases-for-postgresql-and-mysql/how-to/add-users) documentation for more information.
40
42
</Message>
41
43
42
44
## Scheduling jobs
@@ -49,37 +51,52 @@ SELECT cron.schedule(
49
51
'${JOB_NAME}',
50
52
'${SCHEDULE_SPEC}',
51
53
$$
52
-
DELETEFROM ${TABLE_NAME}
53
-
WHERE ${CONDITION_COLUMN} < now() - interval '${TIME_INTERVAL}'
54
+
${SQL_COMMAND}
54
55
$$
55
56
);
56
57
```
57
58
58
59
Replace the variables with the corresponding information:
59
60
60
61
-`${JOB_NAME}` - set a name for the job
61
-
-`${SCHEDULE_SPEC}` - the schedule specification in cron format (e.g. 0 0 * * * for daily at midnight)
62
-
-`${TABLE_NAME}` - the name of the table to delete from
63
-
-`${CONDITION_COLUMN}` - the column to use for the deletion condition
64
-
-`${TIME_INTERVAL}` - the time interval to use for the deletion condition (e.g. 1 week, 1 month, etc.)
62
+
-`${SCHEDULE_SPEC}` - the schedule specification in [cron format](/serverless-jobs/reference-content/cron-schedules/)
63
+
-`${SQL_COMMAND}` - the SQL command to be executed. Depending on the command, you might need to specify other parameters.
64
+
65
+
### Job examples
66
+
67
+
**Example 1 - Deleting old data**
65
68
69
+
You can run the command below to delete old data from the `events` table every Saturday at 3:30am:
0 commit comments