bard
bard

Reputation: 3052

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

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.

Upvotes: 29

Views: 45227

Answers (3)

Sarvar Nishonboyev
Sarvar Nishonboyev

Reputation: 13090

Just set PGCLUSTER

export PGCLUSTER=9.4/main

Upvotes: 5

Jonathan Baker
Jonathan Baker

Reputation: 184

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.

Upvotes: 6

Daniel Vérité
Daniel Vérité

Reputation: 61516

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.

Upvotes: 16

Related Questions