본문으로 건너뛰기
Skillpedia
일반 코딩48k · #5471

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/postgresql-cli/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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.

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#5471
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