> ## Documentation Index
> Fetch the complete documentation index at: https://syteca.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure PostgreSQL for Maximum Performance

> Use pgTune to generate optimized PostgreSQL configuration settings for a Syteca deployment.

<Warning>
  **NOT AVAILABLE IN SAAS.**
</Warning>

To optimize PostgreSQL resource consumption for a Syteca deployment, generate tuned settings using the pgTune tool and apply them to the PostgreSQL server.

<Steps>
  <Step title="Open pgTune">
    Go to [pgtune.leopard.in.ua](https://pgtune.leopard.in.ua/).
  </Step>

  <Step title="Enter your hardware and database version">
    Fill in the form with the PostgreSQL server's hardware specifications and PostgreSQL version.

    <Tip>
      For **Number of Connections**, enter at least the total number of Syteca Clients installed. If you have fewer than 100 Clients, this field can be left empty — the default maximum of 100 connections is already sufficient.
    </Tip>
  </Step>

  <Step title="Generate the configuration">
    Click **Generate** and copy the resulting script.
  </Step>

  <Step title="Apply it to postgresql.conf">
    On the PostgreSQL server, open `postgresql.conf` (by default in `C:\Program Files\PostgreSQL\<version>\data`) and paste the script at the end of the file. Save.
  </Step>

  <Step title="Restart PostgreSQL">
    Restart the **postgresql** service to apply the changes.
  </Step>
</Steps>

## Why connection count matters

Application Server opens a new PostgreSQL connection whenever a Client comes online, and either opens another connection or reuses the existing one whenever that Client starts a new live session, depending on what the database decides. A Client that's online but not actively sending data may have its connection closed or kept open for future use. All manual requests made from the Management Tool (viewing the Audit log, generating reports, viewing sessions) share a single connection.

<Note>
  Terminal servers open one connection when the Client comes online, plus an additional connection for each user who logs in and starts a session — so terminal servers with many concurrent users need a correspondingly higher connection count.
</Note>

## Fix "53300: sorry, too many clients already"

<Warning>
  **NOT AVAILABLE IN SAAS.**
</Warning>

This error appears in the logs when PostgreSQL's maximum concurrent connection limit (100 by default) is reached. Application Server opens a new connection whenever a Client comes online, and either opens another or reuses the existing one whenever that Client starts a new session — terminal servers in particular open one connection per logged-in user, on top of the one opened when the terminal server's Client itself comes online.

<Steps>
  <Step title="Stop the Application Server">
    Stop the **EkranServer** service.
  </Step>

  <Step title="Open postgresql.conf">
    On the PostgreSQL server, open the data folder (by default `C:\Program Files\PostgreSQL\13\data`) and open `postgresql.conf`.
  </Step>

  <Step title="Increase max_connections">
    Replace the default `max_connections` value of `100` with a higher value, for example `1000`.
  </Step>

  <Step title="Save and restart PostgreSQL">
    Save the file, then restart the PostgreSQL service in Windows Services.
  </Step>

  <Step title="Restart the Application Server">
    Restart the **EkranServer** service.
  </Step>
</Steps>

### Check database and table size

```sql theme={"system"}
-- Size of the entire database, human-readable
SELECT pg_size_pretty( pg_database_size('ekranactivitydb') );

-- Size of a specific table, human-readable
SELECT pg_size_pretty( pg_total_relation_size('dbo."SESSIONS"') );
```

## Related

<CardGroup cols={2}>
  <Card title="Creating databases manually" icon="database" href="/docs/administration/database/creating-databases-manually">
    Manual PostgreSQL database and user setup.
  </Card>

  <Card title="Database requirements" icon="database" href="/docs/administration/requirements/database-requirements">
    Supported PostgreSQL versions and hardware sizing.
  </Card>

  <Card title="Database server errors" icon="alert-triangle" href="/docs/resources/troubleshooting/database-server-errors">
    Common database connectivity issues and fixes.
  </Card>
</CardGroup>
