New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pgserve

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pgserve

Embedded PostgreSQL server with true concurrent connections - zero config, auto-provision databases

latest
Source
npmnpm
Version
1.1.7
Version published
Maintainers
1
Created
Source

pgserve

Embedded PostgreSQL Server with TRUE Concurrent Connections

npm version Node.js PostgreSQL License Discord

Zero config, auto-provision databases, unlimited concurrent connections. Just works.

Quick StartFeaturesCLIAPIPerformance


Quick Start

npx pgserve

Connect from any PostgreSQL client — databases auto-create on first connection:

psql postgresql://localhost:8432/myapp

Features

Real PostgreSQL 18Native binaries, not WASM — full compatibility, extensions support
Unlimited ConcurrencyNative PostgreSQL process forking — no connection locks
Zero ConfigJust run pgserve, connect to any database name
Auto-ProvisionDatabases created automatically on first connection
Memory ModeFast and ephemeral for development (default)
RAM ModeUse --ram for /dev/shm storage (Linux, 2x faster)
Persistent ModeUse --data ./path for durable storage
Async ReplicationSync to real PostgreSQL with minimal overhead
pgvector Built-inUse --pgvector for auto-enabled vector similarity search
Cross-PlatformLinux x64, macOS ARM64/x64, Windows x64
Any Client Workspsql, node-postgres, Prisma, Drizzle, TypeORM

Installation

# Zero install (recommended)
npx pgserve

# Global install
npm install -g pgserve

# Project dependency
npm install pgserve

PostgreSQL binaries are automatically downloaded on first run (~100MB).

Windows

Download pgserve-windows-x64.exe from GitHub Releases.

Double-click to run, or use CLI:

pgserve-windows-x64.exe --port 5432
pgserve-windows-x64.exe --data C:\pgserve-data

CLI Reference

pgserve [options]

Options:
  --port <number>       PostgreSQL port (default: 8432)
  --data <path>         Data directory for persistence (default: in-memory)
  --ram                 Use RAM storage via /dev/shm (Linux only, fastest)
  --host <host>         Host to bind to (default: 127.0.0.1)
  --log <level>         Log level: error, warn, info, debug (default: info)
  --cluster             Force cluster mode (auto-enabled on multi-core)
  --no-cluster          Force single-process mode
  --workers <n>         Number of worker processes (default: CPU cores)
  --no-provision        Disable auto-provisioning of databases
  --sync-to <url>       Sync to real PostgreSQL (async replication)
  --sync-databases <p>  Database patterns to sync (comma-separated)
  --pgvector            Auto-enable pgvector extension on new databases
  --max-connections <n> Max concurrent connections (default: 1000)
  --help                Show help message
Examples
# Development (memory mode, auto-clusters on multi-core)
pgserve

# RAM mode (Linux only, 2x faster)
pgserve --ram

# Persistent storage
pgserve --data /var/lib/pgserve

# Custom port
pgserve --port 5433

# Enable pgvector for AI/RAG applications
pgserve --pgvector

# RAM mode + pgvector (fastest for AI workloads)
pgserve --ram --pgvector

# Sync to production PostgreSQL
pgserve --sync-to "postgresql://user:pass@db.example.com:5432/prod"

API

import { startMultiTenantServer } from 'pgserve';

const server = await startMultiTenantServer({
  port: 8432,
  host: '127.0.0.1',
  baseDir: null,        // null = memory mode
  logLevel: 'info',
  autoProvision: true,
  enablePgvector: true, // Auto-enable pgvector on new databases
  syncTo: null,         // Optional: PostgreSQL URL for replication
  syncDatabases: null   // Optional: patterns like "myapp,tenant_*"
});

// Get stats
console.log(server.getStats());

// Graceful shutdown
await server.stop();

Framework Integration

node-postgres
import pg from 'pg';

const client = new pg.Client({
  connectionString: 'postgresql://localhost:8432/myapp'
});

await client.connect();
await client.query('CREATE TABLE users (id SERIAL, name TEXT)');
await client.query("INSERT INTO users (name) VALUES ('Alice')");
const result = await client.query('SELECT * FROM users');
console.log(result.rows);
await client.end();
Prisma
// prisma/schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
# .env
DATABASE_URL="postgresql://localhost:8432/myapp"

# Run migrations
npx prisma migrate dev
Drizzle
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';

const pool = new Pool({
  connectionString: 'postgresql://localhost:8432/myapp'
});

const db = drizzle(pool);
const users = await db.select().from(usersTable);

Async Replication

