Skip to content

Database Health & Maintenance

Nzyme writes to its PostgreSQL database constantly. Every tap report updates sessions and assets, every purge deletes millions of rows, and the free space that this leaves behind is only reclaimed if the database is vacuumed and its indexes are rebuilt from time to time. PostgreSQL does some of this on its own, but its defaults are tuned for small databases with little write load, and they are not enough for Nzyme.

Nzyme therefore maintains its own tables itself: it sets autovacuum thresholds per table, vacuums tables that have accumulated too many dead rows, rebuilds indexes that consist mostly of empty space, and watches the server for signs of trouble. Everything that it cannot change itself, because it requires the PostgreSQL administrator, is shown with the exact configuration lines to apply.

You can find the maintenance pages under System -> Database in your Nzyme web interface. The Health & Maintenance tab shows the state of the database and the maintenance activity, and the Settings tab holds the configuration. Both are available to super administrators only.

Requirements

Nzyme requires PostgreSQL 14 or newer and recommends PostgreSQL 15 or newer. A node refuses to start against an older server. Releases older than 15 are at or past the end of their upstream support, and a node logs a warning at startup and lists the version in the Server Configuration section if it runs against one.

All maintenance runs with the privileges of the Nzyme database user on the tables that Nzyme created. It does not need superuser rights and does not change the configuration of the PostgreSQL server.

The Health & Maintenance Page

The strip at the top of the page summarizes the state of the database: the number of database health indicators that are red or orange, the PostgreSQL version and database size, the cache hit ratio, the highest share of dead rows of any large table, the highest estimated bloat of any index that is large enough for an automatic rebuild together with the number of overdue rebuilds, and whether a maintenance action is running right now.

Health Indicators

Six indicators of the system health console are about the database. They are repeated on this page, and like every other indicator they generate system events that you can subscribe to.

Indicator Orange when Red when
DB Config A required server setting is below the Nzyme requirements. Autovacuum is disabled on the server.
DB Vacuum A table of at least 100 MB has 20% or more dead rows. A table of at least 100 MB has 50% or more dead rows.
DB Bloat An index that qualifies for an automatic rebuild was not rebuilt in a full maintenance window. Such an index is estimated to be 85% or more empty space.
DB Performance The cache hit ratio is below 90%, or temporary files exceed 100 MB per minute, or at least half of at least three recent checkpoints were forced, or queries waited 30 seconds or more per minute for disk. The cache hit ratio is below 70%.
DB Transactions A transaction has been open for an hour or longer, or the transaction ID age exceeds 1,000,000,000. A transaction has been open for six hours or longer, or the transaction ID age exceeds 1,500,000,000.
DB Clock The clock of the database server deviates from the clock of the node.

Every node evaluates the indicators once a minute from its own statistics snapshot. The indicators are unavailable until a node has taken its first snapshot, which happens within a minute of startup. The DB Performance indicator additionally needs five minutes of samples and is not evaluated during the first 15 minutes after a PostgreSQL restart, because the cache is empty and the hit ratio is meaningless until it has warmed up. Indicators go back to green within two minutes after the problem is resolved, the performance indicator within 15 minutes.

The DB Bloat indicator does not react to an index that crosses the rebuild threshold during the day, because the next maintenance window takes care of it. It turns on when a complete window has opened and closed since the index crossed the threshold and the index still qualifies for a rebuild. This is the case if the window is too short for the number of rebuilds, if a rebuild failed, if no node was running during the window, or if automatic rebuilds are disabled. An index that is being rebuilt right now does not count, and neither does an index whose last rebuild did not shrink it.

Each indicator has a resolution procedure on the health console under System -> Health.

Maintenance Activity

This section shows the maintenance action that is running right now, the actions that are queued behind it, the maintenance window in UTC and in the time zone of your browser, and whether each of the three automatic maintenance features is enabled. Nzyme runs one maintenance action at a time across the whole cluster.

Server

The server section is a snapshot of PostgreSQL itself, taken by the node that served the page. Rates and ratios cover the last 15 minutes. After a node start, the window grows from one to 15 minutes and the values are marked as collecting until five minutes of samples exist.

