Skip to content
Rather not run it yourself? OpenRMM Cloud hosts it for you.

Database Schema

PostgreSQL. Immutable migrations under internal/store/migrations/ are embedded in the server and applied on startup. db/schema.sql is the canonical snapshot of the current schema for review/manual use; it is not replayed as the migration mechanism.

schema_migrations records a contiguous version/name/SHA-256 checksum history. Current versions run from 1 baseline to 19 oidc_browser_handoff. Startup accepts only an exact prefix of the binary’s history and rejects gaps, unknown versions, renames, or changed SQL. The migration transaction uses a PostgreSQL advisory lock. Migrations are forward-only: once a newer version is applied, an older binary can reject it, so rollback requires restoring the pre-upgrade database as well as the application. rmm-server -migrate-only applies them with the owner’s credentials and exits, so the serving role need not own the schema (see 01-architecture).

Managed endpoints.

Column Type Notes
id uuid PK agent identity
hostname, os, arch, version text reported at enrollment
description text operator-editable label, shown in the device list (e.g. the user’s name)
note text operator-editable private observation, shown only in device detail
status text online / offline / revoked
token_hash text SHA-256 of the agent’s auth token
pending_token_hash, token_rotation_id text one in-flight replacement credential; promotion occurs on reconnect
token_rotation_canceling boolean durable cancellation fence; prevents replacement-token promotion until restoration is confirmed
revoked_at timestamptz nullable; blocks control, jobs, and relay tickets when set
site_id uuid FK → sites nullable; the agent’s place in the org hierarchy
group_id uuid FK → device_groups nullable
tags text[] free-form labels
mesh_id text MeshCentral node id (nullable)
last_seen timestamptz heartbeat
created_at timestamptz
device_public_key text pinned ECDSA P-256 identity key for E2E native remote sessions (migration 042; empty only on pre-0.13 agents before upgrade)
device_key_issue, pending_device_public_key text active key review state ('' / changed / missing / outdated / duplicate) and the last conflicting key presented (migration 043)
device_key_issue_since, device_key_issue_seen_at, device_key_issue_ip, device_key_issue_version, device_key_issue_count timestamptz / text / int timing, source address, agent version and observation count for the active key review (migration 043)
device_key_changed_at, device_key_changed_by timestamptz / text last administrator-approved key change, shown by browsers that remembered the previous key (migration 043)

Departments: a group bound to a site (id, name, site_id FK → sites cascade, created_at). Company > Site > Department — a group never spans companies/sites; optional. An agent’s group_id must point at a department of the agent’s own site.

Enrollment tokens: one computer, or up to 10,000 for a mass deployment, for at most 90 days. token holds the hex SHA-256 of the token (migration 023 hashed the ones issued before); uses_left counts down from uses_total; created_by is the actor; revoked_at/revoked_by mark a revoked token, whose uses_left is 0. agents.enroll_token_id is the token that admitted each device.

site_id and the optional group_id decide where an enrolling agent lands. A trigger (enroll_token_group_matches_site) rejects an inconsistent pair, so a token can never name a department belonging to a different site than the one it enrols into. The installer’s --site flag does not decide this — it is accepted and discarded; the destination comes from the token row.

Console accounts. password_hash (bcrypt), role (role key such as admin/tech/readonly or a custom role), totp_secret (encrypted, nullable), totp_pending_secret (encrypted candidate, nullable), and totp_enabled for optional TOTP 2FA. Setup/rotation writes the pending candidate; confirmation atomically promotes it, so an active factor is not weakened mid-rotation.

email is the user’s address: where their alerts are delivered, and where a password reset link is sent. Because a reset resolves an account through it, it is an authentication factor rather than a contact detail — unique when set, and only users.email.manage may change it.

disabled_at (nullable) withdraws access without deleting the account, so the record of what it did survives. Nil means active. Every path that grants access filters on it in SQL rather than trusting a caller to check: password login, session lookup, API tokens bound to that user, alert delivery, and the password-reset lookup — that last one otherwise being a way straight back in. A timestamp rather than a boolean because “when was access withdrawn” is what an incident review asks, and re-disabling keeps the original value.

