postgres PEM服务器,连接数据库的问题

时间:2016-05-18 10:35:29

标签: postgresql

我对Postgres数据库故障排除不太满意,但我在其上运行了一个大型项目数据库。

今天突然间我在尝试访问我的服务器时遇到错误,附件是错误截图的图片。我真的不想丢失我的数据,因为它没有备份几个月。

我试图重新安装,但它说端口搞砸了。

重新安装时的消息是:

  

“psql:无法连接到服务器:连接被拒绝(0x0000274D / 10061)
  服务器是否在主机“127.0.0.1”上运行并接受                           端口5432上的TCP / IP连接?

1 个答案:

答案 0 :(得分:0)

Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?这是你可以回答的两个问题:

  • 在主机“127.0.0.1”(aka localhost)上运行的服务器是否使用:
    1. ps auxw | grep postgres#来回答这个问题
  • ...接受端口5432上的TCP / IP连接?有几种方法可以回答这个问题:
    1. psql -h 127.0.0.1 -p 5432 postgres
    2. telnet localhost 5432
    3. nmap -p 5432 localhost

(1)的结果应该是:

postgres 30402  0.0  0.1 238488 12924 ?        S    12:09   0:01 /opt/postgres/bin/postmaster -D /data/db/postgres/pgdata
postgres 30409  0.0  0.0  94644  1308 ?        Ss   12:09   0:00 postgres: logger process                                
postgres 30411  0.0  0.3 238628 46964 ?        Ss   12:09   0:01 postgres: checkpointer process                          
postgres 30412  0.0  0.0 238628  4764 ?        Ss   12:09   0:00 postgres: writer process                                
postgres 30413  0.0  0.0 238628  5832 ?        Ss   12:09   0:00 postgres: wal writer process                            
postgres 30414  0.0  0.0 239036  2820 ?        Ss   12:09   0:01 postgres: autovacuum launcher process                   
postgres 30415  0.0  0.0  97884  2460 ?        Ss   12:09   0:03 postgres: stats collector process           

(2)的结果应该是:

Password:

(3)的结果应该是:

Trying ::1...
Connected to localhost.localdomain.
Escape character is '^]'.

(4)的结果应该是:

Starting Nmap 6.40 ( http://nmap.org ) at 2016-05-18 15:14 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000050s latency).
Other addresses for localhost (not scanned): 127.0.0.1
rDNS record for 127.0.0.1: localhost.localdomain
PORT     STATE SERVICE
5432/tcp open  postgresql

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

如果(1)失败(没有给出相关的输出),postgres显然没有运行。

  • 你没有启动它(在/etc/init.d /中应该有一个服务文件)
  • 您试图启动它,但无法启动
    • 二进制文件不存在,未找到或错误
    • 数据目录不存在,找不到或拥有错误的所有者/权利
    • 数据目录包含文件,但不包含此版本

if(2,3,4)失败(不提供相关输出)

  • postgres没有监听inet套接字,只在unix-domain套接字上检查:检查你的配置文件listen_address = '*'
  • 最后,可能存在防火墙问题。 (检查你的iptables设置。或者其他)