The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Further progress on the connection docs
Paul Copplestonea077f98a06b5
diff --git a/web/docs/guides/database/connecting/connecting-to-postgres.mdx b/web/docs/guides/database/connecting/connecting-to-postgres.mdxindex 3c0a8ae156a..9fa6d58e1c6 100644--- a/web/docs/guides/database/connecting/connecting-to-postgres.mdx+++ b/web/docs/guides/database/connecting/connecting-to-postgres.mdx@@ -7,15 +7,20 @@ 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.-+- Connection pooling, using PgBouncer.## Direct connection vs Connection Pooling-Some details here, and when you should choose which.+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.++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.## Connection strings-Link to reference docs.\ No newline at end of file+Link to reference docs.+diff --git a/web/docs/guides/database/connecting/connection-pooling.mdx b/web/docs/guides/database/connecting/connection-pooling.mdxindex 5a47239b4b6..454784644ff 100644--- a/web/docs/guides/database/connecting/connection-pooling.mdx+++ b/web/docs/guides/database/connecting/connection-pooling.mdx@@ -4,19 +4,19 @@ title: "Connection pooling"description: There are various ways to connect to your Postgres database.----Supabase uses PgBouncer.+Connection pools are useful for managing a large number of _temporary_ connections.-## Connection Pooling-### How connection pooling works+## 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.+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.-### Handling connection surges+## Handling temporary connectionsIn 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.@@ -24,21 +24,26 @@ 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.+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.-### Pool modes+## Pool modesPool 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+### 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. 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+### StatementThis 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.