Value Meaning
PostgreSQL The server version and when the server was last started.
Size The total size of the database, split into table data and indexes.
Connections Open connections and the max_connections limit of the server. Every node opens up to its configured connection pool size.
Cache hit ratio The share of page reads that were served from shared_buffers instead of disk. It should stay above 95%. A low ratio means the server reads from disk for most queries, which is the most common reason for a slow Nzyme installation.
Temporary files Data that sorts and hash operations wrote to disk because they did not fit into work_mem. A constantly high volume slows down queries and wears out the disk.
Forced checkpoints The share of checkpoints that were forced by write-ahead log volume instead of running on the timer. A high share means that max_wal_size is too small for the write load.
Disk wait How long all connections together waited for disk reads and writes per minute. Only measured if track_io_timing is enabled on the server. High read wait while the cache hit ratio is good points at slow storage.
Updates staying on the same page The share of row updates that did not have to touch an index. Nzyme keeps free space on the pages of frequently updated tables so that this share stays high.
Deadlocks Deadlocks per minute. They should not occur.
Transaction ID age How far the server is from transaction ID wraparound. Vacuum resets this value. PostgreSQL stops accepting writes when the maximum of 2,147,483,647 is reached.
Oldest open transaction How long the oldest transaction on the server has been open. A long open transaction prevents vacuum from reclaiming any space that was freed after it started.

The trends chart shows any of the server and table values of the last 24 hours in one minute buckets, averaged across all nodes. The values are recorded as node metrics with names that start with database_. Use the chart to see whether a value is a spike or a trend before you change a server setting, and to confirm that a change had the intended effect.

Server Configuration

Nzyme reads the settings of the PostgreSQL server once a minute and compares them with its requirements. Settings that need attention are listed with their current and recommended value. Settings that live in postgresql.conf are summarized in two blocks, one with required and one with recommended changes, that you can paste into the file. Most of these parameters already exist in postgresql.conf and should be changed in place. Run SHOW config_file; in psql if you do not know where the file is.

If PostgreSQL runs on the same host as the Nzyme node, the recommended memory sizes are computed from the memory of that host. Otherwise, the recommendation is given as a share of the memory of the database server.

Setting Recommended Severity Set in Notes
server_version PostgreSQL 15 or newer Required Server Nzyme requires at least 14.
autovacuum on Required postgresql.conf Reclaims the space of updated and deleted rows and keeps planner statistics current.
shared_buffers A quarter of the memory of the server, at least 1GB Required postgresql.conf Memory for caching table and index pages. Requires a PostgreSQL restart.
maintenance_work_mem 512MB to 1GB Required postgresql.conf Memory for a single vacuum or index build. Too low a value makes vacuum scan the indexes of large tables several times per run.
autovacuum_vacuum_cost_delay 1ms or less, or autovacuum_vacuum_cost_limit of 1000 or more Required postgresql.conf Throttling of autovacuum. The defaults pause it every few pages. Nzyme requires it to run at nearly full speed.
autovacuum_max_workers 4 to 6 Required postgresql.conf Number of tables autovacuum cleans at the same time. Requires a PostgreSQL restart.
max_wal_size 4GB to 8GB Required postgresql.conf Write-ahead log volume that forces a checkpoint. Too low a value causes constant checkpoints under Nzyme write load.
effective_cache_size Three quarters of the memory of the server Recommended postgresql.conf Planner estimate of the data cached by the operating system. Does not allocate memory. Too low a value makes the planner avoid indexes.
checkpoint_timeout 15min Recommended postgresql.conf Maximum time between two checkpoints. Longer intervals reduce repeated writes of hot pages and increase crash recovery time.
random_page_cost 1.1 on SSD storage Recommended postgresql.conf Planner cost of a random disk read relative to a sequential read. The default of 4 describes spinning disks and should be kept on them.
track_io_timing on Recommended postgresql.conf Measures time spent waiting for disk. Required for the disk wait value and the disk wait condition of the DB Performance indicator.
max_connections Larger than the sum of the connection pool sizes of all nodes, plus 20 Recommended postgresql.conf Informational. Nzyme does not flag this setting.
work_mem 64MB on Nzyme connections Recommended Nzyme connection Memory for a single sort or hash operation before it spills to temporary files. Set by Nzyme on its own connections, see Configuration.
jit off on Nzyme connections Recommended Nzyme connection Just-in-time compilation slows down the short queries Nzyme runs. Disabled by Nzyme on its own connections.
table storage parameters managed by Nzyme Recommended Nzyme table Autovacuum thresholds and page fill factors per table class.

The DB Config indicator is orange while a required setting is below its requirement, and red if autovacuum is disabled. A setting whose new value is already in postgresql.conf but not applied yet is shown as waiting for a PostgreSQL restart.

Warning

The postgresql.conf defaults of shared_buffers, max_wal_size and the autovacuum throttling are far too low for Nzyme. Expect every fresh PostgreSQL installation to list required changes. Apply them before you connect taps, because a server that runs with the defaults for weeks accumulates bloated indexes that take a long time to rebuild.

Tables

