Skip to content

Commit 1b87103

Browse files
charislamdshukertjrinian
authored
fix: update connection strings for ipv6/supavisor (supabase#20394)
* fix: update connection strings for ipv6/supavisor * Update redwoodjs quickstarter with the latest prisma instructions * Update screenshot for obtaining connection string * Add the direct_url back to redwood quickstarter guide * update redwood guide * update screenshots and connecting text --------- Co-authored-by: dshukertjr <[email protected]> Co-authored-by: Inian <[email protected]>
1 parent e1b66b4 commit 1b87103

File tree

16 files changed

+52
-53
lines changed

16 files changed

+52
-53
lines changed

apps/docs/pages/guides/ai/google-colab.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ pip install vecs
3939

4040
## Connect to your database
4141

42-
Find the Postgres connection string for your Supabase project in the [database settings](https://supabase.com/dashboard/_/settings/database) of the dashboard. Copy the "URI" format, which should look something like `postgresql:/postgres:<password>@<host>:5432/postgres`
42+
Find the Postgres pooler connection string for your Supabase project in the [database settings](https://supabase.com/dashboard/_/settings/database) of the dashboard. Copy the "URI" format, which should look something like `postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres`
4343

4444
Create a new code block below the install block (`ctrl+m b`) and add the following code using the Postgres URI you copied above:
4545

4646
```py
4747
import vecs
4848

49-
DB_CONNECTION = "postgresql://postgres:<password>@<host>:5432/postgres"
49+
DB_CONNECTION = "postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres"
5050

5151
# create vector store client
5252
vx = vecs.create_client(DB_CONNECTION)

apps/docs/pages/guides/database/connecting-to-postgres.mdx

+17-24
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,47 @@ Supabase provides auto-updating Data APIs. These are the easiest way to get star
2222
- [GraphQL](/docs/guides/graphql/api): interact with your database through a GraphQL interface.
2323
- [Realtime](/docs/guides/realtime#realtime-api): listen to database changes over websockets.
2424

25-
## Direct connections
25+
## Connection pooler
26+
27+
Every Supabase project comes with a connection pooler for managing connections to your Postgres database.
28+
29+
A connection pooler is useful for managing a large number of _temporary_ connections - for example, if you are using Prisma, Drizzle, Kysely, or anything deployed to a Serverless environment (AWS Lambdas or Edge Functions). Supabase's connection pooler also supports ipv4 out of the box.
2630

27-
Every Supabase project provides a full Postgres database. You can connect to the database using any tool which supports Postgres. Direct connections are on port `5432`. You can find the connection string in the [Database settings](https://supabase.com/dashboard/project/_/settings/database) inside the dashboard:
31+
You can find the connection pool config in the [Database settings](/dashboard/project/_/settings/database) inside the dashboard:
2832

2933
1. Go to the `Settings` section.
3034
2. Click `Database`.
31-
3. Find your Connection Info and Connection String.
35+
3. Under `Connect to your database via connection pooling`, copy your `Connection string`.
3236

33-
<video width="99%" muted playsInline controls={true}>
34-
<source
35-
src="https://xguihxuzqibwxjnimxev.supabase.co/storage/v1/object/public/videos/docs/postgres-connection.mp4"
36-
type="video/mp4"
37-
/>
38-
</video>
37+
## Direct connections
3938

40-
## Connection pooler
39+
You can use a direct connection to connect directly to your Postgres database. By default, this connection uses ipv6, which isn't supported by all network providers. If you need an ipv4 address, use the [connection pooler](#connection-pooler) instead.
4140

42-
Every Supabase project comes with a connection pooler for managing connections to your Postgres database. A connection pooler is useful for managing a large number of _temporary_ connections - for example, if you are using Prisma, Drizzle, Kysely, or anything deployed to a Serverless environment (AWS Lambdas or Edge Functions). You can find the connection pool config in the [Database settings](/dashboard/project/_/settings/database) inside the dashboard:
41+
You can find the direct connection string in the [Database settings](https://supabase.com/dashboard/project/_/settings/database) inside the dashboard:
4342

4443
1. Go to the `Settings` section.
4544
2. Click `Database`.
46-
3. Find your Connection Info and Connection String. Connection pooling is on port `6543`.
47-
48-
<video width="99%" muted playsInline controls={true}>
49-
<source
50-
src="https://xguihxuzqibwxjnimxev.supabase.co/storage/v1/object/public/videos/docs/connection-pool-config.mp4"
51-
type="video/mp4"
52-
/>
53-
</video>
45+
3. Under `Connect to your database directly`, copy your `Connection string`.
5446

5547
## Choosing a connection method
5648

5749
- The Data APIs provide programmatic access and have [built-in connection pooling](https://postgrest.org/en/stable/references/connection_pool.html). You can use these for all browser and application interactions. We recommend using these wherever possible.
58-
- A "direct connection" is Postgres' native connection system. You should use this for tools which are always alive - usually installed on a long-running server, like Node.js, Ruby, Python, etc.
59-
- A "connection pooler" is a tool which keeps connections "alive". You should use this for serverless functions and tools which disconnect from the database frequently, like Prisma, Drizzle, Kysely, etc.
50+
- A "connection pooler" is a tool which keeps connections "alive". You should use this for serverless functions and tools which disconnect from the database frequently, like Prisma, Drizzle, Kysely, etc. You should also use this if your network doesn't support ipv6.
51+
- A "direct connection" is Postgres' native connection system. You can use this for tools which are always alive, such as long-running server, as long as your network supports ipv6.
6052

6153
Why would you use a connection pool? Primarily because the way that Postgres handles connections isn't very scalable for a large number of _temporary_ connections. You can use these simple questions to determine which connection method to use:
6254

63-
- Are you connecting to a database and _maintaining_ a connection? If yes, use a direct connection.
64-
- Are you connecting to your database and then _disconnecting_ immediately (e.g. a serverless environment)? If yes, use a connection pool.
55+
- Are you on a network that doesn't support ipv6? Use the connection pooler.
56+
- Are you connecting to your database and then _disconnecting_ immediately (e.g. a serverless environment)? Use the connection pooler.
57+
- Are you connecting to a database and _maintaining_ a connection, and does your network support ipv6? If yes, use a direct connection.
6558

6659
## Connecting with SSL
6760

6861
You should connect to your database using SSL wherever possible, to prevent snooping and man-in-the-middle attacks.
6962

7063
You can obtain your connection info and Server root certificate from your application's dashboard:
7164

72-
![Connection Info and Certificate.](/docs/img/guides/database/connection-info-cert.png)
65+
![Connection Info and Certificate.](/docs/img/database/database-settings-ssl.png)
7366

7467
## Integrations
7568

apps/docs/pages/guides/database/import-data.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ You can use it in conjunction with Supabase by following these steps:
4949
```sql
5050
LOAD DATABASE
5151
FROM sourcedb://USER:PASSWORD@HOST/SOURCE_DB
52-
INTO postgres://postgres:password@db.xxxx.supabase.co:6543/postgres
52+
INTO postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres
5353
ALTER SCHEMA 'public' OWNER TO 'postgres';
5454
set wal_buffers = '64MB', max_wal_senders = 0, statement_timeout = 0, work_mem to '2GB';
5555
```

apps/docs/pages/guides/getting-started/quickstarts/laravel.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const meta = {
6262

6363
```bash .env
6464
DB_CONNECTION=pgsql
65-
DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres
65+
DATABASE_URL=postgres://postgres.xxxx:[email protected].supabase.com:6543/postgres
6666
```
6767

6868
</StepHikeCompact.Code>

apps/docs/pages/guides/getting-started/quickstarts/redwoodjs.mdx

+15-15
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ export const meta = {
2929

3030
<StepHikeCompact.Step step={2}>
3131
<StepHikeCompact.Details title="Gather Database Connection Strings">
32-
After your project is ready, gather the following information about your [database connections](https://supabase.com/dashboard/project/_/settings/database):
3332

34-
* Connection String (port 5432)
35-
* Connection Pooling / Connection String (port 6543)
33+
Go to the [database settings page](https://supabase.com/dashboard/project/_/settings/database). In this quickstart, we are going to connect via the connection pooler. If your network supports IPv6, you can connect to the database directly without using the connection pooler.
3634

37-
You will need these to setup environment variables in Step 5.
35+
We will use the pooler both in `Transaction` and `Session` mode. `Transaction` mode is used for application queries and `Session` mode is used for running migrations with Prisma.
36+
37+
To do this, set the connection mode to `Transaction` in the [database settings page](https://supabase.com/dashboard/project/_/settings/database) and copy the connection string and append `?pgbouncer=true&&connection_limit=1`. `pgbouncer=true` disables Prisma from generating prepared statements. This is required since our connection pooler does not support prepared statements in transaction mode yet. The `connection_limit=1` parameter is only required if you are using Prisma from a serverless environment. This is the Transaction mode connection string.
38+
39+
To get the Session mode connection pooler string, change the port of the connection string from the dashboard to 5432.
40+
41+
You will need the Transaction mode connection string and the Session mode connection string to setup environment variables in Step 5.
3842

3943
<Admonition type="tip">
4044

@@ -86,26 +90,22 @@ export const meta = {
8690

8791
<StepHikeCompact.Step step={5}>
8892
<StepHikeCompact.Details title="Configure Environment Variables">
89-
In your `.env` file, add the following environment variables for your database connection:
9093

91-
* The `DIRECT_URL` should use the `Connection String` from your Supabase project. Hint: the port is `5432`.
92-
93-
* The `DATABASE_URL` should use the `Connection Pooling / Connection String` from your Supabase project. Hint: the port is `6543`.
94+
In your `.env` file, add the following environment variables for your database connection:
9495

95-
<Admonition type="note">
96+
* The `DIRECT_URL` should use the Transaction mode connection string you copied in Step 1.
9697

97-
Also, replace `[YOUR-PASSWORD]` and `[YOUR-PROJECT-REF]` with the password you used when creating your Supabase project and the project reference from the URL in your browser.
98+
* The `DATABASE_URL` should use the Session mode connection string you copied in Step 1.
9899

99-
</Admonition>
100100
</StepHikeCompact.Details>
101101

102102
<StepHikeCompact.Code>
103103
```bash .env
104-
# PostgreSQL connection string used for migrations
105-
DIRECT_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres"
104+
# Transaction mode connection string used for migrations
105+
DIRECT_URL="postgres://postgres.[project-ref]:[db-password]@xxx.pooler.supabase.com:6543/postgres?pgbouncer=true&connection_limit=1"
106106

107-
# PostgreSQL pooler connection string with Supavisor config — used by Prisma Client
108-
DATABASE_URL="postgres://postgres.[YOUR-PROJECT-REF]:[YOUR-PASSWORD]@aws-0-[YOUR-PROJECT-REGION].pooler.supabase.com:6543/postgres"
107+
# Session mode connection string — used by Prisma Client
108+
DATABASE_URL="postgres://postgres.[project-ref]:[db-password]@xxx.pooler.supabase.com:5432/postgres"
109109
```
110110
</StepHikeCompact.Code>
111111

apps/docs/pages/guides/getting-started/quickstarts/ruby-on-rails.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const meta = {
4343
<StepHikeCompact.Code>
4444

4545
```bash Terminal
46-
export DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres
46+
export DATABASE_URL=postgres://postgres.xxxx:[email protected].supabase.com:6543/postgres
4747
```
4848

4949
</StepHikeCompact.Code>

apps/docs/pages/guides/platform/branching.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ You can use the [Supabase CLI](/docs/guides/cli) to manage changes inside a loca
157157
supabase db pull --db-url <db_url>
158158

159159
# Your Database URL looks something like:
160-
# postgresql://username:password@db.ref.supabase.co:5432/postgres
160+
# postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres
161161
```
162162

163163
</CH.Code>
@@ -487,7 +487,7 @@ Dashboard changes aren't automatically reflected in your Git repository. If you'
487487
<CH.Code lineNumbers={false}>
488488

489489
```bash
490-
supabase db pull --db-url "postgres://postgres:[password]@db.[branch-ref].supabase.co:5432/postgres"
490+
supabase db pull --db-url "postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres"
491491
```
492492

493493
</CH.Code>

apps/docs/pages/guides/platform/migrating-and-upgrading-projects.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ Migrating projects can be achieved using the Supabase CLI. This is particularly
139139
- Set environment variables for the old project's database URL as `$OLD_DB_URL` and the new project's as `$NEW_DB_URL`.
140140
To find the database URL for a project, go to the project's dashboard page [Project Settings/Database](https://supabase.com/dashboard/project/_/settings/database) and look at `Connection string / URI`. For example, to set the `$OLD_DB_URL` you would run `export OLD_DB_URL=postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF#].supabase.co:5432/postgres`.
141141

142+
<Admonition type="tip">
143+
144+
Note that this direct connection string to the database uses IPv6. If your network provider doesn't yet support IPv6, you can connect via the pooler connection string, available under the **Connection pooling** section of [**Database settings**](https://supabase.com/dashboard/project/_/settings/database). The connection string has the format `postgres://postgres.xxxx:[email protected]:6543/postgres`.
145+
146+
</Admonition>
147+
142148
### Backup your old database
143149

144150
1. Run the following command from your terminal:

apps/docs/pages/guides/resources/migrating-to-supabase/amazon-rds.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Supabase's core is Postgres, enabling the use of row-level security and providin
2828
1. Under **Connection Info**, note your Host (`$SUPABASE_HOST`).
2929
1. Save your password or [reset it](https://supabase.com/dashboard/project/_/settings/database) if you forgot it.
3030

31-
![Finding Supabase host address](/docs/img/guides/resources/migrating-to-supabase/amazon-rds/supabase_dashboard.png)
31+
![Finding Supabase host address](/docs/img/database/database-settings-host.png)
3232

3333
## Migrate the database
3434

@@ -60,7 +60,7 @@ Alternatively, you can use [pgloader](https://github.com/dimitri/pgloader), a fl
6060
```sql
6161
load database
6262
from mysql://user:password@host/source_db
63-
into postgres://postgres:password@db.xxxx.supabase.co:6543/postgres
63+
into postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres
6464
alter schema 'public' owner to 'postgres';
6565
set wal_buffers = '64MB', max_wal_senders = 0, statement_timeout = 0, work_mem to '2GB';
6666
```
@@ -80,7 +80,7 @@ pgloader config.load
8080
```sql
8181
LOAD DATABASE
8282
FROM mssql://USER:PASSWORD@HOST/SOURCE_DB
83-
INTO postgres://postgres:password@db.xxxx.supabase.co:6543/postgres
83+
INTO postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres
8484
ALTER SCHEMA 'public' OWNER TO 'postgres';
8585
set wal_buffers = '64MB', max_wal_senders = 0, statement_timeout = 0, work_mem to '2GB';
8686
```

apps/docs/pages/guides/resources/migrating-to-supabase/mssql.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Before you begin the migration, you need to collect essential information about
2525
1. Under **Connection Info**, note your Host (`$SUPABASE_HOST`).
2626
1. Save your password or [reset it](https://supabase.com/dashboard/project/_/settings/database) if you forgot it.
2727

28-
![Finding Supabase host address](/docs/img/guides/resources/migrating-to-supabase/amazon-rds/supabase_dashboard.png)
28+
![Finding Supabase host address](/docs/img/database/database-settings-host.png)
2929

3030
## Migrate the database
3131

@@ -57,7 +57,7 @@ Alternatively, you can use [pgloader](https://github.com/dimitri/pgloader), a fl
5757
```sql
5858
LOAD DATABASE
5959
FROM mssql://USER:PASSWORD@HOST/SOURCE_DB
60-
INTO postgres://postgres:password@db.xxxx.supabase.co:6543/postgres
60+
INTO postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres
6161
ALTER SCHEMA 'public' OWNER TO 'postgres';
6262
set wal_buffers = '64MB', max_wal_senders = 0, statement_timeout = 0, work_mem to '2GB';
6363
```

apps/docs/pages/guides/resources/migrating-to-supabase/mysql.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Before you begin the migration, you need to collect essential information about
2626
1. Under **Connection Info**, note your Host (`$SUPABASE_HOST`).
2727
1. Save your password or [reset it](https://supabase.com/dashboard/project/_/settings/database) if you forgot it.
2828

29-
![Finding Supabase host address](/docs/img/guides/resources/migrating-to-supabase/amazon-rds/supabase_dashboard.png)
29+
![Finding Supabase host address](/docs/img/database/database-settings-host.png)
3030

3131
## Migrate the database
3232

@@ -58,7 +58,7 @@ Alternatively, you can use [pgloader](https://github.com/dimitri/pgloader), a fl
5858
```sql
5959
load database
6060
from mysql://user:password@host/source_db
61-
into postgres://postgres:password@db.xxxx.supabase.co:6543/postgres
61+
into postgres://postgres.xxxx:password@xxxx.pooler.supabase.com:6543/postgres
6262
alter schema 'public' owner to 'postgres';
6363
set wal_buffers = '64MB', max_wal_senders = 0, statement_timeout = 0, work_mem to '2GB';
6464
```
Loading
Loading
Binary file not shown.
Loading

0 commit comments

Comments
 (0)