博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
psql:FATAL:数据库“<user>”不存在
阅读量:2290 次
发布时间:2019-05-09

本文共 4343 字,大约阅读时间需要 14 分钟。

本文翻译自:

I'm using the PostgreSql app for mac ( ). 我正在使用PostgreSql应用程序的mac( )。 I've used it in the past on other machines but it's giving me some trouble when installing on my macbook. 我以前在其他机器上使用它但是在我的macbook上安装时给我带来了一些麻烦。 I've installed the application and I ran: 我安装了应用程序,然后运行:

psql -h localhost

It returns: 它返回:

psql: FATAL:  database "
" 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

or if I launch psql from the application drop down menu: 或者如果我从应用程序下拉菜单中启动psql:

Machine stats: 机器统计:

  • OSX 10.8.4 OSX 10.8.4

  • psql (PostgreSQL) 9.2.4 psql(PostgreSQL)9.2.4

Any help is appreciated. 任何帮助表示赞赏。

I've also attempted to install PostgreSql via homebrew and I'm getting the same issue. 我也试图通过自制软件安装PostgreSql,我遇到了同样的问题。 I've also read the applications documentation page that states: 我还阅读了应用程序文档页面,其中说明:

When Postgres.app first starts up, it creates the $USER database, which is the default database for psql when none is specified. 当Postgres.app首次启动时,它会创建$ USER数据库,当没有指定时,它是psql的默认数据库。 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. 所以似乎应用程序没有创建$ USER但是我已经安装了 - >卸载 - 重新安装了几次,所以它必须是我的机器的东西。

I found the answer but I'm not sure exactly how it works as the user who answered on this thread -> didn't follow up. 我找到答案,但我不确定它是如何工作的,因为在这个线程上回答的用户 - > 没有跟进。 I used the following command to get psql to open: 我使用以下命令来打开psql:

psql -d template1

I'll leave this one unanswered until someone can provide an explanation for why this works. 我会留下这个答案,直到有人可以解释为什么这样做。


#1楼

参考:


#2楼

It appears that your package manager failed to create the database named $user for you. 您的包管理器似乎无法为您创建名为$ user的数据库。 The reason that 原因

psql -d template1

works for you is that template1 is a database created by postgres itself, and is present on all installations. 适合你的是template1是由postgres自己创建的数据库,并且存在于所有安装中。 You are apparently able to log in to template1, so you must have some rights assigned to you by the database. 您显然可以登录到template1,因此您必须拥有数据库为您分配的一些权限。 Try this at a shell prompt: 在shell提示符下尝试:

createdb

and then see if you can log in again with 然后看看你是否可以再次登录

psql -h localhost

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. 如果createdb失败,那么您没有足够的权限来创建自己的数据库,您将不得不弄清楚如何修复自制软件包。


#3楼

By default, postgres tries to connect to a database with the same name as your user. 默认情况下,postgres尝试连接到与您的用户同名的数据库。 To prevent this default behaviour, just specify user and database: 要防止此默认行为,只需指定用户和数据库:

psql -U Username DatabaseName

#4楼

在使用自制软件安装postgresql之后我仍然遇到了上述问题 - 我在/ usr / bin之前将/ usr / local / bin放在我的路径中解决了这个问题


#5楼

Since this question is the first in search results, I'll put a different solution for a different problem here anyway, in order not to have a duplicate title. 由于这个问题是搜索结果中的第一个问题,因此无论如何我都会针对不同的问题提出不同的解决方案,以便不会出现重复的标题。

The same error message can come up when running a query file in psql without specifying a database. psql运行查询文件而不指定数据库时,可能会出现相同的错误消息。 Since there is no use statement in postgresql, we have to specify the database on the command line, for example: 由于postgresql中没有use语句,我们必须在命令行中指定数据库,例如:

psql -d db_name -f query_file.sql

#6楼

This error can also occur if the environment variable PGDATABASE is set to the name of a database that does not exist. 如果环境变量PGDATABASE设置为不存在的数据库的名称,也会发生此错误。

On OSX, I saw the following error while trying to launch psql from the Postgress.app menu: 在OSX上,我在尝试从Postgress.app菜单启动psql时看到以下错误:

psql: FATAL: database "otherdb" does not exist

The solution to the error was to remove export PGDATABASE=otherdb from ~/.bash_profile : 该错误的解决方案是从~/.bash_profile删除export PGDATABASE=otherdb

Further, if PGUSER is set to something other than your username, the following error will occur: 此外,如果PGUSER设置为您的用户名以外的其他内容,则会发生以下错误:

psql: FATAL: role "note" does not exist

The solution is to remove export PGUSER=notme from ~/.bash_profile . 解决方案是从~/.bash_profile删除export PGUSER=notme

转载地址:http://yncnb.baihongyu.com/

你可能感兴趣的文章
javascript中编写类似in_array()的原型函数
查看>>
go 数据库操作
查看>>
php读取二进制流
查看>>
Golang热重启
查看>>
热重启golang服务器(graceful restart golang http server)
查看>>
echo框架使用:获取与配置
查看>>
PHP模拟多进程并发将内容写入文件
查看>>
nginx.conf配置说明
查看>>
Eclipse设定和修改文件字符编码格式和换行符
查看>>
git常用操作以及快速入门教程
查看>>
MongoDB 3.0 常见集群的搭建(主从复制,副本集,分片....)
查看>>
在notepad++中 “tab转为空格”、“按tab插入空格”、“文档格式转换”
查看>>
Zend Framework 常用组件概述
查看>>
Zend_Db -> Zend_Db_Adapter
查看>>
Zend_Db -> Zend_Db_Select
查看>>
Zend_Db -> Zend_Db_Table
查看>>
PHP漏洞全解(三)-客户端脚本植入
查看>>
Java学习日记 求最值 排序 选择 冒泡 交换
查看>>
IO流输出系统信息
查看>>
File类常见方法
查看>>