Postgresql 错误:连接终止 [英] Postgresql Error: connection terminated

查看:279
本文介绍了Postgresql 错误:连接终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接到 postgres 数据库的简单应用程序.当您加载应用程序时,它会读取大约 30 行数据.但现在每次都不会加载,当我查看我的服务器时,我收到错误错误:连接终止.

i have a simple application linked up to a postgres database. it reads about 30 rows of data when you load up the application. but every now an then it wont load and when i look at my server i have the error Error: connection terminated.

通常如果我在短时间内加载多次.

usually if i load it up several times in a short space of time.

有谁知道为什么会发生这种情况?我是不是太努力了?

does anyone know why this might be happening? am i working it too hard?

代码如下:

    function getDB(callback){
        console.log('inside getDB')
        Client.connect(function(err){
            if(err){
                return console.log('connection error', err)
            }
            Client.query('SELECT * FROM gallery', function(err, result){
                if(err){
                    return console.log('error receiving data', err)
                } else{
                callback(null, result.rows)
                }
                Client.end()
            })

        })
    }

推荐答案

我在将行插入 Postgres 数据库的 Node 方法上遇到了同样的错误:连接终止"错误.这是我修复它的方法.

I ran into the same "Error: Connection terminated" error on a Node method that was inserting rows into a Postgres database. Here's how I was able to fix it.

控制台错误不是很有帮助,所以我查看了 Postgres 日志.(使用 Mac)

The console error was not very helpful, so I looked at the Postgres logs. (using a Mac)

$ tail -10 /usr/local/var/log/postgres.log 
2019-02-24 10:06:38.920 CST [58520] LOG:  could not receive data from client: Connection reset by peer
2019-02-24 10:06:38.921 CST [58520] LOG:  unexpected EOF on client connection with an open transaction

这意味着客户端在服务器完成之前以某种方式断开了连接.就我而言,我没有正确调用我的异步方法,因此客户端在执行数据库语句并且客户端删除数据库连接之前完成.我使用了 async/await 样式的 Node 方法,但我忘记使用 await 调用我的异步方法,这导致了错误.

This means that the client somehow dropped the connection before the server could finish. In my case, I did not call my asynchronous methods correctly so the client finished before the database statement could be executed and client dropped the DB connection. I used the async/await style Node methods and I forgot to call my async method with await, which caused the error.

对于 Node 中的 Postgres 查询,请务必遵循这些示例之一.

Be sure to follow one of these examples for Postgres queries in Node.

这篇关于Postgresql 错误:连接终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