Sync ephemeral pgserve data to a real PostgreSQL database. Uses native logical replication for zero performance impact on the hot path.

# Sync all databases
pgserve --sync-to "postgresql://user:pass@db.example.com:5432/mydb"

# Sync specific databases (supports wildcards)
pgserve --sync-to "postgresql://..." --sync-databases "myapp,tenant_*"

Replication is handled by PostgreSQL's WAL writer process, completely off the runtime event loop. Sync failures don't affect main server operation.


pgvector is built-in — no separate installation required. Just enable it:

# Auto-enable pgvector on all new databases
pgserve --pgvector

# Combined with RAM mode for fastest vector operations
pgserve --ram --pgvector

When --pgvector is enabled, every new database automatically has the vector extension installed. No SQL setup required.

Using pgvector
-- Create table with vector column (1536 = OpenAI embedding size)
CREATE TABLE documents (id SERIAL, content TEXT, embedding vector(1536));

-- Insert with embedding
INSERT INTO documents (content, embedding) VALUES ('Hello', '[0.1, 0.2, ...]');

-- k-NN similarity search (L2 distance)
SELECT content FROM documents ORDER BY embedding <-> $1 LIMIT 10;

See pgvector documentation for full API reference.

Without --pgvector flag

If you don't use --pgvector, you can still enable pgvector manually per database:

CREATE EXTENSION IF NOT EXISTS vector;

pgvector 0.8.1 is bundled with the PostgreSQL binaries. Supports L2 distance (<->), inner product (<#>), and cosine distance (<=>).


Performance

CRUD Benchmarks

ScenarioSQLitePGlitePostgreSQLpgservepgserve --ram
Concurrent Writes (10 agents)91 qps204 qps1,667 qps2,273 qps4,167 qps 🏆
Mixed Workload383 qps484 qps507 qps1,133 qps2,109 qps 🏆
Write Lock (50 writers)111 qps228 qps2,857 qps3,030 qps4,348 qps 🏆

Vector Benchmarks (pgvector)

MetricPGlitePostgreSQLpgservepgserve --ram
Vector INSERT (1000 × 1536-dim)152/sec392/sec387/sec1,082/sec 🏆
k-NN Search (k=10, 10k corpus)22 qps33 qps31 qps30 qps
Recall@10100%100%100%100%

Why pgserve wins on writes: RAM mode uses /dev/shm (tmpfs), eliminating fsync latency. Vector search is CPU-bound, so RAM mode shows minimal benefit there.

Final Score

EngineCRUD QPSVec QPSRecallP50P99Score
SQLite195N/AN/A6.3ms17.3ms117
PGlite30565100%3.3ms7.0ms209
PostgreSQL1,677152100%6.0ms19.0ms1,067
pgserve2,145149100%5.3ms13.0ms1,347
pgserve --ram3,541381100%3.3ms10.7ms2,277 🏆

Methodology: Recall@k measured against brute-force ground truth (industry standard). PostgreSQL baseline is Docker pgvector/pgvector:pg18. RAM mode available on Linux and WSL2.

Run benchmarks yourself: bun tests/benchmarks/runner.js --include-vector


Use Cases

Development & Testing

  • Local Development — PostgreSQL without Docker
  • Integration Testing — Real PostgreSQL, not mocks
  • CI/CD Pipelines — Fresh databases per test run
  • E2E Testing — Isolated database for Playwright/Cypress

AI & Agents

  • AI Agent Memory — Isolated, concurrent-safe database
  • LLM Tool Use — Give AI models a real PostgreSQL
  • RAG Applications — Store embeddings with pgvector

Multi-Tenant & SaaS

  • Tenant Isolation — Auto-provision per tenant
  • Demo Environments — Instant sandboxed PostgreSQL
  • Microservices Dev — Each service gets its own DB

Edge & Embedded

  • IoT Devices — Full PostgreSQL on Raspberry Pi
  • Desktop Apps — Electron with embedded PostgreSQL
  • Offline-First — Local DB that syncs when online

Requirements

  • Runtime: Node.js >= 18 (npm/npx)
  • Platform: Linux x64, macOS ARM64/x64, Windows x64

Development

Contributors: This project uses Bun internally for development:

# Install dependencies
bun install

# Run tests
bun test

# Run benchmarks
bun tests/benchmarks/runner.js

# Lint
bun run lint

Contributing

Contributions welcome! Fork the repo, create a feature branch, add tests, and submit a PR.


MIT License — Copyright (c) 2025 Namastex Labs

GitHubnpmIssues

Made with love by Namastex Labs

Keywords

postgresql

FAQs

Package last updated on 02 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts