Command line
machbase-neo serve
Start machbase-neo server process.
Flags
General flags
| flag | desc |
|---|---|
--host | listening network addr (default: 127.0.0.1)ex) --host 0.0.0.0 |
-c, --config | config file location ex) --config /data/machbase-neo.conf |
--pid | file path to save pid ex) --pid /data/machbase-neo.pid |
--data | path to database (default: ./machbase_home)ex) --data /data/machbase |
--file | path to files (default: .)ex) --file /data/files |
--backup-dir | path to the backup dir (default: ./backups)ex) --backup-dir /data/backups
Since v8.0.26 |
--pref | path to preference directory path. (default: ~/.config/machbase) |
--preset | database preset auto, fog, edge (default: auto)ex) --preset edge |
Database Sessions flags
Since v8.5.5| flag | desc |
|---|---|
--max-open-conn | the maximum number of open connections to the database. (default -1 unlimited) |
--max-idle-conn | the maximum number of connections in the idle connection pool. if <=0, no idle connections are retained.(default is 2) |
--conn-max-lifetime | the maximum amount of time a connection many be reused. Expired connections may be closed lazily before reuse. if <= 0, connections are not closed due to a connection’s age.(default is 10m) |
--conn-max-idletime | the maximum amount of time a connection may be idle. Expired connections may be closed lazily before resuse. if <= 0, connections are not closed due to a connection’s idle time.(default is 1m) |
Http flags
Since v8.0.43| flag | default | desc |
|---|---|---|
--http-linger | -1 | HTTP socket option, -1 means disable SO_LINGER, >=0 means set SO_LINGER |
--http-readbuf-size | 0 | HTTP socket read buffer size. 0 means use system default. |
--http-writebuf-size | 0 | HTTP socket write buffer size. 0 means use system default. |
--http-debug | false | Enable HTTP Ddebug log |
--http-debug-latency | "0" | Log HTTP requests that take longer than the specified duration to respond (e.g., “3s”). “0” means all request. |
--http-allow-statz | Allow source IPs (comma separated) to access /db/statz API. default allows only 127.0.0.1. |
Log flags
| flag | default | desc |
|---|---|---|
--log-filename | - (stdout) | log file path ex) --log-filename /data/logs/machbase-neo.log |
--log-level | INFO | log level. TRACE, DEBUG, INFO, WARN, ERROR ex) --log-level INFO |
--log-append | true | append existing log file. |
--log-rotate-schedule | @midnight | time scheduled log file rotation |
--log-max-size | 10 | file max size in MB |
--log-max-backups | 1 | maximum log file backups |
--log-max-age | 7 | maximum days in backup files |
--log-compress | false | gzip compress the backup files |
--log-time-utc | false | use UTC time for logging |
Listener flags
| flag | default | desc |
|---|---|---|
--shell-port | 5652 | ssh listen port |
--mqtt-port | 5653 | mqtt listen port |
--mqtt-sock | /tmp/machbase-neo-mqtt-5653.sock | mqtt unix socket |
--http-port | 5654 | http listen port |
--http-sock | /tmp/machbase-neo-http-5654.sock | http unix socket |
--mach-port | 5656 | machbase native listen port |
Since the default of
--host is the loopback address, it is not allowed to access machbase-neo from the remote hosts.Set
--host <host-address> or --host 0.0.0.0 for accepting the network connections from remote clients.If execute machbase-neo serve with no flags,
$ machbase-neo serveit is equivalent with
$ machbase-neo serve --host 127.0.0.1 --data ./machbase_home --file . --preset automachbase-neo shell
Start machbase-neo shell. It will start interactive mode shell if there are no other arguments.
Flags
| flag (long) | default | desc |
|---|---|---|
-s, --server | 127.0.0.1:5654 | machbase-neo’s HTTP address. e.g. --server 127.0.0.1:5654env: NEOSHELL_HOST |
--user | sys | user name. env: NEOSHELL_USER |
--password | manager | password. env: NEOSHELL_PASSWORD |
When machbase-neo shell starts, it is looking for the user name and password
from OS’s environment variables NEOSHELL_HOST, NEOSHELL_USER and NEOSHELL_PASSWORD.
Then if the flags --server, --user and --password are provided,
it will override the provided values instead of the environment variables.
Precedence of username and password
Command line flags
If --server, --user, --password is provided? Use the given values
Environment variables
If $NEOSHELL_HOST (on windows %NEOSHELL_HOST%) is set? Use the value as the server address.
If $NEOSHELL_USER (on windows %NEOSHELL_USER%) is set? Use the value as the user name.
If $NEOSHELL_PASSWORD (on windows %NEOSHELL_PASSWORD%) is set? Use the value as the password.
Default
None of those are provided? Use default value 127.0.0.1:5654, sys and manager.
Practical usage
For the security, use instant environment variables as below example.
$ NEOSHELL_PASSWORD='my-secret' machbase-neo shell --user sysBe aware when you use --password flag, the secret can be exposed by simple ps command as like an example below.
$ machbase-neo shell --user sys --password manager$ ps -aef |grep machbase-neo
501 13551 3598 0 9:33AM ttys000 0:00.07 machbase-neo shell --user sys --password managerRun Query
machbase-neo» select binary_signature from v$version;
┌────────┬─────────────────────────────────────────────┐
│ ROWNUM │ BINARY_SIGNATURE │
├────────┼─────────────────────────────────────────────┤
│ 1 │ 8.0.2.develop-LINUX-X86-64-release-standard │
└────────┴─────────────────────────────────────────────┘
a row fetched.Create Table
machbase-neo» create tag table if not exists example (
name varchar(20) primary key,
time datetime basetime,
value double summarized
);
executed.Schema Table
machbase-neo» desc example;
┌────────┬───────┬──────────┬────────┐
│ ROWNUM │ NAME │ TYPE │ LENGTH │
├────────┼───────┼──────────┼────────┤
│ 1 │ NAME │ varchar │ 20 │
│ 2 │ TIME │ datetime │ 8 │
│ 3 │ VALUE │ double │ 8 │
└────────┴───────┴──────────┴────────┘Insert Table
machbase-neo» insert into example values('tag0', to_date('2021-08-12'), 100);
a row inserted.Select Table
machbase-neo» select * from example;
┌────────┬──────┬─────────────────────┬───────┐
│ ROWNUM │ NAME │ TIME(LOCAL) │ VALUE │
├────────┼──────┼─────────────────────┼───────┤
│ 1 │ tag0 │ 2021-08-12 00:00:00 │ 100 │
└────────┴──────┴─────────────────────┴───────┘
a row fetched.Drop Table
machbase-neo» drop table example;
executed.Sub commands
explain
Syntax explain [--full] <sql>
Shows the execution plan of the sql.
machbase-neo» explain select * from example where name = 'tag.1';
PROJECT
TAG READ (RAW)
KEYVALUE INDEX SCAN (_EXAMPLE_DATA_0)
[KEY RANGE]
* IN ()
VOLATILE INDEX SCAN (_EXAMPLE_META)
[KEY RANGE]
*export
export [options] <table>
arguments:
table table name to read
options:
-o,--output <file> output file (default:'-' stdout)
-f,--format <format> output format
csv csv format (default)
json json format
--compress <method> compression method [gzip] (default is not compressed)
--[no-]heading print header message (default:false)
--[no-]footer print footer message (default:false)
-d,--delimiter csv delimiter (default:',')
--tz timezone for handling datetime
-t,--timeformat time format [ns|ms|s|<timeformat>] (default:'ns')
consult "help timeformat"
-p,--precision <int> set precision of float value to force roundimport
import [options] <table>
arguments:
table table name to write
options:
-i,--input <file> input file, (default: '-' stdin)
-f,--format <fmt> file format [csv] (default:'csv')
--compress <alg> input data is compressed in <alg> (support:gzip)
--no-header there is no header, do not skip first line (default)
--charset set character encoding, if input is not UTF-8
--header first line is header, skip it
--method write method [insert|append] (default:'insert')
--create-table create table if it doesn't exist (default:false)
--truncate-table truncate table ahead importing new data (default:false)
-d,--delimiter csv delimiter (default:',')
--tz timezone for handling datetime
-t,--timeformat time format [ns|ms|s|<timeformat>] (default:'ns')
consult "help timeformat"
--eof <string> specify eof line, use any string matches [a-zA-Z0-9]+ (default: '.')show info
Display the server information.
machbase-neo» show info;
┌────────────────────┬─────────────────────────────┐
│ NAME │ VALUE │
├────────────────────┼─────────────────────────────┤
│ build.version │ v2.0.0 │
│ build.hash │ #c953293f │
│ build.timestamp │ 2023-08-29T08:08:00 │
│ build.engine │ static_standard_linux_amd64 │
│ runtime.os │ linux │
│ runtime.arch │ amd64 │
│ runtime.pid │ 57814 │
│ runtime.uptime │ 2h 30m 57s │
│ runtime.goroutines │ 45 │
│ mem.sys │ 32.6 MB │
│ mem.heap.sys │ 19.0 MB │
│ mem.heap.alloc │ 9.7 MB │
│ mem.heap.in-use │ 13.0 MB │
│ mem.stack.sys │ 1,024.0 KB │
│ mem.stack.in-use │ 1,024.0 KB │
└────────────────────┴─────────────────────────────┘show ports
Display the server’s interface ports
machbase-neo» show ports;
┌─────────┬────────────────────────────────────────┐
│ SERVICE │ PORT │
├─────────┼────────────────────────────────────────┤
│ http │ tcp://127.0.0.1:5654 │
│ mach │ tcp://127.0.0.1:5656 │
│ mqtt │ tcp://127.0.0.1:5653 │
│ shell │ tcp://127.0.0.1:5652 │
└─────────┴────────────────────────────────────────┘show tables
Syntax: show tables [FROM <database>[.<user>]] [LIKE <pattern>] [WITH ALL]
Some show sub commands support the FROM and LIKE clauses.
FROM <database>[.<user>] selects the database and user scope to inspect, and LIKE <pattern> filters the result by name pattern.
The LIKE pattern is a quoted SQL LIKE pattern. % matches zero or more characters, and _ matches one character.
IN can be used as an alias of FROM.
WITH ALL includes hidden items.
machbase-neo» show tables from MACHBASEDB.SYS like 'TAG%' with all;
machbase-neo» show indexes like 'IDX_%';| command | FROM | LIKE | WITH ALL | LIKE target |
|---|---|---|---|---|
show tables | O | O | O | table name |
show indexes | O | O | - | index name |
show table <table> | O | - | O | - |
show index <index> | O | - | - | - |
show tags <table> [tag...] | O | O | - | tag name |
show storage | O | O | - | table name |
show table-usage | O | O | - | table name |
show lsm | O | O | - | table name |
show indexgap | O | O | - | table name |
show tagindexgap | O | O | - | table name |
show rollupgap | O | O | - | table name |
show users | - | O | - | user name |
show databases | - | O | - | database name |
show meta-tables | - | O | - | table name |
show virtual-tables | - | O | - | table name |
show sessions | - | O | - | user name |
show statements | - | O | - | query text |
Commands that take a target name, such as show table, show index, and show tags, cannot use a qualified <database>.<user>.<name> argument together with a FROM clause.
For show tags, LIKE cannot be used together with explicit tag-name arguments.
Display the table list. If WITH ALL is specified, the result includes the hidden tables.
machbase-neo» show tables;
┌────────┬────────────┬──────┬─────────────┬───────────┐
│ ROWNUM │ DB │ USER │ NAME │ TYPE │
├────────┼────────────┼──────┼─────────────┼───────────┤
│ 1 │ MACHBASEDB │ SYS │ EXAMPLE │ Tag Table │
│ 2 │ MACHBASEDB │ SYS │ TAG │ Tag Table │
│ 3 │ MACHBASEDB │ SYS │ TAGDATA │ Tag Table │
└────────┴────────────┴──────┴─────────────┴───────────┘show table
Syntax: show table <table> [WITH ALL]
Display the column list of the table. If WITH ALL is specified, the result includes the hidden columns.
machbase-neo» show table example with all;
┌────────┬───────┬──────────┬────────┬──────────┐
│ ROWNUM │ NAME │ TYPE │ LENGTH │ DESC │
├────────┼───────┼──────────┼────────┼──────────┤
│ 1 │ NAME │ varchar │ 100 │ tag name │
│ 2 │ TIME │ datetime │ 31 │ basetime │
│ 3 │ VALUE │ double │ 17 │ │
│ 4 │ _RID │ long │ 20 │ │
└────────┴───────┴──────────┴────────┴──────────┘show indexes
Syntax: show indexes [FROM <database>[.<user>]] [LIKE <pattern>]
Display the index list. Use FROM to select the scope and LIKE to filter index names.
machbase-neo» show indexes from MACHBASEDB.SYS like 'TAG%';show meta-tables
machbase-neo» show meta-tables;
┌────────┬─────────┬────────────────────────┬─────────────┐
│ ROWNUM │ ID │ NAME │ TYPE │
├────────┼─────────┼────────────────────────┼─────────────┤
│ 1 │ 1000020 │ M$SYS_TABLESPACES │ Fixed Table │
│ 2 │ 1000024 │ M$SYS_TABLESPACE_DISKS │ Fixed Table │
│ 3 │ 1000049 │ M$SYS_TABLES │ Fixed Table │
│ 4 │ 1000051 │ M$TABLES │ Fixed Table │
│ 5 │ 1000053 │ M$SYS_COLUMNS │ Fixed Table │
│ 6 │ 1000054 │ M$COLUMNS │ Fixed Table │
......show virtual-tables
machbase-neo» show virtual-tables;
┌────────┬─────────┬─────────────────────────────────────────┬────────────────────┐
│ ROWNUM │ ID │ NAME │ TYPE │
├────────┼─────────┼─────────────────────────────────────────┼────────────────────┤
│ 1 │ 65 │ V$HOME_STAT │ Fixed Table (stat) │
│ 2 │ 93 │ V$DEMO_STAT │ Fixed Table (stat) │
│ 3 │ 227 │ V$SAMPLEBENCH_STAT │ Fixed Table (stat) │
│ 4 │ 319 │ V$TAGDATA_STAT │ Fixed Table (stat) │
│ 5 │ 382 │ V$EXAMPLE_STAT │ Fixed Table (stat) │
│ 6 │ 517 │ V$TAG_STAT │ Fixed Table (stat) │
......show users
machbase-neo» show users;
┌────────┬───────────┐
│ ROWNUM │ USER_NAME │
├────────┼───────────┤
│ 1 │ SYS │
└────────┴───────────┘
a row fetched.show license
machbase-neo» show license;
┌────────┬──────────┬──────────────┬──────────┬────────────┬──────────────┬─────────────────────┐
│ ROWNUM │ ID │ TYPE │ CUSTOMER │ PROJECT │ COUNTRY_CODE │ INSTALL_DATE │
├────────┼──────────┼──────────────┼──────────┼────────────┼──────────────┼─────────────────────┤
│ 1 │ 00000023 │ FOGUNLIMITED │ VUTECH │ FORESTFIRE │ KR │ 2024-04-22 15:56:14 │
└────────┴──────────┴──────────────┴──────────┴────────────┴──────────────┴─────────────────────┘
a row fetched.session list
Syntax: session list
Since v8.0.17
machbase-neo» session list;
┌────┬───────────┬─────────┬────────────┬─────────┬─────────┬──────────┐
│ ID │ USER_NAME │ USER_ID │ STMT_COUNT │ CREATED │ LAST │ LAST SQL │
├────┼───────────┼─────────┼────────────┼─────────┼─────────┼──────────┤
│ 25 │ SYS │ 1 │ 1 │ 1.667ms │ 1.657ms │ CONNECT │
└────┴───────────┴─────────┴────────────┴─────────┴─────────┴──────────┘session kill
Syntax session kill <ID>
Since v8.0.17
session stat
Syntax: session stat
Since v8.0.17
machbase-neo» session stat;
┌────────────────┬───────┐
│ NAME │ VALUE │
├────────────────┼───────┤
│ CONNS │ 1 │
│ CONNS_USED │ 17 │
│ STMTS │ 0 │
│ STMTS_USED │ 20 │
│ APPENDERS │ 0 │
│ APPENDERS_USED │ 0 │
│ RAW_CONNS │ 1 │
└────────────────┴───────┘desc
Syntax desc [-a] <table>
Describe table structure.
machbase-neo» desc example;
┌────────┬───────┬──────────┬────────┬──────────┐
│ ROWNUM │ NAME │ TYPE │ LENGTH │ DESC │
├────────┼───────┼──────────┼────────┼──────────┤
│ 1 │ NAME │ varchar │ 100 │ tag name │
│ 2 │ TIME │ datetime │ 31 │ basetime │
│ 3 │ VALUE │ double │ 17 │ │
└────────┴───────┴──────────┴────────┴──────────┘machbase-neo restore
Syntax machbase-neo restore --data <machbase_home_dir> <backup_dir>
Since v8.0.17
Restore database from backup.
$ machbase-neo restore --data <machbase home dir> <backup dir>machbase-neo version
Show version and engine info.

machbase-neo gen-config
Prints out default config template.
$ machbase-neo gen-config ↵
define DEF {
LISTEN_HOST = flag("--host", "127.0.0.1")
SHELL_PORT = flag("--shell-port", "5652")
MQTT_PORT = flag("--mqtt-port", "5653")
HTTP_PORT = flag("--http-port", "5654")
......