meshcentral_user is the MeshCentral account this user’s remote sessions sign in as when the server mints MeshCentral login tokens; empty means none (08-remote-access). Only a principal with access to every device and settings.manage sets it.

email_verified_at (nullable) records when the owner confirmed the address; the operator’s shared alert service delivers only to confirmed addresses, and a changed address needs a new confirmation. totp_last_step is the last accepted TOTP time step (unix time / 30), so a code is accepted once. oidc_issuer and oidc_subject link the account to a single sign-on identity (empty when not linked); while SSO is on, a linked account has no password path.

Role definitions and their permission keys. roles.role_key is the stable key stored in users.role and api_tokens.role; system=true marks the built-in readonly, tech, and admin roles. role_permissions is keyed by (role_key, permission) and stores granular module permissions such as devices.view, devices.remote, jobs.create, jobs.manage, roles.manage. The built-in readonly preset includes devices.remote; its name does not mean pure observation.

One-time 2FA recovery codes (id, user_id, code_hash SHA-256, used_at nullable). Issued when 2FA is enabled, single-use; cleared on disable/admin-reset.

Per-user access scope. Each row grants a user access to a Company (client), a Site, a Department (group), or a specific device; a user with no rows is unrestricted. Enforced on read + write paths and on the AI/MCP surface.

Column Type Notes
id uuid PK
user_id uuid FK → users cascade delete
scope_type text client / site / group / agent
scope_id uuid id of the client/site/group/agent
unique on (user_id, scope_type, scope_id)

scope_id is polymorphic, so no foreign key can cover it. Triggers on clients, sites, device_groups and agents stand in for one (migration 006): a scope row dies with its target. Triggers rather than cleanup in the delete handlers, because deleting a company cascades to its sites and departments and a cascade never reaches application code.

Without them a deleted device left a row behind, and a dangling row is not inert: the scope editor counted it but could not draw it, and since the console sends back the scopes it loaded, every save for that account failed validation on an entry the operator could neither see nor remove.

An account left with no rows at all by that pruning is disabled, not promoted: an empty set means unrestricted, so deleting the last thing a restricted technician could see would otherwise hand them the whole fleet. Deliberately granting full access (replacing the set with an empty one) is unaffected — the rule lives only in the pruning path.

Hashed API tokens for the UI/integrations (token_hash, name, role key, nullable user_id). The role key resolves to the same permission set as a user role. When bound to a user, the token inherits that user’s access scope. The bootstrap RMM_ADMIN_TOKEN is also accepted without a row and uses the built-in admin permission set.

Units of work targeted at an agent.

Column Type Notes
id uuid PK
agent_id uuid FK → agents cascade delete
type text run_script, or device_query (a built-in read-only query; script holds the request as JSON)
description text human summary
shell text bash/sh/powershell/cmd/python
script text source to run
status text awaiting_approval→pending→sent→running→completed/failed, or rejected
requires_approval bool true for AI proposals
created_by text actor (admin, api, ai:<actor>, mcp:<actor>)
approved_by text nullable. A user id, or for an autonomous job its basis: autonomy: <permission> or pre-approved by <admin> (hash …). Reads add the usernames behind created_by and approved_by (created_by_name, approved_by_name; not stored)
task_id uuid set when the job was produced by a scheduled task (nullable)
batch_id uuid bulk deployment: jobs created together share it; one batch per company (nullable)
exit_code int nullable until finished
stdout, stderr text result output
created_at, updated_at timestamptz
autonomy text '', query or preapproved: why it ran without approval at the time (23)
script_id uuid FK → scripts the library script a parameterised or released run came from; ON DELETE SET NULL
params jsonb the declared parameters it carried, sent to the agent as environment variables
variables jsonb the script variable names it may receive, snapshotted when the job is created (migration 029), so a later script edit does not change an approved job
secret_redactions text ciphertext of the secret values actually sent, used only to mask the result; never returned by the API

