2

Is there a simple way to save all tables,variables and fucntions and then reload them into another kdb+ instance? For example, lets say my machine is set to restart weekly but I want reload everything that was in my kdb+ session before the restart.

Thanks.

Rtrader
  • 917
  • 4
  • 11
  • 26

2 Answers2

2

If you want something out of the box for maintaining variable state(tables/dicts/lists/atom), then have a look at http://code.kx.com/q/cookbook/logging/

/cmdline startup
q db_main -l -p 8090

/To store state before the restart, modify .z.exit to flush to the qdb file 
.z.exit:{value"\\l"}

This will not cover functions however, but ideally these shouldn't be changing anyway.

If you really need to save these you can look at saving all namespaces to disk.

.z.exit:{`:/tmp/ns set get each {x!x}`$".",/:string key`}

/on startup
{{y set x[y]}[x;]each key x} `.q`.Q _ get `:/tmp/ns

Regards,

Connor

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Connor Gervin
  • 935
  • 5
  • 16
1

Save the state to file using set/get. This is limited to small workspaces.

>q
KDB+ 3.4 2016.06.14 Copyright (C) 1993-2016 Kx Systems

q)a:1
q)t:([] b:til 100)
q)s:select from t where b<5
q)`:session.bin set get `.
`:session.bin
q)\\

>q
KDB+ 3.4 2016.06.14 Copyright (C) 1993-2016 Kx Systems

q)`. set get `:session.bin
`.
q)a
1
q)s
b
-
0
1
2
3
4

Logging and snapshots is an alternative: http://www.timestored.com/kdb-guides/kdb-command-line-options#kdb-logging-replication

Ryan Hamilton
  • 2,601
  • 16
  • 17