-
Notifications
You must be signed in to change notification settings - Fork 90
docs: Document embedded PostgreSQL #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marcelomendoncasoares
merged 8 commits into
serverpod:main
from
marcelomendoncasoares:docs/embedded-postgres
Jul 28, 2026
+85
−4
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c428be
docs: Document embedded PostgreSQL
marcelomendoncasoares 30751b1
docs: Restructure the embedded PostgreSQL section
marcelomendoncasoares a943d1e
docs: Move embedded PostgreSQL to a dedicated page
marcelomendoncasoares 1296051
docs: Show how to reach the embedded database from a database tool
marcelomendoncasoares 36b74b4
docs: Note that integration tests need no database of their own
marcelomendoncasoares 0363995
revert: Revert the testing/get-started change to avoid conflicts with…
marcelomendoncasoares c595f77
fix: Fix the description of the temporary directory
marcelomendoncasoares 1c10c61
Merge commit 'e7942d658aaada92ca39f36f98996afb57226932' into docs/emb…
marcelomendoncasoares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
docs/06-concepts/03-data-and-the-database/02-database/19-embedded-postgres.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| --- | ||
| description: Embedded PostgreSQL is a real PostgreSQL server that Serverpod starts and stops with your server, for local development and testing without Docker. | ||
| --- | ||
|
|
||
| # Embedded PostgreSQL | ||
|
|
||
| New projects run an embedded PostgreSQL in the `development` and `test` run modes. It is a real PostgreSQL server that Serverpod starts and stops together with your server, so local development gets the same database engine as production without installing PostgreSQL or running Docker. | ||
|
|
||
| It is meant for local development and testing only. There are no backups, no replication, and nothing supervising the process, so staging and production connect to a managed or separately operated PostgreSQL instead. See [Connection](./connection) for those setups. | ||
|
|
||
| ## Enable it | ||
|
|
||
| Embedded PostgreSQL is enabled by the `dataPath` setting, which generated projects already include: | ||
|
|
||
| ```yaml title="config/development.yaml" | ||
| database: | ||
| host: localhost | ||
| port: 8090 | ||
| name: myproject | ||
| user: postgres | ||
| dataPath: .serverpod/development/pgdata | ||
| ``` | ||
|
|
||
| The rest of the database settings stay as they are. Serverpod uses `name` and `user` when it creates the database and reads the password from `config/passwords.yaml`, exactly as it would for an external instance. Remove `dataPath` to connect to the `host` and `port` instead. | ||
|
|
||
| A relative `dataPath` is resolved from the root of the server package, and each run mode needs its own directory, for example `.serverpod/test/pgdata` in `config/test.yaml`. The directory holds a complete database, so keep it out of version control. | ||
|
|
||
| ## What happens when the server starts | ||
|
|
||
| The first start downloads the PostgreSQL binaries for your operating system and architecture into a per-user cache, which every later start and every other project reuses. Binaries are available for Linux and macOS on x64 and Arm64, and for Windows on x64. | ||
|
|
||
| Serverpod starts the database before it opens its connection pool, and connects over a Unix domain socket instead of a TCP port, so several projects can run at once without competing for ports. If another Serverpod process already runs a database in the same `dataPath`, the new process attaches to it rather than starting a second one. | ||
|
|
||
| The files under `dataPath` are kept when the server stops, so your data is still there on the next start. After an unclean exit, Serverpod clears the leftover process state and brings the database back up. | ||
|
|
||
| ## Connect a database tool | ||
|
|
||
| Most clients like `psql` and `pgAdmin` connect over TCP, not the Unix socket the server uses. To inspect the data with one of them, start the database on its own while the server is stopped: | ||
|
|
||
| ```bash | ||
| $ serverpod database start | ||
| ``` | ||
|
|
||
| It boots the database configured for the `development` run mode and keeps it listening on the configured port until you stop it with Ctrl+C. Connect with the `name` and `user` from that run mode's configuration, and the password from `config/passwords.yaml`. | ||
|
|
||
| Pass `--mode` to pick another run mode and `--port` to listen somewhere else: | ||
|
|
||
| ```bash | ||
| $ serverpod database start --mode test --port 9090 | ||
| ``` | ||
|
|
||
| ## Run integration tests | ||
|
|
||
| Integration tests bring their own database, so there is nothing to install or start first: | ||
|
|
||
| ```bash | ||
| $ dart test | ||
| ``` | ||
|
|
||
| The started database server will be held open until the test process exits. Every suite in a test process shares the same database server, but each `withServerpod` group creates a randomly named database of its own on it that will be dropped on teardown. That is where the isolation comes from: groups run in parallel without seeing each other's data or leaving anything behind between runs. | ||
|
|
||
| The data directory is not temporary. Like the one for `development`, it stays after the tests, and only the server process is reclaimed when the test process exits. See [Get started with testing](../../testing/get-started) for the rest of the setup. | ||
|
|
||
| :::note | ||
| If a test process is hard-killed, the database server will not be stopped and data can be left behind. This data won't harm future runs because of the named database isolation, but it can occupy disk space. If the directory happens to grow too large, it is fully safe to delete it and let the next test recreate it from scratch. | ||
| ::: | ||
|
|
||
| ## Reset the database | ||
|
|
||
| To start from an empty database, stop the server and delete the directory `dataPath` points at. Serverpod creates a new one on the next start. | ||
|
|
||
| :::warning | ||
| Deleting `dataPath` permanently deletes the database and all local data stored in it. | ||
| ::: | ||
|
|
||
| ## Related | ||
|
|
||
| - [Connection](./connection): connecting to a PostgreSQL instance you run yourself. | ||
| - [Configuration](../../server-fundamentals/configuration#database-backends): the database section of the run mode configuration. | ||
| - [`serverpod database`](../../cli/commands/database): every option of the command above. | ||
| - [serverpod_embedded_postgres](https://pub.dev/packages/serverpod_embedded_postgres): the package behind this, for tools that need a PostgreSQL process of their own. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.