postgresql Postgres 错误:没有现有的本地集群适合作为默认目标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31135703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres error: No existing local cluster is suitable as a default target
提问by bard
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:
我有一个旧项目,我想重新开始,但我无法进入 postgres。跑步sudo -u postgres psql
给了我:
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
:
我想知道这是否可能是因为几个月前我将 postgres 升级到了 9.4 版。这是我的输出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
:
这些是我当前的集群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.
我该怎么做才能再次访问 postgres?谷歌搜索并没有太大帮助。
采纳答案by Daniel Vérité
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".
由于您的集群都没有侦听默认端口5432
,psql
(实际上是到 的链接pg_wrapper
)不知道哪个应该是“默认”。
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.
您可以使用psql --cluster 9.4/apps [other arguments]
访问第一个集群和psql --cluster 9.4/main [other arguments]
第二个集群。
Or alternatively define a $PGCLUSTER
environment variable to 9.4/apps
or 9.4/main
或者或者定义一个$PGCLUSTER
环境变量到9.4/apps
或9.4/main
These come from rules #2 and #4 (out of 8) of pg_wrapper manpage.
这些来自pg_wrapper 手册页的规则 #2 和 #4(共 8 条)。
回答by Jonathan Baker
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.
并且 postgres 不会试图让你聪明并使用“集群”,无论是什么。
回答by Sarvar Nishonboev
Just set PGCLUSTER
只需设置 PGCLUSTER
export PGCLUSTER=9.4/main