Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Adds some videos to the connection docs

Paul Copplestonee1ff1acb480c
diff --git a/web/docs/guides/database/connecting/connecting-to-postgres.mdx b/web/docs/guides/database/connecting/connecting-to-postgres.mdx
index 9fa6d58e1c6..14c050f767a 100644
--- a/web/docs/guides/database/connecting/connecting-to-postgres.mdx
+++ b/web/docs/guides/database/connecting/connecting-to-postgres.mdx
@@ -11,16 +11,20 @@ Supabase provides two options for connection to your Postgres database:
## Direct connection vs Connection Pooling
-A "direct connection" is one where a connection is made to the database server using Postgres' native connection implementation.
-Supabase's connection pool [PgBouncer](https://www.pgbouncer.org/) to manage connections to the database server.
+A "direct connection" is when a connection is made to the database using Postgres' native connection implementation.
+
+A "connection pool" is a system (external to Postgres)
+which manage connections, rather than Postgres' native system.
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:
- Are you connecting to a database an _maintaining_ a connection? If yes, use a direct connection.
-- Are you connecting to your database and then _disconnecting_ immediately (like in a serverless environment)? If yes, use a connection pool.
+- Are you connecting to your database and then _disconnecting_ immediately (e.g. a serverless environment)? If yes, use a connection pool.
-## Connection strings
+## Resources
-Link to reference docs.
+- [Direct Connections](/docs/guides/database/connecting/direct-connections).
+- [Connection Pooling](/docs/guides/database/connecting/connection-pooling).
+- [Connection Strings (Reference Docs)](/docs/reference/postgres/connection-strings).
diff --git a/web/docs/guides/database/connecting/connection-pooling.mdx b/web/docs/guides/database/connecting/connection-pooling.mdx
index 454784644ff..ebd8805311a 100644
--- a/web/docs/guides/database/connecting/connection-pooling.mdx
+++ b/web/docs/guides/database/connecting/connection-pooling.mdx
@@ -1,31 +1,20 @@
---
id: connection-pooling
-title: "Connection pooling"
-description: There are various ways to connect to your Postgres database.
+title: "Connection Pooling"
+description: Connecting to your Supabase database using PgBouncer.
---
Connection pools are useful for managing a large number of _temporary_ connections.
-
## How connection pooling works
-Typically when a client connects to a PostgreSQL database, the client opens and manages their own database connection.
-
-With a connection pool, connections are already open and available for use. When a client makes a request, they use an existing connection from the pool.
-When the client transaction or session is completed the connection is simply returned to the pool and is free to be used by another client or application.
-
-![Connection pooling](/img/guides/connection-pool.png)
-
-## Handling temporary connections
+A "connection pool" is a system (external to Postgres) which manage connections, rather than PostgreSQL's native system. Supabase uses [PgBouncer](https://www.pgbouncer.org/) for connection pooling.
-In a traditional architecture, middleware servers (e.g. APIs) manage a small number of connection to a Postgres database.
-Essentially, the middleware server is a connection pool.
+When a client makes a request, PgBouncer "allocates" and available connection to the client.
+When the client transaction or session is completed the connection is returned to the pool and is free to be used by another client.
-In a Serverless environment, there is no middleware server to maintain a connection, so they create a new connection for each concurrent request.
-Since Serverless functions are typically used for bursty workloads, this can end up opening a lot of connections to the database and overwhelm your Postgres server.
-Connection pools mitigate this. Connections are maintained by the pool and recycled across users and applications.
-Whenever a new connection is required it is taken from a pool of open and available connections instead of initializing an entirely new one. This eliminates the need to spawn a new process.
+![Connection pooling](/img/guides/connection-pool.png)
## Pool modes
@@ -35,19 +24,47 @@ Pool Mode determines how PgBouncer handles a connection.
### Session
When a new client connects, a connection is assigned to the client until it disconnects. Afterward, the connection is returned back to the pool.
+
All PostgreSQL features can be used with this option.
### Transaction
-This is the suggested option for serverless functions. With this, the connection is only assigned to the client for the duration of a transaction. Once done, the connection is returned to the pool.
-Two consecutive transactions from the same client could be done over two, different connections. Some session-based PostgreSQL features such as prepared statements are not available with this option.
-A more comprehensive list of incompatible features can be found here.
+This is the suggested option for serverless functions. A connection is only assigned to the client for the duration of a transaction. Two consecutive transactions from the same client
+could be executed over two different connections.
+
+Some session-based PostgreSQL features such as prepared statements are not available with this option.
+A comprehensive list of incompatible features can be found [here](https://www.pgbouncer.org/features.html).
### Statement
-This is the most granular option. Connections are returned to the pool after every statement. Transactions with multiple statements are not allowed. This is best used when AUTOCOMMIT is in use.
+This is the most granular option. Connections are returned to the pool after every statement. Transactions with multiple statements are not allowed. This is best used when `AUTOCOMMIT` is in use.
+
+## Finding your connection string
+
+<Tabs
+defaultValue="UI"
+values={[
+ {label: 'UI', value: 'UI'}
+]}>
+<TabItem value="UI">
+
+```sh
+1. Go to the "Database" section.
+2. Click "Connection Pooling".
+3. Find your Connection Info and Connection String.
+```
+
+<video width="99%" muted playsInline controls="true">
+ <source src="/videos/pgbouncer-connection.mp4" type="video/mp4" muted playsInline />
+</video>
+
+</TabItem>
+</Tabs>
+
+
-### Finding your connection string
+## Resources
-- How to find it on the dashboard.
-- Link to the reference docs on Connection strings
+- [Direct Connections](/docs/guides/database/connecting/direct-connections).
+- [Connection Pooling](/docs/guides/database/connecting/connection-pooling).
+- [Connection Strings (Reference Docs)](/docs/reference/postgres/connection-strings).
diff --git a/web/docs/guides/database/connecting/direct-connections.mdx b/web/docs/guides/database/connecting/direct-connections.mdx
index 7886269a1b6..bacb26792dd 100644
--- a/web/docs/guides/database/connecting/direct-connections.mdx
+++ b/web/docs/guides/database/connecting/direct-connections.mdx
@@ -1,11 +1,40 @@
---
id: direct-connections
title: "Direct Connections"
-description: Connecting to your Postgres database.
+description: Connecting to your Supabase database.
---
-Some details.
+import Tabs from '@theme/Tabs'
+import TabItem from '@theme/TabItem'
+
+Every Supabase project provides a full Postgres database. You can connect to the database using any tool which supports Postgres.
+
+## Finding your connection string
+
+<Tabs
+defaultValue="UI"
+values={[
+ {label: 'UI', value: 'UI'}
+]}>
+<TabItem value="UI">
+
+```sh
+1. Go to the "Settings" section.
+2. Click "Database".
+3. Find your Connection Info and Connection String.
+```
+
+<video width="99%" muted playsInline controls="true">
+ <source src="/videos/postgres-connection.mp4" type="video/mp4" muted playsInline />
+</video>
+
+</TabItem>
+</Tabs>
+
+## Resources
+
+- [Direct Connections](/docs/guides/database/connecting/direct-connections).
+- [Connection Pooling](/docs/guides/database/connecting/connection-pooling).
+- [Connection Strings (Reference Docs)](/docs/reference/postgres/connection-strings).
-## Connection strings
-Link to reference docs.
\ No newline at end of file
diff --git a/web/spec/postgres.yml b/web/spec/postgres.yml
index 4a6ee6df441..00f0834645a 100644
--- a/web/spec/postgres.yml
+++ b/web/spec/postgres.yml
@@ -284,21 +284,41 @@ pages:
Connection strings:
description: |
- @TODO.
+ There are various ways to connect to your database, depending on the configuration of your Postgres instance and the tool which you are connecting with.
+
notes: |
- - Official Documentation: [postgresql.org/docs/current/libpq-connect.html](https://www.postgresql.org/docs/current/libpq-connect.html).
+ - [Official Documentation](https://www.postgresql.org/docs/current/libpq-connect.html).
+ - Avoid using special characters usernames and passwords. If you use special characters in a connection URL, you'll need to URL encode any special characters.
examples:
- - name: TODO
+ - name: Basic connection string
+ description: |
+ If you're using a default setup, your postgres connection string will likely be in the format:
+
+ `postgres://{user}:{password}@{host}:{port}/{database_name}`
+
isSpotlight: true
sql: |
- ```sh
- postgresql://
- postgresql://localhost
- postgresql://localhost:5433
- postgresql://localhost/mydb
- postgresql://user@localhost
- postgresql://user:secret@localhost
- postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
- postgresql://host1:123,host2:456/somedb?target_session_attrs=any&application_name=myapp
+ ```bash
+ postgres://postgres:postgres@localhost:5432/postgres
+ # or
+ postgresql://postgres:postgres@localhost:5432/postgres
+ ```
+ - name: JDBC
+ description: See full [documentation](http://jdbc.postgresql.org/documentation/head/connect.html).
+ sql: |
+ ```bash
+ jdbc:postgresql://{host}:{port}/{database_name}
+ ```
+ - name: ADO.NET
+ description: See full [documentation](http://npgsql.projects.postgresql.org/docs/manual/UserManual.html).
+ sql: |
+ ```bash
+ Server=host;Port=5432;User Id=username;Password=secret;Database=database_name;
+ ```
+ - name: PHP
+ description: See full [documentation](http://php.net/manual/en/book.pgsql.php).
+ sql: |
+ ```bash
+ host=hostname port=5432 dbname=databasename user=username password=secret
```
\ No newline at end of file
diff --git a/web/static/videos/pgbouncer-connection.mp4 b/web/static/videos/pgbouncer-connection.mp4
new file mode 100644
index 00000000000..f05740fc633
Binary files /dev/null and b/web/static/videos/pgbouncer-connection.mp4 differ
diff --git a/web/static/videos/postgres-connection.mp4 b/web/static/videos/postgres-connection.mp4
new file mode 100644
index 00000000000..1aa7816f924
Binary files /dev/null and b/web/static/videos/postgres-connection.mp4 differ