116
GitHub Stars
3
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill einverne/dotfiles --skill postgresql-psql- EXPLORATION-REPORT.md13.5 KB
- README.md5.6 KB
- SKILL.md34.7 KB
Overview
This skill is a practical, compact guide to using psql, the PostgreSQL interactive terminal client. It covers connecting, querying, scripting, formatting output, transaction control, and advanced psql meta-commands. The content focuses on real-world workflows for developers and DBAs who manage PostgreSQL from the command line.
How this skill works
psql runs as a REPL that accepts SQL statements and psql-specific backslash commands to inspect and control the session. It maintains a single database connection per session, supports scripting via files and variables, and can format or redirect output to files, CSV, HTML, or pipes. Connection options, authentication methods, and .psqlrc configuration let you customize behavior and automate common tasks.
When to use it
- Connect to a local or remote PostgreSQL instance from the terminal
- Run ad-hoc SQL queries and inspect schema, tables, indexes, and roles
- Automate administrative tasks with SQL scripts and psql meta-commands
- Export/import data, format query results for reporting or pipes
- Manage transactions, savepoints, and perform safe bulk operations
Best practices
- Use connection strings or environment variables (PGUSER, PGHOST, PGDATABASE) to avoid exposing passwords on command lines
- Store credentials securely in ~/.pgpass with correct permissions (chmod 600) for unattended scripts
- Enable timing and \pset options in ~/.psqlrc for consistent, readable output during debugging
- Prefer \copy for client-side import/export when server-side permissions are limited
- Develop and test scripts with --echo-all and --single-transaction flags to catch errors before committing
Example use cases
- Quickly inspect a table structure: start psql and run \d+ my_table to view columns, indexes, and storage info
- Run a migration script in a single transaction: psql -f migrate.sql -v ON_ERROR_STOP=1 --single-transaction
- Export query results to CSV: run \pset format csv then \g output.csv or use \copy (SELECT ...) TO 'file.csv' CSV
- Connect through an SSH tunnel for secure remote access: ssh -L 5432:localhost:5432 user@host then psql -h localhost -U user
- Embed psql in automation: use psql -c "SELECT ..." in CI jobs and capture output with --no-align -t for parsing
FAQ
Use a ~/.pgpass file with hostname:port:database:username:password and set file permissions to 600, or export PGPASSWORD in controlled environments.
What’s the difference between COPY and \copy?
COPY runs on the server and requires server filesystem access; \copy runs client-side and reads/writes files from the psql client machine, often requiring fewer privileges.