Files
supabase/apps/docs/content/guides/api/rest/postgrest-error-codes.mdx
Miranda LimonczenkoandClaude Sonnet 5 81523d5d8c fix(docs): fix heading-order skips in guide and troubleshooting content (#48459)
Closes DOCS-1260

_See WAVE plugin no longer flags a jump in header hierarchy. Preview on
left._
<img width="708" height="699" alt="Screenshot 2026-07-29 at 2 30 11 PM"
src="https://github.com/user-attachments/assets/be5bf335-9e03-474f-8215-06fa505ab2db"
/>


## Problem

Beyond the 4 shared components fixed in
[#48456](https://github.com/supabase/supabase/pull/48456), the [header
hierarchy
report](https://app.notion.com/p/supabase/Playwright-E2E-Triage-Reports-3ab5004b775f81e3bc60d058fa5a02c1)
found plain content headings that skip a level. For example, you may see
a `##` followed directly by an `####`.

Jumps in headers breaks page navigation for screen reader users, who
jump between headings expecting each level to nest one at a time.

## Solution

Adjusted heading levels across the affected guide and troubleshooting
pages so every section nests correctly, with no skipped levels.

**Staging previews:**

| Page | Preview |
| --- | --- |
| `/guides/api/rest/postgrest-error-codes` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/api/rest/postgrest-error-codes)
|
| `/guides/auth/oauth-server/getting-started` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/auth/oauth-server/getting-started)
|
| `/guides/database/custom-postgres-config` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/database/custom-postgres-config)
|
| `/guides/database/drizzle` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/database/drizzle)
|
| `/guides/database/extensions` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/database/extensions)
|
| `/guides/database/extensions/pgaudit` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/database/extensions/pgaudit)
|
| `/guides/database/postgres-js` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/database/postgres-js)
|
| `/guides/database/replication/manual-replication-monitoring` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/database/replication/manual-replication-monitoring)
|
| `/guides/database/replication/manual-replication-setup` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/database/replication/manual-replication-setup)
|
| `/guides/database/replication/pipelines-monitoring` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/database/replication/pipelines-monitoring)
|
| `/guides/functions/debugging-tools` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/functions/debugging-tools)
|
| `/guides/functions/development-tips` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/functions/development-tips)
|
| `/guides/functions/examples/auth-send-email-hook-react-email-resend` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/functions/examples/auth-send-email-hook-react-email-resend)
|
| `/guides/functions/examples/image-manipulation` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/functions/examples/image-manipulation)
|
| `/guides/functions/examples/semantic-search` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/functions/examples/semantic-search)
|
| `/guides/functions/examples/send-emails` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/functions/examples/send-emails)
|
| `/guides/functions/examples/sentry-monitoring` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/functions/examples/sentry-monitoring)
|
| `/guides/functions/wasm` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/functions/wasm)
|
| `/guides/getting-started` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/getting-started)
|
| `/guides/platform/aws-marketplace` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/platform/aws-marketplace)
|
| `/guides/platform/aws-marketplace/faq` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/platform/aws-marketplace/faq)
|
| `/guides/platform/billing-faq` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/platform/billing-faq)
|
| `/guides/platform/ipv4-address` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/platform/ipv4-address)
|
| `/guides/platform/migrating-within-supabase/backup-restore` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/platform/migrating-within-supabase/backup-restore)
|
| `/guides/platform/privatelink` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/platform/privatelink)
|
| `/guides/queues/api` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/queues/api)
|
| `/guides/resources` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/resources)
|
| `/guides/security/hipaa-compliance` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/security/hipaa-compliance)
|
| `/guides/security/security-testing` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/security/security-testing)
|
| `/guides/security/soc-2-compliance` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/security/soc-2-compliance)
|
| `/guides/self-hosting` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/self-hosting)
|
| `/guides/storage/cdn/fundamentals` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/storage/cdn/fundamentals)
|
| `/guides/storage/debugging/logs` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/storage/debugging/logs)
|
| `/guides/storage/production/scaling` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/storage/production/scaling)
|
| `/guides/storage/schema/helper-functions` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/storage/schema/helper-functions)
|
| `/guides/storage/serving/image-transformations` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/storage/serving/image-transformations)
|
| `/guides/storage/uploads/resumable-uploads` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/storage/uploads/resumable-uploads)
|
|
`/guides/troubleshooting/an-invalid-response-was-received-from-the-upstream-server-error-when-querying-auth-RI4Vl-`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/an-invalid-response-was-received-from-the-upstream-server-error-when-querying-auth-RI4Vl-)
|
|
`/guides/troubleshooting/are-all-features-available-in-self-hosted-supabase-THPcqw`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/are-all-features-available-in-self-hosted-supabase-THPcqw)
|
|
`/guides/troubleshooting/avoiding-timeouts-in-long-running-queries-6nmbdN`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/avoiding-timeouts-in-long-running-queries-6nmbdN)
|
| `/guides/troubleshooting/database-api-42501-errors` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/database-api-42501-errors)
|
| `/guides/troubleshooting/disabling-prepared-statements-qL8lEL` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/disabling-prepared-statements-qL8lEL)
|
|
`/guides/troubleshooting/discovering-and-interpreting-api-errors-in-the-logs-7xREI9`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/discovering-and-interpreting-api-errors-in-the-logs-7xREI9)
|
| `/guides/troubleshooting/edge-function-504-error-response` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/edge-function-504-error-response)
|
|
`/guides/troubleshooting/high-cpu-and-slow-queries-with-error-must-be-a-superuser-to-terminate-superuser-process`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/high-cpu-and-slow-queries-with-error-must-be-a-superuser-to-terminate-superuser-process)
|
|
`/guides/troubleshooting/how-postgres-chooses-which-index-to-use-_JHrf4`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/how-postgres-chooses-which-index-to-use-_JHrf4)
|
|
`/guides/troubleshooting/how-to-change-max-database-connections-_BQ8P5`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/how-to-change-max-database-connections-_BQ8P5)
|
|
`/guides/troubleshooting/how-to-interpret-and-explore-the-postgres-logs-OuCIOj`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/how-to-interpret-and-explore-the-postgres-logs-OuCIOj)
|
|
`/guides/troubleshooting/how-to-migrate-from-supabase-auth-helpers-to-ssr-package-5NRunM`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/how-to-migrate-from-supabase-auth-helpers-to-ssr-package-5NRunM)
|
| `/guides/troubleshooting/http-api-issues` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/http-api-issues)
|
|
`/guides/troubleshooting/increase-vector-lookup-speeds-by-applying-an-hsnw-index-ohLHUM`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/increase-vector-lookup-speeds-by-applying-an-hsnw-index-ohLHUM)
|
|
`/guides/troubleshooting/interpreting-supabase-grafana-cpu-charts-9JSlkC`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/interpreting-supabase-grafana-cpu-charts-9JSlkC)
|
|
`/guides/troubleshooting/interpreting-supabase-grafana-io-charts-MUynDR`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/interpreting-supabase-grafana-io-charts-MUynDR)
|
| `/guides/troubleshooting/new-branch-doesnt-copy-database` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/new-branch-doesnt-copy-database)
|
|
`/guides/troubleshooting/not-receiving-auth-emails-from-the-supabase-project-OFSNzw`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/not-receiving-auth-emails-from-the-supabase-project-OFSNzw)
|
|
`/guides/troubleshooting/resolving-500-status-authentication-errors-7bU5U8`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/resolving-500-status-authentication-errors-7bU5U8)
|
|
`/guides/troubleshooting/resolving-cannot-execute-update-in-a-read-only-transaction-on-transaction-pooler-connections-ef582c`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/resolving-cannot-execute-update-in-a-read-only-transaction-on-transaction-pooler-connections-ef582c)
|
|
`/guides/troubleshooting/resolving-database-hostname-and-managing-your-ip-address-pVlwE0`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/resolving-database-hostname-and-managing-your-ip-address-pVlwE0)
|
| `/guides/troubleshooting/rls-simplified-BJTcS8` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/rls-simplified-BJTcS8)
|
| `/guides/troubleshooting/security-of-anonymous-sign-ins-iOrGCL` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/security-of-anonymous-sign-ins-iOrGCL)
|
|
`/guides/troubleshooting/supabase--your-network-ipv4-and-ipv6-compatibility-cHe3BP`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/supabase--your-network-ipv4-and-ipv6-compatibility-cHe3BP)
|
| `/guides/troubleshooting/supabase-grafana-memory-charts` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/supabase-grafana-memory-charts)
|
| `/guides/troubleshooting/supavisor-faq-YyP5tI` |
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/supavisor-faq-YyP5tI)
|
|
`/guides/troubleshooting/tracking-postgres-role-activity-to-specific-dashboard-users-8d3715`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/tracking-postgres-role-activity-to-specific-dashboard-users-8d3715)
|
|
`/guides/troubleshooting/transferring-from-cloud-to-self-host-in-supabase-2oWNvW`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/transferring-from-cloud-to-self-host-in-supabase-2oWNvW)
|
|
`/guides/troubleshooting/understanding-postgresql-explain-output-Un9dqX`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/understanding-postgresql-explain-output-Un9dqX)
|
|
`/guides/troubleshooting/understanding-postgresql-logging-levels-and-how-they-impact-your-project-KXiJRm`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/understanding-postgresql-logging-levels-and-how-they-impact-your-project-KXiJRm)
|
|
`/guides/troubleshooting/vercel-integration-environment-variables-not-syncing-for-persistent-git-branches-b9191e`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/vercel-integration-environment-variables-not-syncing-for-persistent-git-branches-b9191e)
|
|
`/guides/troubleshooting/why-are-there-gaps-in-my-postgres-id-sequence-Frifus`
|
[Preview](https://docs-git-docs-heading-hierarchy-supabase.vercel.app/docs/guides/troubleshooting/why-are-there-gaps-in-my-postgres-id-sequence-Frifus)
|

## Manual testing

1. See affected pages. Recommend running a browser plugin like WAVE and
selecting the **Structure** tab.
2. See the headings do not skip.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

* **Documentation**
* Standardized heading hierarchy across many guides and troubleshooting
articles to improve readability and navigation.
* Updated several documentation link targets to the correct new
locations.
* Reformatted multiple sections (including replication monitoring, Edge
Functions, Storage, authentication, security, and networking) without
changing instructions.
* Queue Data API docs were restructured via heading-level adjustments
(no operational changes).
* Billing FAQ received clearer, more detailed payment-failure and tax
guidance, plus related link updates.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-31 10:47:14 -07:00

277 lines
16 KiB
Plaintext

---
id: 'postgrest-error-codes'
title: 'Error Codes'
description: 'PostgREST Error Codes'
subtitle: 'Identify PostgREST errors and resolve them'
sidebar_label: 'Debugging'
---
<Admonition type="note">
The docs reflect the error codes and information in [PostgREST's official
docs](https://docs.postgrest.org/en/stable/).
</Admonition>
## PostgREST error codes
Error codes from the Data API are returned as JSON objects
```json
{
"code": "42703",
"details": null,
"hint": "Perhaps you meant to reference the column some_table.fake_col",
"message": "column some_table.fake_col does not exist"
}
```
Here is the full list of error codes and their descriptions:
## Database level errors
To understand the errors reference the [Postgres Error Docs](https://www.postgresql.org/docs/current/errcodes-appendix.html).
Here's the text formatted as a proper markdown table:
| Postgres error code(s) | HTTP status | Error description |
| ---------------------- | ------------------------------ | ------------------------------- |
| 08\* | 503 | connection error |
| 09\* | 500 | triggered action exception |
| 0L\* | 403 | invalid grantor |
| 0P\* | 403 | invalid role specification |
| 23503 | 409 | foreign key violation |
| 23505 | 409 | uniqueness violation |
| 25006 | 405 | read only SQL transaction |
| 25\* | 500 | invalid transaction state |
| 28\* | 403 | invalid auth specification |
| 2D\* | 500 | invalid transaction termination |
| 38\* | 500 | external routine exception |
| 39\* | 500 | external routine invocation |
| 3B\* | 500 | savepoint exception |
| 40\* | 500 | transaction rollback |
| 53400 | 500 | config limit exceeded |
| 53\* | 503 | insufficient resources |
| 54\* | 500 | too complex |
| 55\* | 500 | obj not in prerequisite state |
| 57\* | 500 | operator intervention |
| 58\* | 500 | system error |
| F0\* | 500 | config file error |
| HV\* | 500 | foreign data wrapper error |
| P0001 | 400 | default code for "raise" |
| P0\* | 500 | PL/pgSQL error |
| XX\* | 500 | internal error |
| 42883 | 404 | undefined function |
| 42P01 | 404 | undefined table |
| 42P17 | 500 | infinite recursion |
| 42501 | if authenticated 403, else 401 | insufficient privileges |
| other | 400 | |
## API level errors
### Connection errors
Errors that prevent that data API from interacting with Postgres.
| Code | HTTP status | Description |
| -------- | ----------- | --------------------------------------------------------------------------------------------------------------------- |
| PGRST000 | 503 | Could not connect with the database due to an incorrect connection string or due to the Postgres service not running. |
| PGRST001 | 503 | Could not connect with the database due to an internal error. |
| PGRST002 | 503 | Could not connect with the database when building the schema cache |
| PGRST003 | 504 | The request timed out waiting for a connection from PostgREST's internal pool |
### API requests
Errors with data structures or request formatting
| Code | HTTP status | Description |
| -------- | ----------- | --------------------------------------------------------------------------------------------------------------------------- |
| PGRST100 | 400 | Parsing error in the query string parameter. |
| PGRST101 | 405 | For database functions, only `GET` and `POST` verbs are allowed. Any other verb will throw this error. |
| PGRST102 | 400 | An invalid request body was sent(e.g. an empty body or malformed JSON). |
| PGRST103 | 416 | An invalid range was specified for limits. |
| PGRST105 | 405 | An invalid `UPDATE`/`UPSERT` request was done |
| PGRST106 | 406 | The schema specified when switching schemas is not exposed to the API. |
| PGRST107 | 415 | The `Content-Type` sent in the request is invalid. |
| PGRST108 | 400 | The filter is applied to an embedded resource that is not specified in the `select` part of the query string. |
| PGRST111 | 500 | An invalid `response.headers` was set. |
| PGRST112 | 500 | The status code must be a positive integer. |
| PGRST114 | 400 | For an `UPSERT` using `PUT` when limits and offsets are used. |
| PGRST115 | 400 | For an `UPSERT` using `PUT` when the primary key in the query string and the body are different. |
| PGRST116 | 406 | More than 1 or no items where returned when requesting a singular response. |
| PGRST117 | 405 | The HTTP verb used in the request in not supported. |
| PGRST118 | 400 | Could not order the result using the related table because there is no many-to-one or one-to-one relationship between them. |
| PGRST120 | 400 | An embedded resource can only be filtered using the `is.null` or `not.is.null` operators. |
| PGRST121 | 500 | API can't parse the JSON objects in RAISE `PGRST` error. |
| PGRST122 | 400 | Invalid preferences found in `Prefer` header with `Prefer: handling=strict`. |
| PGRST123 | 400 | Aggregate functions are disabled. |
| PGRST124 | 400 | `max-affected` preference is violated. |
| PGRST125 | 404 | Invalid path is specified in request URL. |
| PGRST126 | 404 | Open API config is disabled but API root path is accessed. |
| PGRST127 | 400 | The feature specified in the `details` field is not implemented. |
| PGRST128 | 400 | `max-affected` preference is violated with `RPC` call. |
### Schema cache errors
The API is unable to identify relationships or objects within the query requests.
| Code | HTTP status | Description |
| -------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PGRST200 | 400 | Caused by stale foreign key relationships, otherwise any of the embedding resources or the relationship itself may not exist in the database. |
| PGRST201 | 300 | An ambiguous embedding request was made. |
| PGRST202 | 404 | Caused by a stale function signature, otherwise the function may not exist in the database. |
| PGRST203 | 300 | Caused by requesting overloaded functions with the same argument names but different types, or by using a `POST` verb to request overloaded functions with a `JSON` or `JSONB` type unnamed parameter. The solution is to rename the function or add/modify the names of the arguments. |
| PGRST204 | 400 | Caused when the column specified in the columns query parameter is not found. |
| PGRST205 | 404 | Caused when the table specified in the URI is not found. |
### Authentication errors
The request lacks the proper credentials to request data
| Code | HTTP status | Description |
| -------- | ----------- | ------------------------------------------------------------------------------------------------ |
| PGRST300 | 500 | PostgREST does not have an active JWT secret to validate requests |
| PGRST301 | 401 | Provided JWT couldn't be decoded or it is invalid. |
| PGRST302 | 401 | Attempted to do a request without the header `Auth: Bearer` when the anonymous role is disabled. |
| PGRST303 | 401 | JWT claims validation or parsing failed. |
### Internal errors
Data API error unspecified
| Code | HTTP status | Description |
| -------- | ----------- | --------------------------------------------------------------------------- |
| PGRSTX00 | 500 | Internal errors related to the library used for connecting to the database. |
## Viewing errors in the logs
One can filter for API errors in the [log explorer](/dashboard/project/_/logs/explorer). Below are useful queries for filtering and analyzing API errors:
### Find all API errors that occurred at the database level
```sql
select
cast(postgres_logs.timestamp as datetime) as timestamp,
event_message,
parsed.error_severity,
parsed.user_name,
parsed.query,
parsed.detail,
parsed.hint,
parsed.sql_state_code,
parsed.backend_type
from
postgres_logs
cross join unnest(metadata) as metadata
cross join unnest(metadata.parsed) as parsed
where
regexp_contains(parsed.error_severity, 'ERROR|FATAL|PANIC')
and parsed.user_name = 'authenticator' -- the authenticator role represents the database API
order by timestamp desc
limit 100;
```
### Find specific database error from the data API
```sql
select
cast(postgres_logs.timestamp as datetime) as timestamp,
event_message,
parsed.error_severity,
parsed.user_name,
parsed.query,
parsed.detail,
parsed.hint,
parsed.sql_state_code,
parsed.backend_type
from
postgres_logs
cross join unnest(metadata) as metadata
cross join unnest(metadata.parsed) as parsed
where parsed.sql_state_code like '42501' and parsed.user_name = 'authenticator' -- the authenticator role represents the database API
order by timestamp desc
limit 100;
```
<Admonition type="note">
PostgREST error codes are only captured in the logs for projects running V14+. You can check your PostgREST version and upgrade your project in the [Infrastructure Settings](/dashboard/project/_/settings/infrastructure)
</Admonition>
### Find specific API error
```sql
select
cast(timestamp as datetime) as timestamp,
status_code,
event_message,
coalesce(proxy_status, 'not_recorded') as error_codes,
path
from
edge_logs
cross join unnest(metadata) as metadata
cross join unnest(response) as response
cross join unnest(request) as request
where
status_code >= 300
and regexp_contains(path, '^/rest/v1/')
and regexp_contains(proxy_status, '(?i)THE_RELEVANT_STATUS_CODE');
```
### Count errors per path by hour:
```sql
select
format_timestamp(
"%c",
timestamp_trunc(cast(edge_logs.timestamp as timestamp), hour),
"UTC"
) as hour,
count(proxy_status) as error_count,
path,
coalesce(proxy_status, 'not_recorded') as error_codes
from
edge_logs
cross join unnest(metadata) as metadata
cross join unnest(response) as response
cross join unnest(response.headers) as headers
cross join unnest(request) as request
where status_code >= 300 and regexp_contains(path, '^/rest/v1/')
group by hour, proxy_status, path;
```
### Find data API request from specific authenticated user
```sql
select
cast(timestamp as datetime) as timestamp,
event_message,
cf_connecting_ip as requesters_ip,
url as request_url,
request.method as request_method,
sb.auth_user as user_id,
apikey_payload.role as apikey_role,
authorization_payload.role as authorization_token_role,
user_agent,
city,
country,
continent,
postalCode
from
edge_logs
cross join unnest(metadata) as metadata
cross join unnest(request) as request
cross join unnest(sb) as sb
cross join unnest(jwt) as jwt
cross join unnest(jwt.apikey) as jwt_apikey
cross join unnest(jwt_apikey.payload) as apikey_payload
cross join unnest(authorization) as authorization_key
cross join unnest(authorization_key.payload) as authorization_payload
cross join unnest(headers) as headers
cross join unnest(cf) as cf
cross join unnest(response) as response
where regexp_contains(path, '^/rest/v1/') and sb.auth_user = 'SOME_USER_ID' -- <---ADD USER_ID from auth.users table
order by timestamp desc;
```