
postgresql
PostgreSQL administration and setup including installation, configuration, backup/recovery, replication, and high-availability. Learn production PostgreSQL operations.
- Installs
- 52
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-sql --skill postgresql- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads postgresql automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
PostgreSQL Administration
Installation & Setup
# On Linux (Ubuntu/Debian)
sudo apt-get install postgresql postgresql-contrib
# On macOS
brew install postgresql@15
# Docker installation
docker run --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres:15
# Start and enable PostgreSQL
sudo systemctl start postgresql
sudo systemctl enable postgresql
Connection Basics
# Connect to default database
psql -U postgres
# Connect to specific database
psql -U postgres -d mydb -h localhost -p 5432
# List databases
\l
# List tables in current database
\dt
# Get table info
\d table_name
# Quit psql
\q
User & Role Management
-- Create a new role
CREATE ROLE developer WITH LOGIN PASSWORD 'secure_password';
-- Create superuser role
CREATE ROLE admin WITH SUPERUSER LOGIN PASSWORD 'admin_password';
-- Grant privileges on database
GRANT CONNECT ON DATABASE mydb TO developer;
-- Grant privileges on schema
GRANT USAGE ON SCHEMA public TO developer;
-- Grant privileges on tables
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA public TO developer;
-- Grant privileges on specific table
GRANT SELECT ON employees TO developer;
-- Make role a database owner
ALTER DATABASE mydb OWNER TO developer;
-- Revoke privileges
REVOKE INSERT, UPDATE ON employees FROM developer;
-- Drop role
DROP ROLE developer;
Configuration & Tuning
# PostgreSQL configuration file
sudo nano /etc/postgresql/15/main/postgresql.conf
# Key configuration parameters:
# Memory
shared_buffers = 256MB # 25% of RAM for dedicated server
effective_cache_size = 1GB # 50-75% of RAM
work_mem = 64MB # RAM per operation
# Connections
max_connections = 200
superuser_reserved_connections = 3
# Write-Ahead Log
wal_level = replica
max_wal_senders = 3
wal_keep_segments = 64
# Query planning
random_page_cost = 1.1 # For SSD
log_min_duration_statement = 1000 # Log slow queries
Backup & Recovery
# Full database backup (text format)
pg_dump -U postgres -d mydb -f mydb_backup.sql
# Binary backup (faster, compressed)
pg_dump -U postgres -d mydb -Fc -f mydb_backup.dump
# Backup specific table
pg_dump -U postgres -d mydb -t employees -f employees_backup.sql
# Backup all databases
pg_dumpall -U postgres -f all_databases.sql
# Restore from backup
psql -U postgres -d mydb -f mydb_backup.sql
# Restore from binary dump
pg_restore -U postgres -d mydb mydb_backup.dump
Maintenance Operations
-- VACUUM (reclaim space)
VACUUM; -- Full vacuum
-- VACUUM ANALYZE (reclaim space & update stats)
VACUUM ANALYZE;
-- ANALYZE (update table statistics)
ANALYZE;
-- Check database integrity
REINDEX DATABASE mydb;
-- Show database size
SELECT pg_database.datname,
pg_size_pretty(pg_database_size(pg_database.datname))
FROM pg_database;
-- Show table sizes
SELECT schemaname, tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename))
FROM pg_tables
WHERE schemaname != 'pg_catalog'
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
Monitoring
-- Active connections
SELECT * FROM pg_stat_activity WHERE state != 'idle';
-- Database statistics
SELECT * FROM pg_stat_database WHERE datname = 'mydb';
-- Table statistics
SELECT * FROM pg_stat_user_tables;
-- Index statistics
SELECT * FROM pg_stat_user_indexes;
-- Cache hit ratio
SELECT
sum(heap_blks_read) as heap_read,
sum(heap_blks_hit) as heap_hit,
sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) as ratio
FROM pg_statio_user_tables;
Performance Tuning
-- Check slow queries
SELECT query, mean_exec_time, calls
FROM pg_stat_statements
ORDER BY mean_exec_time DESC LIMIT 10;
-- Find unused indexes
SELECT schemaname, tablename, indexname
FROM pg_stat_user_indexes
WHERE idx_scan = 0;
-- Find missing indexes
SELECT * FROM pg_stat_user_tables
WHERE seq_scan > idx_scan
AND n_live_tup > 1000;
-- Analyze query plan
EXPLAIN ANALYZE
SELECT * FROM employees WHERE salary > 50000;
Replication Setup
# On primary server - enable replication in postgresql.conf
wal_level = replica
max_wal_senders = 3
wal_keep_segments = 64
# Create replication user
CREATE ROLE replicator WITH REPLICATION LOGIN PASSWORD 'rep_password';
# On standby - base backup from primary
pg_basebackup -h primary_host -D /var/lib/postgresql/15/main -U replicator -v -P -W
# Create recovery.conf on standby
standby_mode = 'on'
primary_conninfo = 'host=primary_host port=5432 user=replicator password=password'
High Availability with pgBouncer
# Install pgBouncer
sudo apt-get install pgbouncer
# Configuration - /etc/pgbouncer/pgbouncer.ini
[databases]
mydb = host=primary_host port=5432 dbname=mydb
[pgbouncer]
listen_port = 6432
max_client_conn = 1000
default_pool_size = 25
reserve_pool_size = 5
Next Steps
Learn advanced security features including row-level security and SSL/TLS configuration in the postgresql-security skill.
FAQ
What does the postgresql skill do?
PostgreSQL administration and setup including installation, configuration, backup/recovery, replication, and high-availability. Learn production PostgreSQL operations.
How do I install postgresql?
Run npx skills add https://github.com/pluginagentmarketplace/custom-plugin-sql --skill postgresql in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/postgresql/ (personal) or .claude/skills/postgresql/ (project).
Which AI agents can use postgresql?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is postgresql safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains postgresql?
It is published by pluginagentmarketplace in pluginagentmarketplace/custom-plugin-sql. It has 52 recorded installs.
More from pluginagentmarketplace/custom-plugin-sql
mysql
pluginagentmarketplace/custom-plugin-sql
MySQL database administration and development
data-analysis-sql
pluginagentmarketplace/custom-plugin-sql
SQL for data analysis with exploratory analysis, advanced aggregations, statistical functions, outlier detection, and business insights. 50+ real-world analytics queries.
data-warehouse
pluginagentmarketplace/custom-plugin-sql
Open the skill to read its SKILL.md instructions.
redis
pluginagentmarketplace/custom-plugin-sql
Open the skill to read its SKILL.md instructions.
bi-fundamentals
pluginagentmarketplace/custom-plugin-sql
Open the skill to read its SKILL.md instructions.
Popular data & databases skills
supabase-postgres-best-practices
supabase/agent-skills
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pgcron, pgmq), vector/semantic search (pgvector), and restoring dumps (pgrestore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.
prisma-client-api
prisma/skills
Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on "prisma query", "findMany", "create", "update", "delete", "$transaction".
prisma-database-setup
prisma/skills
Deprecated compatibility name for prisma-orm-setup. Use only when a user or existing integration explicitly invokes prisma-database-setup; otherwise select prisma-orm-setup.
prisma-cli
prisma/skills
Prisma ORM 7 CLI reference for existing Prisma 7 applications or explicitly selected Prisma 7 workflows. Covers prisma init, generate, migrate, db, dev, studio, and mcp. For setup, connection repair, or Prisma 8, use prisma-orm-setup; not the Prisma Platform CLI.
prisma-postgres
prisma/skills
Deprecated compatibility name for prisma-postgres-setup. Use only when a user or existing integration explicitly invokes prisma-postgres; otherwise select prisma-postgres-setup.
prisma-driver-adapter-implementation
prisma/skills
Required reference for Prisma ORM 7 SQL driver adapter work. Use when implementing or modifying adapters, adding database drivers, or touching SqlDriverAdapter, Transaction, savepoint, result mapping, or DriverAdapterError behavior. Covers current transaction lifecycle, optional savepoint hooks, original database-error preservation, and verification.