---
title: Solving maximum prepared statements size errors
description: Fix maximum prepared statements reached error in Scaleway SQL databases.
tags: database serverless-sql-database troubleshooting error prepared statement maximum size
dates:
  validation: 2025-07-29
  posted: 2024-07-08
---

## Failed to prepare statement

### Problem

The error message below appears when trying to create a new prepared statement:

```bash
FATAL: failed to prepare statement: adding the prepared statement would exceed the limit of 1048576 bytes for client connection: maximum allowed size of prepared statements for connection reached (SQLSTATE 53400).
```

### Cause

The total size of [prepared statements](https://www.postgresql.org/docs/current/sql-prepare.html) on Serverless SQL Databases is limited to 1,048,576 bytes (1,024 kibibytes) for a single client connection. This limit can be reached for two reasons:

- You (or the PostgreSQL client you are using) created too many prepared statements in a single PostgreSQL connection.

- You (or the PostgreSQL client you are using) created a single prepared statement that exceeds the maximum size.

### Solution

- 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:

1. Execute the command below to list the prepared statements in your current session:
    ```bash
    SELECT * FROM pg_prepared_statements;
    ```

2. Run the command below to remove the desired prepared statement:

    ```bash
    DEALLOCATE prepared_statement_name;
    ```

- 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.

<Message type="note">
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).
</Message>

Refer to the official [PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-prepare.html) for more information on prepared statements.