-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Hyperdrive] Adding example for connecting Hyperdrive to Fly.io #20744
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
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8569c20
Adding example for connecting Hyperdrive to Fly.io
Oxyjun 8c339bb
Update src/content/docs/hyperdrive/examples/fly.mdx
Oxyjun 4138b9f
Update src/content/docs/hyperdrive/examples/fly.mdx
thomasgauvin 147cdbf
Update src/content/docs/hyperdrive/examples/fly.mdx
thomasgauvin 8710412
Update src/content/docs/hyperdrive/examples/fly.mdx
thomasgauvin 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| --- | ||
| type: example | ||
| summary: Connect Hyperdrive to a Fly database instance. | ||
| pcx_content_type: example | ||
| title: Connect to Fly | ||
| sidebar: | ||
| order: 1 | ||
| description: Connect Hyperdrive to a Fly database instance. | ||
| --- | ||
|
|
||
| import { Render, Steps } from "~/components"; | ||
|
|
||
| This example shows you how to connect Hyperdrive to a Fly PostgreSQL database instance. | ||
|
|
||
| ## 1. Allow Hyperdrive access | ||
|
|
||
| You can connect Hyperdrive to any existing Fly database by: | ||
|
|
||
| 1. Allocating a public IP address to your Fly database instance | ||
| 2. Configuring an external service | ||
| 3. Deploying the configuration | ||
| 4. Obtain the connection string, which is used to connect the database to Hyperdrive. | ||
|
|
||
| <Steps> | ||
| 1. Run the following command to [allocate a public IP address](https://fly.io/docs/postgres/connecting/connecting-external/#allocate-an-ip-address). | ||
|
|
||
| ```txt | ||
| fly ips allocate-v6 --app <pg-app-name> | ||
| ``` | ||
|
|
||
| :::note | ||
| Cloudflare recommends using IPv6, but some internet service providers may not support IPv6. In this case, you can [use `flyctl` to establish a local proxy to your database](https://fly.io/docs/postgres/connecting/connecting-with-flyctl/). | ||
| ::: | ||
|
|
||
| 2. [Configure an external service](https://fly.io/docs/postgres/connecting/connecting-external/#configure-an-external-service) by modifying the contents of your `fly.toml` file. Run the following command to download the `fly.toml` file. | ||
|
|
||
| ```txt | ||
| fly config save --app <pg-app-name> | ||
| ``` | ||
|
|
||
| Then, replace the `services` and `services.ports` section of the file with the following `toml` snippet: | ||
|
|
||
| ```toml | ||
| [[services]] | ||
| internal_port = 5432 # Postgres instance | ||
| protocol = "tcp" | ||
|
|
||
| [[services.ports]] | ||
| handlers = ["pg_tls"] | ||
| port = 5432 | ||
| ``` | ||
|
|
||
| 3. [Deploy the new configuration](https://fly.io/docs/postgres/connecting/connecting-external/#deploy-with-the-new-configuration). | ||
| 4. [Obtain the connection string](https://fly.io/docs/postgres/connecting/connecting-external/#adapting-the-connection-string), which is in the form of: | ||
|
|
||
| ```txt | ||
| postgres://{username}:{password}@{hostname}:{port}/{database}?options | ||
thomasgauvin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
| </Steps> | ||
|
|
||
| ## 2. Create a database configuration | ||
|
|
||
| <Render file="create-hyperdrive-config" /> | ||
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.