What environment variables do I need to know about when kdb starts up?

Here are several environment variables used by q during initialization:

You can read the value of any environment variable with the getenv function:

q)getenv `PATH

When I launch kdb with a directory, what exactly happens on start up and in what order?

The short answer is, q initializes itself, loads data, then code.

The exact sequence is as follows:

  1. load $QHOME/q.k
  2. load $QINIT/q.q or $QHOME/q.q
  3. load tables contained in /directorypath
  4. load scripts /directorypath/*.q (and *.k or .s) in alphabetical order

How can I have kdb automatically load q code at startup in every session?

Every time you start q, it looks for a file called q.q (in $QHOME, if defined, or current working directory otherwise). If q finds q.q, it will execute it before presenting a prompt or calling any script you provided on the command line.

If you want to call the file something else, or keep it separate from your q installation, you can set the environment variable QINIT to the path to your initialization file.

It is also possible to add k code to q.k (which will be executed before q.q), although we’ve never needed to.

This work is licensed under a Creative Commons License.
Kdb+ is the registered trademark of Kx Systems, Inc.