The tables section lists the tables of the Nzyme database with their table class, data and index size, live and dead rows, time of the last vacuum, and write counters since the server statistics were last reset. By default, only the twelve largest tables of at least 10 MB are shown.

Dead rows are outdated row versions that remain after updates and deletes until vacuum removes them. They occupy space and slow down queries that have to skip them. A warning next to the index size means that at least one index of the table is above the automatic reindex threshold. The warning is red if the rebuild of such an index is overdue.

The Vacuum button runs VACUUM (ANALYZE) on the table right away, the Reindex button rebuilds all of its indexes. Both are queued as maintenance actions and run in the background without blocking reads or writes.

Indexes

The indexes section lists all indexes of at least 1 MB with their size, estimated bloat, number of scans since the statistics were reset, and type. By default, the 25 largest indexes are shown.

Indexes do not release space on their own. After many updates and deletes, an index can consist mostly of empty pages that still have to be read by every query. The bloat column estimates this empty space from the planner statistics of the table. It is an estimate, and it is unknown for tables that have never been analyzed. Indexes that qualify for an automatic rebuild are highlighted. An index that still qualifies after a complete maintenance window is marked as overdue, and it is what turns the DB Bloat indicator on.

An index that is marked as invalid was left behind by a rebuild that failed or was interrupted. PostgreSQL still maintains it on every write but never uses it. Nzyme drops invalid indexes before the next rebuild of the same table.

Indexes with zero scans since the statistics were reset are not used by any query. They are candidates for removal in a future release of Nzyme, and you do not have to do anything about them.

The Rebuild button rebuilds a single index with REINDEX INDEX CONCURRENTLY. Reads and writes continue while the rebuild runs, but the server needs free disk space for a second copy of the index until the rebuild is complete.

Maintenance Log

The maintenance log lists every maintenance action of the last 90 days with its start, duration, the node that ran it, what triggered it and the result. Vacuum and index rebuilds record the size of the table or index before and after the action in the details.

Action What it does
Vacuum VACUUM (ANALYZE) of a table.
Rebuild index REINDEX INDEX CONCURRENTLY of a single index.
Rebuild all indexes REINDEX TABLE CONCURRENTLY of a table.
Table storage parameters Applies the autovacuum thresholds and fill factors of the table classes to all tables.
Database usage row counts Counts the rows of all tables for the database usage pages.

The trigger column shows whether the action was started automatically, requested by a user, or run at node startup.

How Nzyme Maintains the Database

Every minute, one node of the cluster takes a statistics snapshot and decides whether a maintenance action is needed. Actions are queued in the cluster task queue, and one node at a time executes them under a database lock, so two nodes never maintain the same table at the same time. If an action is already running or queued, no new action is queued until it has completed. Nothing Nzyme does blocks reads or writes of the database.

Table Storage Parameters

PostgreSQL autovacuum decides per table when to vacuum, based on the share of dead rows. Its default of 20% is fine for small tables, but on a table with a hundred million sessions it means that twenty million dead rows accumulate before anything happens. Nzyme assigns every table to one of three table classes and sets autovacuum thresholds and the page fill factor per class. The parameters are applied at node startup and whenever the class settings change, and the maintenance log records which tables were changed. New tables that appear with an upgrade are covered automatically.

The fill factor controls how much of every page is left free when rows are inserted. Free space on the page lets PostgreSQL update a row without moving it to another page, which means that the update does not have to touch any index of the table. This matters for session and asset tables that are updated with every tap report.

If you disable Manage table storage parameters in the settings, all tables are reset to the PostgreSQL defaults.

Automatic Vacuum

If autovacuum falls behind, for example after a large purge, Nzyme vacuums the table itself. A table is vacuumed when it is at least 50 MB in size, more than 20% of its rows are dead, autovacuum has not touched it for 30 minutes, and Nzyme has not vacuumed it in the last hour. Vacuum runs at any time of day, because it never blocks anything, and VACUUM (ANALYZE) also refreshes the planner statistics of the table.

Automatic Index Rebuilds

Vacuum reclaims space inside an index but never shrinks it, so an index that was bloated once stays large until it is rebuilt. Nzyme rebuilds indexes with REINDEX INDEX CONCURRENTLY inside the daily maintenance window. An index is rebuilt when it is at least as large as the configured minimum size, its estimated bloat is at least the configured threshold, and it has not been rebuilt in the last 24 hours. One index is rebuilt at a time, and the next candidate is picked a minute after the previous rebuild has completed, so a window of a few hours is enough to work through the indexes of a large installation over several days.

A rebuild that does not shrink the index by at least 10% means that the bloat estimate is wrong for that index. Nzyme leaves such an index alone for seven days before it tries again.

