chore: convert tailnet tables to UNLOGGED for improved write performance (#21607)

This migration converts all tailnet coordination tables to UNLOGGED:
- `tailnet_coordinators`
- `tailnet_peers`
- `tailnet_tunnels`

UNLOGGED tables skip Write-Ahead Log (WAL) writes, significantly
improving performance for high-frequency updates like coordinator
heartbeats and peer state changes.

The trade-off is that UNLOGGED tables are truncated on crash recovery
and are not replicated to standby servers. This is acceptable for these
tables because the data is ephemeral:
1. Coordinators re-register on startup
2. Peers re-establish connections on reconnect
3. Tunnels are re-created based on current peer state

**Migration notes:**
- Child tables must be converted before the parent table because LOGGED
child tables cannot reference UNLOGGED parent tables (but the reverse is
allowed)
- The down migration reverses the order: parent first, then children

Fixes https://github.com/coder/coder/issues/21333
This commit is contained in:
Spike Curtis
2026-01-28 07:12:32 +04:00
committed by GitHub
parent 2204731ddb
commit f358a6db11
3 changed files with 33 additions and 3 deletions
+3 -3
View File
@@ -1762,14 +1762,14 @@ CREATE TABLE site_configs (
value text NOT NULL
);
CREATE TABLE tailnet_coordinators (
CREATE UNLOGGED TABLE tailnet_coordinators (
id uuid NOT NULL,
heartbeat_at timestamp with time zone NOT NULL
);
COMMENT ON TABLE tailnet_coordinators IS 'We keep this separate from replicas in case we need to break the coordinator out into its own service';
CREATE TABLE tailnet_peers (
CREATE UNLOGGED TABLE tailnet_peers (
id uuid NOT NULL,
coordinator_id uuid NOT NULL,
updated_at timestamp with time zone NOT NULL,
@@ -1777,7 +1777,7 @@ CREATE TABLE tailnet_peers (
status tailnet_status DEFAULT 'ok'::tailnet_status NOT NULL
);
CREATE TABLE tailnet_tunnels (
CREATE UNLOGGED TABLE tailnet_tunnels (
coordinator_id uuid NOT NULL,
src_id uuid NOT NULL,
dst_id uuid NOT NULL,