Skip to content


Partitioned databases

A partitioned table is a splayed table that is further decomposed by grouping records having common values along a column of special type. The allowable special column types have the property that the underlying value is an integer: date, month, year and long.


Q for Mortals §14.3 Partitioned Tables

Segmented databases

File par.txt defines a top-level partitioning of a database into directories. Each row of par.txt is a directory path. Each such directory would itself be partitioned in the usual way, typically by date. The directories should not be empty. The par.txt file should be created in the main database directory.

par.txt is used to unify partitions of a database, presenting them as a single database for querying.

This is particularly useful in combination with multithreading. Starting the kdb+ process with secondary threads (see command line option -s), and where each partition in par.txt is on a separate local disk:

  • when the q process is started with secondary threads, the partitions in par.txt are allocated to secondary threads on a round-robin basis, i.e. if kdb+ is started with n secondary threads, then partition p is given to secondary thread p mod n. This gives maximum parallelization for queries over date ranges.

  • if also, the partitions in par.txt are on separate disks, this means that each thread gets its own disk or disks, and there should be no disk contention (i.e. not more than one thread issuing commands to any one disk). Ideally, there should be one disk per thread. Note that this works best where the disks have fully independent access paths CPU-disk controller-disk, but may be of little use with shared access due to disk contention, e.g. with SAN/RAID.

For example, par.txt might be:


with directories :

~$ ls /0/db
2009.06.01 2009.06.05 2009.06.11 ...

~$ ls /1/db
2009.06.02 2009.06.06 2009.06.12 ...


Some considerations

  • The data should be partitioned correctly across the partitions – i.e. data for a particular date should reside in the partition for that date.
  • The secondary/directory partitioning is for both read and write.
  • The directories pointed to in par.txt may only contain appropriate database subdirectories. Any other content (file or directory) will give an error.
  • The same subdirectory name may be in multiple par.txt partitions. For example, this would allow symbols to be split, as in A-M on /0/db, N-Z on /1/db (e.g. to work around the 2-billion row limit). Aggregations are handled correctly, as long as data is properly split (not duplicated). Note that in this case, the same day would appear on multiple partitions.

Q for Mortals §14.4 Segmented Tables

Table counts

For partitioned databases, q caches the count for a table, and this count cannot be updated from within a reval expression or from a secondary thread.

To avoid noupdate errors on queries on partitioned tables, put count table in your startup script.

count, maps, peach, reval, select
Errors, Parallel execution