Getting Started

Quickstart

Get up and running with HTTP PostgreSQL Gateway in under 5 minutes.

5-Minute Quickstart

This guide starts a local HTTP PostgreSQL Gateway, configures a disposable PostgreSQL database with restricted privileges, creates a least-privilege API key, and runs an authenticated SQL query over HTTP.

The gateway process needs network access to PostgreSQL. Your serverless or edge application does not — it communicates with the gateway over standard HTTPS.


1. Prerequisites

Before starting, ensure your system meets the minimum requirements:

  • Node.js: 22.13+ on the 22.x line, or 23.4+, with built-in node:sqlite enabled.
  • npm: Version 10 or later.
  • PostgreSQL: Version 14 or higher with administrator access.
  • Redis: Optional for local development; required for shared rate limiting across multi-process clusters.

Verify your Node.js and SQLite runtime:

node --version node -e "import('node:sqlite').then(() => console.log('✓ node:sqlite available'))"

2. Install & Configure

Clone the repository and install dependencies:

git clone https://github.com/http-postgres/http-postgres.git cd http-postgres npm ci cp .env.example .env

Configure your PostgreSQL administrator connection in .env:

DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/postgres REDIS_URL=redis://127.0.0.1:6379
The administrator connection is used for schema migrations, health monitoring, durable execution tracking, and provisioning restricted PostgreSQL roles for scoped API keys.

Local Development Without Redis

If you do not have Redis running locally, disable it in gateway.yaml:

redis: enabled: false

When Redis is disabled, rate limits operate in-memory local to the process.


3. Prepare a Disposable Database

Run the following SQL script as a PostgreSQL superuser. Use a development database where revoking public privileges is safe:

-- Create an isolated demo database CREATE DATABASE gateway_demo; -- Revoke default PUBLIC connection rights REVOKE CONNECT ON DATABASE postgres, template1, gateway_demo FROM PUBLIC; GRANT CONNECT ON DATABASE gateway_demo TO postgres; \connect gateway_demo -- Revoke default schema creation rights REVOKE CREATE ON SCHEMA public FROM PUBLIC; -- Create a sample table CREATE TABLE public.messages ( id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, message text NOT NULL, created_at timestamptz NOT NULL DEFAULT now() ); -- Insert sample records INSERT INTO public.messages (message) VALUES ('Hello from HTTP PostgreSQL Gateway'), ('Serverless connection pooling works!');
PostgreSQL privileges are additive. Because PUBLIC has default access in PostgreSQL, revoking public access is necessary. The gateway rejects creating narrow scopes if broader inherited grants make them unsafe.

4. Start the Gateway

Start the development server with live reload:

npm run dev

During the very first startup, the gateway generates and prints a secure administrator password:

================================================================== GENERATED GATEWAY ADMIN PASSWORD: a7e8f9b2c3d4e5f60123456789abcdef... ==================================================================
Save this password immediately in your password manager! The gateway stores only a cryptographic hash and will never print the raw password again.

In another terminal, test the unauthenticated public liveness route:

curl --fail-with-body http://localhost:8080/health

Expected response:

{"status":"ok"}

5. Create a Scoped API Key

Generate an API key with read-only (r) access to the public.messages table. Replace <admin-password> with the password saved from Step 4:

curl --fail-with-body http://localhost:8080/admin/keys \ -H 'x-admin: <admin-password>' \ -H 'content-type: application/json' \ -d '{ "database": ["gateway_demo"], "tables": ["public.messages"], "scope-table": ["r"] }'

Response:

{ "success": true, "data": { "id": "key_01jh9x8q...", "apiKey": "pg_gw_live_9a8b7c6d5e...", "environment": "LIVE", "databases": ["gateway_demo"], "createdAt": "2026-11-23T06:00:00.000Z" } }
Copy and store data.apiKey immediately. Subsequent key list queries return metadata only, never the original secret key.

6. Run Your First HTTP Query

Execute a parameterized SQL query using the scoped API key:

curl --fail-with-body http://localhost:8080/query \ -H 'x-api-key: <api-key>' \ -H 'x-database: gateway_demo' \ -H 'content-type: application/json' \ -d '{ "query": "SELECT id, message, created_at FROM public.messages WHERE id = $1", "parameters": [1] }'

Response:

{ "success": true, "data": { "database": "gateway_demo", "command": "SELECT", "rowCount": 1, "rows": [ { "id": 1, "message": "Hello from HTTP PostgreSQL Gateway", "created_at": "2026-11-23T06:00:00.000Z" } ], "fields": [ {"name": "id", "dataTypeID": 20}, {"name": "message", "dataTypeID": 25}, {"name": "created_at", "dataTypeID": 1184} ], "durationMs": 3.42 } }

Notice that parameters are passed safely as an array, eliminating SQL injection risks and keeping untrusted values out of analytics logs.


7. Inspect Operational Health

Run a deep health inspection of all gateway subsystems:

curl --fail-with-body http://localhost:8080/admin/health \ -H 'x-admin: <admin-password>'

This returns metrics for PostgreSQL connectivity, pool utilization, unverified connection age, and storage subsystems.


Startup Troubleshooting

SymptomCauseResolution
node:sqlite requirement errorNode.js is outdated or built without SQLiteUpgrade to Node.js 22.13+ or 23.4+
Failed to connect to PostgreSQLIncorrect credentials or database offlineCheck DATABASE_URL in .env and verify PostgreSQL service status
Redis connection errorRedis is unreachableStart Redis or set redis.enabled: false in gateway.yaml
Missing environment variableVariable not defined in .envAdd the variable or specify a fallback ${VAR:-fallback} in gateway.yaml
UNSAFE_DATABASE_SCOPE (409)PostgreSQL PUBLIC grants are too broadRevoke CONNECT and CREATE privileges from PUBLIC on the target database

What's Next?

Copyright © 2026