Latest snapshot per agent (agent_id PK, data jsonb, collected_at).

Brokered remote-access sessions (id, agent_id, provider, status, token, connect_url, created_by, expires_at). Native/files/terminal sessions additionally store independent viewer_ticket_hash and agent_ticket_hash values plus single-use timestamps, and e2e (migration 042, whether the session uses end-to-end encryption); raw tickets are returned only at session creation and are never persisted.

One-time guest invitations to a device’s screen (migration 020, docs/08-remote-access.md): agent_id, created_by (the inviting user), mode (view or control), token_hash and code_hash (the link and the code are shown once and never stored), guest_secret_hash (the guest’s credential, bound to the request once the code is accepted), status (open, pending, accepted, rejected, revoked, ended), failed_attempts, the guest’s name, IP and user agent, and expires_at with the request, decision and end times. A share past expires_at is expired whatever its status says; the guest’s own sessions are ordinary remote_sessions rows whose created_by is guest:<share id>. Migration 021 adds reusable (the guest may come back with the same link and code while the share is live) and redeem_count (how many times the code was accepted). Migration 042 adds guest_public_key, guest_sign_key, wrapped_chat_key and chat_key_id for sealed E2E group chat.

Record of sensitive actions (actor, action, target, detail jsonb, created_at). Actions include job.propose, job.approve, job.reject, job.result, remote.start; every action the server records has a console label.

Append-only in three layers (migration 012_audit_append_only):

  1. Triggers refuse UPDATE and DELETE, except retention’s removal of the machine-written entries (job.automated, job.result).
  2. Privileges: run the server as a role that does not own the table (openrmm_app, with migrations applied separately by the owner) and a compromised server cannot disable the triggers or erase the trail. The server says at every start which of these is in force.
  3. Hash chain: each human entry stores prev_hash and entry_hash, so a rewrite by someone with full database access is detectable (SELECT * FROM verify_audit_chain() reports the first break). Machine-written entries are not chained, because retention deletes them.

The API pages it by an opaque cursor (/api/audit, next_cursor) because an offset drifts while entries arrive at the top. See 07-guardrails-security for setting up the restricted role.

Conversations with the AI. chat_sessions.created_by owns the session (private to its creator). chat_messages stores role, content, tool_calls (jsonb), tool_call_id, name — mirroring the OpenAI-compatible schema so history can be replayed to the model verbatim.

The org hierarchy. clients (id, name, created_at) is a customer/organization; sites (id, client_id FK → clients, name, created_at) is a location under a client. An agent’s site_id places it in this tree; deleting a client cascades to its sites, and a deleted site nulls the agents’/enroll-tokens’ site_id.

Reusable script library: id, name, description, category, shell (bash/sh/powershell/cmd/python), body, default_args, created_at, updated_at. Run on a device via /run-script, which creates a job. params (jsonb) declares its parameters. ai_released_by, ai_released_at and ai_released_hash record a release for the AI, bound to the SHA-256 of shell, body and parameters; ai_failure_streak counts consecutive failed autonomous runs (23). proposed_by, approved_by and approved_at (migration 031) mark a script AI Chat or MCP proposed: while proposed_by is set and approved_by is empty it cannot run, be scheduled or be released. script_variables carries the same three columns with the same meaning (25). variables (jsonb, migration 029) lists the script variable names the script may receive; a name it does not list is never sent to it.

Named values a library script reads at run time (25), added by migrations 029–031. script_variables: id, name, description, secret, created_at, updated_at, and the proposed_by / approved_by / approved_at of an AI proposal. A name is a shell identifier (any letter case) that does not start with RMM_ or OPENRMM_, and it is unique ignoring ASCII case, since Windows environment names are (migration 030). script_variable_values holds one value per scope: (variable_id, scope_type, scope_id) is the key, scope_type is global (empty scope_id), client, site, group or agent, and the most specific scope covering a device wins. The value of a secret variable is encrypted with the settings key (AES-GCM) and is never written back to an API response, an audit row or a job’s stored output.

The catalogue of category names (id, name, created_at), added by migration 007. Unique on lower(name), because “Networking” and “networking” are the same category to everyone except a byte comparison.

scripts.category keeps the name, not a foreign key: this table exists so a category can be named before any script is filed under it, not to own the relationship. A script written straight through the API can therefore carry a name nobody registered, so listing unions the registry with the categories in use and such a category is never invisible. Saving a script adopts its category into the registry, so the two do not drift.

A policy (id, name, description) bundles checks and tasks. policy_assignments attaches a policy to a scope: scope_type (client/site/group/agent) + scope_id. An agent inherits every policy whose scope covers it (its own id, its department, its site, or its client) — provided the policy is switched on: enabled (migration 032, default true) gates every resolution, and approved_at records when an AI proposal was reviewed. Since migration 033 an assignment can be narrowed by os and role (empty = any) or be global; policy_exclusions / patch_policy_exclusions (policy_id, agent_id) list devices a policy leaves out; agents.os_role (detected) and agents.role_override (an administrator’s correction) give a device’s role. Since migration 034 agents.logged_in_user (text, '' when no one is logged in or the agent is older than 0.11) holds the user of the active interactive session as the last heartbeat reported it, and agents.logged_in_user_since when it last changed. Since migration 035 agents.last_logged_in_user keeps the last non-empty user after they log off, and agents.last_logged_in_user_at is when a heartbeat last reported them. Since migration 036 agents.last_boot_at is when the device last booted: the time the server stored its latest inventory minus the uptime_sec in it (NULL until the first inventory). It moves only when it changes by more than two minutes, so the few seconds each snapshot drifts do not rewrite the row.

A monitoring check. Since migration 037 it has no owner column: where it applies is its rows in check_attachments (below).

Column Type Notes
id uuid PK
type text diskspace/memory/cpuload/ping/winservice/linuxservice/macservice/script
name text
config jsonb type-specific (path / host / service / inline script)
warn_threshold, err_threshold double nullable
interval_sec int run cadence (default 300)
enabled bool default true
proposed_by text AI actor that authored it ('' = a person). Permanent provenance: it survives review
approved_by text who released it ('' = nobody yet)
failure_count int consecutive failures before the alert is raised (1–100, default 2)
recovery_count int consecutive successes before it clears (1–100, default 2)
hysteresis double band a recovering value must clear the threshold by (0–100, default 2)
cooldown_sec int quiet period before the same condition may raise again (default 300)
timeout_sec int how long the agent may run the check (5–86400, default 180). The server deadline is this plus 30 seconds
timeout_policy text count (default) or ignore. count records one failure; ignore does not move the streak
created_at timestamptz

One dispatch of a check to an agent (id, check_id, agent_id, status, dispatched_at, deadline_at, completed_at). Status is pending/completed/timed_out/canceled. timeout_effect is '', counted or ignored: whether that timeout already changed the failure streak.

A partial unique index on (check_id, agent_id) where status = ‘pending’ allows only one outstanding execution per pair, so a slow or disconnected agent is never sent the same check again while the first is still owed. Passing deadline_at marks the row timed_out instead of leaving it pending forever — without this a dropped agent left a check that had been sent and would never be answered. check_results.execution_id links a result back to the dispatch that asked for it.

The per-(check, agent) running state a flap decision needs: status, consecutive_failures, consecutive_successes, last_value, last_output, last_result_at, last_dispatch_at, reconciled_at. The streaks are what let an alert be raised from a run of readings rather than from the latest one.

Latest status + history per (check, agent): id, check_id FK → checks, agent_id FK → agents, status (passing/warning/failing), value (double, nullable), output, ran_at. Indexed by (check_id, agent_id, ran_at desc).

