本文翻译自:psql: FATAL: database “” does not exist

I'm using the PostgreSql app for mac ( http://postgresapp.com/ ). 我正在使用PostgreSql应用程序的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. 我以前在其他机器上使用它但是在我的macbook上安装时给我带来了一些麻烦。 I've installed the application and I ran: 我安装了应用程序,然后运行:

psql -h localhost

It returns: 它返回:

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

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 -> Getting Postgresql Running In Mac: Database "postgres" does not exist didn't follow up. 我找到答案,但我不确定它是如何工作的,因为在这个线程上回答的用户 - > 获取Postgresql在Mac上运行:数据库“postgres”不存在没有跟进。 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楼

参考:https://stackoom.com/question/1BzG2/psql-FATAL-数据库-user-不存在


#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

psql:FATAL:数据库“user”不存在相关推荐

  1. psql: FATAL: role “appleyuchi” does not exist与修改默认密码

    $ psql 报错如下: psql: FATAL: role "appleyuchi" does not exist 使用: sudo -s -u postgres 就会把当前用户 ...

  2. 同步流复制报错“psql: FATAL: the database system is starting up”

    目录 环境 症状 问题原因 解决方案 相关文档 报错编码 环境 系统平台:Linux x86 Red Hat Enterprise Linux 6,Linux x86-64 Red Hat Enter ...

  3. postgresql安装后链接报错psql: FATAL: Ident authentication failed for user “postgres“

    postgresql 安装成功后,使用链接语句链接 [root@iZbp1hdum7hefdeb75mnyfZ ~]# psql -d postgres -U postgres -W Password ...

  4. psql: FATAL the database system is in recovery解决

    报错: FATAL: the database system is in recovery mode 解决思路: 在hawq master节点 1.执行hawq state ,提示 database ...

  5. PostgreSQL提示:‘psql: FATAL: ”Peer authentication failed for user ”postgres“’错误#将文件Database administ

    #将文件Database administrative 下列中的peer改为trust $sudo nano /etc/postgresql/10/main/pg_hba.conf #重新加载配置 $ ...

  6. postgresql 数据库 报错 FATAL: the database system is shutting down 解决方法

    目录 问题原因 解决过程 查看主机进程 关闭数据库 创建 postmaster.pid 文件 再次尝试关闭数据库 启动数据库 总结 问题原因 服务器在同一个数据目录上启动了两个PostgreSQL实例 ...

  7. 使用psql无法连接数据库,并报错 FATAL:53300

    012269101 使用psql无法连接数据库,并报错 FATAL:53300 目录 环境 症状 问题原因 解决方案 相关文档 报错编码 环境 系统平台:N/A 版本:4.1.1 症状 1) psql ...

  8. psql 无法连接数据库,报错FATAL:53300

    psql: FATAL:  53300: remaining connection slots are reserved for non-replication superuser connectio ...

  9. psql+加载mysql数据库_Go实战--go语言操作PostgreSQL数据库(github.com/lib/pq)

    生命不止,继续 Go go go !!! 之前关于golang操作数据库的博客: 今天跟大家分享golang中使用PostgreSQL数据库. 何为PostgreSQL PostgreSQL is a ...

最新文章

  1. wikioi 3027 线段覆盖 2
  2. 为什么一般要定义析构函数为虚析构函数
  3. 滚动条禁止_Axure 教程:不可见滚动条的页面滚动效果
  4. 物联网、云计算商用或从“家庭自动化”得以突破
  5. Hadoop-Yarn-框架原理及运作机制
  6. android 数据回传代码,安卓向.net core api传输图片,执行保存到数据库命令后返回400错误代码,用postman测试没有问题安卓程序不行...
  7. 带网格的_装修要不要用网格布,了解这几点之后再做决定
  8. Tomcat启动时日志报 dcom.sun.manager.jmxremote 异常导致无法正常启动使用
  9. java 面向对象 1
  10. 2021东营高考成绩查询,2021东营市地区高考成绩排名查询,东营市高考各高中成绩喜报榜单...
  11. Silverlight 2.5D RPG游戏技巧与特效处理:纸娃娃系统
  12. 怎么压缩图片的大小?收好这几个压缩方法
  13. 《缠中说禅108课》6:本 ID 如何在五粮液、包钢权证上提款的
  14. ctf-web-never_give_up
  15. 依山傍水,云淡风轻-----只是传说
  16. 2008年4月28日A股市场存在筑底异样
  17. 计算机双语论文,计算机双语教学初探论文
  18. Anaconda 安装及配置
  19. 阿朱推荐的产品经理读物30本书(修订版)
  20. python经典面试题100例 面试宝典

热门文章

  1. 新雨个人面试经验总结
  2. android toolbar 开发总结
  3. eclipse 插件,直接打开文件路径
  4. 【剑指offer-Java版】01为了准备面试也为了提升编程技巧开始刷宝典了
  5. Ubuntu12.04配置LAMP 环境
  6. Spark Shuffle两种Manager
  7. (0007) iOS 开发之Xcode8上传AppStore遇到的TencentOpenApi_IOS_Bundle.bundle
  8. 计算机教室要配备空调吗,孩子们教室里的空调 到底要不要装?能不能装?
  9. 医院挂号设计源代码_锡盟蒙医医院设立智慧导诊系统服务患者
  10. python 错误与异常