Skip to main content
This plugin manages databases on Shuttle and connects them to your app. A shared database is in the same cluster as other user’s databases, but it is not accessible by other users. If you want a high performing and isolated database, we also offer dedicated Shuttle AWS RDS.
You can connect to any type of remotely hosted database from your code, so do not let our current database offerings limit your creativity! Got other databases you want to see on Shuttle? Let us know!
The Shared Database is intended primarily for experimentation and development. Since it runs on AWS RDS instances shared with other Shuttle users, performance may be impacted during times of high demand from other databases. For business-critical workloads, we recommend using a dedicated Shuttle AWS RDS database.
The Shuttle Shared Postgres cluster is RDS-based and uses Postgres version 16. Contact support if you want to enable common Postgres Extensions for your project.

Usage

Start by adding the shuttle-shared-db dependency. Each type of shareable database is behind its own feature flag and macro attribute path.

Output type

By default, you can get the connection string to the database and connect to it with your preferred library. You can also specify other return types to get rid of common boilerplate. Depending on which type declaration is used as the output type in the macro, additional feature flags need to be activated: Postgres output types: Lastly, add a macro annotation to the Shuttle main function. Here are examples for Postgres:
The Shuttle builder does not currently support sqlx compile-time checked macros. Use cargo sqlx prepare to enable offline building.

Parameters

When passing in strings, you can also insert secrets from Secrets.toml using string interpolation. To insert the PASSWORD secret, pass it in like this:
Caveat: If you are interpolating a secret from Secrets.dev.toml, you need to set the same secret in Secrets.toml to a empty string so that this step does not crash in deployment.
The URI should be formatted according to the Postgres documentation. If you do not specify a local_uri, then cargo-shuttle will attempt to spin up a Docker container and launch the database inside of it. For this to succeed, you must have Docker installed and you must also have started the Docker engine. If you have not used Docker before, the easiest way is to install the desktop app and then launch it in order to start the Docker engine.

Connection string

After deploying a project with a database macro, you can view the connection string with credentials with:
Using the connection string, you can connect to it for manual querying, inspection, and migration.

Example

The Shuttle main function below uses the #[shuttle_shared_db::Postgres] attribute macro to provision a shared Postgres database, which can be accessed with an sqlx Pool.
main.rs
The full example can be found on GitHub.