现场保存工具 - minirepro

在使用 YMatrix 的过程中,你可能会遇到如下问题:

  • 慢查询
  • 查询执行失败等

当遇到如上问题的时候,需要技术支持人员介入进行故障诊断,而技术人员做故障诊断则需要复原现场。minirepro 就是做现场保存的工具,只需要提供执行的 SQL,就可以通过该工具生成现场环境,供技术人员在本地环境复现并追查。

1 minirepro 使用方法

minirepro 会随着 YMatrix 一起安装在 $GPHOME/bin/minirepro。可以通过如下命令查看使用方法:

[mxadmin@mdw ~]$ minirepro --help
Usage: minirepro <database> [options]

Options:
  --version             show program's version number and exit
  -?, --help            Show this help message and exit
  -h HOST, --host=HOST  Specify a remote host
  -p PORT, --port=PORT  Specify a port other than 5432
  -U USER, --user=USER  Connect as someone other than current user
  -q QUERY_FILE         file name that contains the query
  -f OUTPUT_FILE        minirepro output file name
  -l, --hll             Include HLL stats

WARNING: This tool collects statistics about your data, including most common
values, which requires some data elements to be included in the output file.
Please review output file to ensure it is within corporate policy to transport
the output file.

使用 minirepro 做 SQL 执行现场保存首先要将 SQL 语句存放在文件中。如:要保存 SQL 语句 SELECT * FROM data; 执行现场,将其保存在文件 query.sql 中:

[mxadmin@mdw ~]$ cat query.sql
SELECT * FROM data;

然后执行命令,连接数据库并指定 SQL 文件和输出文件:

[mxadmin@mdw ~]$ minirepro mxadmin -h 127.0.0.1 -U mxadmin -p 5432 -q query.sql -f outfile.sql
Connecting to database: host=127.0.0.1, port=5432, user=mxadmin, db=mxadmin ...
Extracting metadata from query file query.sql ...
psql mxadmin --pset footer --no-psqlrc -Atq -h 127.0.0.1 -p 5432 -U mxadmin -f /tmp/20210729132431/toolkit.sql
Invoking pg_dump to dump DDL ...
pg_dump -h 127.0.0.1 -p 5432 -U mxadmin -sxO mxadmin --relation-oids 32820 --function-oids 0 -f /tmp/20210729132431/pg_dump_out.sql
Writing schema DDLs ...
Writing relation and function DDLs ...
Writing table statistics ...
Writing column statistics ...
Attaching raw query text ...
--- MiniRepro completed! ---
WARNING: This tool collects statistics about your data, including most common values, which requires some data elements to be included in the output file.
Please review output file to ensure it is within corporate policy to transport the output file.

这样,现场环境就保存到了 outfile.sql 文件中,其内容包含了数据表和相关 catalog 信息。将该文件提供给技术人员即可。