postgresql

postgresql is a skill for Claude Code, Codex from chaterm/terminal-skills. It costs 9 tokens per session (1,601 once invoked), scanned A, original, Apache-2.0.

A guide for administering PostgreSQL, a database system that stores application data and supports SQL queries. It covers connections, users and permissions, database objects, backups, extensions, and query optimisation.

In plain words
What is it for?
Use it to connect locally or remotely, run SQL files and queries, inspect databases, tables, schemas, indexes, and functions, manage roles and grants, and check query timing.
Why use it?
It provides practical commands for common PostgreSQL tasks without requiring you to remember the command-line syntax.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/chaterm/terminal-skills/postgresql
Any agent
npx skills add chaterm/terminal-skills --skill postgresql
Clone the repo
git clone --depth 1 https://github.com/chaterm/terminal-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for postgresql

README.md
[![agentmods](https://agentmods.dev/badge/skills/chaterm/terminal-skills/postgresql.svg)](https://agentmods.dev/skills/chaterm/terminal-skills/postgresql)
Your own site
<a href="https://agentmods.dev/skills/chaterm/terminal-skills/postgresql"><img src="https://agentmods.dev/badge/skills/chaterm/terminal-skills/postgresql.svg" alt="Measured on agentmods" height="20"></a>
Per session 9 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,601 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00009 $0.01601
Opus 5 $0.00005 $0.00800
Sonnet 5 $0.00002 $0.00320
Haiku 4.5 $0.00001 $0.00160

Measured 6d ago against content hash 8003718c49df, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

postgresql scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

database/postgresql/SKILL.md · 240 lines

How it starts

The opening of the file, as written. The whole thing — 240 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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/

Read the full file on GitHub · 240 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 240 lines · 9 tokens per session scan A 8003718c49df

Subscribe to this mod's changes

postgresql is a skill published in the GitHub repository chaterm/terminal-skills (58 stars, last pushed 6mo ago), licensed Apache-2.0. It adds 9 tokens to every session and 1,601 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.