Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mikro-orm error: password authentication failed for user "postgres"

I'm trying to code along this React GraphQL TypeScript tutorial

The project uses MikroOrm to communicate with a PostgreSQL database. I have PostgreSQL(12.4) installed on my Ubuntu 18.04, created a "postgres" user and I can log in to the user and run psql without any problems. However, when I start using mikro-orm commands like npx mikro-orm migration:create (video timestamp), I get the following error:

error: password authentication failed for user "postgres"
    at Parser.parseErrorMessage (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:357:11)
    at Parser.handlePacket (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:186:21)
    at Parser.parse (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:101:30)
    at Socket.<anonymous> (/home/<username>/newstack/node_modules/pg-protocol/src/index.ts:7:48)
    at Socket.emit (events.js:315:20)
    at Socket.EventEmitter.emit (domain.js:483:12)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  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: '333',
  routine: 'auth_failed'
}

Here is the error in PostgreSQL log file:

2020-08-28 01:45:18.218 EEST [23088] postgres@newstack FATAL:  password authentication failed for user "postgres"
2020-08-28 01:45:18.218 EEST [23088] postgres@newstack DETAIL:  Password does not match for user "postgres".
    Connection matched pg_hba.conf line 96: "host    all             all             127.0.0.1/32            md5"

And here is my pg_hba.conf:

local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

local   all             all                                     peer
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

I have figured that if the connection would've been local, then it wouldn't have required a password, but why isn't it using local socket? If that can't be changed, then how can I give MikroOrm my database credentials?

like image 660
Laaden Avatar asked Aug 27 '20 23:08

Laaden


People also ask

How do I fix Postgres password authentication failed?

Restart the PostgreSQL service from the Services control panel ( start->run->services. msc ) Connect using psql or pgAdmin4 or whatever you prefer. Run ALTER USER postgres PASSWORD 'fooBarEatsBarFoodBareFoot'


2 Answers

Change "md5" to "trust" like this:

local   all             all                                     peer
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
like image 59
Jyu Viole Grace Avatar answered Nov 09 '22 14:11

Jyu Viole Grace


For me it's worked after i'am added

clientUrl: 'http://localhost:5433'
user: 'postgres',
password: <user pasword for postgres user>

in options object

like image 24
Ivan Gorovoy Avatar answered Nov 09 '22 13:11

Ivan Gorovoy