Skip to content

Commit 8be711e

Browse files
authored
chore: update minimum supported PostgreSQL version (#2393)
* chore: update minimum supported PostgreSQL version closes #2388 * fix: refactor database doc * chore: format
1 parent 4070e3e commit 8be711e

File tree

1 file changed

+52
-23
lines changed

1 file changed

+52
-23
lines changed

docs/hydra/self-hosted/dependencies-environment.md

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,65 @@ id: dependencies-environment
33
title: Database setup and configuration
44
---
55

6-
Ory Hydra is built cloud native and implements [12factor](https://www.12factor.net/) principles. The Docker Image is 5 MB light
7-
and versioned with [verbose upgrade instructions](https://github.com/ory/hydra/blob/master/UPGRADE.md) and
8-
[detailed changelogs](https://github.com/ory/hydra/blob/master/CHANGELOG.md). Auto-scaling, migrations, health checks, it all
9-
works with zero additional work required. It's possible to run Ory Hydra on any platform, including but not limited to OSX, Linux,
10-
Windows, ARM, FreeBSD and more.
6+
Ory Hydra requires a database to store OAuth 2.0 clients, consent sessions, and access tokens. Choose between two operational
7+
modes based on your deployment needs.
118

12-
Ory Hydra has two operational modes:
9+
## In-memory mode
1310

14-
- In-memory: This mode doesn't work with more than one instance ("cluster") and any state is lost after restarting the instance.
15-
Ory Hydra uses SQLite with in-memory mode to achieve this.
16-
- SQL: This mode works with more than one instance and state isn't lost after restarts.
11+
Set `DSN=memory` to run Hydra with an ephemeral SQLite database. This mode is useful for development and testing but has
12+
limitations:
1713

18-
No further dependencies are required for a production-ready instance.
14+
- Data is lost when the instance restarts
15+
- Only single-instance deployments work (no clustering)
1916

20-
## Database configuration
17+
## SQL mode
2118

22-
For more information on configuring
19+
For production deployments, configure Hydra with a persistent database. Hydra supports PostgreSQL 12.0+, MySQL 8.0+, CockroachDB,
20+
and SQLite. Older MySQL versions have known issues with Hydra's database schema.
2321

24-
The SQL adapter supports PostgreSQL 9.6+, MySQL 8.0+ and SQLite. Please note that older MySQL versions have issues with Ory
25-
Hydra's database schema. For more information [go here](https://github.com/ory/hydra/issues/377).
22+
Set the database connection using the `DSN` environment variable or the `dsn` configuration key.
2623

27-
If you do run the SQL adapter, you must first create the database schema. The `hydra serve` command doesn't do this automatically,
28-
instead you must run `hydra migrate sql` to create the schemas. The `hydra migrate sql` command also runs database migrations in
29-
case of an upgrade. Please follow the [upgrade instructions](https://github.com/ory/hydra/blob/master/UPGRADE.md) to see when you
30-
need to run this command. Always create a backup before running `hydra migrate sql`!
24+
PostgreSQL:
3125

32-
Running SQL migrations in Docker is very easy, check out the
33-
[docker-compose](https://github.com/ory/hydra/blob/master/quickstart-postgres.yml) example to see how we did it!
26+
```shell
27+
DSN=postgres://user:password@host:5432/database
28+
```
3429

35-
### Configuration
30+
MySQL:
3631

37-
For more information on configuring the DSN (Data-Source-Name), head over to the
38-
[Deployment Fundamentals and Requirements](../../self-hosted/deployment) document.
32+
```shell
33+
DSN=mysql://user:password@tcp(host:3306)/database?parseTime=true
34+
```
35+
36+
CockroachDB:
37+
38+
```shell
39+
DSN=cockroach://user:password@host:26257/database?sslmode=verify-full
40+
```
41+
42+
SQLite (file-based):
43+
44+
```shell
45+
DSN=sqlite:///path/to/hydra.sqlite?_fk=true
46+
```
47+
48+
The `_fk=true` parameter is required for SQLite to enable foreign key constraints.
49+
50+
For additional DSN options including SSL/TLS configuration, see
51+
[Deployment Fundamentals and Requirements](../../self-hosted/deployment).
52+
53+
## Running migrations
54+
55+
Hydra doesn't create the database schema automatically. You must run migrations before starting the server and after every
56+
upgrade.
57+
58+
Always back up your database before running migrations. For upgrade-specific guidance, see the
59+
[upgrade instructions](./upgrade.mdx).
60+
61+
```shell
62+
hydra migrate sql -e
63+
```
64+
65+
The `-e` flag reads the DSN from the environment variable.
66+
67+
For Docker deployments, see the [docker-compose example](https://github.com/ory/hydra/blob/master/quickstart-postgres.yml).

0 commit comments

Comments
 (0)