postgresql-cli
하는 일
psql은 터미널에서 직접 PostgreSQL 데이터베이스와 상호작용하도록 해 주는 도구입니다. 명령을 작성해 실행하고, 테이블 및 기타 데이터베이스 객체에 대한 정보를 확인하는 데 쓸 수 있습니다.
사용하는 경우
- ✓PostgreSQL 데이터베이스에서 SQL 명령을 실행해야 할 때.
- ✓테이블, 뷰 또는 기타 데이터베이스 정보의 구조를 확인할 때.
- ✓데이터베이스에서 데이터를 가져오거나 내보낼 때.
스킬 링크
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/postgresql-cli/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“사용자 ‘my_user’로 호스트 ‘my_host’의 ‘my_database’ 데이터베이스에 연결해서 ‘SELECT * FROM customers;’ 쿼리를 실행해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
터미널에 명령을 입력해 데이터베이스에 연결한 다음, SQL 명령을 작성합니다. psql이 명령을 실행하고 결과를 보여 줍니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
psql — PostgreSQL Interactive Terminal
psql is PostgreSQL's feature-rich interactive terminal. It lets you write and execute queries, inspect database objects, import/export data, script batch operations, and customize output formatting — all from the command line.
Prerequisites
Before using psql, verify it is installed and available:
# Check if psql is installed
psql --version
# If not found, install PostgreSQL client tools:
# macOS (Homebrew)
brew install libpq
brew link --force libpq
# Ubuntu / Debian
sudo apt install postgresql-client
# CentOS / RHEL
sudo yum install postgresql
# Alpine
apk add postgresql-client
# Windows — install PostgreSQL via the official installer or use WSL
psql ships as part of the postgresql-client package. The server (postgresql) is not required — you only need the client to connect to a remote PostgreSQL instance.
Quick Reference
Connecting
# 1. CLI flags
psql -h host -p port -U user -d dbname
# 2. Connection URI
# WARNING: Password in URI is visible in shell history and process listings.
# Prefer ~/.pgpass for production use (see method 4 below).
psql "postgresql://user:YOUR_PASSWORD@host:port/dbname"
# 3. Environment variables (no flags needed)
export PGHOST=localhost
export PGPORT=5432
export PGDATABASE=mydb
export PGUSER=postgres
# WARNING: PGPASSWORD is visible in process listings (e.g. `ps aux`).
# Use ~/.pgpass in production instead.
export PGPASSWORD=YOUR_PASSWORD
psql # picks up all params from env
# 4. ~/.pgpass file (RECOMMENDED for passwords)
# Format: hostname:port:database:username:password
touch ~/.pgpass && chmod 600 ~/.pgpass
# Then manually edit ~/.pgpass and add entries (avoids password in shell history):
# hostname:port:database:username:password
# Example: localhost:5432:mydb:postgres:YOUR_PASSWORD
psql -h localhost -U postgres -d mydb # no password prompt
# 5. Execute and exit
psql -f script.sql dbname # execute file then exit
psql -c "SELECT 1" dbname # run single command then exit
psql -1 -f migration.sql dbname # run in single transaction
# 6. Service connection (reads from pg_service.conf)
psql service=mydb_prod
# 7. Reconnect within a session
\c dbname # reconnect to different db
\c -reuse-previous=on sslmode=require # change only sslmode
\c "host=newhost port=5432 dbname=mydb" # conninfo string
On connection failure: interactive mode keeps the previous connection; script mode closes it and all subsequent database commands fail until the next successful \c.
Key flags: -h host, -p port, -U user, -d database, -w no password prompt, -W force password prompt, -1 single transaction, -f execute file, -c execute command, -t tuples only, -x expanded, -A unaligned, -E echo hidden queries (\d internals), -L log file, -X skip ~/.psqlrc.
Connection precedence: CLI flags > environment variables > pg_service.conf > defaults. Password precedence: connection string/password flag > PGPASSWORD env > ~/.pgpass. Use ~/.pgpass instead of PGPASSWORD in production — PGPASSWORD is visible in process listings (ps aux).
Object Inspection (\d family)
| Command | Shows |
|---|---|
\d |
All tables, views, materialized views, sequences, foreign tables (equiv.\dtvmsE) |
\dP |
Partitioned tables |
\dt |
Tables only |
\dv |
Views only |
\di |
Indexes only |
\ds |
Sequences only |
\dm |
Materialized views only |
…
자주 묻는 질문
psql을 쓰려고 PostgreSQL 전체를 설치해야 하나요?
아니요, psql 도구가 들어 있는 ‘postgresql-client’만 설치하면 됩니다. 다른 컴퓨터의 PostgreSQL 데이터베이스에도 연결할 수 있습니다.
데이터베이스에 어떻게 연결하나요?
`psql -h host -p port -U user -d dbname` 같은 명령을 사용할 수 있습니다. 환경 변수나 설정 파일을 쓰는 다른 방법도 있습니다.
데이터베이스의 테이블은 어떻게 보나요?
연결한 뒤 터미널에 `\dt`를 입력하면 모든 테이블 목록이 나옵니다.
상세 정보
작성자의 원본 설명
PostgreSQL interactive terminal (psql) reference and usage guide.
인기도
- GitHub 스타
- 48k
- 순위
- #5471
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
00-andruia-consultant
48k에이전트가 AI 프로젝트를 시작하거나 개선할 수 있도록 코드를 분석하고 스페인어로 실행 계획을 세워 줍니다.
007
48k에이전트가 보안 감사와 위협 모델링을 수행해 공격과 취약점으로부터 프로젝트를 보호하도록 돕습니다.
10-andruia-skill-smith
48k에이전트가 AI 도구의 작동 방식을 정의하고 문서를 쓰며 구조를 검증하도록 돕습니다.
20-andruia-niche-intelligence
48k에이전트가 신뢰할 수 있는 자료를 바탕으로 특정 산업의 맥락, 규칙, 사용 패턴, 위험을 정리한 요약을 만들도록 돕습니다.