Files
shz-backend/.codex/skills/query-shz-highgo/SKILL.md

46 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: query-shz-highgo
description: 通过 SSH 网关和受保护的只读 psql 流程查询测试或生产环境中的 SHZ HighGo Security Enterprise Edition 数据库。适用于 Codex 在 shz-backend 项目中检查数据库 schema、表、列、行数或应用数据诊断数据相关行为或对项目 HighGo 数据库执行 SELECT、WITH、SHOW 或 EXPLAIN 语句。
---
# 查询 SHZ HighGo 数据库
使用随附脚本,通过已配置的 SSH 网关执行只读 SQL。省略环境参数时查询生产环境`test` 作为第一个参数传入以查询测试环境。
## 查询流程
1. 构造范围最小且有用的查询。检查数据行时增加较小的 `LIMIT`
2. 对陌生表,先检查 `information_schema.columns`,再查询业务数据。
3. 运行:
```bash
.codex/skills/query-shz-highgo/scripts/query.sh 'SELECT current_database(), current_user, current_schema()'
# 测试环境
.codex/skills/query-shz-highgo/scripts/query.sh test 'SELECT current_database(), current_user, current_schema()'
```
4. 总结查询结果,并区分返回的事实和推断。
脚本只接受以 `SELECT`、`WITH`、`SHOW` 或 `EXPLAIN` 开头的语句,拒绝多条语句,将 `search_path` 设置为 `shz,public`,启用数据库级只读模式,并设置 30 秒超时。不得绕过这些控制,也不得执行写入;除非用户明确要求,否则不得使用单独的可写流程。
## 发现 schema
列出用户表:
```bash
.codex/skills/query-shz-highgo/scripts/query.sh "SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('pg_catalog', 'information_schema') ORDER BY 1, 2"
```
检查列:
```bash
.codex/skills/query-shz-highgo/scripts/query.sh "SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_schema = 'shz' AND table_name = 'lowercase_table_name' ORDER BY ordinal_position"
```
HighGo 可能将未加引号的标识符以小写暴露,也可能将加引号的标识符保持精确大小写。无法确定拼写时,先查询 `information_schema`。
## 连接信息
只有在排查连接问题或更新端点时,才阅读 [references/connection.md](references/connection.md)。不得打印、引用或暴露密码文件。