Programming/Kdb/Installing kdb
Kdb+/q
Downloading
Kdb+/q can be downloaded from https://kx.com/developers/download-licenses/.
In particular, there are two free versions of kdb+/q: the 32 Bit Personal Edition and the 64 Bit Personal Edition (On-Demand).
Both editions are licensed for personal use.
The 32 Bit Personal Edition:
- is permitted to run on-premises;
- is permitted to run on cloud;
- provides access to KX Fusion interfaces and integrations;
- provides access to community support;
- Linux/Mac/Windows/Raspberry pi versions are available.
The main limitation of the 32 Bit Personal Edition and, more generally, of any 32-bit program, is that it can only ever use up to 4 GB of memory. That's due to the 32-bit address space, since 2^32 = 4,294,967,296 bytes. For some use cases this may be a serious limitation.
The 64 Bit Personal Edition (On-Demand):
- requires "always on" internet connection;
- is permitted to run on-premises;
- is compatible with KX Developer and KX Dashboards Direct;
- provides access to KX Fusion interfaces and integrations;
- provides access to community support;
- gives regular access to upgrades;
- Linux/Mac/Windows versions are available.
The 32 Bit Personal Edition can be downloaded immediately, whereas for the 64 Bit Personal Edition (On-Demand) you would need to request a license. Both editions are available via https://kx.com/developers/download-licenses/.
Installing
Kdb+/q can be installed on Linux, macOS, or Windows.
There are three installation scenarios:
- You are a commercial user, with a k4.lic file.
- You have the 64 Bit Personal Edition On Demand for non-commercial use. This is enabled by a kc.lic license-key file and requires an always-on internet connection. (This version of kdb+ is not licensed for use on cloud servers.)
- You have the 32 Bit Personal Edition for non-commercial use. It does not require a license-key file.
The first step is to download kdb+/q from https://kx.com/developers/download-licenses/.
Once you have downloaded the archive, unzip it to:
- ~/q on Linux;
- ~/q on macOS;
- C:\q on Windows.
Here ~ represents your HOME directory.
You can use the command line to unzip the archive. On Linux:
unzip l64.zip -d $HOME/q
On macOS:
unzip m64.zip -d $HOME/q
On Windows (PowerShell):
Expand-Archive w64.zip -DestinationPath C:\q
It is possible to install kdb+/q to another directory, however, if you install it to a different directory from the ones listed above, you need to set the QHOME environment variable to point to that directory. You can install kdb+ anywhere as long as you set the path in QHOME.
Note that 32-bit applications will not run in macOS 10.15+ (Catalina and later).
Thus you end up with the following directory structure:
- C:\ (for example)
- q
- w32 (or w64)
- q.exe
- q.k
- q.q
- README.txt
- s.k
- sp.q
- trade.q
- w32 (or w64)
- q
Tips and tricks
Running 32-bit kdb+ on 64-bit Linux
Use the
uname -m
command to determine whether your machine is using the 32-bit or 64-bit Linux distribution.
If the result is
- i686 or i386 or similar, you are running a 32-bit Linux distribution;
- x86_64, you are running a 64-bit Linux distribution.
To install 32-bit kdb+ on a 64-bit Linux distribution, you need a 32-bit library. Use your usual package manager to install i686 or i386, for example:
sudo apt-get install libc6-i386
For more details on how to run 32-bit programs on Ubuntu 64-bit, see https://askubuntu.com/questions/454253/how-to-run-32-bit-app-in-ubuntu-64-bit.
rlwrap
On Linux and macOS the rlwrap command allows the Up arrow to retrieve earlier expressions in the q session. It is very useful and we recommend installing it.
Ask for its version number:
rlwrap -v
If you see one, rlwrap is already installed. Otherwise, you will see
rlwrap: command not found.
Install rlwrap using your package manager. (Common package managers: apt, dnf, and yum for Linux; Homebrew and MacPorts for macOS.)
It is straightforward to "wrap" the q process into rlwrap:
rlwrap ~/q/l64/q
taskset
If your machine has many cores, you may encounter the following error:
'licence error: cores
This means you are trying to run kdb+/q on a machine with two many cores. The number of licensed cores appears in parentheses in the message that appears when you launch kdb+/q. For example:
KDB+ 4.0 2020.05.04 Copyright (C) 1993-2020 Kx Systems l64/ 72(16)core 1029691MB paul ...
This means that kdb+/q is running on a machine with 72 cores, but only 16 of them are covered by the license.
In this situation you have to restrict the cores visible to the kdb+/q process using taskset. According to the documentation,
taskset is used to set or retrieve CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs [or CPU cores] on the system. The Linux scheduler will honour the given CPU affinity and the process will not run on any other CPUs.
For example, we could run the q process as follows:
rlwrap taskset -c 0,1,2,3,4,5,6,7,8,9,10,11 ~/q/l64/q
In our example, this will force kdb+/q to use only the cores from 0 to 11 (inclusive) and will resolve the "cores" error.
Integrated development environments (IDEs)
There is no one-size-fits-all IDE for kdb+/q. Therefore we recommend that the reader download some/all of the tools listed above and give them a try.
Q Insight Pad (Windows-only)
Q Insight Pad (sometimes referred to simply as qPad) by Oleg G. Zakharov is a kdb+ client, written in C++ to run under Windows; as a result, it is fast, memory-efficient and easy to use. The author makes a special emphasis on providing a Windows-style GUI that is visual, simple and intuitive.
Q Insight Pad provides simple but useful visualization capabilities.
An unregistered but fully functional version (working with free versions of q) can be downloaded for free from http://www.qinsightpad.com/.
This version expires every 3 months. If you want to license Q Insight Pad for use in your organization, contact the author: http://www.qinsightpad.com/contact.html.
qStudio
qStudio by TimeStored is an intelligent code editor for kdb+/q that provides:
- q syntax highlighting;
- q code completion;
- ability to query servers direct from the editor;
- server browser for viewing server objects;
- charts for displaying your data;
- database management tools to modify your database structure;
- a data loader for importing large data files easily;
- language programming tools to increase programmer productivity:
- qDoc for generating HTML documentation;
- qUnit — a unit testing framework for kdb.
qStudio can be downloaded from http://www.timestored.com/qstudio/.
qStudio Pro can be purchased from http://www.timestored.com/qstudio/buy.
This application requires a Java Runtime Environment 1.8.0_66 or above.
Studio for kdb+
Studio for kdb+ is a rapid development environment for kdb+. In the style of commonly used SQL clients, it allows you to
- connect to kdb+ processes;
- execute selected text from the editor window;
- view results as tables, charts, or classic console style.
The editor component is based on the NetBeans editor component, and includes the following features:
- find/search/replace;
- cut/copy/paste;
- undo/redo;
- syntax highlighting for the q language;
- most recent files menu.
Additionally, the application features:
- export to Excel;
- drag and drop;
- immediate charting of grid data.
Studio for kdb+ is free, provided under the Apache 2 license, and can be downloaded from https://github.com/CharlesSkelton/studio.
The program is portable and comes in the form of a JAR file. You need the Java runtime environment (JRE) to run it:
java -jar studio.jar