# Tuning: your database's settings

> See the settings that matter, tune them for your server in one click, and undo any change.

Source: https://rowsafe.sh/docs/guides/tuning

A fresh PostgreSQL uses settings for a tiny machine: 128 MB of cache, whatever your server has. **Tuning** explains the settings that matter and sets them for your server when you click.

Open a database, then **Tuning**. This page shows PostgreSQL; see [MySQL and MariaDB](#mysql-and-mariadb), [MongoDB and ClickHouse](#mongodb-and-clickhouse) and [Redis and Valkey](#redis-and-valkey) for differences.

## What you see

- **Your server:** memory, CPUs, disk type (SSD or spinning).
- **The settings that matter**, by group: what each does, its value and default, where it's set, and whether it needs a restart.
- **Other settings** from configuration files.
- **Changes made through Rowsafe**, with **Undo**.

Refreshed every 5 minutes.

## Tune for this server

**Tune for this server** lists each recommended change with the current value, the new one, and why. Click **Apply**, check the list, and confirm.

Rowsafe saves a [Mark](https://rowsafe.sh/docs/concepts/restore-points) (on a backed-up database).

The agent rechecks each value, sets it with `ALTER SYSTEM`, and reloads. Apps keep working.

Start-only settings (like `shared_buffers`) wait for a restart. **Nothing restarts now.** Click **Restart PostgreSQL now** when it suits you (where [restarts are allowed](https://rowsafe.sh/docs/guides/adopt)), or wait for the next restart.

**More options** sets the workload (**Web app**, **Analytics** or **Mixed**, the default) and the disk type: cloud disks often say "spinning" on SSDs.

**How the recommendations are computed**

The formulas follow [PGTune](https://pgtune.leopard.in.ua), for a server that runs mostly PostgreSQL:

| Setting                                        | Recommendation                                                                                                                                                  |
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `shared_buffers`                               | 25% of memory (at least 128 MB)                                                                                                                                 |
| `effective_cache_size`                         | 75% of memory                                                                                                                                                   |
| `maintenance_work_mem`                         | memory / 16 (analytics: / 8), between 64 MB and 2 GB                                                                                                            |
| `work_mem`                                     | (memory − `shared_buffers`) / ((`max_connections` + `max_worker_processes`) × 3) / parallel workers per query, halved for mixed and analytics; never below 4 MB |
| `max_wal_size`, `min_wal_size`                 | 4 GB and 1 GB (analytics: 16 GB and 4 GB), at most a tenth of the data disk; only ever raised                                                                   |
| `checkpoint_completion_target`                 | 0.9                                                                                                                                                             |
| `random_page_cost`, `effective_io_concurrency` | 1.1 and 200 on an SSD                                                                                                                                           |
| `default_statistics_target`                    | 500 for analytics                                                                                                                                               |
| Parallel workers (4 or more CPUs)              | one worker per CPU; per query half the CPUs (at most 4 for web and mixed); only where still at PostgreSQL's default                                             |
| Automatic cleanup                              | scale factors 0.05 (vacuum) and 0.02 (analyze) once the databases pass 10 GB                                                                                    |
| `idle_in_transaction_session_timeout`          | 10 minutes for web and mixed. Optional: it ends sessions an app forgot, and the app gets an error                                                               |
| `shared_preload_libraries`                     | adds `pg_stat_statements` when it is installed, so [Top queries](https://rowsafe.sh/docs/guides/monitoring) works                                                                 |

Values already close are left alone: within 5% at the default, or 75% to 175% when set on purpose (400% for `work_mem`). No memory or SSD reading means no memory or disk recommendations.

## Change one setting

Click the pencil next to a setting, enter a value (like `512MB` or `30s`), and click **Change it**. **Reset to default** removes Rowsafe's value. Same safety: a Mark, the checks below, undo.

## Undo

**Undo** (in the success message, or under **Changes made through Rowsafe**) restores the previous values. Restart-only settings go back at the next restart. You can undo a setting's latest change, once.

## What Rowsafe refuses

Rowsafe changes nothing when a change:

- touches what Rowsafe relies on: backups (`archive_mode`, `archive_command`, `archive_timeout`, `archive_library`), restores and standbys (`restore_command`, `recovery_target*`, `primary_conninfo`, `primary_slot_name`), or the agent's connection (`port`, `unix_socket_directories`);
- could stop PostgreSQL from starting: `shared_buffers` above 60% of memory, a missing `shared_preload_libraries` library, `huge_pages = on` where it isn't already, `max_connections` not above the admin-reserved ones, `wal_level = minimal`;
- lets a few queries eat memory: `work_mem` above a quarter of memory, `maintenance_work_mem` above half;
- is a restart-only setting Rowsafe can't check (like `listen_addresses`);
- is overridden on the command line (for example `-c` in Docker);
- comes while the config already has an error that would stop the next start, or on a standby.

If PostgreSQL rejects a value or reports a config error after the reload, the agent puts the old values back.

## Pulse

| Finding                                                                    | Fix                                                                                             |
| -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| PostgreSQL is using default memory settings on a server with 4 GB or more  | **Tune for this server**                                                                        |
| Query statistics are off: `pg_stat_statements` is installed but not loaded | **Turn on query statistics** (takes effect after a restart; Rowsafe also creates the extension) |
| Changed settings are waiting for a restart                                 | **Restart PostgreSQL**                                                                          |

## From a terminal

```sh
rowsafe settings app                      # the settings that matter, by group
rowsafe settings app shared_buffers       # one setting, explained
rowsafe tune app --workload web           # the recommendations; asks before applying
rowsafe settings set app work_mem=64MB    # change one (VALUE "default" resets it)
rowsafe settings undo app                 # undo the latest change
rowsafe restart app                       # apply restart-only settings
```

See the [CLI reference](https://rowsafe.sh/docs/reference/cli#settings-and-tuning). AI agents read settings with `database_settings` ([MCP](https://rowsafe.sh/docs/reference/mcp)) and apply recommendations [as the person who connected them](https://rowsafe.sh/docs/guides/agent-autonomy), an owner or admin (a Mark first).

## MySQL and MariaDB

Same page: buffer pool, redo log, connections, temporary tables, disk speed, timeouts, slow query log. **Tune for this server** gives the buffer pool about 70% of memory (8 GB or more), a bigger redo log and SSD-sized disk speed. A Mark first; undo works.

- **MySQL** keeps changes with `SET PERSIST`; start-only settings use `SET PERSIST_ONLY`.
- **MariaDB** keeps them in `/etc/rowsafe/mysql/server.cnf` and applies them live (`SET GLOBAL`). In Docker, set them in the container's command instead.
- Rowsafe never touches the binary log settings restores need, and never makes commits wait less for the disk (`innodb_flush_log_at_trx_commit`, `sync_binlog`).
- Start-only settings wait for a **Restart** you choose (where root allowed restarts).

## MongoDB and ClickHouse

Their settings files belong to root. Where root allowed it (`sudo rowsafe-allow tuning`, or yes at install), root's copy of the agent writes your changes, from a fixed list of plain values, into Rowsafe's own file only. A Mark first; undo restores the old file.

- **ClickHouse:** memory per query and per server, spilling big GROUP BY and ORDER BY to disk, concurrent queries and connections, threads, merges, the longest query. In `config.d/rowsafe-tuning.xml` and `users.d/rowsafe-tuning.xml`; picked up within seconds, except a few that say they need a restart.
- **MongoDB:** WiredTiger cache, connections, longest transaction, slow operation threshold, profiler. Written to its YAML config (a copy is kept). Cache, transaction limit and slow threshold also apply live; the rest at restart.

Restarts are yours (**Restart**, where root allowed it). In Docker, set these in the container's configuration.

## Redis and Valkey

Every setting applies live (`CONFIG SET`), no restart. Changes made together all apply or none do.

- **Memory:** `maxmemory`, `maxmemory-policy`, `activedefrag`.
- **Persistence:** `save`, `appendonly`, `appendfsync`. The replication backlog and `min-replicas-to-write` are locked (Rowsafe's link needs them).
- **Connections:** max connections, idle `timeout`, `tcp-keepalive`.
- **Slow log and latency:** threshold, length, latency monitor, per-command latency.

Passwords, port, address and data folder aren't shown; Rowsafe never reads passwords.

**Tune for this server** asks: **Cache**, **Store or queue** (no key may be lost), or **Not sure** (almost all keys expiring means cache). It proposes:

- **A memory limit** if none: about 75% of memory, shared equally with other databases Rowsafe protects there. The rest leaves room for snapshots. Nothing if the data already needs more.
- **Eviction:** `allkeys-lru` for a cache on `noeviction`; `noeviction` for a store or queue that evicts (writes are refused rather than keys lost).
- **Snapshots** for a store with nothing on disk, so a restart doesn't empty it. Never persistence off, never the append-only file: your backups keep every change.
- **Keepalives** if off, the latency monitor at 100 ms, the slow log at 10 ms if off.

Refused: a memory limit above 90% of memory, below current use, or under 64 MB; an idle timeout under 10 seconds; a slow log of every command; fewer than 32 connections.

**Surviving a restart** (the page tells you first):

- Where root allowed Tuning, root's agent also writes it to `redis.conf` or `valkey.conf`, replacing only those lines (a copy is kept; undo restores them).
- Otherwise the server saves it with `CONFIG REWRITE`, if it may write its config.
- Without a config file (common in Docker), the change lasts until restart. Put it in the container's command or a config file.

A Mark first, except on a server Rowsafe can't follow. A replica's settings are changed on its primary.

## Limits

- Changes are server-wide (`ALTER SYSTEM`, `postgresql.auto.conf`). `ALTER DATABASE` and `ALTER ROLE` settings override them and aren't shown.
- PostgreSQL in Docker: memory and CPUs are the host's, the disk type is unknown (set it under **More options**), and Rowsafe can't restart the container.
- Recommendations assume PostgreSQL is the main thing on the server. If your app shares it, keep memory lower.
- A standby follows its primary: change settings there.
