更多命令
ha getmode
在将 xSQL 用作 SmartEDB 高可用性主节点或副本节点时,ha getmode 会显示 xSQL 实例的当前高可用性角色。对于主节点,它还会打印出高可用性模式标志:
XSQL>ha getmode
Running in MASTER mode, options are : HOTSYNCH
相应的函数 xsql_ha_get_mode() 在 xSQL 以主模式运行时返回 MCO_HAMODE_* 标志的总和,在以副本模式运行时返回 0 。
sleep
正如 xSQL 教程中所解释的那样,有时将一组 SQL 语句写入脚本文件,然后使用脚本命令执行该脚本是有用的。但有时可能需要在 SQL 语句之间暂停一小段时间。例如,假设我们有一个如下所示的脚本文件,在一个集群节点上插入一条记录,然后在另一个节点上查询数据以验证更改是否已传播。这里需要在这两行之间短暂暂停,这通过 sleep 命令来实现:
File test_sleep.sql
1:create table t(n int);
1:insert into t values([1,2,3]);
sleep 3
2:select * from t;
echo
在运行脚本文件时,在脚本执行期间显示进度或状态信息可能会很有用。为此提供了 echo [字符串] 命令。它将字符串参数写入标准输出(类似于在 bash 或任何其他 UNIX shell 中的 echo)。例如,上面的 test_sleep 脚本可以修改如下:
File test_sleep.sql
1:create table t(n int);
1:insert into t values([1,2,3]);
echo Sleep for 3 seconds
sleep 3;
2:select * from t;
help
帮助命令会显示 xSQL 命令的简短语法描述。例如:
XSQL>help
<sql-statement>';' any valid SQL statement
dumplog <file-path> Dump XSQL logs on the server side
xlog [bynode|byquery] [all]Show server's logs
cluster Cluster related commands
sleep Do sleep for N seconds
shutdown Shutdown database server
save <file-path> Save database image to specified file
saveclass <file-path> <table-name>Save table content to the specified file
loadclass <file-path> [ <table-name> ]Load table content from the specified file
savemeta <file-path> Save database metadata to specified file
savedict <file-path> Save database dictionary to specified file
detach Do not close database on exit (leave it in shared memory)
backup <database-file-path> <log-file-path> <n-threads=1>Online backup of disk database to the specified files
mem [-b|-k|-m|-g|-t|-p] Show memory usage in bytes (-b), Kb (-k, default), Mb (-m), Gb (-g), Tb (-t) or memory pages (-p)
memddl Show dictionary memory usage
exit Terminate interactive SQL session
pause Pause interactive SQL session
trace (on|off) Toggle query execution trace
progress (on|off) Show progress of query execution
input (<file>|console) Redirect input from specified file
script <file-path> Execute SQL script from specified file
output [<file>|console|null]Redirect output to specified file
logsession (on|off) [<file>]Save session to specified file
format (TEXT|HTML|XML|CSV [delimiter 'C'][header on|off]|LIST)Select query output format
dtformat FORMAT Output date/time format (see strftime)
numformat FORMAT Output real number format (see sprintf)
strformat width=<N> Set width for string fields
seqformat {default|short|long} [<first> <last>]Output sequences format.
arrayformat {default|short|long} [<first> <last>]Output arrays format.
nullformat NULLSTR String representation for null values
help Print supported commands
echo Print arguments
import TABLE CSV-FILE [(use|skip) header] [commit N]Import data from CSV file