比较来自世界各地的卖家的域名和 IT 服务价格

PostgreSQL 连接超时 OperationalError 上 Django 和一个新服务器

我的服务器受到损害后,我不得不去一个新的下降 - 如何 DigitalOcean, 和 Debian 杰西,所以我不应该有问题 Heroku, 这似乎涵盖了许多类似的问题。

我使用的是数据库 pg_dump, 它似乎完好无损。 PostgreSQL 安装和工作,但每当我尝试使用数据库 Django ORM, 我得到一个错误 -


OperationalError: could not connect to server: Connection timed out
Is the server running on host "localhost" /127.0.0.1/ and accepting
TCP/IP connections on port 5432?


所以,第一个明显的事情。

Netstat 显示:


tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 613/postgres 
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 554/redis-server 12


我看到了几个进程 PostgreSQL 在
top

和帮助
ps auxw | grep postgres

:


1072 postgres 20 0 234680 129672 126676 S 6.0 3.2 3:06.98 postgres: me databasename [local] COPY +
640 postgres 20 0 227000 119564 117876 S 0.3 2.9 0:03.77 postgres: checkpointer process +
613 postgres 20 0 226712 21252 19824 S 0.0 0.5 0:00.05 /usr/lib/postgresql/9.4/bin/postgres -D /var/lib/postgresql/9.4/main -c config_f+
641 postgres 20 0 226712 5556 4080 S 0.0 0.1 0:02.59 postgres: writer process



systemctl

shows


postgresql.service loaded active exited 
postgresql@9.4-main.service loaded active running


psycopg2 is installed, and I'm working from inside the virtualenv.

Any queries I run from shell using the Django ORM return the above error. I can access and run queries from psql, and it returns data fine, so PostgreSQL appears to be running, but Django can't reach it for whatever reason. The password and username are correct, although I think that would throw a different error in anycase.
https://coderoad.ru/29636574/
it makes no difference.

My Django settings are:


DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "databasename",
"USER": "databaseusername",
"PASSWORD": "databasepasswordhere",
"HOST": "localhost",
"PORT": "5432",
"CONN_MAX_AGE":360,
}
}


/I've tried both localhost and 127.0.0.1 as host, in case it was an IPv4/IPv6 resolution thing, albeit unlikely/
pip freeze

shows:


Django==1.9.6
argparse==1.2.1
click==6.6
django-extensions==1.6.7
django-redis==4.4.3
django-redis-cache==1.6.5
django-rq==0.9.1
django-rq-dashboard==0.3.0
gunicorn==19.5.0
hiredis==0.2.0
newrelic==2.64.0.48
nltk==3.2.1
oauthlib==1.1.1
psycopg2==2.6.1
requests==2.10.0
requests-oauthlib==0.6.1
rq==0.6.0
six==1.10.0
tweepy==3.5.0
wsgiref==0.1.2


https://coderoad.ru/32805224/
I've checked that PostgreSQL, PostgreSQL-contrib, libpq-dev Python-dev are installed.

Testing the connection on command-line
https://coderoad.ru/32098797/
throws the same error.

The real kicker here is - this is all working on the old server, and I can run ORM queries just fine - but it's not a secure server anymore, package manager is broken, so I need to abandon it, and need the new one to work. I can't see any differences in configuration between the two - I wondered if there was a permissions issue, but I get the same issue running as root/via sudo as my regular user.

I'm sure there's a simple configuration setting I've missed, but I'm pretty stumped at the moment!

Edit:

Grabbing the PID of postgres main process and running lsof gives this, though:


postgres 613 postgres 6u IPv4 11589 0t0 TCP localhost:postgresql /LISTEN/
postgres 613 postgres 7u unix 0xffff8800d8e1cc00 0t0 11591 /var/run/postgresql/.s.PGSQL.5432


看起来很奇怪。 这将默认为套接字。 Unix 那里?
已邀请:

八刀丁二

赞同来自:

连接超时错误表示数据库服务器无法以这样的方式使用您的网络设置,以免返回立即错误。 在我的经验中,最好的方法是分别消除连接两侧的故障。 这意味着首先从命令行测试服务器部分连接 psql, 然后在许可后测试Django一侧。

我假设你可以安装 psql.on 服务器。

立即检查:

你能从服务器上发一个服务器吗? 如果没有,请从网络上进行故障排除开始。 /我明白了这一点 localhost, 但仍然尝试 - 这需要很少,至少需要检查假设/.

你能通过吗?可以通过 psql, 使用相同的端口,IP地址等如果您尝试执行此操作时不纠正您获得的错误,请首先尝试修复它们。 最有可能的是,这里出现了同样的问题。 您可能必须检查防火墙和配置 postgresql, 如果这个时间过期了。

一旦他们赚钱,就开始尝试 django. 然后你知道它是特殊的 Django/Python 并且没有服务器端。

要回复问题请先登录注册