简体   繁体   中英

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

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:

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. 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.

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 . 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. 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. 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..

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

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.

create postgresql database cluster:

$ 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.

You can restart service postgresql in ubuntu 14.04 with this command:

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

In new Ubuntu with systemd, to restart postgresql with this command:

$ sudo systemctl restart postgresql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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