我在安装和配置了postgresql的地方有一个Ubuntu 18.04 LTS vps。 我可以通过命令行登录到PostgreSQL。但是我无法建立与项目的连接。
但是在部署Adonis项目后,我立即看到以下错误消息
error: error: password authentication failed for user "postgres"
完全错误如下:
error: error: password authentication failed for user "postgres"
0|server | at Connection.parseE (project_directory/node_modules/pg/lib/connection.js:614:13)
0|server | at Connection.parseMessage (project_directory/node_modules/pg/lib/connection.js:413:19)
0|server | at Socket.<anonymous> (project_directory/node_modules/pg/lib/connection.js:129:22)
0|server | at Socket.emit (events.js:315:20)
0|server | at addChunk (_stream_readable.js:295:12)
0|server | at readableAddChunk (_stream_readable.js:271:9)
0|server | at Socket.Readable.push (_stream_readable.js:212:10)
0|server | at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
0|server | From previous event:
0|server | at Client_PG.acquireRawConnection (project_directory/node_modules/knex/lib/dialects/postgres/index.js:147:12)
0|server | at create (project_directory/node_modules/knex/lib/client.js:280:23)
0|server | at project_directory/node_modules/tarn/lib/Pool.js:315:34
0|server | at Object.tryPromise (project_directory/node_modules/tarn/lib/utils.js:53:24)
0|server | at project_directory/node_modules/tarn/lib/Pool.js:315:17
0|server | at new Promise (<anonymous>)
0|server | at callbackOrPromise (project_directory/node_modules/tarn/lib/Pool.js:306:12)
0|server | at Pool._create (project_directory/node_modules/tarn/lib/Pool.js:236:9)
0|server | at Pool._doCreate (project_directory/node_modules/tarn/lib/Pool.js:208:36)
0|server | at Pool._tryAcquireOrCreate (project_directory/node_modules/tarn/lib/Pool.js:159:18)
0|server | at Pool.acquire (project_directory/node_modules/tarn/lib/Pool.js:85:14)
0|server | at project_directory/node_modules/knex/lib/client.js:335:26
0|server | From previous event:
0|server | at Client_PG.acquireConnection (project_directory/node_modules/knex/lib/client.js:334:34)
0|server | at Runner.ensureConnection (project_directory/node_modules/knex/lib/runner.js:228:24)
0|server | at Runner.run (project_directory/node_modules/knex/lib/runner.js:34:42)
0|server | at Builder.Target.then (project_directory/node_modules/knex/lib/interface.js:20:43) {
0|server | length: 104,
0|server | severity: 'FATAL',
0|server | code: '28P01',
0|server | detail: undefined,
0|server | hint: undefined,
0|server | position: undefined,
0|server | internalPosition: undefined,
0|server | internalQuery: undefined,
0|server | where: undefined,
0|server | schema: undefined,
0|server | table: undefined,
0|server | column: undefined,
0|server | dataType: undefined,
0|server | constraint: undefined,
0|server | file: 'auth.c',
0|server | line: '333',
0|server | routine: 'auth_failed'
0|server | }
尽管我进行了一些研究,但按照这些说明,我更新了pg_hba.conf
文件。在下面:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 peer
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
这是我的项目environemnt(.env)文件
HOST=127.0.0.1
PORT=8989
NODE_ENV=development
APP_NAME=
APP_URL=http://${HOST}:${PORT}
CACHE_VIEWS=false
APP_KEY=my_app_key
DB_CONNECTION=pg
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=my_db_pass
DB_DATABASE=my_db_name
... other credential goes here ....
注意:my_db_pass
是我的postgres用户名的密码。我可以在命令行中使用此密码成功登录。
有人可以帮我弄清楚哪里出了问题吗?
答案 0 :(得分:1)
我刚刚改变了这个
let client = new Client({
user: process.env.USER,
host: process.env.HOST,
database: process.env.DATABASE,
password: process.env.PASSWORD,
port: process.env.DB_PORT,
});
到这里
let client = new Client({
user: "postgres",
host: process.env.HOST,
database: process.env.DATABASE,
password: "aaaaa",
port: process.env.DB_PORT,
});
在服务器中,process.env.USER
不是我给定的用户名。 IDK为什么但是值被改变了。
答案 1 :(得分:0)
进入config / database.js
找到PostgreSQL配置并像这样替换密码值
password: "direct set your password",
并尝试在Cpanel托管中遇到相同的问题,并且尝试使用此方法