Where a check or task applies (migration 037): one row per policy or device, exactly one of policy_id / agent_id set, unique per item and target. Columns: check_id (or task_id), policy_id, agent_id, added_by, added_at. The migration turned each former owner column into one row dated when the item was made, and dropped the columns. An item with no row is Not in use.

Edits the AI proposed to existing objects (migration 038): kind (script, check, task, policy, patch_policy), target_id, base_hash (the object’s editable view as the proposal saw it), changes (JSONB: fields, attachments, assignments, exclusions), reason, proposed_by, status (pending, applied, rejected, stale, superseded, failed), decided_by, outcome, created_at, decided_at. One pending row per object (partial unique index). A decision locks both the proposal and its target. The edit, outcome and audit commit in one transaction. The claimed_at column is retained for compatibility with existing rows. Migration 039 orders default human audit timestamps under the chain lock so records from one transaction have consistent predecessors.

What a check-scoped silence covered when it was made (migration 037): one row per device the check was attached to directly, with that device’s monitoring_scope_since; the silence holds on a device only while it keeps that scope. alert_suppressions.covers_policy_reach is true when the check had a policy attachment then, and the silence follows the check everywhere it reaches.

Scheduled automation. Like checks, it applies through its rows in task_attachments.

Column Type Notes
id uuid PK
name text
script_id uuid FK → scripts nullable; inline shell+script is the fallback
shell, script text inline source when no script_id
schedule_kind text interval / daily / weekly
interval_sec int for interval
run_at_minute int for daily: minutes since midnight in timezone
days_of_week smallint for weekly: bitmask, bit N = time.Weekday N (0 = Sunday), in timezone
run_at_minutes int[] for weekly: times of day, minutes since midnight in timezone
timezone text IANA zone the times of day are in, daylight saving included; default UTC (migration 025)
enabled bool default true
proposed_by text AI actor that authored it ('' = a person). Permanent provenance: it survives review
approved_by text who released it ('' = nobody yet)
created_at timestamptz

Each dispatched run links back via jobs.task_id.

tasks and checks both carry CHECK (proposed_by = '' OR approved_by <> '' OR NOT enabled). An AI proposal nobody has reviewed cannot be enabled, and the scheduler only ever selects WHERE enabled — so it cannot run. The rule is in the database because the AI tools and the REST handlers are separate paths into these rows; see 07-guardrails-security. Since migration 032 policies and patch_policies carry the same columns and the same rule (policies_proposal_needs_review, patch_policies_proposal_needs_review): an AI policy or patch policy is created switched off and the database refuses to switch it on before a person reviewed it.

Beyond the original fields, an alert carries its whole lifecycle (migration 008):

  • Identity and dedup — condition_key collapses repeats of the same condition into one alert, counted by occurrence_count with first_seen_at / last_seen_at, so a value oscillating on its threshold is one alert rather than one per reading.
  • Evidence — observed_value, threshold_value, output.
  • Scope, denormalized — agent_hostname, site_id, client_id, group_id, agent_snapshot_id. The list can be filtered and paginated by scope without a join per row, and an alert still names its device after the device is deleted.
  • Attribution — acked_at/acked_by, resolved_by, resolution_kind, resolution_note, and reopened_from when a resolved condition returns.
  • Concurrency — version, so two operators acting at once cannot silently overwrite each other (the API takes expected_version).
  • Silencing — silenced_until, silenced_by, silence_reason.
  • Delivery — last_notified_at, notification_pending, notification_kind, notification_seq.

Raised by a failing/warning check or an offline agent.

Column Type Notes
id uuid PK
agent_id uuid FK → agents nullable
source_type text check / task / agent
source_id uuid the check/task id (nullable)
severity text info / warning / error
message text
status text new / acked / resolved
created_at, resolved_at timestamptz

A partial unique index (uq_alert_open on source_type, source_id, agent_id where status <> 'resolved') guarantees at most one open alert per source.

The timeline of an alert (alert_id, event_type, actor, detail, timestamp) — raised, acknowledged, suppressed, resolved, reopened. The alert row holds current state; this holds how it got there.

A silence or maintenance window (kind = silence/maintenance, ends_at, reason, author). Lets a known-noisy condition or a planned window stop mailing without deleting the alert or disabling the check.

Browser login sessions (id, user_id FK → users, token_hash unique, expires_at, created_at). A bearer login token from POST /api/auth/login maps to a row here; logout / password-change revoke them.

Editable runtime configuration as key/value (key PK, value, is_secret, updated_at). Secret values such as the AI API key and MeshCentral token key are encrypted (enc:v1:) before storage and never returned by the config API. TOTP secrets use the same encryption helper but live on users, not in app_settings. Production requires a stable, dedicated RMM_SETTINGS_ENCRYPTION_KEY (normally through RMM_SETTINGS_ENCRYPTION_KEY_FILE). It is not stored in PostgreSQL and must be recovered separately with the database backup.

patches is the fleet catalog keyed by (os, identifier). agent_patches tracks each device’s missing/approved/installing/installed/failed/ excluded state. patch_approvals stores the latest global/client/site/agent approve-or-decline decision; a device reporting a patch takes the most specific one covering it, and a new decision replaces the narrower ones inside its scope. patch_policies stores auto-approval, exclusions, maintenance windows (with the IANA timezone their days and minutes are in, default UTC, migration 025) and reboot behavior; patch_policy_assignments attaches definitions to client/site/agent scopes.

oauth_clients stores Dynamic Client Registration metadata, plus status (approved or pending, per the registration policy), approved_by/approved_at and last_used_at. oauth_codes stores single-use, expiring, PKCE-bound code hashes. oauth_tokens stores access and refresh hashes, user/client/scope binding, and independent access/refresh expiry; plaintext OAuth credentials are returned only when issued.

password_resets holds single-use reset links (token_hash unique, expires_at, used_at). email_verifications holds address confirmation links (token_hash PK, the email they confirm, expires_at, used_at); a link for an address the user no longer has confirms nothing.

notifications / notification_subscriptions

Section titled “notifications / notification_subscriptions”

notifications is the durable alert-mail outbox: one row per message (event_type, recipient, subject, body, optional alert_id/agent_id/ user_id), status pending → processing → sent or failed, with attempts, last_error, next_attempt_at, a dedupe_key, and a delivery lease (lease_token, lease_until) so a worker that dies mid-send does not lose the message. notification_subscriptions is each user’s opt-in per event type (check_failed, check_recovered, agent_offline, job_failed). See 20-email-notifications.

Moves and deletions of devices proposed by the AI or an MCP client. kind move (with destination site_id, optional group_id) or delete; agent_ids (1–500); status awaiting_approval → approved → completed/failed, or rejected; proposed_by and, once decided, decided_by (enforced by a check); result jsonb with per-device outcomes. Deleting the destination site or department deletes a pending move to it.

oidc_login_states holds a sign-in in progress (state_hash, nonce, PKCE code_verifier, redirect_to, and oauth_request when it started from the MCP consent page), expiring after a few minutes. oidc_console_handoffs holds the single-use code the callback hands the console (ticket_hash, user_id, and browser_hash — the browser that started the sign-in, the only one that can exchange it). oauth_sso_grants holds the five-minute, single-use grant an SSO sign-in gives the MCP consent page, bound to client_id, redirect_uri and the PKCE code_challenge.

Forward migration ledger (version bigint PK, immutable name, SHA-256 checksum, applied_at). Do not edit rows or applied migration files to force a rollback.

clients 1───* sites 1───* agents
device_groups 1───* agents
policies 1───* policy_assignments (scope: client | site | agent)
policies 1───* checks / tasks (or owned directly by an agent)
agents 1───* jobs 0..1───* tasks (jobs.task_id, for scheduled runs)
agents 1───1 inventory
agents 1───* check_results / alerts / remote_sessions
checks 1───* check_results
roles 1───* role_permissions
users 1───* sessions / user_scopes / user_recovery_codes
chat_sessions 1───* chat_messages