From 19548dd3c3bf5875d2381e72a45df84889f4f957 Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Mon, 17 Feb 2025 18:04:31 +0100
Subject: [PATCH 01/11] fix(rdb): pgcron
---
.../api-cli/using-pgcron.mdx | 149 ++++++++++++++++++
1 file changed, 149 insertions(+)
create mode 100644 pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
new file mode 100644
index 0000000000..9d288241e0
--- /dev/null
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -0,0 +1,149 @@
+---
+meta:
+ title: Setting up and using the pgcron extension
+ description: This page explains how to set up and use the pgcron extension.
+content:
+ h1: Setting up and using the pgcron extension
+ paragraph: This page explains how to set up and use the pgcron extension.
+tags: managed-database postgresql pgcron pg-extensions
+dates:
+ validation: 2025-02-17
+ posted: 2025-02-17
+categories:
+ - managed-databases
+ - postgresql-and-mysql
+---
+
+The pg_cron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, to run at regular intervals. This allows you to automate the tasks to be run regularly, on a daily, weekly or monthly basis, for example.
+
+The `pgcron` extension is available with Scaleway Managed Databases for PostgreSQL. The extension is natively loaded in the `shared_preload_libraries` of the Database Instances by default.
+
+
+
+- A Scaleway account logged into the [console](https://console.scaleway.com)
+- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
+- A [Database Instance](/managed-databases-for-postgresql-and-mysql/how-to/create-a-database/) running a PostgreSQL engine
+
+## Installing pgcron
+
+
+1. Run the following command to install the extension:
+
+```sql
+rdb=> CREATE EXTENSION pg_cron;
+CREATE EXTENSION
+```
+
+## Configuring pg_cron
+
+
+ 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.
+
+
+## Scheduling jobs
+
+To schedule jobs, you can run the following commands:
+
+```sql
+-- Delete old data on Saturday at 3:30am (GMT)
+SELECT cron.schedule('30 3 * * 6', $$DELETE FROM events WHERE event_time < now() - interval '1 week'$$);
+```
+
+```sql
+-- Change to vacuum at 3:00am (GMT)
+SELECT cron.schedule('nightly-vacuum', '0 10 * * *', 'VACUUM');
+```
+
+**Listing Jobs**
+
+To list all scheduled jobs, you can run the following command:
+
+```sql
+SELECT * FROM cron.job;
+-[ RECORD 1 ]-------------------------------------------------------------
+jobid | 1
+schedule | 30 3 * * 6
+command | DELETE FROM events WHERE event_time < now() - interval '1 week'
+nodename | /var/run/postgresql
+nodeport | 5432
+database | rdb
+username | myuser
+active | t
+jobname |
+-[ RECORD 2 ]-------------------------------------------------------------
+jobid | 2
+schedule | 0 10 * * *
+command | VACUUM
+nodename | /var/run/postgresql
+nodeport | 5432
+database | rdb
+username | myuser
+active | t
+jobname | nightly-vacuum
+```
+
+**Unscheduling Jobs**
+
+To unschedule a job, you can run the following command:
+
+```sql
+SELECT cron.unschedule(1);
+unschedule
+------------
+t
+(1 row)
+```
+
+or
+
+```sql
+SELECT cron.unschedule('nightly-vacuum');
+unschedule
+------------
+t
+(1 row)
+```
+
+**Scheduling Jobs in Other Databases**
+
+To schedule a job in another database, you can use the `schedule_in_database` function:
+
+```sql
+SELECT cron.schedule_in_database('job-in-another-db', '0 12 * * *', 'INSERT INTO public.another_db_table values (now())', 'mydb');
+schedule
+----------
+3
+```
+
+Note that cron.schedule_in_database runs jobs as the user who created them, so you'll need to connect as that user to execute the job.
+Additionally, this function doesn't allow specifying a different user, as it would require superuser privileges.
+
+**Editing Jobs**
+
+To edit a job, you can use the `alter_job` function:
+
+```sql
+SELECT cron.alter_job(job_id:=3,database:='anotherdb');
+-[ RECORD 1 ]
+alter_job |
+```
+
+**Cron Syntax**
+
+The schedule uses the standard cron syntax:
+
+```
+┌───────────── min (0 - 59)
+│ ┌────────────── hour (0 - 23)
+│ │ ┌─────────────── day of month (1 - 31) or last day of the month ($)
+│ │ │ ┌──────────────── month (1 - 12)
+│ │ │ │ ┌───────────────── day of week (0 - 6) (0 to 6 are Sunday to
+│ │ │ │ │ Saturday, or use names; 7 is also Sunday)
+│ │ │ │ │
+│ │ │ │ │
+* * * * *
+```
+
+**Time Zone**
+
+The time zone of the pg_cron extension can be changed in the advanced settings of the instance: `cron.timezone`. By default, the time zone is set to GMT.
\ No newline at end of file
From ada661ea08926760c3436c2924c54d679f101ad2 Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 10:06:42 +0100
Subject: [PATCH 02/11] fix(rdb): pgcron pt2
---
.../api-cli/using-pgcron.mdx | 26 ++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index 9d288241e0..0d877242fd 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -14,7 +14,7 @@ categories:
- postgresql-and-mysql
---
-The pg_cron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, to run at regular intervals. This allows you to automate the tasks to be run regularly, on a daily, weekly or monthly basis, for example.
+The pg_cron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, using jobs that run at the intervals you set. This allows you to automate the tasks and run them regularly, on a daily, weekly or monthly basis, for example.
The `pgcron` extension is available with Scaleway Managed Databases for PostgreSQL. The extension is natively loaded in the `shared_preload_libraries` of the Database Instances by default.
@@ -26,7 +26,6 @@ The `pgcron` extension is available with Scaleway Managed Databases for PostgreS
## Installing pgcron
-
1. Run the following command to install the extension:
```sql
@@ -42,7 +41,28 @@ CREATE EXTENSION
## Scheduling jobs
-To schedule jobs, you can run the following commands:
+Jobs allow you to define the SQL command or task you want to run based on a cron schedule.
+
+To schedule jobs, you can run the following command in the SQL client:
+```sql
+SELECT cron.schedule(
+ '${JOB_NAME}',
+ '${SCHEDULE_SPEC}',
+ $$
+ DELETE FROM ${TABLE_NAME}
+ WHERE ${CONDITION_COLUMN} < now() - interval '${TIME_INTERVAL}'
+ $$
+);
+```
+
+Replace the variables with the corresponding information:
+
+- `${JOB_NAME}` - set a name for the job
+- `${SCHEDULE_SPEC}` - the schedule specification in cron format (e.g. 0 0 * * * for daily at midnight)
+- `${TABLE_NAME}` - the name of the table to delete from
+- `${CONDITION_COLUMN}` - the column to use for the deletion condition
+- `${TIME_INTERVAL}` - the time interval to use for the deletion condition (e.g. 1 week, 1 month, etc.)
+
```sql
-- Delete old data on Saturday at 3:30am (GMT)
From 86fbb41f34bba59b27e96caa166942fa00b23370 Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 11:50:51 +0100
Subject: [PATCH 03/11] fix(rdb): cron jobs pt3
---
.../api-cli/using-pgcron.mdx | 62 +++++++++++++------
1 file changed, 42 insertions(+), 20 deletions(-)
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index 0d877242fd..fce4a75171 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -35,8 +35,10 @@ CREATE EXTENSION
## Configuring pg_cron
+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.
+
- 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.
+ 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.
## Scheduling jobs
@@ -49,8 +51,7 @@ SELECT cron.schedule(
'${JOB_NAME}',
'${SCHEDULE_SPEC}',
$$
- DELETE FROM ${TABLE_NAME}
- WHERE ${CONDITION_COLUMN} < now() - interval '${TIME_INTERVAL}'
+ ${SQL_COMMAND}
$$
);
```
@@ -58,28 +59,44 @@ SELECT cron.schedule(
Replace the variables with the corresponding information:
- `${JOB_NAME}` - set a name for the job
-- `${SCHEDULE_SPEC}` - the schedule specification in cron format (e.g. 0 0 * * * for daily at midnight)
-- `${TABLE_NAME}` - the name of the table to delete from
-- `${CONDITION_COLUMN}` - the column to use for the deletion condition
-- `${TIME_INTERVAL}` - the time interval to use for the deletion condition (e.g. 1 week, 1 month, etc.)
+- `${SCHEDULE_SPEC}` - the schedule specification in [cron format](/serverless-jobs/reference-content/cron-schedules/)
+- `${SQL_COMMAND}` - the SQL command to be executed. Depending on the command, you might need to specify other parameters.
+
+### Job examples
+
+**Example 1 - Deleting old data**
+You can run the command below to delete old data from the `events` table every Saturday at 3:30am:
```sql
--- Delete old data on Saturday at 3:30am (GMT)
SELECT cron.schedule('30 3 * * 6', $$DELETE FROM events WHERE event_time < now() - interval '1 week'$$);
```
+**Example 2 - Scheduling a VACUUM job**
+
+You can run the command below to execute the VACUUM task every day at 10:00am.
+
```sql
--- Change to vacuum at 3:00am (GMT)
SELECT cron.schedule('nightly-vacuum', '0 10 * * *', 'VACUUM');
```
-**Listing Jobs**
+## Listing Jobs
To list all scheduled jobs, you can run the following command:
```sql
SELECT * FROM cron.job;
+```
+Each job is represented by a record. You can see the following information in the response:
+
+- `jobid` - a unique job ID
+- `schedule` - the schedule specification in cron format
+- `command` - the SQL command
+- `database`, `username`, `nodename`, `nodeport` - connection details
+- `active` - whether the job is active or not
+- `jobname` - the name of the job
+
+```sql
-[ RECORD 1 ]-------------------------------------------------------------
jobid | 1
schedule | 30 3 * * 6
@@ -102,32 +119,37 @@ active | t
jobname | nightly-vacuum
```
-**Unscheduling Jobs**
+## Unscheduling Jobs
To unschedule a job, you can run the following command:
+```sql
+SELECT cron.unschedule('${JOB_ID}');
+```
+Replace ${JOB_ID} with the ID of the job you want to unschedule.
+
+### Examples
+
+To unschedule the jobs set in the previous section, you can run:
+
```sql
SELECT cron.unschedule(1);
-unschedule
-------------
-t
-(1 row)
```
or
```sql
SELECT cron.unschedule('nightly-vacuum');
-unschedule
-------------
-t
-(1 row)
```
-**Scheduling Jobs in Other Databases**
+## Scheduling jobs in other databases
To schedule a job in another database, you can use the `schedule_in_database` function:
+```sql
+SELECT cron.unschedule('${JOB_ID}');
+```
+
```sql
SELECT cron.schedule_in_database('job-in-another-db', '0 12 * * *', 'INSERT INTO public.another_db_table values (now())', 'mydb');
schedule
From fa72abad6c115ad306392919def946ca80760c39 Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 15:26:27 +0100
Subject: [PATCH 04/11] fix(rdb): cron pt 4
---
.../api-cli/using-pgcron.mdx | 44 ++++++++++++-------
1 file changed, 27 insertions(+), 17 deletions(-)
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index fce4a75171..c57ff941fa 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -144,35 +144,31 @@ SELECT cron.unschedule('nightly-vacuum');
## Scheduling jobs in other databases
-To schedule a job in another database, you can use the `schedule_in_database` function:
+To schedule a job in another database, you can use the `schedule_in_database` function.
-```sql
-SELECT cron.unschedule('${JOB_ID}');
-```
+In the example below we create a job to insert values into another table.
```sql
SELECT cron.schedule_in_database('job-in-another-db', '0 12 * * *', 'INSERT INTO public.another_db_table values (now())', 'mydb');
-schedule
-----------
-3
```
+
+ The `cron.schedule_in_database` function runs jobs as the user who created them. Therefore, you need to connect as said user to execute the job. This function does not allow specifying a different user, as it would require superuser privileges.
+
-Note that cron.schedule_in_database runs jobs as the user who created them, so you'll need to connect as that user to execute the job.
-Additionally, this function doesn't allow specifying a different user, as it would require superuser privileges.
-**Editing Jobs**
+## Editing Jobs
-To edit a job, you can use the `alter_job` function:
+To edit a job, you can use the `alter_job` function.
+
+In the example below
```sql
SELECT cron.alter_job(job_id:=3,database:='anotherdb');
--[ RECORD 1 ]
-alter_job |
```
-**Cron Syntax**
+## Cron specifications
-The schedule uses the standard cron syntax:
+Schedules in `pgcron` use the standard Cron syntax:
```
┌───────────── min (0 - 59)
@@ -186,6 +182,20 @@ The schedule uses the standard cron syntax:
* * * * *
```
-**Time Zone**
+
+ Refer to the [Cron schedules reference](/serverless-jobs/reference-content/cron-schedules/) for a detailed explanation of the cron format and examples.
+
+
+### How to configure your schedule timezone
+
+The time zone of the `pg_cron` extension can be changed in the advanced settings of the Database Instance. By default, the time zone is set to GMT.
-The time zone of the pg_cron extension can be changed in the advanced settings of the instance: `cron.timezone`. By default, the time zone is set to GMT.
\ No newline at end of file
+1. Go to the **Advanced settings** of your Database Instance in the Scaleway console.
+ 2. Click .
+ 3. Click **+ Add parameters**.
+ 4. Select `cron.timezone` in the drop-down.
+ 5. Enter the time zone of your choice.
+ 6. Click to validate.
+
+ The configuration takes a few seconds to be applied. During this time the Database Instance connection remains uninterrupted. However, you must wait until the new configuration is applied to edit your advanced settings again.
+
From 66fcfc165acf054f8c6ebed54745a4b8020cb691 Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 15:28:23 +0100
Subject: [PATCH 05/11] fix(rdb): cron petit fix
---
.../api-cli/using-pgcron.mdx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index c57ff941fa..f4510a5d15 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -160,7 +160,7 @@ SELECT cron.schedule_in_database('job-in-another-db', '0 12 * * *', 'INSERT INTO
To edit a job, you can use the `alter_job` function.
-In the example below
+In the example below we alter an existing job to run in a different database. You must specify the `job_id` and `database`.
```sql
SELECT cron.alter_job(job_id:=3,database:='anotherdb');
From e49248e79d83d73d388b98cad51373c4c9d818df Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 15:42:54 +0100
Subject: [PATCH 06/11] fix(rdb): cron fix build
---
menu/navigation.json | 4 ++
.../api-cli/using-pgcron.mdx | 41 +++++++++++--------
2 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/menu/navigation.json b/menu/navigation.json
index 42823a2293..28905d0465 100644
--- a/menu/navigation.json
+++ b/menu/navigation.json
@@ -2426,6 +2426,10 @@
"label": "Setting up and using the pgaudit extension",
"slug": "pg-audit"
},
+ {
+ "label": "Setting up and using the pgcron extension",
+ "slug": "using-pgcron"
+ },
{
"label": "Verifying Servers' Certificate Authority on PostgreSQL",
"slug": "verify-ca-postgresql"
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index f4510a5d15..3d756e3891 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -7,14 +7,14 @@ content:
paragraph: This page explains how to set up and use the pgcron extension.
tags: managed-database postgresql pgcron pg-extensions
dates:
- validation: 2025-02-17
- posted: 2025-02-17
+ validation: 2025-02-18
+ posted: 2025-02-18
categories:
- managed-databases
- postgresql-and-mysql
---
-The pg_cron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, using jobs that run at the intervals you set. This allows you to automate the tasks and run them regularly, on a daily, weekly or monthly basis, for example.
+The pg_cron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, using jobs that run at the intervals you set. On a daily, weekly or monthly basis, for example.
The `pgcron` extension is available with Scaleway Managed Databases for PostgreSQL. The extension is natively loaded in the `shared_preload_libraries` of the Database Instances by default.
@@ -26,7 +26,7 @@ The `pgcron` extension is available with Scaleway Managed Databases for PostgreS
## Installing pgcron
-1. Run the following command to install the extension:
+Run the following command to install the extension:
```sql
rdb=> CREATE EXTENSION pg_cron;
@@ -62,9 +62,9 @@ Replace the variables with the corresponding information:
- `${SCHEDULE_SPEC}` - the schedule specification in [cron format](/serverless-jobs/reference-content/cron-schedules/)
- `${SQL_COMMAND}` - the SQL command to be executed. Depending on the command, you might need to specify other parameters.
-### Job examples
+### Examples
-**Example 1 - Deleting old data**
+**Deleting old data**
You can run the command below to delete old data from the `events` table every Saturday at 3:30am:
@@ -72,7 +72,7 @@ You can run the command below to delete old data from the `events` table every S
SELECT cron.schedule('30 3 * * 6', $$DELETE FROM events WHERE event_time < now() - interval '1 week'$$);
```
-**Example 2 - Scheduling a VACUUM job**
+**Scheduling a VACUUM job**
You can run the command below to execute the VACUUM task every day at 10:00am.
@@ -126,7 +126,7 @@ To unschedule a job, you can run the following command:
```sql
SELECT cron.unschedule('${JOB_ID}');
```
-Replace ${JOB_ID} with the ID of the job you want to unschedule.
+Replace `${JOB_ID}` with the ID of the job you want to unschedule.
### Examples
@@ -183,19 +183,26 @@ Schedules in `pgcron` use the standard Cron syntax:
```
- Refer to the [Cron schedules reference](/serverless-jobs/reference-content/cron-schedules/) for a detailed explanation of the cron format and examples.
+ Refer to the [Cron schedules reference](/serverless-jobs/reference-content/cron-schedules/) for a detailed description of the cron format and examples.
### How to configure your schedule timezone
The time zone of the `pg_cron` extension can be changed in the advanced settings of the Database Instance. By default, the time zone is set to GMT.
+
+ The `cron.timezone` setting is only available with PostgreSQL 16.
+
+
1. Go to the **Advanced settings** of your Database Instance in the Scaleway console.
- 2. Click .
- 3. Click **+ Add parameters**.
- 4. Select `cron.timezone` in the drop-down.
- 5. Enter the time zone of your choice.
- 6. Click to validate.
-
- The configuration takes a few seconds to be applied. During this time the Database Instance connection remains uninterrupted. However, you must wait until the new configuration is applied to edit your advanced settings again.
-
+2. Click .
+3. Click **+ Add parameters**.
+4. Select `cron.timezone` in the drop-down.
+5. Enter the time zone of your choice.
+
+ Refer to the [official PostgreSQL documentation](https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-TIMEZONES) for more information about timezone conventions.
+
+6. Click to validate.
+
+ The configuration takes a few seconds to be applied. During this time the Database Instance connection remains uninterrupted. However, you must wait until the new configuration is applied to edit your advanced settings again.
+
From 2aeca0e6a0a068e063003a7c1e94ed0cf500ed2d Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 15:44:13 +0100
Subject: [PATCH 07/11] fix(rdb): review neda
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Néda <87707325+nerda-codes@users.noreply.github.com>
---
.../api-cli/using-pgcron.mdx | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index 3d756e3891..01a0256f44 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -80,7 +80,7 @@ You can run the command below to execute the VACUUM task every day at 10:00am.
SELECT cron.schedule('nightly-vacuum', '0 10 * * *', 'VACUUM');
```
-## Listing Jobs
+## Listing jobs
To list all scheduled jobs, you can run the following command:
@@ -119,7 +119,7 @@ active | t
jobname | nightly-vacuum
```
-## Unscheduling Jobs
+## Unscheduling jobs
To unschedule a job, you can run the following command:
@@ -156,7 +156,7 @@ SELECT cron.schedule_in_database('job-in-another-db', '0 12 * * *', 'INSERT INTO
-## Editing Jobs
+## Editing jobs
To edit a job, you can use the `alter_job` function.
From 224cb89fefff930445338b30f201953a74cbdf73 Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 16:06:35 +0100
Subject: [PATCH 08/11] fix(rdb): make naming iso
---
.../api-cli/using-pgcron.mdx | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index 01a0256f44..d51c0c5bbd 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -14,7 +14,7 @@ categories:
- postgresql-and-mysql
---
-The pg_cron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, using jobs that run at the intervals you set. On a daily, weekly or monthly basis, for example.
+The pgcron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, using jobs that run at the intervals you set. On a daily, weekly or monthly basis, for example.
The `pgcron` extension is available with Scaleway Managed Databases for PostgreSQL. The extension is natively loaded in the `shared_preload_libraries` of the Database Instances by default.
@@ -29,13 +29,13 @@ The `pgcron` extension is available with Scaleway Managed Databases for PostgreS
Run the following command to install the extension:
```sql
-rdb=> CREATE EXTENSION pg_cron;
+rdb=> CREATE EXTENSION pgcron;
CREATE EXTENSION
```
-## Configuring pg_cron
+## Configuring pgcron
-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.
+To fully use the extension, you must grant read/write rights to the user who will be running the `pgcron` 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.
@@ -188,7 +188,7 @@ Schedules in `pgcron` use the standard Cron syntax:
### How to configure your schedule timezone
-The time zone of the `pg_cron` extension can be changed in the advanced settings of the Database Instance. By default, the time zone is set to GMT.
+The time zone of the `pgcron` extension can be changed in the advanced settings of the Database Instance. By default, the time zone is set to GMT.
The `cron.timezone` setting is only available with PostgreSQL 16.
From fa3c780097e6dee5bb07164398481f12024fb6ce Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 16:53:32 +0100
Subject: [PATCH 09/11] fix(rdb): review hugo
---
.../api-cli/using-pgcron.mdx | 30 +++++++++++--------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index d51c0c5bbd..86938ea052 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -1,11 +1,11 @@
---
meta:
- title: Setting up and using the pgcron extension
- description: This page explains how to set up and use the pgcron extension.
+ title: Setting up and using the pg_cron extension
+ description: This page explains how to set up and use the pg_cron extension.
content:
- h1: Setting up and using the pgcron extension
- paragraph: This page explains how to set up and use the pgcron extension.
-tags: managed-database postgresql pgcron pg-extensions
+ h1: Setting up and using the pg_cron extension
+ paragraph: This page explains how to set up and use the pg_cron extension.
+tags: managed-database postgresql pg_cron pg-extensions
dates:
validation: 2025-02-18
posted: 2025-02-18
@@ -14,9 +14,9 @@ categories:
- postgresql-and-mysql
---
-The pgcron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, using jobs that run at the intervals you set. On a daily, weekly or monthly basis, for example.
+The pg_cron extension for PostgreSQL is used to execute periodic tasks. You can schedule SQL tasks, such as queries and data imports, using jobs that run at the intervals you set. On a daily, weekly or monthly basis, for example.
-The `pgcron` extension is available with Scaleway Managed Databases for PostgreSQL. The extension is natively loaded in the `shared_preload_libraries` of the Database Instances by default.
+The `pg_cron` extension is available with Scaleway Managed Databases for PostgreSQL. The extension is natively loaded in the `shared_preload_libraries` of the Database Instances by default.
@@ -24,18 +24,22 @@ The `pgcron` extension is available with Scaleway Managed Databases for PostgreS
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A [Database Instance](/managed-databases-for-postgresql-and-mysql/how-to/create-a-database/) running a PostgreSQL engine
-## Installing pgcron
+## Installing pg_cron
+
+
+ The `pg_cron` extension can only be installed in the `rdb` database, which is created by default upon Database Instance creation. To run jobs in another database, you can use the [schedule_in_database](#scheduling-jobs-in-other-databases) function.
+
Run the following command to install the extension:
```sql
-rdb=> CREATE EXTENSION pgcron;
+rdb=> CREATE EXTENSION pg_cron;
CREATE EXTENSION
```
-## Configuring pgcron
+## Configuring pg_cron
-To fully use the extension, you must grant read/write rights to the user who will be running the `pgcron` functions to manage jobs on the database.
+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.
@@ -168,7 +172,7 @@ SELECT cron.alter_job(job_id:=3,database:='anotherdb');
## Cron specifications
-Schedules in `pgcron` use the standard Cron syntax:
+Schedules in `pg_cron` use the standard Cron syntax:
```
┌───────────── min (0 - 59)
@@ -188,7 +192,7 @@ Schedules in `pgcron` use the standard Cron syntax:
### How to configure your schedule timezone
-The time zone of the `pgcron` extension can be changed in the advanced settings of the Database Instance. By default, the time zone is set to GMT.
+The time zone of the `pg_cron` extension can be changed in the advanced settings of the Database Instance. By default, the time zone is set to GMT.
The `cron.timezone` setting is only available with PostgreSQL 16.
From c21753b49955ec4f31b77881933fa3cf95789f24 Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Tue, 18 Feb 2025 16:54:37 +0100
Subject: [PATCH 10/11] fix(rdb): fix name cron
---
menu/navigation.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/menu/navigation.json b/menu/navigation.json
index 28905d0465..e48ed3e5b1 100644
--- a/menu/navigation.json
+++ b/menu/navigation.json
@@ -2427,7 +2427,7 @@
"slug": "pg-audit"
},
{
- "label": "Setting up and using the pgcron extension",
+ "label": "Setting up and using the pg_cron extension",
"slug": "using-pgcron"
},
{
From 5647aae7ba94c12b54c52b171a2bcd85cf11277f Mon Sep 17 00:00:00 2001
From: ldecarvalho-doc <82805470+ldecarvalho-doc@users.noreply.github.com>
Date: Thu, 20 Feb 2025 13:35:47 +0100
Subject: [PATCH 11/11] fix(rdb): review bene
Co-authored-by: Benedikt Rollik
---
.../api-cli/using-pgcron.mdx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
index 86938ea052..818615f1a0 100644
--- a/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
+++ b/pages/managed-databases-for-postgresql-and-mysql/api-cli/using-pgcron.mdx
@@ -4,7 +4,7 @@ meta:
description: This page explains how to set up and use the pg_cron extension.
content:
h1: Setting up and using the pg_cron extension
- paragraph: This page explains how to set up and use the pg_cron extension.
+ paragraph: This page explains how to set up and use the pg_cron extension on Scaleway's Managed Databases for PostgreSQL.
tags: managed-database postgresql pg_cron pg-extensions
dates:
validation: 2025-02-18