Skip to content

Commit 89ebfb3

Browse files
authored
docs: describe postgresql ttl jobs (#2024)
* docs: describe postgresql ttl jobs * chore: format * chore: update * chore: update * docs: add pgcron description * chore: u * chore: update sidebar * chore: update title * chore: update title
1 parent 2be47db commit 89ebfb3

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
id: migrate-postgresql-ttl
3+
title: PostgreSQL TTL jobs for Hydra OEL
4+
---
5+
6+
# PostgreSQL TTL jobs for Ory Hydra
7+
8+
This guide outlines the steps to enable and configure the PostgreSQL TTL jobs for Ory Hydra. The TTL jobs are executed
9+
periodically to remove expired data from the PostgreSQL database. They are essential for maintaining database performance and
10+
preventing uncontrolled growth.
11+
12+
This feature is available in Ory Hydra Enterprise License (OEL) and it requires the PostgreSQL database with the `pg_cron`
13+
extension installed.
14+
15+
By default, Postgresql TTL jobs are disabled. They can be installed by enabling an additional migration job, similar to the
16+
default migration job that introduces schema changes. This additional job populates the database with the necessary cron job
17+
definitions containing delete statements for expired data. The cron jobs are executed by the `pg_cron` extension at 00:00 UTC.
18+
19+
## Prerequisites
20+
21+
Before starting the upgrade process, ensure that you meet the following requirements:
22+
23+
1. **Ory Hydra Version**: Your current Ory Hydra OEL installation must be version `e17b2ea61cc69e70f252e384d5ccbac83e504ced` or
24+
newer.
25+
2. **PostgreSQL Database**: The PostgreSQL database must be installed and configured with the `pg_cron` extension.
26+
3. **Backup and Testing**: Create a backup of your current Ory Hydra database and test the migration on a test environment to
27+
ensure compatibility and minimize risks.
28+
29+
## Installation process
30+
31+
If you are using the official [Hydra helm chart](https://github.com/ory/k8s/tree/master/helm/charts/hydra) modify your values.yaml
32+
file to include the following configuration:
33+
34+
```yaml
35+
hydra:
36+
customMigrations:
37+
jobs:
38+
oel-postgresql-ttl:
39+
enabled: true
40+
```
41+
42+
This change enables the additional migration job that introduces the TTL jobs to the PostgreSQL database. By default, it executes
43+
the `hydra` binary with following arguments:
44+
45+
```
46+
migrate postgresql-addons up --hydra-db-name ory_hydra --pgcron-db-name postgres
47+
```
48+
49+
If you use a different database name, you can override it by setting the `--hydra-db-name` and `--pgcron-db-name` flags in the
50+
`values.yaml` file:
51+
52+
```yaml
53+
hydra:
54+
customMigrations:
55+
jobs:
56+
oel-postgresql-ttl:
57+
enabled: true
58+
customArgs:
59+
[
60+
"migrate",
61+
"postgresql-addons",
62+
"up",
63+
"--hydra-db-name",
64+
"<your hydra database>",
65+
"--pgcron-db-name",
66+
"<database where pg_cron is installed>",
67+
]
68+
```
69+
70+
## Possible issues
71+
72+
### pg_cron extension not installed
73+
74+
If the `pg_cron` extension is not installed in the PostgreSQL database, the migration job will fail with the following error:
75+
76+
```
77+
ERROR: schema "cron" does not exist (SQLSTATE 3F000)
78+
```
79+
80+
To resolve this issue, install the `pg_cron` extension and enable it in the postgres database.

src/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ const selfhostingSidebar = [
685685
items: [
686686
"self-hosted/oel/oauth2/token-prefix",
687687
"self-hosted/oel/oauth2/upgrade",
688+
"self-hosted/oel/oauth2/migrate-postgresql-ttl",
688689
"self-hosted/oel/oauth2/changelog",
689690
],
690691
},

0 commit comments

Comments
 (0)