The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
[bot] fix lint errors (#32888)
github-actions[bot]d60410be39cc
diff --git a/apps/docs/content/troubleshooting/discovering-and-interpreting-api-errors-in-the-logs-7xREI9.mdx b/apps/docs/content/troubleshooting/discovering-and-interpreting-api-errors-in-the-logs-7xREI9.mdxindex cb7e13cefc0..3df39f7060d 100644--- a/apps/docs/content/troubleshooting/discovering-and-interpreting-api-errors-in-the-logs-7xREI9.mdx+++ b/apps/docs/content/troubleshooting/discovering-and-interpreting-api-errors-in-the-logs-7xREI9.mdx@@ -107,7 +107,7 @@ cross join unnest(request) AS request;cross join unnest(headers) AS headers;```-### query type and formatting data:+### Query type and formatting data:**Suggested use cases:**@@ -164,7 +164,7 @@ from# Finding errors-### API Level errors+### API level errorsThe `metadata.request.url` contains PostgREST formatted queries.diff --git a/apps/docs/content/troubleshooting/how-to-interpret-and-explore-the-postgres-logs-OuCIOj.mdx b/apps/docs/content/troubleshooting/how-to-interpret-and-explore-the-postgres-logs-OuCIOj.mdxindex 1da8df97ff0..c1f3db9d17a 100644--- a/apps/docs/content/troubleshooting/how-to-interpret-and-explore-the-postgres-logs-OuCIOj.mdx+++ b/apps/docs/content/troubleshooting/how-to-interpret-and-explore-the-postgres-logs-OuCIOj.mdx@@ -8,11 +8,11 @@ database_id = "8b000bb4-180b-4a6c-b280-ba02965060f6"> A complimentary guide was made for the [API logs](https://github.com/orgs/supabase/discussions/22849)-# Debugging and Monitoring Postgres with Logs+# Debugging and monitoring Postgres with logsLogs provide insights into Postgres operations. They help meet compliance requirements, detect suspicious activity, and troubleshoot problems.-## Table of Contents+## Table of contents- Querying Logs- `postgres_logs` Table Structure@@ -33,7 +33,7 @@ Logs provide insights into Postgres operations. They help meet compliance requir- Frequently Asked Questions- Other resources-## Querying Logs+## Querying logsThe most practical way to explore and filter logs is through the [Logs Explorer](https://supabase.com/dashboard/project/_/logs/explorer).@@ -47,7 +47,7 @@ Although there are many strategies to filter logs, such as `like` and `in` stateThe `postgres_logs` table contains Postgres events.-### `postgres_logs` Table Structure+### `postgres_logs` table structureThe table contains 3 fundamental columns:@@ -73,9 +73,9 @@ cross join unnest(metadata) AS metadatacross join unnest(parsed) AS parsed;```-### Parsed Metadata Fields+### Parsed metadata fields-#### Query Information+#### Query information| Field | Description | Example || --------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------- |@@ -88,7 +88,7 @@ cross join unnest(parsed) AS parsed;- Identifying slow queries- Identifying failing queries-#### Error/Warning Information+#### Error/Warning information| Field | Description | Example || --------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------- |@@ -103,7 +103,7 @@ cross join unnest(parsed) AS parsed;- Filter by error severity or sql code- Get hints, details, and context about error events-#### Connection/Identification Information+#### Connection/Identification information| Field | Description | Example || ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |@@ -124,9 +124,9 @@ cross join unnest(parsed) AS parsed;- Filter connections by sessions for debugging- identify extension events-## Filtering Logs+## Filtering logs-### Excluding Routine Events+### Excluding routine eventsMost Postgres logs during normal periods are routine events, such as connection authorizations and checkpoints. To see the default types of events that are logged, you can check this [guide](https://gist.github.com/TheOtherBrian1/991d32c2b00dbc75d29b80d4cdf41aa7).@@ -139,7 +139,7 @@ wherenot regexp_contains(event_message, '^cron|PgBouncer|checkpoint|connection received|authenticated|authorized';```-### By Timeframe+### By timeframeTo investigate issues around a specific period:@@ -150,7 +150,7 @@ wheretimestamp between '2024-05-06 04:44:00' and '2024-05-06 04:45:00'```-### By Error Severity+### By error severityThis filter finds all errors, fatals, and panics:@@ -169,7 +169,7 @@ whereFailure events include an sql_state_code that can be referenced in the [Postgres Docs](https://www.postgresql.org/docs/current/errcodes-appendix.html)-### By Query+### By query> NOTE: Unless pg_audit is configured, only failed queries are logged@@ -191,7 +191,7 @@ Queries can use complex syntax, so it is often helpful to isolate by referencedAll failed queries, including those from PostgREST, Auth, and external libraries (e.g., Prisma) are logged with helpful error messages for debugging.-#### Server/Role Mapping+#### Server/Role mappingAPI servers have assigned database roles for connecting to the database:@@ -217,7 +217,7 @@ where...```-## By Dashboard Queries+## By Dashboard queriesQueries from the Supabase Dashboard are executed under the postgres role and include the comment `-- source: dashboard`. To isolate or exclude Dashboard requests during debugging, you can filter by this comment.@@ -228,7 +228,7 @@ whereregexp_contains(parsed.query, '-- source: dashboard')```-## Full Example For Finding Errors+## Full example for finding errors```sqlselect@@ -255,9 +255,9 @@ order by timestamp desclimit 100;```-# Logging for Compliance and Security+# Logging for compliance and security-### Customized Object and Role Activity Logging+### Customized object and role activity logging> ⚠️ NOTE: This is specifically designated for those using the `postgres` role or [custom roles](https://supabase.com/docs/guides/database/postgres/roles) to interact with their database. Those utilizing the Database REST API should reference the [Database API Logging Guide](https://github.com/orgs/supabase/discussions/22849) instead.@@ -279,7 +279,7 @@ whereparsed.user_name = 'API_role'```-### Filtering By IP+### Filtering by IP> If you are connecting from a known, limited range of IP addresses, you should enable [network restrictions](https://supabase.com/docs/guides/platform/network-restrictions).@@ -306,7 +306,7 @@ order by ip_count desclimit 100;```-# Reviewing Log Settings+# Reviewing log settingsThe `pg_settings` table describes system and logging configurations.@@ -337,7 +337,7 @@ whereand name like '%log%';```-## Changing Log Settings+## Changing log settings> WARNING: lenient settings can lead to overlogging, impacting database performance while creating noise in the logs.diff --git a/apps/docs/content/troubleshooting/understanding-postgresql-explain-output-Un9dqX.mdx b/apps/docs/content/troubleshooting/understanding-postgresql-explain-output-Un9dqX.mdxindex d4a7046c797..102a13c34dd 100644--- a/apps/docs/content/troubleshooting/understanding-postgresql-explain-output-Un9dqX.mdx+++ b/apps/docs/content/troubleshooting/understanding-postgresql-explain-output-Un9dqX.mdx@@ -14,11 +14,11 @@ sdk = [ "explain" ]This guide is designed to help you understand how to use the PostgreSQL [EXPLAIN and EXPLAIN ANALYZE](https://www.postgresql.org/docs/current/sql-explain.html) commands to optimize and debug SQL queries. Understanding the output of these commands can help you improve the performance of your applications by optimizing database interactions.-### What is EXPLAIN?+### What is explain?The PostgreSQL EXPLAIN command shows the execution plan of a SQL query. This plan describes how the PostgreSQL database will execute the query, including how tables will be scanned—by using sequential scans, index scans, etc.—and how rows will be joined.-### How to Use EXPLAIN in Supabase+### How to use explain in Supabase**Using EXPLAIN through the SQL Editor**@@ -39,9 +39,9 @@ const { data, error } = await supabase.explain({analyze:true,verbose:true})```-### Detailed Breakdown of EXPLAIN Output Components+### Detailed breakdown of explain output components-### 1. Plan Type+### 1. Plan type**- Seq Scan:** A sequential scan that reads all rows from a table. This is often seen in the absence of indexes that can be used for the query.@@ -68,13 +68,13 @@ const { data, error } = await supabase**Filter: (user_id = 1):** This shows any filters applied post-scan. Filters are conditions that are checked after retrieving the rows. A high number of rows being filtered out could indicate a need for better indexing.-### 6. Execution Time+### 6. Execution time**Execution Time: 0.069 ms:** measures how long it took to actually execute the query, including retrieving the data, performing any sorts, joins, or other operations defined in the execution plan, and returning the final results. This time is measured in milliseconds.-### Detailed Components in EXPLAIN ANALYZE+### Detailed components in explain analyzeWhen running EXPLAIN ANALYZE, additional information is provided, including:@@ -109,7 +109,7 @@ To answer you, one is for the estimated cost and performance, and another for th**Identifying Bottlenecks**: If the actual time is significantly higher than expected, or if loops are more frequent than anticipated, these could be indicators of performance bottlenecks in the query.-### How to read a Complex EXPLAIN Output+### How to read a complex explain outputFirst, you have to understand that a PostgreSQL execution plan is a tree structure consisting of several nodes. The top node (the Aggregate above) is at the top, and lower nodes are indented and start with an arrow (->). Nodes with the same indentation are on the same level (for example, the two relations combined with a join).@@ -133,7 +133,7 @@ PostgreSQL executes a plan top down, that is, it starts with producing the firstOn top of that, you have to multiply the cost and the time with the number of “loops” to get the total time spent in a node.-### Common Nodes in PostgreSQL EXPLAIN Output+### Common nodes in PostgreSQL explain output| Node Type | Description || --------------------- | ---------------------------------------------------------------------------- |@@ -155,7 +155,7 @@ On top of that, you have to multiply the cost and the time with the number of| **Foreign Scan** | Fetches data from foreign data sources outside the local database. || **Function Scan** | Retrieves results from a set-returning function. |-### What to focus on in EXPLAIN ANALYZE output+### What to focus on in explain analyze output- Find the nodes where most of the execution time was spent.`Hash Join (cost=100.00..200.00 rows=1000 width=50) (actual time=50.012..150.023 rows=1000 loops=1)`@@ -176,7 +176,7 @@ Seq Scan on products (cost=0.00..100.00 rows=300 width=50) (actual time=50.000.Explanation:This sequential scan took 50 to 100 milliseconds and filtered out 2997 of 3000 rows, indicating that only a few rows met the condition. This scenario is ideal for an index on the price column to optimize the performance by reducing the need for a full table scan.-### Understanding the Significance of Milliseconds in Query Performance+### Understanding the significance of milliseconds in Query PerformanceDetermining whether 100 milliseconds for e.g is noteworthy in the context of identifying performance bottlenecks depends on various factors:@@ -190,12 +190,12 @@ For complex queries that involve multiple joins, subqueries, or aggregation funcSo, the acceptable performance threshold can vary by application. For real-time systems or high-frequency trading platforms, even a few milliseconds can be critical, whereas for batch processing or data warehousing, longer execution times might be acceptable.-### Tools to interpret EXPLAIN ANALYZE output+### Tools to interpret explain analyze outputSince reading a longer execution plan is quite cumbersome, you can use the website https://explain.depesz.com/ to better visualize the query. If you paste the execution plan in the text area and hit “Submit”, you will get output like this:-### Tips for Optimizing Queries+### Tips for optimizing queries- **Add Indexes:** Improve performance by adding indexes on columns that are frequently used in WHERE clauses or JOIN conditions.diff --git a/apps/docs/content/troubleshooting/understanding-postgresql-logging-levels-and-how-they-impact-your-project-KXiJRm.mdx b/apps/docs/content/troubleshooting/understanding-postgresql-logging-levels-and-how-they-impact-your-project-KXiJRm.mdxindex d746fa541ef..7dcb8b6c64c 100644--- a/apps/docs/content/troubleshooting/understanding-postgresql-logging-levels-and-how-they-impact-your-project-KXiJRm.mdx+++ b/apps/docs/content/troubleshooting/understanding-postgresql-logging-levels-and-how-they-impact-your-project-KXiJRm.mdx@@ -9,7 +9,7 @@ database_id = "10186830-8cce-4f10-8cb9-7cbf39310763"Since each Supabase project uses PostgreSQL as its underlying database engine, it’s common to adjust logging settings for various reasons—whether for debugging issues, monitoring database performance, or auditing actions. However, modifying logging levels improperly can lead to an excessive amount of log data being generated, which can quickly fill up your disk space and cause significant performance degradation or even system failure.-### 1. Overview of PostgreSQL Logging Levels+### 1. Overview of PostgreSQL logging levelsPostgreSQL provides multiple logging levels that allow you to control how much information gets logged. These include:@@ -39,7 +39,7 @@ PANIC: database system shutdown requestedThe default log level is set to **WARNING** through the log_min_messages setting, and we recommend keeping it that way.-### 2. How High Log Levels Can Affect Your Database+### 2. How high log levels can affect your databaseWhen users alter a high level of log settings, the database can start generating an overwhelming number of log entries. This can quickly escalate to issues such as:@@ -49,7 +49,7 @@ When users alter a high level of log settings, the database can start generating- Database Lockups: In extreme cases, if the disk is filled to capacity with logs, your database could lock up, leading to downtime or severe performance degradation.-### 3. Common Scenarios That Cause Log Overload+### 3. Common scenarios that cause log overloadHere are a few common scenarios where excessive logging can become a problem:@@ -59,7 +59,7 @@ Here are a few common scenarios where excessive logging can become a problem:- Frequent Write Operations: If your database processes a lot of write operations (such as inserts, updates, or deletes), even low-level logs (like NOTICE or INFO) can lead to significant log accumulation.-### 4. How to Manage PostgreSQL Log Levels Effectively+### 4. How to manage PostgreSQL log levels effectively**a. Choose the Right Log Level**For most users, setting PostgreSQL logs to WARNING or ERROR is sufficient for regular operations. Here’s a general guideline: