tikv-ctl的简单学习

发布时间 2023-08-07 21:59:07作者: 济南小老虎

tikv-ctl的简单学习


摘要

最近在学习使用 tidb.
有一个场景,单独使用了tikv作为键值对的数据库. 
但是比较不幸.总是出现宕机的情况 
因为这个环境是单独使用tikv 二进制进行安装的
没有grafana和dashboard的界面. 比较难以处理.
只能想着使用tikv-ctl等工具进行一些简单处理. 

部署方式

计划使用 tiup 进行部署.
因为能上网, 所以比较简单处理, 就不进行无网络的处理了 

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
source /root/.bash_profile 

安装 ctl
tiup ctl:v7.2.0
然后修改一下环境变量
echo "PATH=\$PATH:/root/.tiup/components/ctl/v7.2.0/ " >>/root/.bash_profile 
source /root/.bash_profile

需要注意 tiup 其实就将 ctl 安装到默认的一个版本目录下面:
/root/.tiup/components/ctl/v7.2.0/
增加上环境变量后就可以使用 直接使用ctl相关的命令了. 

命令学习

1. 查看regions 是否健康
tikv-ctl --data-dir=/data/tikv/data/tikv1 bad-regions
需要注意, 这个命令必须离线才能够验证. 在线是无法验证的. 
正常会如此提示: all regions are healthy

2. 查看所有的键值对
tikv-ctl --data-dir=/data/tikv/data/tikv1  raw-scan --limit=99999 >/root/zhaobsh.txt 
最后会将键值对的 总数给罗列出来. 

3. 查看第二个regions的相关信息.
tikv-ctl  --data-dir=/data/tikv/data/tikv1 size -r 2

4. tikv查看具体的键值信息:
tikv-ctl  --data-dir=/data/tikv/data/tikv1 print -k  zzhaohankey

5. ldb的指令
比较复杂, 参看下面

ldb的帮助信息

# 我怀疑是 rocksDB 复用了 levelDB的命令行工具
# 可以执行备份和恢复的操作. 也可以dump 所有的key 信息. 
# 感觉与redis 有一些相似. 
ldb - RocksDB Tool

commands MUST specify --db=<full_path_to_db_directory> when necessary

Data Access Commands:
  put <key> <value> [--create_if_missing] [--ttl]
  get <key> [--ttl]
  batchput <key> <value> [<key> <value>] [..] [--create_if_missing] [--ttl]
  scan [--from] [--to]  [--ttl] [--timestamp] [--max_keys=<N>q]  [--start_time=<N>:- is inclusive] [--end_time=<N>:- is exclusive] [--no_value]
  delete <key>
  deleterange <begin key> <end key>
  query [--ttl]
    Starts a REPL shell.  Type help for list of available commands.
  approxsize [--from] [--to]
  checkconsistency
  list_file_range_deletes [--max_keys=<N>] : print tombstones in SST files.


Admin Commands:
  dump_wal --walfile=<write_ahead_log_file_path> [--header]  [--print_value]  [--write_committed=true|false]
  compact [--from] [--to]
  reduce_levels --new_levels=<New number of levels> [--print_old_levels]
  change_compaction_style --old_compaction_style=<Old compaction style: 0 for level compaction, 1 for universal compaction> --new_compaction_style=<New compaction style: 0 for level compaction, 1 for universal compaction>
  dump [--from] [--to]  [--ttl] [--max_keys=<N>] [--timestamp] [--count_only] [--count_delim=<char>] [--stats] [--bucket=<N>] [--start_time=<N>:- is inclusive] [--end_time=<N>:- is exclusive] [--path=<path_to_a_file>]
  load [--create_if_missing] [--disable_wal] [--bulk_load] [--compact]
  manifest_dump [--verbose] [--json] [--path=<path_to_manifest_file>] [--sst_file_number=<sst_file_number>]
  file_checksum_dump [--path=<path_to_manifest_file>]
  get_property <property_name>
  list_column_families
  create_column_family --db=<db_path> <new_column_family_name>
  drop_column_family --db=<db_path> <column_family_name_to_drop>
  dump_live_files
  idump [--from] [--to]  [--input_key_hex] [--max_keys=<N>] [--count_only] [--count_delim=<char>] [--stats]
  list_live_files_metadata [--sort_by_filename]
  repair [--verbose]
  backup [--backup_env_uri | --backup_fs_uri]  [--backup_dir]  [--num_threads]  [--stderr_log_level=<int (InfoLogLevel)>]
  restore [--backup_env_uri | --backup_fs_uri]  [--backup_dir]  [--num_threads]  [--stderr_log_level=<int (InfoLogLevel)>]
  checkpoint [--checkpoint_dir]
  write_extern_sst <output_sst_path>
  ingest_extern_sst <input_sst_path> [--move_files]  [--snapshot_consistency]  [--allow_global_seqno]  [--allow_blocking_flush]  [--ingest_behind]  [--write_global_seqno]
  unsafe_remove_sst_file <SST file number>      MUST NOT be used on a live DB.