You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/pages/guides/ai/google-colab.mdx
+2-2
Original file line number
Diff line number
Diff line change
@@ -39,14 +39,14 @@ pip install vecs
39
39
40
40
## Connect to your database
41
41
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`
43
43
44
44
Create a new code block below the install block (`ctrl+m b`) and add the following code using the Postgres URI you copied above:
Copy file name to clipboardExpand all lines: apps/docs/pages/guides/database/connecting-to-postgres.mdx
+17-24
Original file line number
Diff line number
Diff line change
@@ -22,54 +22,47 @@ Supabase provides auto-updating Data APIs. These are the easiest way to get star
22
22
-[GraphQL](/docs/guides/graphql/api): interact with your database through a GraphQL interface.
23
23
-[Realtime](/docs/guides/realtime#realtime-api): listen to database changes over websockets.
24
24
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.
26
30
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:
28
32
29
33
1. Go to the `Settings` section.
30
34
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`.
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.
41
40
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:
43
42
44
43
1. Go to the `Settings` section.
45
44
2. Click `Database`.
46
-
3. Find your Connection Info and Connection String. Connection pooling is on port `6543`.
3. Under `Connect to your database directly`, copy your `Connection string`.
54
46
55
47
## Choosing a connection method
56
48
57
49
- 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.
60
52
61
53
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:
62
54
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.
65
58
66
59
## Connecting with SSL
67
60
68
61
You should connect to your database using SSL wherever possible, to prevent snooping and man-in-the-middle attacks.
69
62
70
63
You can obtain your connection info and Server root certificate from your application's dashboard:
71
64
72
-

65
+

After your project is ready, gather the following information about your [database connections](https://supabase.com/dashboard/project/_/settings/database):
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.
36
34
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.
In your `.env` file, add the following environment variables for your database connection:
90
93
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:
94
95
95
-
<Admonitiontype="note">
96
+
* The `DIRECT_URL` should use the Transaction mode connection string you copied in Step 1.
96
97
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.
Copy file name to clipboardExpand all lines: apps/docs/pages/guides/platform/migrating-and-upgrading-projects.mdx
+6
Original file line number
Diff line number
Diff line change
@@ -139,6 +139,12 @@ Migrating projects can be achieved using the Supabase CLI. This is particularly
139
139
- Set environment variables for the old project's database URL as `$OLD_DB_URL` and the new project's as `$NEW_DB_URL`.
140
140
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`.
141
141
142
+
<Admonitiontype="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`.
0 commit comments