Search code examples
postgresqldockerdrizzledrizzle-orm

`drizzle-kit studio` is giving `error: password authentication failed for user "postgres"`


I've reproduced the issue in a blank project from scratch. Here is a conclusion of the issue I'm encountering:

docker-compose.yml

version: '3'

services:
  db:
    image: postgres
    restart: always
    volumes:
      - ./data/db:/var/lib/postgresql/data
    ports:
      - 5432:5432
    environment:
      - POSTGRES_DB=testDB
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

drizzle.config.ts

import type { Config } from "drizzle-kit";

import { config } from "dotenv";

config({
  path: "./.env.local",
});

export default {
  schema: "./src/lib/db/schema/*.sql.ts",
  out: "./drizzle",
  driver: "pg",
  dbCredentials: {
    connectionString: process.env.DATABASE_URL,
  },
  verbose: true,
  strict: true,
} satisfies Config;

.env.local

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/testDB

When running docker compose up, It successfully initialize the database and the adminer. and I can access the db via adminer successfully.

The problem is when runnint drizzle-kit studio I get password authentication failed for user "postgres".

Full Console error

{
  length: 104,
  severity: 'FATAL',
  code: '28P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '326',
  routine: 'auth_failed'
}

I'm newbie to the either postgres and drizzle and would appreciate any help. Thanks in advance

I've reproduced the issue in a blank project from scratch. Here is a conclusion of the issue I'm encountering:

docker-compose.yml

version: '3'

services:
  db:
    image: postgres
    restart: always
    volumes:
      - ./data/db:/var/lib/postgresql/data
    ports:
      - 5432:5432
    environment:
      - POSTGRES_DB=testDB
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

drizzle.config.ts

import type { Config } from "drizzle-kit";

import { config } from "dotenv";

config({
  path: "./.env.local",
});

export default {
  schema: "./src/lib/db/schema/*.sql.ts",
  out: "./drizzle",
  driver: "pg",
  dbCredentials: {
    connectionString: process.env.DATABASE_URL,
  },
  verbose: true,
  strict: true,
} satisfies Config;

.env.local

DATABASE_URL=postgresql://postgres:postgres@localhost:5432/testDB

When running docker compose up, It successfully initialize the database and the adminer. and I can access the db via adminer successfully.

The problem is when runnint drizzle-kit studio I get password authentication failed for user "postgres".

Full Console error

{
  length: 104,
  severity: 'FATAL',
  code: '28P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '326',
  routine: 'auth_failed'
}

I'm newbie to the either postgres and drizzle and would appreciate any help. Thanks in advance


Solution

  • Here is my answer after a long day of debugging with hope to help someone else.

    The problem was that PostgresSQL Windows server was running on port 5432 the same port of Postgres in Docker. I expected it to connect to the docker db. but it was connecting to Windows app. I solved it by changing the port of Docker and then it's working.

    Isn't Docker supposed to error when the port is in use?


    That what worked for me. If you're an expert in that field and something is wrong in this, feel free to write an answer