Back to Agent Skills
Data & Analytics
PostgreSQL Database Management
Manage PostgreSQL databases with advanced querying, indexing, and performance optimization for production workloads.
Claude Code Cursor Copilot Windsurf Gemini CLI Codex
Overview
node-postgres (pg) is the foundational PostgreSQL client for Node.js, providing both low-level connection management and high-level query building. It supports connection pooling, prepared statements, streaming queries, and COPY protocol for bulk data operations. The library handles type parsing automatically, converting PostgreSQL types to JavaScript equivalents.
For modern applications, node-postgres works seamlessly with ORMs like Prisma and Drizzle, or can be used directly for maximum control over SQL queries. It supports transactions with savepoints, advisory locks, LISTEN/NOTIFY for real-time updates, and JSON/JSONB operations for semi-structured data. Connection pooling via pg-pool manages database connections efficiently, preventing connection exhaustion under load.
PostgreSQL itself offers advanced features that set it apart from other databases: full-text search, JSONB columns with GIN indexes, CTEs (Common Table Expressions), window functions, materialized views, and row-level security. The node-postgres library exposes all of these through parameterized queries, protecting against SQL injection while providing full access to PostgreSQL capabilities.
For modern applications, node-postgres works seamlessly with ORMs like Prisma and Drizzle, or can be used directly for maximum control over SQL queries. It supports transactions with savepoints, advisory locks, LISTEN/NOTIFY for real-time updates, and JSON/JSONB operations for semi-structured data. Connection pooling via pg-pool manages database connections efficiently, preventing connection exhaustion under load.
PostgreSQL itself offers advanced features that set it apart from other databases: full-text search, JSONB columns with GIN indexes, CTEs (Common Table Expressions), window functions, materialized views, and row-level security. The node-postgres library exposes all of these through parameterized queries, protecting against SQL injection while providing full access to PostgreSQL capabilities.
Who Is This For?
- Set up connection pooling for a production Node.js API
- Implement full-text search with PostgreSQL tsvector
- Manage database migrations with versioned SQL scripts
- Optimize slow queries with EXPLAIN ANALYZE and indexes
Installation
Setup for Claude Code
npm install pg && npm install -D @types/pg Configuration
import { Pool } from "pg"
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
})
const { rows } = await pool.query(
"SELECT * FROM users WHERE email = $1",
[email]
) Explore AI Tools
Discover the best AI tools that complement your skills
Read AI & Design Articles
Tips and trends in the world of design and AI
Related Skills
Data & Analytics
Sentry Error Tracking
Monitor errors and performance issues in production with Sentry. AI agents can triage alerts and suggest fixes based on stack traces.
Claude Code Cursor Copilot
Data & Analytics PostHog Product Analytics
Track product usage, manage feature flags, and analyze user behavior with PostHog, an open-source product analytics platform.
Claude Code Cursor
Data & Analytics Database Query Builder
Generate and optimize SQL queries with AI assistance. Build complex queries, analyze execution plans, and improve database performance.
Claude Code Codex Copilot