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

时间:2016-08-21 04:12:50

标签: node.js postgresql pg knex.js

使用以下命令会出现问题:

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

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

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

如何让它使用我的UNIX帐户?

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

以下是我安装的软件包:

├── bluebird@2.10.2
├── body-parser@1.15.2
├── bookshelf@0.10.0
├── chai@3.5.0
├── chai-as-promised@5.3.0
├── colors@1.1.2
├── convict@1.4.0
├── cors@2.7.1
├── express@4.14.0
├── gulp@4.0.0-alpha.2 (git://github.com/gulpjs/gulp.git#d8f5c90a0622d19ef1943a2a3d02dc50e3c853e7)
├── gulp-exit@0.0.2
├── gulp-mocha@2.2.0
├── gulp-nodemon@2.1.0
├── gulp-using@0.1.0
├── jsonwebtoken@5.7.0
├── knex@0.11.10
├── lodash@3.10.1
├── pg@6.1.0
├── request-promise@0.4.3
├── sinon@1.17.5
├── sinon-as-promised@4.0.2
├── sinon-chai@2.8.0
├── supertest@1.2.0
└── validator@4.9.0

1 个答案:

答案 0 :(得分:0)

事实证明,将方法从md5重命名为trust是正确的解决方案。我在进行更改后忘记重新启动postgresql服务,因此第一次无效。