|
| 1 | +--- |
| 2 | +meta: |
| 3 | + title: Solving maximum prepared statements size errors |
| 4 | + description: This page explains how to solve errors related to the maximum prepared statements size on Serverless SQL Databases |
| 5 | +content: |
| 6 | + h1: Solving maximum prepared statements size reached |
| 7 | + paragraph: This page explains how to solve errors related to the maximum prepared statements size on Serverless SQL Databases |
| 8 | +tags: database serverless-sql-database troubleshooting error prepared statement maximum size |
| 9 | +dates: |
| 10 | + validation: 2024-07-08 |
| 11 | + posted: 2024-07-08 |
| 12 | +--- |
| 13 | + |
| 14 | +## Failed to prepare statement |
| 15 | + |
| 16 | +### Problem |
| 17 | + |
| 18 | +The error message below appears when trying to create a new prepared statement: |
| 19 | + |
| 20 | +```sh |
| 21 | +FATAL: failed to prepare statement: adding the prepared statement would exceed the limit of 524288 bytes for client connection: maximum allowed size of prepared statements for connection reached (SQLSTATE 53400). |
| 22 | +``` |
| 23 | + |
| 24 | +### Cause |
| 25 | + |
| 26 | +The total size of [prepared statements](https://www.postgresql.org/docs/current/sql-prepare.html) on Serverless SQL Databases is limited to 524288 bytes (512 kibibytes) for a single client connection. This limit can be reached for two reasons: |
| 27 | + |
| 28 | +- You (or the PostgreSQL client you are using) created too many prepared statements in a single PostgreSQL connection. |
| 29 | + |
| 30 | +- You (or the PostgreSQL client you are using) created a single prepared statement that exceeds the maximum size. |
| 31 | + |
| 32 | +### Solution |
| 33 | + |
| 34 | +- If you (or the PostgreSQL client you are using) created too many prepared statements in a single PostgreSQL connection, reduce the number of prepared statements, or use the [deallocate](https://www.postgresql.org/docs/current/sql-deallocate.html) feature to remove prepared statements in an active session: |
| 35 | + |
| 36 | +1. Execute the command below to list the prepared statements in your current session: |
| 37 | + ```sh |
| 38 | + SELECT * FROM pg_prepared_statements; |
| 39 | + ``` |
| 40 | + |
| 41 | +2. Run the command below to remove the desired prepared statement: |
| 42 | + |
| 43 | + ```sh |
| 44 | + DEALLOCATE prepared_statement_name; |
| 45 | + ``` |
| 46 | + |
| 47 | +- If you (or the PostgreSQL client you are using) created a single prepared statement that exceeds the maximum size, remove the query causing the issue, or split it into multiple statements. |
| 48 | + |
| 49 | +<Message type="note"> |
| 50 | +This issue is usually caused by long single queries, exceeding thousands of characters, such as thousands of values in a single `INSERT` statement, or queries using [Large Objects](https://www.postgresql.org/docs/current/largeobjects.html). |
| 51 | +</Message> |
0 commit comments