Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@vercel/postgres] - Error: VercelPostgresError - 'invalid_connection_string' using drizzle orm #614

Closed
kenny-mwendwa opened this issue Feb 20, 2024 · 2 comments

Comments

@kenny-mwendwa
Copy link

When attempting to establish a connection to the PostgreSQL database and drizzle orm using Vercel, the following error occurred:

VercelPostgresError - 'invalid_connection_string': This connection string is meant to be used with a direct connection. Make sure to use a pooled connection string or try 'createClient()' instead.
//db.ts
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";
import * as schema from "./schema";

const db = drizzle(sql, { schema });

export default db;
//drizzle.config.ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./src/database/schema.ts",
  out: "./drizzle/migrations",
  driver: "pg",
  dbCredentials: {
    connectionString: process.env.POSTGRES_URL!,
  },
  verbose: true,
  strict: true,
});

I have already set the POSTGRES_URL in the .env file

# npm packages
@vercel/postgres: ^0.7.2 => 0.7.2 
drizzle-orm: ^0.29.3 => 0.29.3
@janpio
Copy link

janpio commented Feb 23, 2024

You have to use the other connection string that Vercel gives you, the connection pooled one. It should contain -pooler in the hostname. Vercel ensures here that you do not create a local pool against the direct connection string - as that would quickly exhaust he open connecitons on the database side.

@vvo
Copy link
Member

vvo commented Mar 11, 2024

Thank you @janpio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants