Skip to content

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

migrate(docs): troubleshooting 10 (#30938)

Charis7b1c4e09ae7d
diff --git a/apps/docs/content/troubleshooting/42501--permission-denied-for-table-httprequestqueue-KnozmQ.mdx b/apps/docs/content/troubleshooting/42501--permission-denied-for-table-httprequestqueue-KnozmQ.mdx
new file mode 100644
index 00000000000..23d67e668d5
--- /dev/null
+++ b/apps/docs/content/troubleshooting/42501--permission-denied-for-table-httprequestqueue-KnozmQ.mdx
@@ -0,0 +1,17 @@
+---
+title = "42501 : permission denied for table http_request_queue"
+github_url = "https://github.com/orgs/supabase/discussions/21450"
+date_created = "2024-02-22T10:26:29+00:00"
+topics = ["database"]
+keywords = ["permission", "pg_net", "http_request_queue"]
+
+[[errors]]
+code = "42501"
+message = "permission denied for table http_request_queue"
+---
+
+If you're currently blocked by the above error, please run the following in your Supabase SQL editor:
+
+- Check `select * from net.http_request_queue` and make sure it's empty.
+- Try `drop extension pg_net; create extension pg_net schema extensions;`
+- If that doesn't work (e.g. because some objects depend on it), then please [contact support](https://supabase.com/support).
diff --git a/apps/docs/content/troubleshooting/all-about-supabase-egress-a_Sg_e.mdx b/apps/docs/content/troubleshooting/all-about-supabase-egress-a_Sg_e.mdx
new file mode 100644
index 00000000000..0c72ca48486
--- /dev/null
+++ b/apps/docs/content/troubleshooting/all-about-supabase-egress-a_Sg_e.mdx
@@ -0,0 +1,33 @@
+---
+title = "All about Supabase Egress"
+github_url = "https://github.com/orgs/supabase/discussions/26605"
+date_created = "2024-05-21T11:52:49+00:00"
+topics = ["platform", "database", "functions", "storage", "realtime", "auth", "supavisor"]
+keywords = ["egress", "bandwidth"]
+---
+
+**What is Egress?**
+
+Egress (also known as bandwidth) is any amount of network packets/bytes being streamed back to a connected client. Means, the data that is leaving the Supabase platform. Egress in Supabase includes any calls through PostgREST, to Storage, Realtime, Auth, Edge Functions, Database and Supavisor.
+
+You can read about Unified egress, included quota, and how to check the egress usage here: https://supabase.com/docs/guides/platform/org-based-billing#unified-egress. Additionally, the [project reports](https://supabase.com/dashboard/project/_/reports) have a few egress related stats. You can create a custom report to look into daily egress.
+
+- Example: Log Explorer -> Custom Reports -> Add/Remove charts -> Database API -> API Egress.
+
+**What is contributing to Egress?**
+
+While pointing out the exact cause for egress may not be straightforward, there are various steps you can take to determine the source of these issues:
+
+- Picking the "Top Paths" from the [log explorer](https://app.supabase.com/project/_/logs/explorer/templates) will help you identify heavily queried paths
+- By finding the most requested queries from Query performance report: https://app.supabase.com/project/_/reports/query-performance
+- Supavisor Egress is independent of client. There is no direct relation between a single query and Supavisor egress, it is harder to debug and identify. But you can make use of frequent queries from the link in above step that also displays average number of rows which will help to identify queries with a large number of rows returned. While this does not display Supavisor queries specifically, it will give an overview of queries with lots of rows that can help.
+- For Storage Egress, all outgoing traffic for storage-related requests to download/view your Storage items are considered as Storage egress. We have a "Storage Egress Requests" template in logs explorer that you can use to get the number of requests for each Storage object
+- If you pull 1mb of data out of the database using the Supavisor connection in your edge function, but only sends 100kb back to the user, you will have the Egress from the Supavisor to your Edge function plus from the edge function to your user
+
+**How can you decrease egress?**
+
+- Reduce the number of fields selected or entries when querying
+- Reduce the number of queries/calls by optimising client code or use caches to reduce the number of requests/queries being done: https://github.com/psteinroe/supabase-cache-helpers/
+- In case of update/insert queries, if you don’t need the entire row to be returned, configure your ORM/queries to not return the entire row
+- In case of running manual backups through Supavisor, remove unneeded tables and/or reduce the frequency
+- For Storage, if you start using the [smartCDN](https://supabase.com/docs/guides/storage/cdn/smart-cdn) Storage Egress usage can be managed. You can also use the [Supabase Image Transformations](https://supabase.com/docs/guides/storage/image-transformations) to optimize the images and reduce the egress.
diff --git a/apps/docs/content/troubleshooting/certain-operations-are-too-complex-to-perform-directly-using-the-client-libraries-8JaphH.mdx b/apps/docs/content/troubleshooting/certain-operations-are-too-complex-to-perform-directly-using-the-client-libraries-8JaphH.mdx
new file mode 100644
index 00000000000..2d08391e9af
--- /dev/null
+++ b/apps/docs/content/troubleshooting/certain-operations-are-too-complex-to-perform-directly-using-the-client-libraries-8JaphH.mdx
@@ -0,0 +1,55 @@
+---
+title = "Certain operations are too complex to perform directly using the client libraries."
+github_url = "https://github.com/orgs/supabase/discussions/21294"
+date_created = "2024-02-15T12:37:11+00:00"
+topics = ["database"]
+keywords = ["stored", "function", "complex"]
+---
+
+**Solution**
+In cases where operations are overly complex or not feasible to implement directly using the client libraries, it might be beneficial to leverage stored functions within your database.
+
+Follow these steps to create and run a stored function:
+
+**Create the Stored Function:**
+
+Go to the [SQL query editor](https://supabase.com/dashboard/project/_/sql/new) on your database dashboard.
+Run the following SQL script to create a stored function tailored to your specific complex query:
+
+```
+DROP FUNCTION IF EXISTS get_my_complex_query;
+CREATE FUNCTION get_my_complex_query(parameter INT)
+RETURNS TABLE (column1 INTEGER, column2 VARCHAR, column3 DATE) AS
+$$
+BEGIN
+ RETURN QUERY
+ SELECT t1.column1, t1.column2, t2.column3
+ FROM "TableName1" AS t1
+ INNER JOIN "TableName2" AS t2 ON t1.column = t2.column
+ INNER JOIN "TableName3" AS t3 ON t2.another_column = t3.another_column
+ LEFT JOIN "TableName4" AS t4 ON t3.some_column = t4.some_column
+ WHERE t2.column = parameter
+ AND t3.column_name = 'some_value';
+END;
+$$
+LANGUAGE plpgsql VOLATILE;
+```
+
+**Call the Stored Function:**
+
+Use the supabase.rpc method to call the stored function from your application code. Replace "get_my_complex_query" with the appropriate function name and provide the necessary parameters:
+
+```
+supabase.rpc("get_my_complex_query", { parameter: 1 })
+ .then(response => {
+ // Handle the response
+ })
+ .catch(error => {
+ // Handle errors
+ });
+```
+
+**Further Resources:**
+
+For more information on PostgreSQL database functions, refer to the following resource:
+[Supabase Stored Procedures](https://supabase.com/docs/guides/database/functions#quick-demo)
diff --git a/apps/docs/content/troubleshooting/fixing-520-errors-in-the-database-rest-api-Ur5-B2.mdx b/apps/docs/content/troubleshooting/fixing-520-errors-in-the-database-rest-api-Ur5-B2.mdx
new file mode 100644
index 00000000000..150b964ec0a
--- /dev/null
+++ b/apps/docs/content/troubleshooting/fixing-520-errors-in-the-database-rest-api-Ur5-B2.mdx
@@ -0,0 +1,56 @@
+---
+title = "Fixing 520 Errors in the Database REST API"
+github_url = "https://github.com/orgs/supabase/discussions/23422"
+date_created = "2024-04-29T16:56:27+00:00"
+topics = ["database"]
+keywords = ["520", "cloudflare", "url", "headers", "rpcs"]
+
+[[errors]]
+http_status_code = 520
+message = "Web server returns an unknown error due to request exceeding 16KB in headers/URL."
+---
+
+In the context of the database API, [Cloudflare 520 errors](https://developers.cloudflare.com/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-5xx-errors/#error-520-web-server-returns-an-unknown-error) most often occur when 16+KB worth of data is present in the headers/URL of your requests.
+
+The API will include filters within the URL, so a request like so:
+
+```javascript
+let { data: countries, error } = await supabase.from('countries').select('name')
+```
+
+translates to a URL like:
+
+```bash
+https://<project ref>.supabase.co/rest/v1/countries?select=name
+```
+
+However, appending too much data to the URL can exceed the 16KB limitation, triggering a 520 failure. This typically occurs with lengthy `in` clauses, as demonstrated here:
+
+```javascript
+const { data, error } = await supabase
+ .from('countries')
+ .select()
+ .not('id', 'in', '(5,6,7,8,9,...10,000)')
+```
+
+To circumvent this issue, you must use [RPCs](https://supabase.com/docs/reference/javascript/explain?queryGroups=example&example=call-a-postgres-function-with-arguments). They are database functions that you can call from the API. Instead of including a query's structure within the URL or header, they move it into the request's payload.
+
+Here is a basic example of a [database function](https://supabase.com/docs/guides/database/functions)
+
+```sql
+create or replace function example(id uuid[])
+returns uuid[]
+language plpgsql
+as $$
+begin
+ raise log 'the function example was called with an array size of: %', (select array_length(id, 1));
+ return id;
+end;
+$$;
+```
+
+The [RPC](https://supabase.com/docs/reference/javascript/explain?queryGroups=example&example=call-a-postgres-function-with-arguments) can then call the function with an array that contains more than 16KB of data
+
+```javascript
+const { data, error } = await supabase.rpc('example', { id: ['e2f34fb9-bbf9-4649-9b2f-09ec56e67a42', ...900 more UUIDs] })
+```