无法连接到postgres

时间:2019-12-24 00:40:11

标签: node.js linux postgresql sequelize.js

几天前,我从Windows迁移到linux,并且一直做得很棒,直到我不得不与同事一起进行特定项目为止,现在由于以下原因,我似乎无法启动该应用程序:数据库配置不断被拒绝并引发错误。

我的.env文件

## Setup NODE_ENV
NODE_ENV=development

## Setup your psql development database
DB_USER=postgres
DB_PASS= password
DB_NAME=data
DB_HOST=localhost

现在,此.env配置在Windows计算机上可以正常工作,但是当我尝试在Linux上使用它时,出现以下错误

ERROR: password authentication failed for user "optimusPrime"

有人可以解释为什么它以optimusPrime(这是我的工作名称)optimusPrime@root的身份而不是postgres的身份吗?我该如何配置它或编辑代码以使其与我的Node.js应用程序一起使用linux(我和我的团队正在使用续集ORM),就像在Windows上一样。配置文件看起来像

require('dotenv').config();

module.exports = {
  development: {
    username: process.env.DB_USER,
    password: process.env.DB_PASS,
    database: process.env.DB_NAME,
    host: process.env.DB_HOST,
    dialect: 'postgres',
  }
 }

这是日志文件中的错误

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/home/optimusPrime/.nvm/versions/node/v12.0.0/bin/node',
1 verbose cli   '/home/optimusPrime/.nvm/versions/node/v12.0.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'postinstall'
1 verbose cli ]
2 info using npm@6.13.1
3 info using node@v12.0.0
4 verbose run-script [ 'postinstall' ]
5 info lifecycle Dae-Alright-Backend@1.0.0~postinstall: Dae-Alright-Backend@1.0.0
6 verbose lifecycle Dae-Alright-Backend@1.0.0~postinstall: unsafe-perm in lifecycle true
7 verbose lifecycle Dae-Alright-Backend@1.0.0~postinstall: PATH: /home/optimusPrime/.nvm/versions/node/v12.0.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/optimusPrime/Documents/projects/Dae-Alright-Backend/node_modules/.bin:/home/optimusPrime/.nvm/versions/node/v12.0.0/bin:/home/optimusPrime/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
8 verbose lifecycle Dae-Alright-Backend@1.0.0~postinstall: CWD: /home/optimusPrime/Documents/projects/Dae-Alright-Backend
9 silly lifecycle Dae-Alright-Backend@1.0.0~postinstall: Args: [ '-c', 'npm run build && npm run db:migrate' ]
10 silly lifecycle Dae-Alright-Backend@1.0.0~postinstall: Returned: code: 1  signal: null
11 info lifecycle Dae-Alright-Backend@1.0.0~postinstall: Failed to exec postinstall script
12 verbose stack Error: Dae-Alright-Backend@1.0.0 postinstall: `npm run build && npm run db:migrate`
12 verbose stack Exit status 1
12 verbose stack     at EventEmitter.<anonymous> (/home/optimusPrime/.nvm/versions/node/v12.0.0/lib/npm/node_modules/npm-lifecycle/index.js:332:16)
12 verbose stack     at EventEmitter.emit (events.js:210:5)
12 verbose stack     at ChildProcess.<anonymous> (/home/optimusPrime/.nvm/versions/node/v12.0.0/lib/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
12 verbose stack     at ChildProcess.emit (events.js:210:5)
12 verbose stack     at maybeClose (internal/child_process.js:1023:16)
12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:281:5)
13 verbose pkgid Dae-Alright-Backend@1.0.0
14 verbose cwd /home/optimusPrime/Documents/projects/Dae-Alright-Backend
15 verbose Linux 4.15.0-54-generic
16 verbose argv "/home/optimusPrime/.nvm/versions/node/v12.0.0/bin/node" "/home/optimusPrime/.nvm/versions/node/v12.0.0/bin/npm" "run" "postinstall"
17 verbose node v12.0.0
18 verbose npm  v6.13.1
19 error code ELIFECYCLE
20 error errno 1
21 error Dae-Alright-Backend@1.0.0 postinstall: `npm run build && npm run db:migrate`
21 error Exit status 1
22 error Failed at the Dae-Alright-Backend@1.0.0 postinstall script.
22 error This is probably not a problem with npm. There is likely additional logging output above.
23 verbose exit [ 1, true ]

1 个答案:

答案 0 :(得分:0)

显然,我的pg_hba.conf文件需要进行更好的编辑

sudo nano /etc/postgresql/10/main/pg_hba.conf

所以我以超级用户身份对其进行了打开和编辑,以便使我想使用的用户(我在启动该项目时最初创建的用户)将其从md5更改为trust

# Database administrative login by Unix domain socket
local   all             postgres                                trust

local   all             otherUser                               trust

为了安全起见,如果我将otherUser设置为postgres超级用户,那么我可以更改其密码,也可以在项目中使用它