Repository navigation
Coding Standards
The authority is coding-standards.md; this page summarises it. Each rule names the tool or review step that enforces it, and a rule without a tool is checked in review. The document still marks a few commands "to be confirmed"; where it names a CI job, no CI exists (see Development and Testing), so the check is run by hand. Tool versions: Go 1.27.3 (the go directive of both go.mod files) and Node.js 24.22.1 (pinned for the release build in versions.env; the engines field of the console asks for 22 or newer).
- English only. Code, identifiers, comments, commit messages, documents, file names, test data and log messages. Plain prose, no marketing language, no emojis.
- Comments say why. A comment that repeats the code is deleted; one that records a constraint, an upstream behaviour, a failure mode or a decision is required.
- No secrets in the repository, including tests and examples. Test credentials are generated at test time.
-
Licence header. Every new KingresDB source file starts with two header lines in the first comment,
SPDX-License-Identifier: AGPL-3.0-onlyandCopyright (c) 2026, RooyeKhat Media Co, in the comment syntax of the file type (/* */in C,--in SQL,//in Go and TypeScript,<!-- -->in Markdown,#in scripts and YAML). Files copied from upstream keep their upstream header and are not re-headed. KingresDB's own code is AGPL-3.0-only (ADR 0024); PostgreSQL's code keeps the PostgreSQL License. - Third-party code is not copied in without a decision of its own; a dependency needs a licence that can be combined with AGPL-3.0; Citus code, tests and comments are never copied or closely paraphrased (Citus is AGPL-3, and the project uses its documentation only as a source of concepts).
- Needs-verification discipline. A design item marked [Needs verification] is checked against the PostgreSQL source before code depends on it, and the result goes in the work log.
- Commits. One logical change per commit. Core patches follow extra rules (Branching and Synchronisation).
KingresDB C code must look like PostgreSQL C code.
-
Language level: C99 only; declarations at the top of the block;
/* */comments only; PostgreSQL types and macros (bool,Oid,Datum,Assert); no-Wno-*flag to hide warnings. -
Formatting:
pgindentwith the tree'ssrc/tools/pgindent/typedefs.list; new typedefs are added to that file in a separate commit (the only upstream-file change that needs no patch ID). Tabs are 4 columns. Line endings are LF (core.autocrlf=false,core.eol=lf,.gitattributes,.editorconfig). -
Naming: non-static symbols use
kingres_(functions, variables),Kingres(types) orKINGRES_(macros); inside the extensionskingres_shard_andkingres_ledger_. SQL-callable functions arekingres_<name>withPG_FUNCTION_INFO_V1. Every GUC carries the extension prefix and the prefix is reserved withMarkGUCPrefixReserved()in_PG_init. -
Errors:
ereport(ERROR, (errcode(...), errmsg(...)))with a specific SQLSTATE;ERRCODE_INTERNAL_ERRORis not used for conditions a user can cause;elogonly for "cannot happen". Messages follow the PostgreSQL style guide (short, lower case, no trailing period;errdetailanderrhintare sentences). Each error path has a test that asserts its SQLSTATE and message. -
Memory:
palloc/pfree/repalloc, nevermalloc; long-lived data in a named context underTopMemoryContextorCacheMemoryContext; shared memory requested inshmem_request_hookand initialised inshmem_startup_hook. -
PG_TRY: prefer resource owners and
PG_FINALLY; variables read afterPG_CATCHarevolatile; neverreturn,gotoorbreakout of aPG_TRY; noereport(ERROR)under a spinlock. -
Hooks: save the previous hook in
_PG_initand call it (or the standard function) when the query is not yours. A regression test loads another extension that uses the same hook. -
Files:
postgres.hfirst in every.c; onePG_MODULE_MAGIC;per extension;_PG_initis the only place that installs hooks, defines GUCs and requests shared memory; both aMakefile(PGXS) and ameson.build, listing the same sources, data files (every upgrade script) and tests. -
Comments: every file starts with a banner (purpose, licence,
IDENTIFICATION); every non-trivial function has a comment block before it saying what it does and why. The banner of the extension sources carriesPortions Copyright (c) 2026, RooyeKhat Media Co.
ADR 0023 and section 1.13 of the standards:
- Each extension has one compatibility header,
src/pg_compat.h, holding every difference between PostgreSQL 18 and 19 (a renamed function, a changed signature, a moved header, a changed struct member). It exists forkingres_shard,kingres_ledger,kingres_sketchandkingres_columnar. - Nothing outside
pg_compat.htestsPG_VERSION_NUMorPG_MAJORVERSION_NUM. Code calls a macro orstatic inlinefunction that the header defines for each major, named after what the code means. Check:grep -rn PG_VERSION_NUM contrib/kingres_*lists onlypg_compat.hfiles (and one compatibility header of a columnar test helper,t/kcevents/kcevents_compat.h). - A feature of the newer major alone lives in its own file; on the older major its SQL function raises a clear "needs PostgreSQL N" error. SQL scripts are the same on every major. Expected output that legitimately differs uses
expected/<test>_1.out. - No compiler warning on any major;
kingres/dev/ext-majors.shbuilds with-Werroron each.
- The control file's
default_versionnames the current version; the install script creates the full current state; each version has an upgrade scriptkingres_<name>--<old>--<new>.sql. Scripts start with the\echo Use "CREATE EXTENSION ..." \quitguard. - A released script is never edited. Ledger hash formats are versioned with
hash_version, and an upgrade must never change how existing hashes are computed.
- All objects are in the schema
kingres; names are lower casesnake_case; constraints and indexes are named explicitly. - Every function sets
search_pathexplicitly (SET search_path = pg_catalog, kingres);SECURITY DEFINERonly when needed, with a dedicated owner,REVOKE ALL ... FROM PUBLIC, explicitGRANT EXECUTEand validated arguments. - Dynamic SQL uses
format()with%Iand%L; noSELECT *in interfaces;COMMENT ONfor every public object.
-
cmd/<binary>/main.goper executable andinternal/for everything else; onego.modper module (control plane, verifier). -
gofmtwithout a diff,go vet ./...,golangci-lint run, tests with-race. -
context.Contextis the first parameter of anything that does I/O or blocks; errors are returned and wrapped with%w; logging islog/slogonly and never logs secrets; no global mutable state and no work ininit(); interfaces are defined where they are used. - Tests are table-driven, next to the code, with no sleeping to wait for conditions.
- Standard library first; a new module needs a licence check, a maintenance check and a note naming module, version, licence and reason (
kingres/control-plane/DEPENDENCIES.mdandkingres/web/DEPENDENCIES.mdhold the lists). - The REST server is written against
openapi.yaml; a handler that is not in the spec is a bug.
- Vue 3 with
<script setup lang="ts">(ADR 0017); TypeScriptstrict, noany, no@ts-ignore. - ESLint (flat config) and Prettier; the API client is generated from
openapi.yaml, never written by hand, and the checks fail if the generated files are stale. - Accessibility rules: semantic HTML, keyboard operation with a visible focus, labelled controls, status never by colour alone (badges carry text), dialogs that trap and restore focus. Tests find controls by role and label.
- User-visible text is English.
A fix is trusted only if its test fails without it. Authors and reviewers apply one-line mutants (the fix removed or a condition changed) and require a test to fail; a test that passes with the fix removed is a finding. See Testing Strategy and Review Process.
From documentation.md: say each thing once and link; keep sourced facts, recommendations and needs-verification items apart; do not state commands or numbers that were not checked; describe the current state in present tense (history belongs in the work log and ADR statuses). An ADR holds one decision with context, alternatives, consequences and status, is not edited once accepted except for its status, and is replaced by a new ADR that says "Supersedes ADR NNNN". A work-log entry has the date and title, what was done, how it was verified (including "not verified"), needs-verification items checked, decisions and deviations, what is still open, and core patches touched.
- kingres/docs/dev/coding-standards.md
- kingres/docs/dev/documentation.md
- kingres/docs/adr/0023-one-extension-source-for-several-majors.md
- kingres/docs/adr/0024-agpl-for-kingresdb-code.md
- contrib/kingres_shard/src/pg_compat.h
- kingres/COPYRIGHT
- kingres/control-plane/DEPENDENCIES.md
- kingres/web/DEPENDENCIES.md
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