节点/ PostgreSQL错误:在TCPConnectWrap.afterConnect上连接ECONNREFUSED 127.0.0.1:5432 [作为oncomplete](net.js:1141:16)

时间:2020-06-01 15:34:12

标签: javascript node.js postgresql npm knex.js

我一直在运行连接到Postgresql DB(通过Knex)的Node服务器。一切正常,一切正常,直到笔记本电脑崩溃。自重新启动以来,数据库连接根本无法工作,并且出现以下错误:

Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)

尝试通过DBeaver进行Postgresql连接也会导致相同的错误。我的服务器本身可以完全启动。仅在尝试尝试连接到数据库的API调用时出现错误。我的数据库连接设置如下:

const db = knex({
  client: 'pg',
  connection: DATABASE_URL,
});

同样,一切正常,直到我的笔记本电脑崩溃为止。我猜想在此过程中发生了某些事情,但是我不确定该如何解决。任何想法/建议将不胜感激!

完整的npm日志如下:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/Users/<name>/.nvm/versions/node/v12.16.2/bin/node',
1 verbose cli   '/Users/<name>/.nvm/versions/node/v12.16.2/bin/npm',
1 verbose cli   'run',
1 verbose cli   'dev'
1 verbose cli ]
2 info using npm@6.14.4
3 info using node@v12.16.2
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle express-boilerplate@1.0.0~predev: express-boilerplate@1.0.0
6 info lifecycle express-boilerplate@1.0.0~dev: express-boilerplate@1.0.0
7 verbose lifecycle express-boilerplate@1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle express-boilerplate@1.0.0~dev: PATH:         /Users/<name>/.nvm/versions/node/v12.16.2/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/<name>/Desktop/BLOC/productify-server/node_modules/.bin:/Users/<name>/.nvm/versions/node/v12.16.2/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/<name>/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/<name>/Downloads/apache-maven-3.6.1 :/usr/local/share/dotnet
9 verbose lifecycle express-boilerplate@1.0.0~dev: CWD: /Users/<name>/Desktop/BLOC/productify-server
10 silly lifecycle express-boilerplate@1.0.0~dev: Args: [ '-c', 'nodemon src/server.js' ]
11 silly lifecycle express-boilerplate@1.0.0~dev: Returned: code: 130  signal: null
12 info lifecycle express-boilerplate@1.0.0~dev: Failed to exec dev script
13 verbose stack Error: express-boilerplate@1.0.0 dev: `nodemon src/server.js`
13 verbose stack Exit status 130
13 verbose stack     at EventEmitter.<anonymous> (/Users/<name>/.nvm/versions/node/v12.16.2/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:310:20)
13 verbose stack     at ChildProcess.<anonymous> (/Users/<name>/.nvm/versions/node/v12.16.2/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:310:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid express-boilerplate@1.0.0
15 verbose cwd /Users/<name>/Desktop/BLOC/productify-server
16 verbose Darwin 19.4.0
17 verbose argv "/Users/<name>/.nvm/versions/node/v12.16.2/bin/node" "/Users/<name>/.nvm/versions/node/v12.16.2/bin/npm" "run" "dev"
18 verbose node v12.16.2
19 verbose npm  v6.14.4
20 error code ELIFECYCLE
21 error errno 130
22 error express-boilerplate@1.0.0 dev: `nodemon src/server.js`
22 error Exit status 130
23 error Failed at the express-boilerplate@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 130, true ]

1 个答案:

答案 0 :(得分:3)

您在Windows计算机上的PostgreSQL遇到问题,请尝试使用以下命令重新启动PostgreSQL服务器:

pg_ctl -D "C:\Program Files\PostgreSQL\9.6\data" restart

如果这不能解决您的问题,请尝试查看问题所在的日志。

日志可在目录%PROGRAMFILES%\PostgreSQL\9.3\data\pg_log中使用(如果不使用默认值,则根据PostgreSQL版本和PostgreSQL安装位置进行调整)。