node-postgres (pg)

The most widely-used PostgreSQL client for Node.js. Provides both a simple Client for single connections and a Pool for connection pooling. Supports parameterized queries (preventing SQL injection), prepared statements, transactions, COPY operations, and PostgreSQL notifications (LISTEN/NOTIFY). Pure JavaScript with TypeScript typings. The foundational layer used by ORMs like Knex, Drizzle, and Sequelize.

Evaluated Mar 06, 2026 (0d ago) v8.x
Homepage ↗ Repo ↗ Developer Tools postgresql postgres node sql database typescript connection-pool
⚙ Agent Friendliness
66
/ 100
Can an agent use this?
🔒 Security
86
/ 100
Is it safe for agents?
⚡ Reliability
90
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
88
Error Messages
85
Auth Simplicity
90
Rate Limits
90

🔒 Security

TLS Enforcement
85
Auth Strength
88
Scope Granularity
85
Dep. Hygiene
90
Secret Handling
85

Parameterized queries prevent SQL injection natively. SSL configurable. Database-level RBAC for fine-grained access. Minimal dependencies. Long history of security maintenance.

⚡ Reliability

Uptime/SLA
90
Version Stability
90
Breaking Changes
90
Error Recovery
88
AF Security Reliability

Best When

You need direct SQL access to PostgreSQL from Node.js with full control over queries, or when building a custom abstraction layer on top of raw PostgreSQL.

Avoid When

You want type-safe queries and schema-first development — use an ORM like Drizzle or Prisma that provides compile-time safety.

Use Cases

  • Execute parameterized SQL queries against PostgreSQL from Node.js applications with automatic SQL injection prevention
  • Manage database connection pools for Node.js web servers handling concurrent requests efficiently
  • Run database transactions with proper BEGIN/COMMIT/ROLLBACK using pool.connect() and client.query()
  • Receive real-time PostgreSQL NOTIFY events for database-driven event triggers in Node.js applications
  • Execute raw SQL for complex queries that ORM query builders can't express, with pg as the escape hatch

Not For

  • Schema management and migrations — use Knex, Drizzle, or Flyway for database migrations
  • Type-safe query building — use Drizzle ORM, Prisma, or TypeORM for compile-time SQL type checking
  • Non-PostgreSQL databases — use mysql2 for MySQL, better-sqlite3 for SQLite

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: password ssl_cert
OAuth: No Scopes: No

PostgreSQL native auth: password in connection string or config object. SSL/TLS configured via ssl option. Database-level permissions control access. Use environment variables for connection strings — never hardcode credentials.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

Fully free, MIT licensed. Costs are from the PostgreSQL database hosting (Supabase, Neon, RDS, etc.).

Agent Metadata

Pagination
offset
Idempotent
Partial
Retry Guidance
Not documented

Known Gotchas

  • Always use parameterized queries ($1, $2 syntax) — never interpolate user input into SQL strings directly; pg's query(text, values) format is the safe pattern
  • Pool clients must be released after use — pool.connect() returns a client that must be client.release() in finally block; leaked clients exhaust the connection pool
  • Connection pool size should match PostgreSQL max_connections — default pool max is 10; set based on (PostgreSQL max_connections / number of app instances)
  • Transactions require checking out a dedicated client — cannot use pool.query() for multi-statement transactions; must use pool.connect() → BEGIN → queries → COMMIT → release pattern
  • pg returns all values as strings by default for some types — JSON, numeric, timestamptz may need type casting; configure pg.types.setTypeParser() for custom type parsing
  • SSL is not enforced by default — in production, always set ssl: { rejectUnauthorized: true } to verify PostgreSQL server certificate

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for node-postgres (pg).

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered