Knex:错误池2 - 错误:密码验证失败的用户“用户名”(不使用UNIX帐户)

问题描述:

用下面的命令,会出现问题:Knex:错误池2 - 错误:密码验证失败的用户“用户名”(不使用UNIX帐户)

knex --knexfile config/db/knexfile.js migrate:latest

我收到以下错误:

Knex:warning - Pool2 - Error: Pool was destroyed 
Knex:Error Pool2 - error: password authentication failed for user "dennis" 
Knex:Error Pool2 - error: password authentication failed for user "dennis" 
Error: Pool was destroyed 
    at Pool._destroyPool (/home/dennis/projects/amgen-sites/data-api/node_modules/pool2/lib/pool.js:560:20) 
    at Pool.<anonymous> (/home/dennis/projects/amgen-sites/data-api/node_modules/pool2/lib/pool.js:474:18) 
    at Pool.<anonymous> (/home/dennis/projects/amgen-sites/data-api/node_modules/pool2/lib/pool.js:517:17) 
    at tryCatcher (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/util.js:16:23) 
    at Promise.errorAdapter [as _rejectionHandler0] (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/nodeify.js:35:34) 
    at Promise._settlePromise (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/promise.js:558:21) 
    at Promise._settlePromise0 (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/promise.js:606:10) 
    at Promise._settlePromises (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/promise.js:681:18) 
    at Async._drainQueue (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/async.js:138:16) 
    at Async._drainQueues (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/async.js:148:10) 
    at Immediate.Async.drainQueues (/home/dennis/projects/amgen-sites/data-api/node_modules/knex/node_modules/bluebird/js/release/async.js:17:14) 
    at runCallback (timers.js:570:20) 
    at tryOnImmediate (timers.js:550:5) 
    at processImmediate [as _immediateCallback] (timers.js:529:5) 

它似乎不是使用我的UNIX帐户,而是尝试使用用户名/密码进行身份验证。

我曾尝试以下解决方案:

  • 更新pg最新
  • 更新knex最新
  • 替换的方法,从信任:

    # IPv4 local connections: host all all 127.0.0.1/32 trust

  • 从替换连接字符串到[postgres://[db name]

    connection: { 
        database: 'postgres://data-api-dev', 
        user:  '', 
        password: '' 
    }, 
    

,我怎么把它用我的UNIX帐户?

我在Ubuntu 16.04上使用Node v6.3.1。

这里是我安装的软件包:

├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] (git://github.com/gulpjs/gulp.git#d8f5c90a0622d19ef1943a2a3d02dc50e3c853e7) 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
└── [email protected] 
+0

hello,AFAIK knex只是将配置对象传递给pg库:https://github.com/brianc/node-postgres/wiki/Client如果是这样,那么最好提供一些方法来使用unix套接字tcp连接。 – Sombriks

+0

@Sombriks你是对的,这是一个postgresql配置问题。 – MrSnappingTurtle

原来,从更名到md5trust方法是正确的解决方案。进行更改后,我忘记重新启动postgresql服务,因此第一次无法运行。