KDB knowledge

Settings page (data folder, old log, capacity, program files and users)

Where the server keeps its data, how to point it at another folder, and who may log in - all from the console.

The Settings page of the web console has these parts: Storage (where the databases live), Old log kept per database (the wal_archive size), Result cache (cache_mb), Backups, Calls from SQL (http_functions), Capacity and waits (HTTP threads, PostgreSQL connections, the lock timeout, the drain time), Program files (the folders of the console, the help and the Claude skill) and Users (who may log in). Only a user whose own ROLE is admin may open it; everybody else sees a line saying so.

Storage

The top of the page shows the data folder in use, and a badge saying where that choice came from. Under it: how many databases are in it, how much they use, and how much room is left on that disk.

Where the data folder comes from, strongest first:

SourceBadgeSet by
--data-dir <folder>--data-dir on the command linethe command that started the server
kdb.confthis Settings page (kdb.conf)Save on this page
KDB_DATA_DIRthe KDB_DATA_DIR environment variablethe environment
the defaultprogram folderdata next to kdb

A flag always wins. When the server was started with --data-dir, the page says so in a yellow banner: a folder saved here will only be used once the server is started without that flag. This is worth reading before pressing anything - it is the difference between a setting that works and one that quietly does nothing.

How this server was started folds open to show the settings file (config_path) and the whole command line (command_line), as GET /api/settings gives them.

In Docker the image passes the data folder as the environment variable KDB_DATA_DIR=/data, not as --data-dir, on purpose: a flag would always win, and this page could then never change the folder. The image also keeps kdb.conf in the volume (--config /data/kdb.conf), so a setting saved here survives a new image and a new container. A folder you choose here must be under a mounted volume too; anywhere else is inside the container and is lost with it (Docker).

Changing the folder

Type a folder and press Save. Before anything is written, the server:

  1. makes the folder if it is not there,
  2. writes a small file in it and removes it again, to be sure it can write there,
  3. refuses a folder that is itself one database (it holds a _manifest.a) - the data folder is the one above those, the one with a folder per database.

Only then is the folder written to kdb.conf. A folder that fails any of those checks is refused with the reason, and the file is not touched.

{"data_dir":"E:/kdb-data"}

Nothing is copied. The databases in the old folder stay exactly where they are; the server simply looks somewhere else from the next start. To take them along:

  1. Save the new folder here.
  2. Stop the server.
  3. Move the database folders yourself.
  4. Start it again.

Restart

Restart the server closes every database cleanly and starts again in the same process. No service manager, Docker restart policy or supervisor is needed, and the server keeps the same port, so the console reconnects by itself after a few seconds.

If the saved folder cannot be used when the server starts again - an unplugged disk, a renamed share - the server does not refuse to boot. It prints a warning and starts on the usual folder instead, so there is always a console to fix the setting in:

warning: the data folder saved in 'C:/kdb/kdb.conf' cannot be used: cannot make the folder 'Z:/gone'
         starting with the usual folder instead. Fix it on the Settings page.

When it cannot be changed here

The page shows the folder without a Save button when the settings file cannot be written - a read-only program folder, for instance, as in some container images. It then says why, and the folder is set with --data-dir or KDB_DATA_DIR as before. --config <file> puts the settings file somewhere writable:

kdb serve --config /var/lib/kdb/kdb.conf

A server started on one database folder (kdb serve D:\kdb\market) has no data folder to change, so Storage is read-only there too.

Old log kept per database

Each database keeps old log files in its wal_archive folder. They are only used to repair a damaged file and by backups; the data does not need them. This part of the page sets how much each database keeps: a size in MB, or Off.

Where the value comes from, strongest firstShown as
wal_archive_mb in kdb.conf (Save here)this page (kdb.conf)
the environment variable KDB_WAL_ARCHIVE_MBKDB_WAL_ARCHIVE_MB
the defaultthe default (1 GB)
{"data_dir":"E:/kdb-data","wal_archive_mb":100}

Result cache

The result cache keeps the results of repeated SELECTs in memory. This part of the page sets its size for all databases together, in MB; 0 turns it off.

Where the value comes from, strongest firstShown as
--cache-mb on the command line (the page cannot change it then)--cache-mb
cache_mb in kdb.conf (Save here)this page (kdb.conf)
the environment variable KDB_CACHE_MBKDB_CACHE_MB
the defaultthe default (256 MB)

Backups

The backup folder, the schedule, how many backups are kept, and the command that copies each backup off the server. Each line says where its value came from: a flag, this page (kdb.conf), the environment or the default (where the settings come from).

LineWhat it is
Folderwhere backups go; _backups in the data folder by default
Schedulewhen the server makes backups by itself (daily 02:00, every 6h, off)
Keptthe newest backup of each of the last N days and weeks
Copy off the serverthe backup command, or none with a warning: backups on the same disk are lost with it
{"data_dir":"/data","backup_schedule":"daily 02:00","backup_keep_daily":14,"backup_command":"aws s3 cp --recursive {dir} s3://my-bucket/kdb/{database}/{name}"}

Calls from SQL

Which hosts http_get and http_post may call, and how long one call may take.

Capacity and waits

What the server was started with, and where each value came from. It is read-only: the server reads these when it starts, so a change needs a restart.

LineSettingSet with, strongest first
HTTP requests at oncehttp_threads--http-threads, then kdb.conf, then KDB_HTTP_THREADS, then the CPU threads (at least 8)
PostgreSQL connectionsmax_connections--max-connections, then kdb.conf, then KDB_MAX_CONNECTIONS, then 500
Wait for a busy tablelock_timeout_ms--lock-timeout, then kdb.conf, then KDB_LOCK_TIMEOUT, then 5 s. A session changes its own with SET lock_timeout.
Idle open transaction rolled back afteridle_in_transaction_timeout_ms--idle-in-transaction-timeout, then kdb.conf, then KDB_IDLE_IN_TRANSACTION_TIMEOUT, then 30 s. A session: SET idle_in_transaction_session_timeout.
Time to finish on stop--drain-timeout--drain-timeout, then KDB_DRAIN_TIMEOUT, then 30 s (stopping)
Requests per second per addressrate_limit_ip--rate-limit-ip, then kdb.conf, then KDB_RATE_LIMIT_IP, then no limit (rate limits)
Requests per second per userrate_limit_user--rate-limit-user, then kdb.conf, then KDB_RATE_LIMIT_USER, then no limit
Timers running at oncetimer_workers--timer-workers, then kdb.conf, then KDB_TIMER_WORKERS, then 3 (timers)
TCP keepalive: idle before the first probe, between probes, probes before giving uptcp_keepalives_idle, tcp_keepalives_interval, tcp_keepalives_count--tcp-keepalives-*, then kdb.conf, then KDB_TCP_KEEPALIVES_*, then the system's. A Postgres session: SET tcp_keepalives_idle.

To change one, write its key into kdb.conf by hand and press Restart under Storage; a flag or an environment variable changes only when the server is started again. Every option of the server, with its flag, variable and key, is in every option.

{"data_dir":"E:/kdb-data","http_threads":32,"max_connections":300,"lock_timeout_ms":20000}

Program files

The web console, the help pages and the Claude skill are folders of plain files next to the kdb program, not part of it. This part shows which folder the server uses for each, and what chose it. It is read-only.

LineFolderChosen by, strongest first
Web consoleweb_dirkdb.conf "web_dir", then KDB_WEB_DIR, then web/ next to the program, then share/kdb/web beside the program folder, then a source checkout
Help pageshelp_dirthe same, with "help_dir", KDB_HELP_DIR and help/
Claude skillskill_dirthe same, with "skill_dir", KDB_SKILL_DIR and skill/
{"data_dir":"E:/kdb-data","web_dir":"E:/kdb/web","help_dir":"E:/kdb/help","skill_dir":"E:/kdb/skill"}

Users

The same users as CREATE USER and kdb user - this page just sends that SQL for you.

ButtonWhat it sends
Add a userCREATE USER name WITH PASSWORD '...' ROLE read
ChangeALTER USER name WITH PASSWORD '...' ROLE write (only the parts you filled in)
GrantsGRANT write ON DATABASE shop TO name, or REVOKE ALL ON DATABASE shop FROM name
RemoveDROP USER name

On a server with no users yet, the page says so and offers Add the first user. That first user must have ROLE admin, so the role box is fixed. As soon as that user exists, every request needs a login - the console notices at once and shows its login form, so have the password ready.

The rules the server enforces, which the page simply reports:

Roles, and what each one may do, are in users and roles. Keeping a server reachable from outside safe is in server security.