skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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 working in this feel free to write an answer


  2. While I can’t upvote your answer due to low reputation points your solution worked for me. The explanation is that the locally installed and the Docker PostgreSQL services were running on the same port.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search