# FATAL error: sorry, too many clients already
# Symptoms

Periodically, the error `[object Object]` appears in the interface

In the Network tab, some requests fail with error 500 Internal error has occurred

In the postgres container logs, the error is `FATAL:  sorry, too many clients already`

# Solution

Increase the number of connections for postgres

1. In the docker-compose.yml configuration file, in the postgres section, edit the value of the N parameter:

```yaml
  postgres:
    image: postgres:14.2-bullseye
    container_name: swarmica-postgres
    shm_size: 4gb
    command: postgres -N 300 -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c wal_keep_size=512MB -c work_mem=8MB -c temp_buffers=16MB -c shared_buffers=4GB -c track_activity_query_size=16384
    restart: always
    volumes:
      - swarmica_postgres_data:/var/lib/postgresql/data:Z
      - swarmica_postgres_data_backups:/backups:z
      - ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
    env_file:
      - .env
    ports:
      - "5432:5432"
```

:::tip
**Important** The number N * work_mem should not exceed the size of shared_buffers! Also, it is important to consider the amount of free memory on the server. If `free -lmt` shows that more than 20% of memory is used in Swap, this means that the server does not have enough memory and before increasing the number of connections, you need to add RAM
:::

2. Restart the application `docker compose down && docker compose up -d`

# Cause

The allowed number of connections to the database has been exceeded. This can happen if the server has a heavy load in terms of the number of simultaneous users.