postgresql-psql

Document psql meta-commands, connection options, and scripting patterns for PostgreSQL administration.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/timelessco/recollect --skill postgresql-psql-timelessco
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgresql-psql
Source: https://github.com/timelessco/recollect/tree/main/.claude/skills/postgresql-psql
Command: npx skills add https://github.com/timelessco/recollect --skill postgresql-psql-timelessco

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

psql is the PostgreSQL interactive terminal; this Skill provides a comprehensive reference and practical guidance to connect, query, manage, and automate PostgreSQL tasks using psql. It reduces guesswork and speeds up DBA and developer workflows by consolidating commands, meta-commands, and scripting patterns.

Core Features & Use Cases

  • Meta-Command Reference: Documented 40+ psql backslash commands for databases, schemas, output formatting, file operations, and transactions.
  • Connection & Authentication: Guidance on host/port, SSL modes, password files, SSH tunnels, and environment-based credentials.
  • SQL & Scripting: Patterns for running queries, scripting with \i, \copy, and batch execution; transaction management and error handling.
  • Real-World Scenarios: Examples for exporting data, debugging queries, and automating routine admin tasks.

Quick Start

  1. Start a session: connect to a database, e.g., psql -h localhost -U postgres -d mydb
  2. Run an essential command: \dt to list tables or \d+ table to get details
  3. Execute a simple script: \i script.sql

Frequently Asked Questions about postgresql-psql

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I connect to a PostgreSQL database using psql?

Connect to PostgreSQL with psql by specifying host, user, and database: psql -h localhost -U postgres -d mydb. Use -p for custom ports, SSL modes for encryption, password files for automation, and SSH tunnels for remote access through secure channels.

What are psql meta-commands and how do I use them?

psql meta-commands are backslash commands that control the client rather than the database. Over 40 are documented for listing databases (\l), tables (\dt), schemas (\dn), formatting output, managing transactions, and running scripts (\i). Prefix queries with \ to execute them.

How do I automate PostgreSQL tasks and run scripts with psql?

Automate tasks by running SQL scripts with \i script.sql, using \copy for data import/export, and batch execution for routine admin work. Combine meta-commands with shell scripting and error handling to orchestrate backups, recovery workflows, and repetitive database operations.

Can I use psql for data export and import workflows?

Yes, psql supports data import and export through \copy for CSV and formatted files, SQL script execution, and batch operations. Configure variables and connection options to handle export jobs, data migration, and integration with external systems across development, testing, and production.

What's the best way to debug and optimize PostgreSQL queries in psql?

Debug queries by using \d+ for detailed table inspection, \timing to measure execution time, and transaction management with BEGIN/COMMIT for testing. Apply performance analysis and optimization guidance directly in the psql terminal to identify slow queries and schema issues.

How do I manage PostgreSQL users and permissions from psql?

Manage users and permissions through psql by creating roles, granting privileges on databases and tables, and configuring authentication methods. Use meta-commands and SQL statements to enforce access control and user management policies across development and production environments.