Repository navigation
Memory and Warm up
How KingresDB uses the memory of a server today, how a table can be kept in memory, and what phase 20 of the roadmap plans. Phase 20 is planned for release 0.3.0 and not built: the Warm-up section of the console described below does not exist in release 0.2.1. Its design is written, was reviewed and revised three times on 2026-11-29, and awaits the owner's review. The authorities are the section "Phase 20" of architecture.md, the design memory-warmup-phase20.md and the ADRs 0047, 0048, 0049 , 0050 (superseded) and 0051.
PostgreSQL has no in-memory table, and it cannot pin a table in memory: any page in the shared buffers can be evicted when another page needs the buffer. Four things are possible without changing PostgreSQL:
| What | How | Effect |
|---|---|---|
| Warm a table | The function pg_prewarm reads its pages into the shared buffers |
Reads are answered from memory |
| Keep it warm | Warm it again when pages fell out | The table stays in memory as long as there is room |
| Give it room | The size of the shared buffers | A warm set that does not fit is evicted again |
| Restore after a restart | The automatic prewarm of the library pg_prewarm
|
A restarted server gets its buffers back by itself |
Writes still reach the disk. Every commit writes WAL. How long a commit waits for it is the durability level of the database (async, sync, syncApply; see Servers Databases and Roles). Warming a table changes nothing about that.
KingresDB says "warm", never "pinned" or "in-memory table". It does not use unlogged tables for this (they are refused as distributed and reference tables, are not replicated to a standby and cannot move with a bucket), nor a tablespace on a memory file system (the PostgreSQL documentation warns that losing a tablespace risks the whole cluster), nor an in-memory table access method.
-
The memory quota sets
shared_buffersto a quarter of the quota,effective_cache_sizeto half andmaintenance_work_memto a sixteenth (at most 2 GiB). The ratios are fixed. The quota is in effect per instance: a server that runs several instances (its own primary and standbys of other groups) has that many pools. The quota is changed on the page This server and applies when the instance is restarted. -
pg_prewarmandpg_buffercacheare supported entries of the extension registry (Extensions). They act on the node they run on, so warming a table today is manual work on every node:- A distributed table is, on each node, one partition
<table>_bNNNNper bucket that the node owns. The partitioned parent has no storage, so the bucket partitions and their indexes are warmed, each withSELECT pg_prewarm('<relation>'). A reference table is warmed as a whole on every node. -
pg_buffercacheshows what is in the shared buffers of that node. - The warmth is lost at a restart, and a standby that is promoted starts cold. After a bucket move the new owner has not warmed the bucket.
- A distributed table is, on each node, one partition
-
The automatic prewarm cannot be switched on: the library
pg_prewarmis not an allowed preload library. -
huge_pagescannot be set on the Configuration page (a value the host cannot honour stops the server from starting; see Configuration). PostgreSQL's default istry, so huge pages are used when an operator has reserved them in the operating system. -
A separate WAL directory is refused at the setup. The packaged service may write only below
/var/lib/kingresand holds no capability.
Decided by the project owner on 2026-11-29:
| Id | Decision |
|---|---|
| M1 | A Warm-up section of the console. The cluster itself, server by server, compares the size of the chosen tables with the memory of each server, sets the memory so that they fit, warms the tables and their indexes on every server (standby instances too), and shows the result |
| M2 |
Automatic prewarm: pg_prewarm becomes an allowed preload library |
| M3 | Warm tables: a table is marked in the console; a keeper warms it on every server after a start, after a promotion and after the arrival of a bucket, and warms again what fell out; a budget refuses a selection that does not fit; the console shows the share in memory per table and per server |
| M4 | The memory architecture: memory profiles instead of the one fixed ratio, huge pages as a checked step, the WAL on a separate device |
| M5 | The feature must not disturb the use of the system: it is managed in the console, it is off until an administrator switches it on, and every part of it is a setting |
| M6 | The whole phase ships with release 0.3.0, all four parts, not in stages |
| M7 | The mark of a warm table is stored in the control plane (its system database), not in a catalog of the sharding extension. A table renamed or dropped by SQL is noticed at the next pass of the keeper, not at once |
| M8 | Moving the WAL of an existing server is part of the phase, as the last thing built |
| M9 | The design of the whole phase is written in one document before any code |
| M10 | The move of an existing WAL ships with 0.3.0 without a condition: a fault test of it that fails holds the release back |
| M11 | All four profiles are offered (balanced, cache, analytic, custom); the three that are not balanced are labelled "provisional until measured". balanced is today's values and stays the default |
| M12 | The extensions are installed automatically when an administrator switches Warm-up on for a database: pg_prewarm in its own schema with EXECUTE revoked from PUBLIC, pg_buffercache in one database per instance. The result is shown and audited; switching off does not remove them |
| M13 | A manual warm-up run that loses its manager leader stays paused and is continued with one click; the task engine is not changed |
| M14 | The WAL of the instances of a server lives below one fixed root, /var/lib/kingres/wal, and the service gets no new access: no capability, no helper, the sandbox of the unit unchanged. The operator only mounts the device there; the package puts its ownership right at boot and at each start of the service; kingresd does everything else. This replaces a first form of the same day (the capability CAP_CHOWN below a list of mount roots, ADR 0050), after a review showed the capability reaches further than first thought (ADR 0051) |
| M15 | A memory calculator with a ceiling per server: the shared buffers of all instances of a server together take at most a set share of its physical memory, 50 percent by default and never above 60; every memory-changing path of the phase must pass it; a server that is already above the ceiling is shown, not refused and not changed (ADR 0049) |
| M16 | The task engine stays unchanged; a resume that the engine takes too early is retried automatically (an occasional delay of some seconds) |
| M17 | The WAL of the instance that holds the system database of the control plane is never moved in place: a cluster of one server, or one whose map group has no standby, gets a separate WAL for it only at the setup |
| M18 | A switchover is required before the WAL of a primary that has a ready standby is moved |
| M19 to M29 | Decided on 2026-11-30: a preload change is refused for lack of worker slots only for pg_prewarm; a recreated table is adopted by one click; unlogged tables are refused; the quota of a server is divided among its instances when an advice is applied; a simple WAL move in 0.3.0; whole tables only; a console button that stops the automatic prewarm; the warm-up runs as the service user with safeguards; an allowlist of file system types for a WAL device; the standbys of groups that wait for apply are not warmed by default; a WAL move is refused when it risks a standby rebuild |
The first wordings of some rules promised more than PostgreSQL can deliver. After the reviews of the design they were reworded to what is true:
- Off means nothing. No job, task, session or statement of the feature, and no changed setting; the control plane only reads its own switch. An upgraded cluster behaves as before. The switch is read at the moment of each decision, so a server that becomes the manager leader later cannot act on a stale value.
- Every part has its own switch. Switching off stops starting and reading within about a second; it restarts nothing and removes nothing. It never stops finishing: a started apply of memory values or a started move of the WAL is brought to its end. It cannot stop the automatic prewarm, which is PostgreSQL's own worker: only taking the library out of the preload list, with a restart, stops it.
- Nothing restarts by itself. Changed memory values are staged and change nothing on a running instance; they are taken up only at a restart that an administrator starts, and can be reverted before it.
- Warming only reads. No row, plan or result changes. It does cause I/O: its backend may write out dirty pages of other relations when it takes their buffers.
-
A bounded wait, not none. Warming takes the lock
ACCESS SHAREon one relation for one short chunk. A statement that needs an exclusive lock on a table that is being warmed waits, on each node, for at most one chunk (one second at most by default, typically a tenth of that), and the statements queued behind it wait with it. A table whose lock is not free is set aside and tried later. - It gives way. A limit on the megabytes read per second, and a stop within about a second while a bucket move, a rebalance, a table change, an export, an import or a failover works on the table, or while the standbys lag.
- A budget. Warm tables take at most a set share of the shared buffers of an instance. No call of the feature evicts a page; but reading into a full pool displaces other pages by PostgreSQL's ordinary replacement. The automatic prewarm is not bounded by the budget.
- A failure stays inside the feature: an alert, and no failed statement of a user.
- Honest figures. The console shows the share in memory as read from the buffers, with the age of the reading; a warm table below its target is an alert.
- Roles and audit: every change and every run is recorded.
- "Warm" is a strong tendency, not a guarantee: under memory pressure PostgreSQL evicts pages and the keeper brings them back.
- Memory given to warm tables is taken from everything else; the calculator and the ceiling bound it.
- The automatic prewarm, once switched on, loads at every start of an instance without the limits of the keeper, holds a lock on each relation while it loads it, behaves differently on PostgreSQL 18 and 19 when the buffers are full, and cannot be switched off without a restart.
- Switching on the automatic prewarm, a changed quota or profile, and a WAL directory each need a restart of the servers.
- Moving the WAL of an existing server stops that instance for the time of the copy and has no way back after its point of no return. It has its own switch, off by default.
- Every instance of a server shares the one WAL device below
/var/lib/kingres/wal; if a configured WAL device fails to mount after a reboot, the service of that server does not start until the mount is fixed. - No figure exists yet. The phase measures first (cold against warm reads, the cost of a warm-up on a write load, the profiles), and the default values of its settings are fixed after that. Phase 17 measures the cluster as a whole.
Open for the owner: about a dozen choices of behaviour that the design lists with a recommendation and the alternative (among them refusing unlogged tables, warming part of a table, the file system types accepted for a WAL device, warming the standbys of databases that wait for apply), and the ratios of the profiles, after the measurements.
- Status and Roadmap
- Configuration
- Extensions
- Limitations and Known Issues
- Architecture Risks and Technical Debt
- kingres/docs/architecture.md, "Phase 20: memory warm-up of tables from the console"
- kingres/docs/design/memory-warmup-phase20.md
- ADRs 0047 to 0051 (linked at the top)
- kingres/docs/guide/limitations.md
- kingres/control-plane/README.md
- kingres/extensions/extensions.yaml
KingresDB's own code is licensed under AGPL-3.0-only. PostgreSQL code keeps the PostgreSQL License. Copyright of the project's own code: RooyeKhat Media Co. KingresDB is derived from PostgreSQL and is not endorsed by the PostgreSQL project. Repository | Licence | COPYRIGHT
KingresDB
1. Product
- Product Overview and Features
- Status and Roadmap
- User Guide
- Administrator Guide
- REST API Reference
- Web Console
- Command Line Client
- Extensions
- Limitations and Known Issues
- Release Notes
Features in detail
- Sharding
- Sharding Query Pushdown
- Sharding Table Lifecycle
- High Availability
- Ledger
- Ledger Signing and Publication
- Ledger Anchoring
- The Verifier
- Analytics Extensions
Administration
- Cluster Setup
- Servers Databases and Roles
- Rebalancing
- Configuration
- Memory and Warm-up
- Control Plane and REST API
- Upgrades
2. Architecture (arc42)
- Architecture
- Architecture Introduction and Goals
- Architecture Constraints
- Architecture System Context
- Architecture Containers
- Architecture Components
- Architecture Runtime Views Sharding
- Architecture Runtime Views Availability and Ledger
- Architecture Deployment
- Architecture Crosscutting Concepts
- Security Model
- Architecture Decisions
- Architecture Quality Requirements
- Architecture Risks and Technical Debt
- Enterprise Architecture
3. Data architecture
- Data Architecture
- Data Model Sharding
- Data Model Ledger
- Data Model System Database
- Data Model Analytics
- Data Lifecycle
- Backup Restore and PITR
- Data Security
- Data Quality and Integrity
4. Development
- Building from Source
- Development and Testing
- Repository Layout
- Coding Standards
- Branching and Synchronisation
- Testing Strategy
- Review Process
- Release Process
- Contributing
5. Operations