Skip to content

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

initialize some docs related to connection pooling

Paul Copplestone20f50230db1b
diff --git a/web/docs/guides/database/connecting/connecting-to-postgres.mdx b/web/docs/guides/database/connecting/connecting-to-postgres.mdx
new file mode 100644
index 00000000000..3c0a8ae156a
--- /dev/null
+++ b/web/docs/guides/database/connecting/connecting-to-postgres.mdx
@@ -0,0 +1,21 @@
+---
+id: connecting-to-postgres
+title: "Overview"
+description: There are various ways to connect to your Postgres database.
+---
+
+Supabase provides two options for connection to your Postgres database:
+
+- Direct connections.
+- Connection pooling , using PgBouncer.
+
+
+## Direct connection vs Connection Pooling
+
+Some details here, and when you should choose which.
+
+![Connection pooling](/img/guides/connection-pool.png)
+
+## Connection strings
+
+Link to reference docs.
\ No newline at end of file
diff --git a/web/docs/guides/database/connecting/connection-pooling.mdx b/web/docs/guides/database/connecting/connection-pooling.mdx
new file mode 100644
index 00000000000..5a47239b4b6
--- /dev/null
+++ b/web/docs/guides/database/connecting/connection-pooling.mdx
@@ -0,0 +1,48 @@
+---
+id: connection-pooling
+title: "Connection pooling"
+description: There are various ways to connect to your Postgres database.
+---
+
+Supabase uses PgBouncer.
+
+## Connection Pooling
+
+### How connection pooling works
+
+Typically when a client connects to a PostgreSQL database, they need to open and manage their own database connection.
+With a connection pool, connections are already opened and available for use. When a client makes a request, they use a connection from the pool.
+When the transaction or session is completed the underlying connection is simply returned to the pool and is once again free to be used by another user or application.
+
+![Connection pooling](/img/guides/connection-pool.png)
+
+### Handling connection surges
+
+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.
+
+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 opened beforehand and recycled across users and applications.
+What's more, connection pools are specialized for this task. A small number of connections is sufficient to handle demand ten, twenty times its size, or even more.
+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.
+
+
+### Pool modes
+
+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.
+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.
+
+### Finding your connection string
+
+- How to find it on the dashboard.
+- Link to the reference docs on Connection strings
diff --git a/web/docs/guides/database/connecting/direct-connections.mdx b/web/docs/guides/database/connecting/direct-connections.mdx
new file mode 100644
index 00000000000..e8433924aa3
--- /dev/null
+++ b/web/docs/guides/database/connecting/direct-connections.mdx
@@ -0,0 +1,11 @@
+---
+id: direct-connections
+title: "Direct connections"
+description: Connecting to your Postgres database.
+---
+
+Some details.
+
+## Connection strings
+
+Link to reference docs.
\ No newline at end of file
diff --git a/web/sidebars.js b/web/sidebars.js
index 7f35c1dfee4..d34518e5098 100755
--- a/web/sidebars.js
+++ b/web/sidebars.js
@@ -127,6 +127,16 @@ module.exports = {
'guides/database/extensions/uuid-ossp',
],
},
+ {
+ type: 'category',
+ label: 'Connecting to Postgres',
+ collapsed: false,
+ items: [
+ 'guides/database/connecting/connecting-to-postgres',
+ 'guides/database/connecting/direct-connections',
+ 'guides/database/connecting/connection-pooling',
+ ],
+ },
],
},
{
diff --git a/web/spec/postgres.yml b/web/spec/postgres.yml
index 60087722c5b..4a6ee6df441 100644
--- a/web/spec/postgres.yml
+++ b/web/spec/postgres.yml
@@ -281,4 +281,24 @@ pages:
from pg_timezone_names()
where name ilike '%york%';
```
-
+
+ Connection strings:
+ description: |
+ @TODO.
+ notes: |
+ - Official Documentation: [postgresql.org/docs/current/libpq-connect.html](https://www.postgresql.org/docs/current/libpq-connect.html).
+
+ examples:
+ - name: TODO
+ 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
+ ```
\ No newline at end of file
diff --git a/web/static/img/guides/connection-pool.png b/web/static/img/guides/connection-pool.png
new file mode 100644
index 00000000000..c1206da9695
Binary files /dev/null and b/web/static/img/guides/connection-pool.png differ