psql:致命:数据库“<用户>"不存在 [英] psql: FATAL: database &quot;&lt;user&gt;&quot; does not exist

查看:72
本文介绍了psql:致命:数据库“<用户>"不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Mac 版 PostgreSql 应用程序(http://postgresapp.com/).我过去曾在其他机器上使用过它,但在我的 macbook 上安装时给我带来了一些麻烦.我已经安装了应用程序并运行了:

I'm using the PostgreSql app for mac (http://postgresapp.com/). I've used it in the past on other machines but it's giving me some trouble when installing on my macbook. I've installed the application and I ran:

psql -h localhost

它返回:

psql: FATAL:  database "<user>" does not exist

似乎我什至无法运行控制台来创建它试图找到的数据库.当我刚运行时也会发生同样的事情:

It seems I can't even run the console to create the database that it's attempting to find. The same thing happens when I just run:

psql 

或者如果我从应用程序下拉菜单中启动 psql:

or if I launch psql from the application drop down menu:

机器统计:

  • OSX 10.8.4

  • OSX 10.8.4

psql (PostgreSQL) 9.2.4

psql (PostgreSQL) 9.2.4

感谢任何帮助.

我还尝试通过自制软件安装 PostgreSql,但遇到了同样的问题.我还阅读了说明的应用程序文档页面:

I've also attempted to install PostgreSql via homebrew and I'm getting the same issue. I've also read the applications documentation page that states:

当 Postgres.app 首次启动时,它会创建 $USER 数据库,当没有指定时,这是 psql 的默认数据库.这默认用户是 $USER,没有密码.

When Postgres.app first starts up, it creates the $USER database, which is the default database for psql when none is specified. The default user is $USER, with no password.

所以看起来应用程序没有创建 $USER 但是我已经安装->卸载-重新安装了好几次,所以它一定是我的机器有问题.

So it would seem the application is not creating $USER however I've installed->uninstalled-reinstalled several times now so it must be something with my machine.

我找到了答案,但我不确定作为在此线程上回答的用户它是如何工作的 -> 让 Postgresql 在 Mac 中运行:数据库postgres"不存在没有跟进.我使用以下命令打开 psql:

I found the answer but I'm not sure exactly how it works as the user who answered on this thread -> Getting Postgresql Running In Mac: Database "postgres" does not exist didn't follow up. I used the following command to get psql to open:

psql -d template1

我不会回答这个问题,直到有人可以解释为什么会这样.

推荐答案

您的包管理器似乎未能为您创建名为 $user 的数据库.原因

It appears that your package manager failed to create the database named $user for you. The reason that

psql -d template1

对您有用的是 template1 是由 postgres 本身创建的数据库,并且存在于所有安装中.您显然能够登录到 template1,因此您必须拥有数据库分配给您的某些权限.在 shell 提示下试试这个:

works for you is that template1 is a database created by postgres itself, and is present on all installations. You are apparently able to log in to template1, so you must have some rights assigned to you by the database. Try this at a shell prompt:

createdb

然后看看你是否可以用

psql -h localhost

这将简单地为您的登录用户创建一个数据库,我认为这正是您正在寻找的.如果 createdb 失败,那么您没有足够的权限来创建自己的数据库,您将不得不弄清楚如何修复 homebrew 包.

This will simply create a database for your login user, which I think is what you are looking for. If createdb fails, then you don't have enough rights to make your own database, and you will have to figure out how to fix the homebrew package.

这篇关于psql:致命:数据库“<用户>"不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