简体   繁体   English

用于Django Web应用程序的ubuntu上的Postgresql 9.3错误:cluster_port_ready:找不到psql二进制文件

[英]Postgresql 9.3 on ubuntu for Django web application Error: cluster_port_ready: could not find psql binary

I'm having some issues with postgresql 9.3 running on ubuntu 14.04.5 我在ubuntu 14.04.5上运行的PostgreSQL 9.3遇到一些问题

I had a django web application running using NGINX/Gunicorn, for a few weeks, then one day I went to use it and I got an OperationalError: 我有一个使用NGINX / Gunicorn运行的django Web应用程序,运行了几个星期,然后有一天我去使用它,并且遇到了OperationalError:

Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?

After researching, it became apparent that the postgresql server wasn't running. 经过研究,很明显postgresql服务器没有运行。 I then attempted to start it, and got the following error: 然后,我尝试启动它,并收到以下错误:

* No PostgreSQL clusters exist; see "man pg_createcluster"

Alarming, but my data is backed up just fine, so I did: 令人震惊的是,但是我的数据备份很好,所以我做到了:

pg_createcluster 9.3 main --start

and then I got: 然后我得到:

Error: cluster configuration already exists

No problem. 没问题。 I'll drop it and create a new one, I thought: 我想将其删除并创建一个新的,我认为:

pg_dropcluster 9.3 main --stop

that ran fine, and so I ran: 很好,所以我跑了:

pg_createcluster 9.3 main --start

again, and now it created the cluster apparently, but would not start: 再次,现在它显然创建了集群,但无法启动:

Creating new cluster 9.3/main ...
  config /etc/postgresql/9.3/main
  data   /var/lib/postgresql/9.3/main
  locale en_US.UTF-8
  port   5432
Error: cluster_port_ready: could not find psql binary

does anyone have any advice as to how to address this? 有没有人对如何解决这个问题有任何建议? I have done apt-get remove and install for postgresql, and still same results. 我已经完成了apt-get remove和postgresql的安装,结果仍然相同。

Thanks in advance! 提前致谢!

UPDATE: 更新:

So, I tried the suggestion below to run the following: 因此,我尝试了以下建议以运行以下命令:

/usr/lib/postgresql/9.3/bin/initdb -D /var/lib/postgresql/data -W -A md5

which returned: 返回:

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/data/base/1 ... ok
initializing pg_authid ... ok
Enter new superuser password:
Enter it again:
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/data
or
    /usr/lib/postgresql/9.3/bin/pg_ctl -D /var/lib/postgresql/data -l logfile start

So I ran: 所以我跑了:

user$ /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgres
ql/data

and got: 并得到:

LOG:  could not bind IPv6 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING:  could not create listen socket for "localhost"
FATAL:  could not create any TCP/IP sockets

So I was unable to recover the postgres instance I was trying to run, so I used this stack overflow article on How to purge and thoroughly uninstall postgres . 因此,我无法恢复尝试运行的postgres实例,因此我使用了这篇有关如何清除和彻底卸载postgres的堆栈溢出文章。 As far as why this happened, I am still at a loss. 至于为什么发生这种情况,我仍然茫然。 I read that my issue could have been caused by my locale environment variables for LANGUAGE, and LANG_ALL. 我读到我的问题可能是由于我的LANGUAGE和LANG_ALL的区域设置环境变量引起的。 Or it's possible that this could have been caused after an update because I didn't specify what version of postgres I wanted to install when I ran apt-get initially. 或者这可能是由于更新后引起的,因为我最初运行apt-get时没有指定要安装的postgres版本。 Regardless, here are the commands I ran that got me back into business: 无论如何,以下是我运行的命令使我重新开始工作:

apt-get --purge remove postgresql\*

After this command, I got some errors complaining about an invalid data directory again, so on the advice of a post that's not marked as the answer from the link above, I also ran: 执行此命令后,我再次抱怨无效的数据目录时遇到一些错误,因此,根据上面链接未标记为答案的帖子的建议,我也运行了:

apt-get autoremove postgresql*

That seemed to go well, so I returned to the instructions as laid out by the accepted answer: 这似乎进展顺利,所以我回到了被接受的答案所列出的说明中:

rm -r /etc/postgresql/
rm -r /etc/postgresql-common/
rm -r /var/lib/postgresql/
userdel -r postgres
groupdel postgres

That appeared to complete without errors, except that the postgres user had already been removed by the previous commands.. 这似乎没有错误地完成,除了postgres用户已被先前的命令删除。

I then ensured that my locale environment variables were set, based on an a related article titled: Solving "no PostgresSQL Clusters found" error I ran: #dpkg-reconfigure locales 然后,我根据标题为“ 解决“未找到PostgresSQL群集””的相关文章,确保我设置了语言环境环境变量:#dpkg-reconfigure locales

Once that was all finished, I did a fresh install, this time specifying the version number: 完成所有操作后,我进行了全新安装,这次指定版本号:

apt-get install postgresql-9.3 postgresql-contrib-9.3 postgresql-doc-9.3

after the install completed postgres started automatically, and it seems to be fine now. 安装完成后,postgres自动启动,现在看来还不错。

create postgresql database cluster: 创建PostgreSQL数据库集群:

$ sudo su
# mkdir /var/lib/postgresql/data
# chown -R postgres:postgres /var/lib/postgresql/data

# su postgres
$ /usr/lib/postgresql/9.3/bin/initdb -D /var/lib/postgresql/data -W -A md5

If this error messages: 如果出现此错误信息:

LOG:  could not bind IPv4 socket: Address already in use

It mean postgresql already running, you need to restart it. 这意味着postgresql已经在运行,您需要重新启动它。

You can restart service postgresql in ubuntu 14.04 with this command: 您可以使用以下命令在ubuntu 14.04中重新启动服务postgresql:

$ sudo sh /etc/init.d/postgresql restart

In new Ubuntu with systemd, to restart postgresql with this command: 在具有systemd的新Ubuntu中,使用以下命令重新启动postgresql:

$ sudo systemctl restart postgresql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM