psql: 服务器意外关闭了连接 [英] psql: server closed the connection unexepectedly

查看:145
本文介绍了psql: 服务器意外关闭了连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试运行这个通过 Postgre DB 服务器的批处理文件并运行两个不同的 sql 文件,如下所示:

I've been trying to run this batch file that goes through the Postgre DB Server and run two different sql files, as shown below:

set PGPASSWORD=blah
cls
@echo on
"C:Progra~1pgAdmin III1.16psql" -d [db name] -h [server name] -p 5432 -U postgres -f C:query1.sql
"C:Progra~1pgAdmin III1.16psql" -d [db name] -h [server name] -p 5432 -U postgres -f C:query2.sql

但问题来了,有时我会为 query1 或 query2 的命令收到以下错误:

But the issue comes that sometimes I will get the following error for either the command for query1 or query2:

psql: server closed the connection unexpectedly 
This probably means the server terminated abnormally
before or while processing the request.

这只是偶尔发生,所以我不完全确定为什么会发生.有人可以解释为什么会这样,以及是否有解决此问题的方法.谢谢!

This only happens sometimes, so I'm not entirely sure why it is happening. Can someone explain why this is the case and if there's a solution to this problem. Thanks!

更新:在实际 Postgre 应用程序中尝试打开远程服务器时,有时我也会遇到相同的错误:发生错误:"服务器意外关闭了连接这可能意味着服务器异常终止在处理请求之前或期间."

Update: I also get the same error SOMETIMES when trying to open the remote server in the actual Postgre application: "An error has occured: "server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request."

在我单击错误弹出窗口后,我也立即收到了 Guru Hint 提示:

I also get this Guru Hint thing right after I click out of the error popup:

数据库编码创建数据库 VA-trac 以使用 SQL_ASCII 编码存储数据.此编码仅针对 7 位字符定义;未定义第 8 位设置的字符(非 ASCII 字符 127-255)的含义.因此,服务器不可能将数据转换为其他编码.如果您在数据库中存储非 ASCII 数据,强烈建议您使用代表您的语言环境字符集的正确数据库编码,以便在需要时从自动转换为不同的客户端编码中获益.如果您将非 ASCII 数据存储在 SQL_ASCII 数据库中,您可能会遇到由代码转换问题引起的写入数据库或从数据库读取的奇怪字符.在使用不同的客户端程序和驱动程序访问数据库时,这可能会让您很头疼.对于大多数安装,Unicode (UTF8) 编码将提供最灵活的功能.

Database encoding The database VA-trac is created to store data using the SQL_ASCII encoding. This encoding is defined for 7 bit characters only; the meaning of characters with the 8th bit set (non-ASCII characters 127-255) is not defined. Consequently, it is not possible for the server to convert the data to other encodings. If you're storing non-ASCII data in the database, you're strongly encouraged to use a proper database encoding representing your locale character set to take benefit from the automatic conversion to different client encodings when needed. If you store non-ASCII data in an SQL_ASCII database, you may encounter weird characters written to or read from the database, caused by code conversion problems. This may cause you a lot of headache when accessing the database using different client programs and drivers. For most installations, Unicode (UTF8) encoding will provide the most flexible capabilities.

无论如何,服务器在之后仍然打开,从那时起我就可以访问数据库了.

Regardless, the server still opens up afterward and I'm able to access the database from that point on.

推荐答案

留在这里获取信息,

如果 PostgreSQL 服务器在另一台机器上并且未侦听外部接口,也可能导致此错误.

This error can also be caused if PostgreSQL server is on another machine and is not listening on external interfaces.

要调试此特定问题,您可以按照以下步骤操作:

To debug this specific problem, you can follow theses steps:

  • 看看你的postgresql.conf,sudo vim/etc/postgresql/9.3/main/postgresql.conf
  • 添加这一行:listen_addresses = '*'
  • 重启服务sudo/etc/init.d/postgresql restart

(注意,上面的命令是针对 ubuntu 的.其他 linux 发行版或操作系统可能有不同的这些文件的路径)

(Note, the commands above are for ubuntu. Other linux distro or OS may have different path to theses files)

注意:使用'*'作为监听地址将监听所有接口.如果你做 '0.0.0.0' 那么它会监听所有的 ipv4,如果你做 '::' 那么它会监听所有的 ipv6.

Note: using '*' for listening addresses will listen on all interfaces. If you do '0.0.0.0' then it'll listen for all ipv4 and if you do '::' then it'll listen for all ipv6.

http://www.postgresql.org/docs/9.3/static/runtime-config-connection.html

这篇关于psql: 服务器意外关闭了连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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