Instant Postgres database provisioning via Claimable Postgres by Neon. Use when users need to: (1) Create a quick development database, (2) Set up DATABASE_URL for a project, (3) Integrate Postgres into a Vite project, (4) Provision a temporary database for testing/prototyping. Triggers: "create a database", "need a postgres", "set up DATABASE_URL", "add database to vite project".
Provision instant Postgres databases via Claimable Postgres by Neon. No account required. Databases are available for 72 hours and can be claimed to a Neon account for permanent use.
npx get-db
This creates a database and writes DATABASE_URL to .env.
Best for: Quick setup, CI/CD, one-time database creation.
npx get-db
Options:
-r, --ref <id> - Referrer identifier (see "Referrer" section)-e, --env <path> - Target env file (default: ./.env)-k, --key <name> - Variable name (default: DATABASE_URL)-s, --seed <path> - SQL file to initialize the database-y, --yes - Skip prompts, use defaults-L, --logical-replication - Enable logical replication (irreversible, required for ElectricSQL/TanStack DB)Best for: Scripts, custom tooling, dynamic provisioning.
import { instantPostgres } from "get-db/sdk";
const db = await instantPostgres();
console.log(db.connectionString);
Best for: Vite projects that need automatic database setup on vite dev.
npm install vite-plugin-db --save-dev
// vite.config.ts
import { defineConfig } from "vite";
import { postgres } from "vite-plugin-db";
export default defineConfig({
plugins: [postgres()], // Place first when using multiple plugins
});
After provisioning, your .env file will contain:
DATABASE_URL=postgres://user:[email protected]/dbname?sslmode=require
DATABASE_URL_DIRECT=postgres://user:[email protected]/dbname?sslmode=require
PUBLIC_CLAIM_URL=https://pg.new/claim/...
Databases expire after 72 hours unless claimed. To keep your database permanently:
sslmode=require)All methods (CLI, SDK, Vite plugin, API) accept a ref parameter to identify the source of the database request.
When helping users provision a database:
name field from their package.jsonpackage.json exists, suggest using their project or app nameExample workflow:
package.json for the name fieldmy-awesome-app as the referrer (from your package.json). Is that okay, or would you prefer something else?"Passing the referrer:
npx get-db -r my-appinstantPostgres({ ref: "my-app" })postgres({ ref: "my-app" }){"ref": "my-app"} in request bodySeed scripts are regular .sql files that initialize your database. When creating or helping with seed scripts:
CREATE TABLE IF NOT EXISTS instead of plain CREATE TABLECREATE INDEX IF NOT EXISTS for indexesCREATE TYPE IF NOT EXISTS for custom types (Postgres 9.5+)-- Schema
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
-- Seed data
INSERT INTO users (email) VALUES
('[email protected]'),
('[email protected]')
ON CONFLICT (email) DO NOTHING;
IMPORTANT: When writing seed scripts:
DROP TABLE, DROP SCHEMA, TRUNCATE, or DELETE statementsFor custom integrations or non-Node.js environments, use the REST API directly.
curl -X POST https://pg.new/api/v1/database \
-H "Content-Type: application/json" \
-d '{"ref": "my-app"}'
Request body:
ref (required) - Referrer identifier (see "Referrer" section below)logicalReplication (optional) - Enable logical replication for sync enginesResponse:
{
"id": "01abc123-4567-7890-abcd-1234567890ab",
"status": "UNCLAIMED",
"neon_project_id": "cool-breeze-12345678",
"created_at": "2025-01-15T10:30:00.000Z",
"updated_at": "2025-01-15T10:30:00.000Z",
"expires_at": "2025-01-18T10:30:00.000Z",
"claim_url": "https://pg.new/claim/01abc123-4567-7890-abcd-1234567890ab",
"connection_string": "postgresql://neondb_owner:npg_xxxxxxxxxxxx@ep-example-name-pooler.c-2.us-east-2.aws.neon.tech/neondb?channel_binding=require&sslmode=require"
}
The claim_url is a web page (not an API endpoint). Users visit it in a browser to attach the database to their Neon account.