Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres error: No existing local cluster is suitable as a default target

Tags:

postgresql

I have an old project that I'm trying to get back into, but I can't enter postgres. Running sudo -u postgres psql gives me:

Error: No existing local cluster is suitable as a default target. 
Please see man pg_wrapper(1) how to specify one.

I'm wondering if this might be because I upgraded postgres to version 9.4 a few months back. This is my output for dpkg --get-selections |grep postgres:

postgresql                          install
postgresql-9.3                      install
postgresql-9.4                      install
postgresql-client-9.3               install
postgresql-client-9.4               install
postgresql-client-common            install
postgresql-common                   install
postgresql-contrib                  install
postgresql-contrib-9.3              install
postgresql-contrib-9.4              install
postgresql-server-dev-9.3           install

These are my current clusters from pg_lsclusters:

Ver Cluster Port Status Owner    Data directory               Log file
9.4 apps    5434 online postgres /var/lib/postgresql/9.4/apps /var/log/postgresql/postgresql-9.4-apps.log

9.4 main    5433 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log

What can I do to be able to access postgres again? Googling hasn't been much help.

like image 948
bard Avatar asked Jun 30 '15 10:06

bard


3 Answers

As none of your clusters listens on the default port 5432, psql (which is in fact a link to pg_wrapper) doesn't know which one should be the "default".

You may use psql --cluster 9.4/apps [other arguments] to access the first cluster and psql --cluster 9.4/main [other arguments] for the second one.

Or alternatively define a $PGCLUSTER environment variable to 9.4/apps or 9.4/main

These come from rules #2 and #4 (out of 8) of pg_wrapper manpage.

like image 158
Daniel Vérité Avatar answered Nov 02 '22 22:11

Daniel Vérité


If you don't care what your default cluster is, and just want things to work like they did before, just specify the port you want to connect to with

psql -p 5432

and postgres won't try to be clever for you and use a "cluster", whatever that is.

like image 5
Jonathan Baker Avatar answered Nov 02 '22 20:11

Jonathan Baker


Just set PGCLUSTER

export PGCLUSTER=9.4/main
like image 4
nsv Avatar answered Nov 02 '22 22:11

nsv