pgtyped icon indicating copy to clipboard operation
pgtyped copied to clipboard

Unable to connect to posgresql 16.1 with scram-sha-256 password authentication

Open yevon opened this issue 9 months ago • 5 comments

Describe the bug I'm migrating a backend node express project for using TypeScript and pgtyped, but right now I'm unable to make it to work with my postgresql 16.1 database. The project and env vars work without problems locally. I can manually connect to the database without issues in dbeaver. Pgtyped is reading the env vars properly, so the only thing I found so far could be to the compatibility with scarm-sha-256 authentication? I read that this was supported already. The error received is just: Connection failed: password authentication failed for user "postgres"

If I look at the logs in the database,I can see the following, so it is already allowing connections from all hosts but with scram-sha-256 only:

"error_severity":"FATAL","sql_state_code":"28P01","message":"password authentication failed for user \"postgres\"","detail":"Connection matched file \"/var/lib/postgresql/data/pgdata/pg_hba.conf\" line 25: \"host all all all scram-sha-256\""

This is my current pgtyped.config.cjs

// pgtyped.config.cjs
require("dotenv").config({ path: ".env.local" });

module.exports = {
  transforms: [
    {
      mode: "sql",
      include: "**/*.sql",
      emitTemplate: "{{dir}}/{{name}}.queries.ts",
    },
  ],
  srcDir: "./src/trpc/queries/",
  camelCaseColumnNames: true,
  failOnError: true,
  db: {
    dbName: process.env.POSTGRES_DB,
    user: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    host: process.env.POSTGRES_HOST,
    port: Number(process.env.POSTGRES_PORT),
    ssl: false,
  },
};

yevon avatar Mar 12 '25 13:03 yevon

I realized that if I try to print pgtyped version it always shows 1.0.0, maybe this is the reason, but I have latest version installed I think: npx pgtyped --version

1.0.0

I tried reinstalling it multiple times, and forcing latest 2.4.2 version and it always returns version 1.0.0

Image

yevon avatar Mar 12 '25 13:03 yevon

I'm experiencing the same, except I'm on Pg 17

kaushalyap avatar May 15 '25 08:05 kaushalyap

It cannot be due scram-sha-256 changing to md5 also give the same error

kaushalyap avatar May 15 '25 08:05 kaushalyap

In my case there was old PGPASSWORD in my shell hanging around from some other configuration, removing that fixed the issue,

In order to resolve authentication failures better to turn on postgres logging.

kaushalyap avatar May 16 '25 04:05 kaushalyap

I faced the same issue, and it's 100% not about the incorrect password

dilame avatar Aug 12 '25 16:08 dilame