# KDB (KARELA DataBase) > KDB is a SQL database for time-series and relational data, made by Amrit Shrestha: one program with an HTTP/JSON API and web console (port 9900) and the PostgreSQL wire protocol (port 8832). It is not kdb+/q. This is its documentation for AI assistants: every topic is a markdown file whose examples ran on kdb 0.2.0-dev and show their real results. How to use it: read this index, then fetch only the topics the task needs. The Agent Skills give the essentials in one file each. Sample tables the examples use are in fixtures/. ## Start here - [KDB skill](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/skills/kdb/SKILL.md): connecting, running SQL over HTTP and PostgreSQL, table design, fast queries, server options, cautions - [KDB geometry skill](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/skills/kdb-geometry/SKILL.md): survey, CAD and 3D data in KDB - [About KDB](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/about-kdb.md): What KDB is, who made it, what you can use it for, how it keeps your data safe, how fast it is and how it is tested. - [Quick start](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/quick-start.md): Get kdb, make a database, create a table, add rows, query them and open the web console. - [SQL basics](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/sql-basics.md): How KDB reads SQL text: statements, names, text, numbers, TRUE/FALSE/NULL, comments, errors and reserved words. - [HTTP API overview](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-overview.md): How to talk to kdb serve over HTTP - the address, choosing the database, JSON answers, errors, safety rules and limits. - [CREATE TABLE](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/create-table.md): Make a relational or a time-series table, with partitions, sort order, a dedup key, rounded times and computed columns, or make one from a query with CREATE TABLE ... AS. - [Limits](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/limits.md): The sizes and counts KDB allows, what happens at each limit, and the features that are not there yet. ## Getting started - [About KDB](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/about-kdb.md): What KDB is, who made it, what you can use it for, how it keeps your data safe, how fast it is and how it is tested. Covers: One program, three doors, What you can use KDB for, How your data is kept safe, How fast it is, How it is tested - [What's new](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/whats-new.md): Everything added to KDB since 2026-09-12, grouped by what it does for you, with the measured number and the topic that explains it. Covers: 2026-10-18: streamed reads over the Postgres port run three to four times faster; a view's one-day read in half the time, 2026-10-18: a join to a small table runs as a key lookup; a day's grouping in fewer steps, 2026-10-17: sums over a year of windows and of buy/sell views on the column engine, 2026-10-17: year-long reads of joined and lag views fit in memory, 2026-10-16: big answers stream over the Postgres port; long view ranges run in parts, 2026-10-10: a cold scan keeps the disk busy, 2026-10-09: big scans in a full memory budget stop reading the same files again, 2026-10-06: less work around each statement on the PostgreSQL port, 2026-10-02: big sorted copies fit a 3 GB memory limit, 2026-10-02: reads take turns on a small CPU limit, 2026-10-02: cache tables with a memory cap, 2026-10-02: a Redis-like key-value store, ... - [Install packages and the Claude skill](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/install-packages.md): The Windows and Linux install packages, the Docker image, and the skill file that teaches an AI assistant in another project how to use KDB. Covers: Windows, Linux, Where kdb finds the console, the help and the skill, Docker, The Claude skill, Building the packages yourself - [Quick start](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/quick-start.md): Get kdb, make a database, create a table, add rows, query them and open the web console. Covers: Get kdb, Your first database, CREATE TABLE, INSERT and SELECT, kdb shell, Load the sample data, Open the web console (kdb serve), Next steps - [SQL basics](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/sql-basics.md): How KDB reads SQL text: statements, names, text, numbers, TRUE/FALSE/NULL, comments, errors and reserved words. Covers: Statements and ;, Upper and lower case, Names and "quoted names", Text: 'single quotes', Numbers, TRUE, FALSE and NULL, Comments, Error messages, Reserved words, Clause words, NULL logic - [SQL command groups: DDL, DML, DCL, TCL, DQL](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/sql-command-groups.md): The five groups of SQL statements, every KDB statement in its group, and the role each group needs. Covers: DDL: Data Definition Language, DML: Data Manipulation Language, DCL: Data Control Language, TCL: Transaction Control Language, DQL: Data Query Language, Which group is my statement? - [Database models: relational, hierarchical, network, NoSQL, object](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/data-models.md): The five classic kinds of database, and how much of each KDB can be - with a picture and a working example for each. Covers: Relational, Hierarchical, Network, Non-relational (NoSQL), Object-oriented - [Sample data](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/sample-data.md): The small made-up stock market dataset that most help examples use, with a few rows of each. Covers: securities, brokers, ochl_day, ochl_minutes, trade_log, live_data ## Tutorial - [1. Install KDB](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/01-install.md) - [2. Your first database](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/02-first-database.md) - [3. Tables](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/03-tables.md) - [4. Writing data](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/04-writing-data.md) - [5. Queries](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/05-queries.md) - [6. Web console](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/06-web-console.md) - [7. Command line and scripts](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/07-command-line-and-scripts.md) - [8. HTTP API](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/08-http-api.md) - [9. Backup and safety](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/09-backup-and-safety.md) - [10. Moving from QuestDB](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/10-migrating-from-questdb.md) - [11. SQL reference](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/11-sql-reference.md) - [12. Troubleshooting](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/12-troubleshooting.md) - [13. Functions, procedures and triggers](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/13-functions-procedures-triggers.md) - [14. PostgreSQL protocol](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/14-postgres-protocol.md) - [15. Transactions and accounting](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/15-transactions-and-accounting.md) - [16. Users, passwords and security](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/16-users-passwords-security.md) - [17. Indexes and search](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/17-indexes-and-search.md) - [18. Content data: companies, reports, news and a forum](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/18-content-data.md) - [19. Analysis functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/19-analysis-functions.md) - [20. Charts and dashboards](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/20-charts-and-dashboards.md) - [21. Protection](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/21-protection.md) - [22. PostgreSQL schema compatibility](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/22-postgresql-compatibility.md) - [23. PostgreSQL queries and data changes](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/23-postgresql-queries.md) - [24. Versions and upgrades](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/24-versions-and-upgrades.md) - [Known limitations](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/tutorial/known-limitations.md) ## Databases & folders - [Databases and the data folder](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/databases.md): Where KDB keeps databases, how to name them, and CREATE DATABASE, DROP DATABASE, SHOW DATABASES and USE. Covers: The data folder, Database names and folder paths, CREATE DATABASE, DROP DATABASE, PURGE TRASH, PURGE VERSIONS, TRUNCATE ALL TABLES, SHOW DATABASES, USE, ALTER DATABASE ... SET DIALECT, ALTER DATABASE ... SET WAL_ARCHIVE, ALTER DATABASE ... SET RESULT_CACHE, ... - [Time travel and branches: SELECT ... AS OF, CREATE DATABASE ... BRANCH OF](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/as-of-and-branches.md): Read a table as it was at an earlier time or commit, undo a bad change with one query, and make a full writable copy of a database in a moment, without copying its files. Covers: SELECT ... AS OF, How far back, CREATE DATABASE ... BRANCH OF - [Queries across databases](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/cross-database-queries.md): Read a table of another database on the same server as database.table - in SELECT, JOIN, subqueries and INSERT ... SELECT. Covers: Name a table of another database, What works, Changes stay in your database, Rights, Speed, Locks ## Tables - [CREATE TABLE](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/create-table.md): Make a relational or a time-series table, with partitions, sort order, a dedup key, rounded times and computed columns, or make one from a query with CREATE TABLE ... AS. Covers: CREATE TABLE, Temporary tables: CREATE TEMP TABLE, CREATE TABLE ... AS, Relational tables (RECORDS), TIMESERIES, PARTITION BY, SORT BY, DEDUP KEY, ROUND, Computed columns: AS (expr), Stored generated columns: GENERATED ALWAYS AS (expr) STORED, Rows that expire: WITH (ttl_column = ...), ... - [Column types](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/column-types.md): Every column type, its range, how NULL is kept, and which values it accepts. Covers: BOOL, BOOLEAN, BYTE, SHORT, INT, INTEGER, LONG, BIGINT, FLOAT, DOUBLE, DECIMAL(s), DATE, TIMESTAMP, SYMBOL, ENUM types (CREATE TYPE), ... - [ALTER, RENAME and DROP TABLE](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/alter-table.md): Add, drop, rename and change columns, drop partitions, set a TTL, add and drop rules and keys, turn DEDUP on or off, rename and drop tables. Covers: ADD COLUMN, DROP COLUMN, RENAME COLUMN, ALTER COLUMN, DROP PARTITION, SET TTL, DEDUP ENABLE and DEDUP DISABLE, ADD CONSTRAINT ... CHECK, ADD UNIQUE, ADD FOREIGN KEY, DROP CONSTRAINT, RENAME TABLE, DROP TABLE, ... - [SHOW TABLES, COLUMNS, CREATE TABLE](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/show-tables.md): List the tables of a database, the columns of a table, its partitions, and the full CREATE TABLE statement - also with QuestDB's tables() and table_columns(). Covers: SHOW TABLES, SHOW COLUMNS FROM, SHOW CREATE TABLE, SHOW PARTITIONS FROM, QuestDB's meta functions - [Rules](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/rules.md): Name a check, the trading hours or the dedup choice of a table once, and KDB applies it to every row written - saying which rule refused a row and why. Covers: CREATE RULE, ALTER RULE, DROP RULE, See the rules: SHOW RULES - [The trash - UNDROP TABLE](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/trash.md): DROP TABLE keeps the table hidden for some days; UNDROP TABLE brings it back with its rows and indexes. Covers: DROP TABLE and the trash, UNDROP TABLE, SHOW DROPPED TABLES ## Constraints - [Constraints](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/constraints.md): Rules that keep table data correct: PRIMARY KEY, AUTO, NOT NULL, UNIQUE, DEFAULT, REFERENCES and CHECK. Covers: PRIMARY KEY, PRIMARY KEY AUTO, NOT NULL, UNIQUE, DEFAULT, REFERENCES, CHECK ## Writing data - [INSERT](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/insert.md): Add rows with INSERT, decide what happens with duplicate keys, get new ids back with RETURNING, and write times correctly. Covers: INSERT INTO ... VALUES, Duplicate keys, INSERT OR REPLACE, INSERT OR IGNORE, RETURNING, Times and time zones in values, INSERT ... SELECT, DEFAULT VALUES, ON CONFLICT (PostgreSQL upsert) - [UPDATE and DELETE](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/update-delete.md): Change rows with UPDATE, remove rows with DELETE, empty tables with TRUNCATE, get the changed rows back with RETURNING, and fix wrong data safely. Covers: UPDATE, DELETE, TRUNCATE, RETURNING, Fix wrong rows safely - [Loading many rows](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/loading-data.md): Load thousands or millions of rows: multi-row INSERT, SQL files, CSV files (POST /imp, COPY), the line protocol and the C++ InsertRows API, with speed tips. Covers: Multi-row INSERT, SQL files: kdb sql -, CSV files, Over HTTP: POST /exec, Line protocol: POST /write, C++ API: InsertRows, Speed tips, Going back to QuestDB or PostgreSQL, Shadow period: compare QuestDB and KDB - [Line protocol (POST /write)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/line-protocol.md): Load many rows fast with the InfluxDB line format over HTTP - one line per row, answered with 204. Covers: Line format, Times in the wrong unit, Update some columns: upsert=merge, A table that is not there, POST /write, POST /api/v2/write ## Querying - [SELECT](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/select.md): Choose the columns and values that a query gives back, and the table they come from. Covers: SELECT, *, table.*, AS: column names, SELECT without FROM, FROM, DISTINCT - [WHERE](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/where.md): Keep only the rows you want, with comparisons, IN, BETWEEN, LIKE, IS NULL and time ranges. Covers: WHERE, AND, OR, NOT, =, ==, !=, <>, <, <=, >, >=, BETWEEN, NOT BETWEEN, IN (list), NOT IN (list), time IN 'interval', Interval lists, today() and DECLARE, LIKE, NOT LIKE, ILIKE, NOT ILIKE, SIMILAR TO, NOT SIMILAR TO, IS NULL, IS NOT NULL, Row comparison: (a, b) < (x, y), ... - [Operators](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/operators.md): Every operator of KDB SQL, which one is done first, and what NULL does to each of them. Covers: Operator precedence, Arithmetic: + - * / %, Integer division: SET int_division, Comparison operators, || : join text, -> and ->> : parts of JSON, :: : change the type, NULL rules - [Joins](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/joins.md): Put rows of two or more tables side by side: JOIN, LEFT / RIGHT / FULL JOIN, USING, CROSS JOIN, and ASOF / LT / SPLICE JOIN for time series. Covers: JOIN, INNER JOIN, LEFT JOIN, LEFT OUTER JOIN, RIGHT JOIN, RIGHT OUTER JOIN, FULL JOIN, FULL OUTER JOIN, USING, CROSS JOIN, ASOF JOIN, LT JOIN, SPLICE JOIN, Table aliases, Joining a subquery - [GROUP BY and HAVING](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/group-by.md): Make one row per group (per symbol, per broker, per account) with totals like count, sum and max, and filter the groups with HAVING. Covers: GROUP BY, ROLLUP, CUBE and GROUPING SETS, Big GROUP BY: many groups and memory, Implicit GROUP BY, HAVING, Columns that are not grouped - [PIVOT](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/pivot.md): Turn the values of one column into columns, like a pivot table in Excel: turnover per symbol with one column per day. Covers: PIVOT (...) - [ORDER BY, LIMIT, OFFSET](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/order-by-limit.md): Sort the result, and give back only the first rows or one page of rows. Covers: ORDER BY, ASC, DESC, COLLATE: dictionary order, NULLS FIRST, NULLS LAST, LIMIT, OFFSET, Paging - [UNION and subqueries](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/union-subqueries.md): Put the rows of two queries together, and use one query inside another. Covers: UNION ALL, (SELECT ...) as a value, IN (SELECT ...), NOT IN (SELECT ...), EXISTS, NOT EXISTS, FROM (SELECT ...) alias, Correlated subqueries - [EXPLAIN](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/explain.md): See how KDB will read the tables for a query, without running it; with ANALYZE, run it and see what really happened. Covers: EXPLAIN, EXPLAIN ANALYZE, EXPLAIN (FORMAT JSON), EXPLAIN INSERT, UPDATE, DELETE, EXPLAIN CALL, The plan lines, Zone maps: partitions skipped by column stats, Answers without reading rows ## Time-series - [SAMPLE BY](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/sample-by.md): Put rows into time buckets (1 minute, 15 minutes, 1 hour, 1 day, 1 week, 1 month) and make candles. Covers: SAMPLE BY, Intervals, FILL, FROM / TO, ALIGN TO CALENDAR, ALIGN TO FIRST OBSERVATION, TIME ZONE, WITH OFFSET, WEEK START - [LATEST ON](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/latest-on.md): Keep only the newest row of each symbol (or of each group of columns). Covers: LATEST ON, WHERE with LATEST ON, LATEST ON with other clauses, Errors - [Time and time zones](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/time-and-time-zones.md): How KDB stores times (UTC milliseconds), how to write a local time with its offset (like +05:45), the session's time zone (SET TIME ZONE, --timezone), time zone names, and time ranges with IN '...'. Covers: Storage, Time text, A local time: Nepal +05:45, The session's time zone: SET TIME ZONE, Time zone names, Zones with summer time, IN 'interval' for time ranges, Times in results - [Trading calendars](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/calendars.md): Say which days a market trades - its weekdays, how they changed over the years, and its holidays - and ask it in SQL and in timers. Covers: CREATE CALENDAR, ALTER CALENDAR, DROP CALENDAR, The functions, Find missing days, See the calendars: kdb_calendars, Find the eras in your data: suggest_calendar_eras, Timers on trading days, How it is stored - [Prices adjusted for splits and bonus shares](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/adjusted-prices.md): Read a price table as if every split and bonus share had always been there - a chart without the jump on the ex-date - while the table keeps the traded prices. Covers: The table of corporate actions, How a row is adjusted, Which columns change, Filters, candles and indicators, Errors - [Partitions, SORT BY and DEDUP KEY](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/partitions-and-dedup.md): How PARTITION BY, SORT BY and DEDUP KEY of a time-series table change where rows go, their order, and what happens to duplicates; DROP PARTITION deletes old data fast. Covers: PARTITION BY, PARTITION BY time, SYMBOL(col), SORT BY, DEDUP KEY, Ragged seconds: a DEDUP KEY on the minute, A plain INSERT that replaces: dedup_insert, Packed partitions: compression, Appending without rewriting: tail files, Small changes without rewriting: delta files, How a load finds duplicates, Loads without the duplicate check: dedup=skip, DEDUP TABLE, ... - [Candles cookbook](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/candles-cookbook.md): Ready market-data queries: candles from minute data and from trades, daily change, top gainers, volume leaders, 52-week high and low, moving averages and filled gaps. Covers: Candles from minute data, Hourly candles on a local clock (Nepal), Daily candles from trade log trades, Weekly candles, Sunday to Thursday, Monthly and yearly candles, Daily change %, Top gainers and losers, Volume and turnover leaders, 52-week high and low, Moving averages and crossovers, Indicators on candles, Candle and indicator tables kept by a timer, ... ## Functions — math - [Finance and price functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-finance.md): Money math like Excel (interest, loan EMI, NPV, IRR, XIRR, CAGR), price ticks and pivot points for traders. Covers: cagr, compound_interest, fv, pv, pmt, nper, npv, irr, xnpv, xirr, round_tick, floor_tick, ceil_tick, pivot_point, ... - [Math functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-math.md): Round and cut numbers, take powers, roots and logarithms, divide safely, put values in buckets, and make random numbers. Covers: abs, round, round_half_even, floor, ceil, ceiling, trunc, truncate, sqrt, cbrt, pow, power, exp, ln, log, log10, ... - [Trigonometry and probability](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-math-more.md): Sine, cosine, tangent and their inverses, hyperbolic functions, and the normal distribution (chance, bell height and inverse). Covers: sin, cos, tan, cot, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh, normal_cdf, normal_pdf, ... ## Functions — text - [Regular expressions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-regex.md): Find, count, cut out and replace text with patterns like \d+ (one or more digits). Covers: regexp_like, regexp_substr, regexp_count, regexp_replace, Flags, regexp_match, regexp_matches, regexp_split_to_array, regexp_split_to_table, PostgreSQL flags, Regular expression syntax - [Text functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-text.md): Change case, cut, trim, pad, search and join text. A letter of any language (Nepali, Chinese, ...) counts as one character. Covers: lower, upper, length, char_length, character_length, octet_length, substr, substring, left, right, trim, btrim, ltrim, rtrim, replace, split_part, ... ## Functions — date and time - [Date and time functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-date-time.md): Take a time apart, find the weekday, quarter and week, cut, add and build times, count days or months between times, fiscal years (also Nepal's), and write a time as text. Covers: now, systimestamp, year, month, day, hour, minute, second, day_of_week, is_trading_day, date_part, extract, quarter, day_of_year, ... ## Functions — conditional and NULL - [Conditional and NULL functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-conditional.md): Choose a value with CASE, replace NULL with coalesce, and turn a value into NULL with nullif. Covers: CASE WHEN, CASE value WHEN, coalesce, nullif, NULL rules ## Functions — conversion - [Conversion functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-conversion.md): Change a value from one type to another with CAST, ::, to_timestamp and to_date. Covers: CAST, :: (short cast), to_timestamp, to_date, Into integers, Into DOUBLE and FLOAT, Into DECIMAL(s), Into TIMESTAMP, Into DATE, Into BOOL, Into STRING and SYMBOL, Into JSON, ... ## Functions — aggregate - [Aggregate functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-aggregate.md): Make one value from many rows: count, sum, avg, min, max, first, last, median, percentile, vwap, twap, conditional counts and sums, the row of the maximum, and lists of text. Covers: count(*), count(x), count(DISTINCT x), count_distinct, sum, avg, min, max, first, last, first_not_null, last_not_null, median, ... ## Functions — window and series - [Window and series functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-window.md): Look at a series of rows: previous and next values, running totals, moving windows, time windows and ranks, with OVER (...). Covers: OVER (...), PARTITION BY (window), ORDER BY (window), ROWS n PRECEDING, ROWS UNBOUNDED PRECEDING, ROWS BETWEEN n PRECEDING AND CURRENT ROW, ROWS BETWEEN ... FOLLOWING, RANGE BETWEEN, lag, lead, cumsum, cumprod, ... ## Functions — technical indicators - [Momentum indicators](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-indicators-momentum.md): MACD, stochastic, stochastic RSI, Williams %R, CCI, rate of change, momentum and TRIX on candles, with the same results as TA-Lib. Covers: macd, macd_signal, macd_hist, stoch_k, stoch_d, stochf_k, stochrsi_k, stochrsi_d, willr, williams_r, cci, roc, rocp, rocr, mom, momentum, trix - [Technical indicators](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-indicators.md): Moving averages (SMA, EMA, WMA, DEMA, TEMA, TRIMA, KAMA, HMA, VWMA), RSI and ATR on candles, per symbol, with the same results as TA-Lib. Covers: sma, ema, wma, dema, tema, trima, kama, hma, vwma, rsi, atr - [Trend indicators](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-indicators-trend.md): Is the price going up, down or sideways, and how strong is the move? ADX and DI, Aroon, parabolic SAR, Ichimoku, SuperTrend, linear regression and Heikin-Ashi candles. Covers: cross_above, cross_below, plus_di, minus_di, dx, adx, adxr, aroon_up, aroon_down, aroon_osc, sar, parabolic_sar, ichimoku_tenkan, ichimoku_kijun, ichimoku_senkou_a, ichimoku_senkou_b, ichimoku_chikou, ... - [Volatility indicators and bands](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-indicators-volatility.md): How much the price moves: true range, ATR in percent, Bollinger bands, Keltner and Donchian channels. Covers: trange, true_range, natr, bb_upper, bb_middle, bb_lower, bb_percent_b, bb_width, kc_upper, kc_lower, kc_middle, dc_upper, dc_middle, dc_lower - [Volume indicators](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-indicators-volume.md): Is money flowing in or out? On-balance volume, the A/D line, Chaikin money flow and oscillator, MFI, force index and ease of movement. Covers: obv, ad, ad_line, cmf, adosc, chaikin_osc, mfi, efi, force_index, eom, ease_of_movement ## Functions — statistics - [Correlation and regression](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-correlation.md): Do two series move together? corr, covariance, a straight trend line (regr_slope, regr_intercept, regr_r2), and the beta and alpha of a share against the market. Covers: corr, covar_pop, covar_samp, regr_slope, regr_intercept, regr_r2, regr_count, regr_avgx, regr_avgy, regr_sxx, regr_syy, regr_sxy, beta, alpha - [Returns and risk](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-returns-risk.md): Returns, drawdown, volatility, z-score and the risk numbers of an investment: Sharpe, Sortino, Calmar, information ratio, value at risk and expected shortfall. Covers: pct_return, percent_return, returns, log_return, cum_return, drawdown, volatility, zscore, minmax_scale, max_drawdown, sharpe_ratio, sortino_ratio, calmar_ratio, information_ratio, ... - [Statistics functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-statistics.md): Describe a set of numbers: spread (stddev, variance, mad, iqr, range), shape (skewness, kurtosis), other averages (geomean, harmonic_mean, mode) and exact percentiles. Covers: stddev, stddev_samp, stddev_pop, variance, var_samp, var_pop, skewness, skew, skewness_pop, kurtosis, kurt, kurtosis_pop, geomean, geometric_mean, harmonic_mean, mode, percentile_cont, quantile_cont, ... ## Functions — JSON and bytes - [Bytes, hex and base64](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-bytes.md): Store raw bytes (hashes, keys, small images) and turn them into hex or base64 text and back. Covers: X'...' bytes literal, hex, unhex, to_base64, from_base64, encode, decode, convert_to, convert_from - [JSON functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-json.md): Check, read, build and change JSON values, like company profiles and report numbers. Covers: JSON column type, JSON paths, json, to_json, json_valid, json_extract, json_value, json_value_text, json_value_double, json_value_long, json_value_bool, json_type, ... ## Functions — security - [Security functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-security.md): Hash and check passwords, make SHA-256 hashes, random tokens and random ids (UUIDs), and encrypt data with PostgreSQL's pgcrypto functions. Covers: password_hash, password_verify, sha256, digest, hmac_sha256, random_bytes, random_token, gen_random_uuid, PostgreSQL pgcrypto functions, pgp_sym_encrypt, pgp_sym_decrypt, encrypt, ... ## Views - [Views](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/views.md): Save a query with a name, and select from it like a table. Covers: CREATE VIEW, ALTER VIEW, Selecting from a view, CREATE CACHED VIEW, CREATE MATERIALIZED VIEW, REFRESH VIEW, DROP VIEW, SHOW VIEWS, Simple, complex and materialized views ## Saved functions - [Saved functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/saved-functions.md): Save a formula with a name, and use it in any query like a built-in function. Covers: CREATE FUNCTION, Using a saved function, Rules for the body, DROP FUNCTION, SHOW FUNCTIONS ## Stored procedures - [Stored procedures](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/procedures.md): Save many SQL steps under one name and run them with CALL, as one transaction. Covers: CREATE PROCEDURE, CALL, A CALL is one transaction, A CALL that only reads, Matching another system's rounding, CALL ... WITH DEBUG, DROP PROCEDURE, SHOW PROCEDURES - [The procedure language](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/procedure-language.md): Variables, IF, WHILE, FOR, RETURN, RAISE, PRINT and cursors inside a procedure or trigger body. Covers: DECLARE, SET, IF, ELSIF, ELSEIF, ELSE, WHILE, FOR, RETURN, RAISE, PRINT, EXECUTE (dynamic SQL), Cursors in a body: DECLARE CURSOR, OPEN, FETCH INTO, CLOSE, Limits of the procedure language - [Calling web services from SQL (http_get, http_post)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-functions.md): http_get and http_post call a web address from SQL, a procedure or a timer. Off until an admin lists the hosts they may call. Covers: http_get, http_post, Reading the answer, Turning them on, What a call may do, Who may call - [Timers](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/timers.md): Let the server run a procedure, a function or any SQL by itself at set times, so a table stays up to date. Covers: Schedules, How a run works, In the console, GET /api/timers, POST /api/timers, Run, turn off, delete, Good to know ## Triggers - [Triggers](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/triggers.md): SQL that runs by itself when rows of a table are inserted, updated or deleted. Covers: CREATE TRIGGER, BEFORE and AFTER, NEW, OLD, Once per statement, Per-user results kept up to date, Triggers and load speed, Errors in a trigger, How long a trigger may run, Deferred triggers, ALTER TABLE ... ENABLE TRIGGER, DISABLE TRIGGER, DROP TRIGGER, SHOW TRIGGERS, ... ## Transactions - [Transactions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/transactions.md): BEGIN, COMMIT and ROLLBACK: save many changes together, or none of them. Covers: BEGIN, COMMIT, ROLLBACK, SAVEPOINT, What is one transaction by itself, When a statement fails, A text that ends without COMMIT, Statements not allowed inside a transaction, SELECT ... FOR UPDATE, Transactions in kdb shell, Transactions over HTTP, One writer per table, ... ## Cursors - [Cursors](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/cursors.md): Run a query once, keep its rows, and read them a few at a time. Covers: DECLARE CURSOR, FETCH, CLOSE, Where a cursor lives, Cursors over HTTP: POST /cursor, Limits of cursors ## Indexes & search - [Indexes](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/indexes.md): Make WHERE and ORDER BY ... LIMIT fast with an index, and keep values unique with a UNIQUE index. Covers: CREATE INDEX, CREATE UNIQUE INDEX, Bitmap index, DROP INDEX, SHOW INDEXES, Built at open, When an index is used - [Full-text search](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/full-text-search.md): Find rows that contain words, rank the best matches first, and mark the found words in bold. Covers: CREATE FULLTEXT INDEX, Language: stems and stop words, match, How the index is used, Segments on disk, search_rank, highlight, Search text ## Users & security - [Users and roles](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/users-and-roles.md): Database users with passwords, and the roles read, write, ddl and admin for every database or for one. Covers: CREATE USER, ALTER USER, ALTER USER ... SET statement_timeout, ALTER USER ... SET timezone, DROP USER, SHOW USERS, GRANT, REVOKE, SET ROLE, Roles: what each one may do, Where users are kept - [Table rights - GRANT ON TABLE](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/table-rights.md): Give a user rights on one table (GRANT SELECT ON TABLE prices), on some of its columns (GRANT SELECT (id, name) ON staff) or on some of its rows (CREATE POLICY), or take some rights of the role away (REVOKE UPDATE, DELETE ON TABLE ledger). Covers: GRANT ... ON TABLE, REVOKE ... ON TABLE, Column rights, Row rights (row-level security), REVOKE role ON DATABASE - [API tokens](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/api-tokens.md): Named, revocable secrets for apps - each acts as one user, and DROP TOKEN stops it at once. Covers: CREATE TOKEN, DROP TOKEN, SHOW TOKENS, Where tokens and logins are kept - [Two-factor login (TOTP)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/two-factor-login.md): A database user can log in to the console and POST /api/login with a password and a 6-digit code from an authenticator app. Covers: ALTER USER ... ENABLE TOTP, kdb user reset-2fa, Password policy, Session tokens, Step-up codes for dangerous actions - [Keeping kdb serve safe](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/server-security.md): Keep the server on 127.0.0.1, use users or a token, put HTTPS in front, and pick strong passwords. Covers: --bind, --token, Users and logins, HTTPS in front, Password rules, Checklist - [TLS (https and sslmode=require)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/tls.md): Encrypt both ports with one certificate - https:// for the HTTP API and the console, sslmode=require for PostgreSQL clients. Covers: Turn it on, A self-signed certificate (auto), What changes for clients, Docker - [Encryption at rest](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/encryption.md): CREATE DATABASE x WITH (encryption = on) - every file, log record and backup of it is encrypted; without the master key a copied disk shows nothing. Covers: Turn it on, Keys, Change the master key, Backups and restore, What is encrypted, Speed - [Protection - timeouts, limits, safe updates, read-only](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/protection.md): Stop slow statements (timeout and cancel), limit the memory of one query and the statements of one user, refuse UPDATE or DELETE without WHERE, and make a database read-only. Covers: SET statement_timeout, Cancel a running statement, DELETE /exec/, Memory limits, --max-queries-per-user, --rate-limit-ip and --rate-limit-user, SET safe_updates, ALTER DATABASE ... SET READ ONLY, Stopping the server without cutting requests off - [Audit log](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/audit-log.md): KDB writes security events (logins, users, DDL, backups, refused rights) and, for chosen tables, every changed row with who, when, old and new values. Covers: SHOW AUDIT, ALTER TABLE ... SET AUDIT ON, The hash chain, SHOW AUDIT VERIFY, GET /api/audit, --audit-keep-days, Erase one user's data ## Backup, check, repair, restore - [Troubleshooting a running server](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/troubleshooting.md): What to look at, and what to change, when the server is slow, readers wait, memory or disk grows, the start is slow, a timer or a backup does not run, or data must come back. Covers: The server is slow, Readers wait for a writer, Errors 55P03 and 40001: the table is busy, Memory is high, The disk keeps growing, The start is slow, or says "last shutdown: not clean", A timer does not run, A backup failed, Getting data back - [Backup, check, repair and restore](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/backup-and-safety.md): How KDB keeps your data safe, how to make and test backups, and how to get the data back after damage or a mistake. Covers: How KDB protects your data, The log is compressed, When the disk is full, When the system is short of memory, BACKUP DATABASE, CHECK TABLE, CHECKPOINT, kdb backup, kdb backups, kdb verify-backup, kdb restore, Restore while the server runs, ... - [Backups on a schedule](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/backup-schedule.md): kdb serve makes a verified backup of every database at set times, checks a second copy on another disk, runs your command to copy each backup off the server, and warns when the last good backup is old. Covers: Where the settings come from, Set a daily backup, --backup-schedule, --backup-copy, --backup-command, --backup-warn-hours, Backup status in /api/info - [Versions and upgrades](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/versions.md): A new KDB opens the data of an older KDB. An older KDB refuses the data of a newer KDB with "needs a newer KDB" and changes nothing. Covers: kdb version , SHOW VERSION, kdb upgrade, Going back to an older version, "needs a newer KDB", The features, Two options named late, Changes that need no format change - [Standby server: a live read-only copy (--standby-of, kdb promote)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/standby.md): A second KDB server that copies every database of a primary from its log, a moment behind, and serves reads. Covers: Start a standby, Read-only, How far is it?, Promote: the standby becomes the primary, Starting from a backup, GET /api/wal ## Command line - [The kdb program](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/cli-overview.md): What the kdb program is, how it finds your databases, and what its exit codes mean. Covers: kdb help, kdb version, : a name or a folder path, The data folder, Exit codes, How options are read - [kdb sql and kdb shell](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/cli-sql-and-shell.md): Run SQL from the command line once (kdb sql) or type it at a prompt (kdb shell). Covers: kdb sql, Output formats: table, CSV, JSON, SQL from a file or a pipe, BACKUP DATABASE from kdb sql, kdb shell, Statements over many lines, Transactions in the shell, Shell commands, .help, .tables, .schema, .format, ... - [kdb serve](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/cli-serve.md): Start the KDB server - web console, HTTP API, line protocol and PostgreSQL port - on one database or on the whole data folder. Covers: kdb serve, Every option at a glance, What kdb serve prints, Self-tuning to the CPU and memory limits, Pinning threads to CPUs, Priority lanes, Memory limit for the whole process, Many databases, Stopping the server, Port in use, database in use - [kdb info, check, repair, dump-file](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/cli-maintenance.md): Look inside a database, find damage, repair it, and check one file. Covers: kdb info, kdb check, kdb repair, kdb dump-file - [kdb user](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/cli-users.md): Add, list and remove the users of the KDB server, set their passwords and roles, from the command line. Covers: kdb user add, kdb user passwd, kdb user role, kdb user list, kdb user remove, Errors of kdb user ## HTTP API - [HTTP API overview](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-overview.md): How to talk to kdb serve over HTTP - the address, choosing the database, JSON answers, errors, safety rules and limits. Covers: All routes, Choosing the database, Answers and errors, GET reads, POST changes, Retrying safely: Idempotency-Key, Logins, tokens and cookies in short, Safety rules, CORS, Limits, Clients, GET /, GET /help, GET /help/, ... - [Run SQL over HTTP (/exec, /exp)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-exec.md): Run SQL with GET or POST /exec and get JSON, or download the rows of a SELECT as CSV with /exp. Covers: GET /exec, POST /exec, GET /exp, POST /exp - [Databases over HTTP (/api/databases)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-databases.md): List the databases of a server, create a new one, and drop one (its folder moves to _trash). Covers: GET /api/databases, POST /api/databases, DELETE /api/databases/ - [Saved queries as URLs (CREATE ENDPOINT)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-endpoints.md): Save a SELECT with named parameters under a name; programs then call GET /v/?param=value and get JSON, without sending SQL. Covers: CREATE ENDPOINT, Calling an endpoint, DROP ENDPOINT, How it is stored - [Health, info, check and backup over HTTP](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-server-info.md): Check that the server is alive, read the tables, disk use and health of a database, look for damage, make and list backups, watch deferred trigger queues, and read the server's memory, processor and settings. Covers: GET /health, GET /api/info, GET /api/disk, GET /api/trigger-queue, POST /api/check, POST /api/backup, GET /api/backups, POST /api/restore, POST /api/databases/swap, GET /api/stats, GET /metrics, GET /api/slow-queries, ... - [Key-value store (Redis-like)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/kv.md): GET, SET, INCR, EXPIRE, DEL, KEYS, MGET and the other Redis string commands, hashes, sets, sorted sets, lists (with BLPOP), SORT and WATCH / MULTI / EXEC over HTTP (POST /kv, one command or a pipeline) and as SQL functions (kv_get, kv_set, kv_incr); PUBLISH / SUBSCRIBE and keyspace events. Keys are kept in memory and in the table _kv. Covers: POST /kv, The commands, Publish and subscribe, A memory cap: CONFIG SET maxmemory, Hashes, sets, sorted sets and lists, From SQL: kv_get, kv_set, kv_incr, The table _kv - [Sessions and cursors over HTTP](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-sessions-and-cursors.md): Keep a transaction open over several HTTP requests with a session, and read a big result a part at a time with a cursor. Covers: POST /session, DELETE /session/, POST /cursor, GET /cursor/, DELETE /cursor/ - [CSV import over HTTP (POST /imp)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-import.md): Send a CSV file to kdb serve and it loads the rows, making the table from the file when it is new - QuestDB's /imp. Covers: POST /imp - [Pinned queries](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/pinned-queries.md): Pin a SELECT so its result is always ready in the result cache - computed when the database opens, never pushed out, computed again after a write. Covers: GET /api/pins, POST /api/pins, DELETE /api/pins - [Change revisions: GET /api/rev and kdb_rev()](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/revisions.md): A cheap number per table and per symbol that changes when committed rows change, so a chart polls it and reads its candles again only when they changed. Covers: Which column has revisions, GET /api/rev, kdb_rev - [Change stream and live subscriptions: changes('t'), GET /api/changes, GET /api/subscribe](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/change-stream.md): Every committed INSERT, UPDATE and DELETE of a table as an ordered stream you can resume from its LSN, in SQL or over HTTP, and queries that push their changed rows. Covers: changes('t'), GET /api/changes, How long changes are kept, GET /api/subscribe - [Logins, tokens and roles over HTTP](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/http-login.md): How a program or the console proves who it is - the access token, HTTP Basic, POST /api/login - and the 401, 403 and 429 answers. Covers: Ways to send a login, POST /api/login, POST /api/logout, GET /api/me, The access token (--token), POST /api/session, CSRF: the X-KDB-CSRF header, HTTP Basic, Roles: what each route needs, 401, 403 and 429 answers ## Postgres protocol - [PostgreSQL protocol (port 8832)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/postgres-protocol.md): Connect to KDB with PostgreSQL tools and drivers - psql, DBeaver, Python, Node, C#, Go - and what works and what does not. Covers: Start the Postgres port, Connection settings, Passwords and logins, psql, DBeaver, Python (psycopg, pg8000), Node (pg), C# (Npgsql), Go (pgx), Parameters ($1, $2), Types, Times and --pg-timestamptz, ... - [PostgreSQL-compatible functions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/functions-postgres.md): Functions a PostgreSQL app expects: arrays, sequence numbers (nextval), who you are and what you may do (current_user, has_table_privilege), comments (COMMENT ON), advisory locks and session settings, so app code runs on KDB without changes. Covers: Arrays in KDB, array_append, array_prepend, array_cat, array_remove, array_position, array_length, array_upper, cardinality, array_to_string, unnest, nextval, currval, ... - [pg_stat_activity and pg_stat_statements](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/server-activity.md): See who is connected and what runs now (pg_stat_activity, query_activity(), GET /api/sessions), stop a statement or close a connection (pg_cancel_backend, pg_terminate_backend, CANCEL QUERY, DELETE /api/sessions/), close idle and vanished clients (idle_session_timeout, tcp_keepalives_*), and see the totals of every statement shape (pg_stat_statements). Covers: pg_stat_activity, pg_cancel_backend and pg_terminate_backend, query_activity, CANCEL QUERY and cancel_query, pg_sleep, Idle and vanished clients, GET /api/sessions and DELETE /api/sessions/, pg_stat_statements - [LISTEN and NOTIFY](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/listen-notify.md): Send a message to every client that listens on a channel when a transaction commits - over the PostgreSQL port (LISTEN) or HTTP (GET /listen, server-sent events). Covers: NOTIFY and pg_notify(), LISTEN on the PostgreSQL port, GET /listen: server-sent events, Limits - [Settings - SET, SHOW ALL, ALTER SYSTEM](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/server-settings.md): One list of the server's settings behind pg_settings, SHOW ALL, SHOW PARAMETERS and GET /api/settings; SET for a session, ALTER SYSTEM and pg_reload_conf() for the server. Covers: Change a setting for this session, The planner settings KDB applies, Memory settings set at start, The plan cache, Change a setting for the server, Also fixed on 2026-09-26 ## C API - [C API (kdb.h)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/c-api.md): Use KDB inside your own program with no server - open a folder, run SQL, read rows as text or native numbers - through the C header include/kdb.h and the kdb_c library. Covers: Build the library, Open, run SQL, read rows, Reading a result, Errors and SQLSTATE, Bulk rows: kdb_append, Transactions: sessions, Threads, From Go: the cgo package ## Web console - [Web console](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/web-console.md): The browser page of kdb serve - run SQL, see results as a grid or a chart, switch databases, check health, make backups and open this help. Covers: Open the console, The screen, Editor, History, Results grid, Chart, Charts and dashboards, Export CSV, Object list, Timers, Right side: Monitor, Health, Samples, Databases, Terminal, ... - [Dashboard page (many charts on one page)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/console-dashboards.md): Put many charts on one page, each from its own query, with pickers such as $symbol at the top and an automatic refresh. Dashboards are saved in the database. Covers: The screen, Panels, Variables, Saving, and who may do what - [View data page (browse and edit rows)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/console-data-page.md): Look at the rows of a table in the console and change them with forms - add, edit and delete - without writing SQL. Covers: The screen, Which tables can be edited, What it sends, Notes - [Keep data page (how long tables keep their rows)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/console-keep-data.md): See every table of a database with how long it keeps its rows, and set "keep only the last N months or years": the older days, months or years are dropped, the newest stay. Covers: The screen, Disk space - [Monitor panel (memory, processor, caches)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/console-monitor.md): What the server is doing right now - memory it holds, processor it uses, what each database keeps in memory, deferred trigger queues, and the statements running this second. Covers: Warnings and databases opening, The server process, Statements running now, Lanes, Slow statements, Timers, Each database, Server activity, What it does not show - [Settings page (data folder, old log, capacity, program files and users)](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/console-settings.md): Where the server keeps its data, how to point it at another folder, and who may log in - all from the console. Covers: Storage, Old log kept per database, Result cache, Backups, Calls from SQL, Capacity and waits, Program files, Users - [Comments and suggestions](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/feedback.md): How people who use a KDB server send comments, suggestions and problem reports, and how its admins read them. Covers: The page in the console, POST /api/feedback, GET /api/feedback, POST /api/feedback/ ## Geometry & CAD - [Survey, CAD and 3D data: points, drawings, blocks, meshes](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/geometry-and-cad.md): How to keep survey points, 2D drawings (lines, arcs, polylines, blocks, layers) and 3D meshes in KDB, load only the part a canvas can see, and do distance, area and volume maths in SQL - with the rule that the camera stays in the client. Covers: Coordinates and the one rule, Survey points and control, Raw observations, reduced in SQL, Drawings, layers and entities, Blocks and groups, Partial load: only what the canvas can see, The camera stays in the client, Save, open, undo and history, 3D: vertices, faces, volumes, Measurements in SQL, Limits and what would come next ## Performance tips - [Performance tips](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/performance-tips.md): Make loading and queries fast - memory, threads, batch commits, bulk INSERTs, good table design, time filters, what the column engine takes, zone maps, saved stats, and how to measure. Covers: Measure: timings and EXPLAIN, EXPLAIN lines to look for, Filter on time and symbol first, Parameters, variables and computed dates, LIMIT, LATEST ON with a time filter, Bulk INSERT: many rows per statement, Many small writes: --sync-commits batch, Memory: --memory, Big GROUP BY over a UNION, Threads: --threads, Result cache: --cache-mb, ... ## Limits - [Limits](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/limits.md): The sizes and counts KDB allows, what happens at each limit, and the features that are not there yet. Covers: Names, Values, Nesting, Rows, Writers, readers and transactions, Server and HTTP, Disk and memory, Switches for measuring, Not supported yet ## Quality - [Test report](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/test-report.md): How KDB is tested as of 2026-09-23, what each test proves, the real results, and what is not tested yet. Covers: Summary, Storage safety: crash, power cut, damage, A full disk, Dirty text and pattern attacks, SQL and server tests, Web console and HTTP API tests, Fuzz and stress, Soak, Linux and Docker, Help and tutorial examples, Not tested, or not finished - [Benchmark report](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/benchmark-report.md): How fast KDB is against QuestDB and PostgreSQL on the same PC, and what each engine change of 2026-09-23 gave, including where KDB is still slower and what is not measured. Covers: Setup, KDB vs QuestDB: time-series, 2026-09-12, KDB vs QuestDB: time-series re-run, 2026-09-23, Floor sheet: KDB vs QuestDB, News search: KDB vs PostgreSQL, App workload: KDB vs PostgreSQL, PostgreSQL wire protocol: KDB vs QuestDB, Indexes, and indexes built at open, Memory and disk, Engine changes of 2026-09-23, Where the time of one request goes, Where KDB is still slower, or not measured ## Data formats - [How KDB stores data](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/docs/data-formats.md): A short tour of the files in a KDB database folder - data files, blocks and checksums, the log, the manifest and backups. Covers: The database folder, Data files are never changed, Blocks and CRC32C checksums, The write-ahead log (WAL), The manifest: two copies, Backup folders, Indexes are not stored ## Optional - [All topics in one file](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/llms-full.txt): large; for an assistant that reads everything at once - [index.json](https://raw.githubusercontent.com/Amritshr/kdb-knowledge/main/index.json): topics, parts and keywords as JSON