Saltar al contenido
Skillpedia
Programación general48 mil · #5471

postgresql-cli

Qué hace

psql es una herramienta que te permite interactuar directamente con bases de datos PostgreSQL desde tu terminal. Puedes usarla para escribir y ejecutar comandos, y consultar información sobre tablas y otros objetos de la base de datos.

Cuándo usarla

  • ✓Cuando necesites ejecutar comandos SQL en una base de datos PostgreSQL.
  • ✓Para revisar la estructura de tablas, vistas u otra información de la base de datos.
  • ✓Cuando importes o exportes datos de una base de datos.

Link de la skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/postgresql-cli/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/postgresql-cli/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Conéctate a la base de datos 'my_database' con el usuario 'my_user' en el host 'my_host' y ejecuta la consulta 'SELECT * FROM customers;'”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

Escribes comandos en la terminal para conectarte a la base de datos y luego escribes tus comandos SQL. psql ejecuta estos comandos y te muestra los resultados.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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

…

Preguntas frecuentes

¿Necesito instalar PostgreSQL completo para usar psql?

No, solo necesitas instalar 'postgresql-client', que contiene la herramienta psql. Esta puede conectarse a bases de datos PostgreSQL que estén en otros equipos.

¿Cómo me conecto a una base de datos?

Puedes conectarte con un comando como `psql -h host -p port -U user -d dbname`. Hay otras formas, como usar variables de entorno o un archivo de configuración.

¿Cómo veo las tablas de una base de datos?

Una vez conectado, escribe `\dt` en la terminal para listar todas las tablas.

Detalles

Descripción original del autor

PostgreSQL interactive terminal (psql) reference and usage guide.

repo: sickn33/agentic-awesome-skills

Popularidad

Estrellas en GitHub
48 mil
Posición en el ranking
#5471
Licencia
MIT
Actualizada
15/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas