— No reviews yet
0 installs
15 views
0.0% view→install
Install
$ agentstack add skill-chaterm-terminal-skills-postgresql ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Are you the author of Postgresql? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claimAbout
PostgreSQL 数据库管理
概述
PostgreSQL 数据库管理、扩展使用、查询优化等技能。
连接管理
# 本地连接
psql -U postgres
psql -U username -d database
# 远程连接
psql -h hostname -p 5432 -U username -d database
# 执行 SQL 文件
psql -U username -d database -f script.sql
# 执行单条命令
psql -U username -d database -c "SELECT version();"
psql 常用命令
\l -- 列出数据库
\c dbname -- 切换数据库
\dt -- 列出表
\d tablename -- 表结构
\du -- 列出用户
\dn -- 列出 schema
\df -- 列出函数
\di -- 列出索引
\q -- 退出
\? -- 帮助
\timing -- 显示执行时间
\x -- 扩展显示模式
用户与权限
-- 创建用户
CREATE USER username WITH PASSWORD 'password';
CREATE ROLE username WITH LOGIN PASSWORD 'password';
-- 创建超级用户
CREATE USER admin WITH SUPERUSER PASSWORD 'password';
-- 授权
GRANT ALL PRIVILEGES ON DATABASE dbname TO username;
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA public TO username;
GRANT USAGE ON SCHEMA schema_name TO username;
-- 设置默认权限
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT ON TABLES TO readonly_user;
-- 查看权限
\du username
SELECT * FROM information_schema.role_table_grants WHERE grantee = 'username';
-- 修改密码
ALTER USER username WITH PASSWORD 'newpassword';
数据库操作
-- 创建数据库
CREATE DATABASE dbname;
CREATE DATABASE dbname OWNER username ENCODING 'UTF8';
-- 删除数据库
DROP DATABASE dbname;
-- 查看数据库大小
SELECT pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname))
FROM pg_database ORDER BY pg_database_size(pg_database.datname) DESC;
-- 查看表大小
SELECT relname, pg_size_pretty(pg_total_relation_size(relid))
FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
备份与恢复
pg_dump
# 备份单个数据库
pg_dump -U username dbname > backup.sql
pg_dump -U username -Fc dbname > backup.dump # 自定义格式
# 备份所有数据库
pg_dumpall -U postgres > all_backup.sql
# 只备份结构
pg_dump -U username --schema-only dbname > schema.sql
# 只备份数据
pg_dump -U username --data-only dbname > data.sql
# 备份特定表
pg_dump -U username -t tablename dbname > table.sql
# 并行备份(大数据库)
pg_dump -U username -Fd -j 4 dbname -f backup_dir/
恢复
# 恢复 SQL 格式
psql -U username -d dbname 1000
ORDER BY n_dead_tup DESC;
-- 清理膨胀
VACUUM FULL tablename;
故障排查
| 问题 | 排查方法 | |------|----------| | 连接数过多 | pg_stat_activity, 检查 max_connections | | 查询慢 | EXPLAIN ANALYZE, 检查索引 | | 锁等待 | pg_locks, pg_stat_activity | | 磁盘满 | 检查 WAL、清理旧数据 | | 复制延迟 | pg_stat_replication |
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: chaterm
- Source: chaterm/terminal-skills
- License: Apache-2.0
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.