The rebuild needs free disk space for a second copy of the index while it runs. If it fails or the node is stopped during the rebuild, PostgreSQL leaves an invalid copy behind that is dropped before the next rebuild of the table.

Session Settings

Nzyme sets work_mem and disables just-in-time compilation on every connection it opens. These are settings that PostgreSQL allows every client to change for itself. work_mem is the memory a single sort or hash operation may use before it spills to a temporary file. The default of 4 MB is too small for the queries behind the Nzyme web interface, and the temporary file volume in the server section shows whether the configured value is sufficient. Changes to the session settings take effect after a node restart.

Multiple Nodes

All nodes of a cluster see the same database, but each node takes its own statistics snapshot and evaluates the health indicators from it. The server section names the node that took the snapshot you are looking at. The trends chart averages the values of all nodes. Maintenance actions and the row counts of the usage pages run on one node for the whole cluster, and the maintenance log shows which node it was.

A long index rebuild occupies the task worker of the node that runs it. Other cluster tasks of that node wait until the rebuild is complete.

Configuration

The Settings tab under System -> Database holds the maintenance configuration. Changes take effect immediately unless noted otherwise.

Setting Default Description
Manage table storage parameters on Set autovacuum thresholds and page fill factors per table class. Turning this off resets all tables to the PostgreSQL defaults.
Vacuum tables with too many dead rows on Run automatic vacuum.
Rebuild bloated indexes in the maintenance window on Run automatic index rebuilds.
Rebuild indexes estimated to be more than this percent empty 60 Bloat threshold for automatic rebuilds. Between 20 and 95.
Only rebuild indexes of at least this size (MB) 100 Minimum index size for automatic rebuilds. Between 1 and 1000000.
Apply session settings to Nzyme connections on Set work_mem and disable JIT on every connection. Takes effect after a node restart.
work_mem of Nzyme connections (MB) 64 Memory a single sort or hash operation may use before it spills to disk. Between 4 and 4096. Takes effect after a node restart.

Maintenance Window

Automatic index rebuilds run only inside the maintenance window. The window is configured as a start hour and a length in full hours, in UTC, and applies to the whole cluster. The default window is 02:00 to 06:00 UTC. The settings page shows the same window in the time zone of your browser. Vacuum and manually requested actions do not wait for the window.

Setting Default Description
Window start (Hour, UTC) 2 Hour of the day the window opens. 0 to 23.
Window length (Hours) 4 How long the window stays open. 1 to 24.

Table Classes

Every table of the Nzyme database belongs to one of three classes. Each class has its own autovacuum thresholds and page fill factor, which you can change per class on the settings page. The percentages are relative to the row count of each table.

Class Tables Vacuum at dead rows Minimum dead rows Analyze at changed rows Fill factor
Session and ledger tables Layer 4 sessions, TLS sessions, VPN tunnels, SSH sessions, DHCP transactions, asset attributes, asset activity and other tables that are inserted once and then updated with every tap report. 1% 1000 2% 85%
Time series tables DNS log, ARP packets, WiFi observations, timeline events, metrics and other tables that are inserted, never updated, and deleted in bulk when they age out. 5% 1000 2% 100%
Small, constantly updated tables Nodes, taps, assets, health indicators, registry and other small tables whose rows are rewritten many times per minute. 5% 50 10% 50%

Session and ledger tables are vacuumed early and without throttling, because every update leaves a dead row behind, and they keep 15% of every page free so that updates can stay on the same page. Time series tables are filled completely because nothing is ever updated in place, and frequent analyze keeps the planner statistics fresh for time range queries. Small, constantly updated tables keep half of every page free and are vacuumed after a few dozen changes because that is cheap.

Working With the Page

Open the page after every installation and after every PostgreSQL upgrade, and apply the required block from the server configuration section. Most installations need it.

Check the indicators once a week. A green row means that the automatic maintenance is keeping up. An orange DB Vacuum indicator that clears on its own within a day is normal after a large purge. One that stays means that autovacuum is throttled. An orange DB Bloat indicator means that the maintenance window is too short for the amount of index bloat or that rebuilds are failing. Check the maintenance log and extend the window before you rebuild indexes by hand.

A cache hit ratio below 95% with a good disk wait means that shared_buffers is too small for the working set. Raise it, or reduce the retention times so that the working set fits. Growing temporary file volume calls for a larger work_mem on Nzyme connections. Frequent forced checkpoints call for a larger max_wal_size.

An open transaction of several hours is almost always a psql session or a reporting tool that somebody left open. It stops vacuum from reclaiming anything, so close it.