简体   繁体   English

psql:错误:连接到套接字“/tmp/.s.PGSQL.5432”上的服务器失败:致命:数据库“myname”不存在

[英]psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "myname" does not exist

I a rails app running on my local environment using postgresql. This morning I spun up a new one and after install the pg gem, etc. I am running into the following error when trying to run我使用 postgresql 在我的本地环境上运行一个 Rails 应用程序。今天早上我启动了一个新应用程序并在安装 pg gem 等之后。我在尝试运行时遇到以下错误

psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL:  database "jackcollins" does not exist

What's strange is the db name "jackcollins" is from my other rails app.奇怪的是数据库名称“jackcollins”来自我的其他 Rails 应用程序。

I ran我跑了

pgrep -l postgres

and the output was output 是

20902 postgres
20919 postgres
20920 postgres
20921 postgres
20922 postgres
20923 postgres
20924 postgres

I'm unsure how to proceed so that these apps can both run their own postgres instance.我不确定如何继续,以便这些应用程序都可以运行自己的 postgres 实例。

I had the same problem as you, after making attempts to reinstall, rm -rf xxx.pid, etc., I ended up executing the following command and was eventually able to connect to the PostgreSQL database.我和你有同样的问题,在尝试重新安装、rm -rf xxx.pid 等之后,我最终执行了以下命令并最终能够连接到 PostgreSQL 数据库。

  1. brew install postgresql
  2. an error message appears出现一条错误消息
  3. run createdb (because macs don't create username databases after installing PostgreSQL)运行createdb (因为 macs 在安装 PostgreSQL 后不会创建用户名数据库)
  4. execute psql to connect successfully.执行psql连接成功。

If you type如果你输入

psql --help

in the terminal, you will see that the default database is your username.在终端中,您会看到默认数据库是您的用户名。 Unless you have that database in PostgreSQL, you will get an error.除非你在 PostgreSQL 中有那个数据库,否则你会得到一个错误。 Instead, you can run the command相反,您可以运行命令

psql -d your_database_name

Also, if you want to log in as a specific user (by default it is a current user):另外,如果您想以特定用户身份登录(默认情况下是当前用户):

psql -d your_database_name -U your_username -W

The last -W is for password.最后一个 -W 是密码。 Hope, it helps!希望能帮助到你!

Regarding the error, you are trying to connect to jackcollins , please can you test trying to connect using the database flag?:关于错误,您正在尝试连接到jackcollins ,请您测试尝试使用数据库标志连接吗?:

psql -d your_database_name

In the absence of -d <database_name> psql will use the OS user name as the database name.在没有-d <database_name>的情况下, psql将使用 OS 用户名作为数据库名。 As in many things it better to be explicit rather then implicit, especially when working on a new instance.与许多事情一样,最好是显式而不是隐式,尤其是在处理新实例时。 In addition use -h <host_name> , -p <port_number> and -U <user_name> .此外使用-h <host_name>-p <port_number>-U <user_name> Then you know who you are connecting as, as well as how.然后你知道你在连接谁,以及如何连接。 It is spelled out here psql and since psql is a libpq program in more detail here Key words .它在这里拼写出来psql并且因为psql是一个libpq程序在这里更详细的关键字

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ActiveRecord::ConnectionNotEstablished:连接到套接字“/tmp/.s.PGSQL.5432”上的服务器失败:致命:角色“{my_laptop_name1}”不存在 - ActiveRecord::ConnectionNotEstablished: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: role "{my_laptop_name1}" does not exist 导轨 | 连接到套接字“/tmp/.s.PGSQL.5432”上的服务器失败:没有这样的文件或目录 - Rails | connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory PG::ConnectionBad:连接到套接字“/var/run/postgresql/.s.PGSQL.5432”上的服务器失败:没有这样的文件或目录 - PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory 没有这样的文件或目录服务器是否在本地运行并且在Unix域套接字“ /tmp/.s.PGSQL.5432”上接受连接? - No such file or directory Is the server running locally and accepting connections on Unix domain socket “/tmp/.s.PGSQL.5432”? BlueHost-没有这样的文件或目录服务器是否在本地运行并且在Unix域套接字“ /tmp/.s.PGSQL.5432”上接受连接 - BlueHost - No such file or directory Is the server running locally and accepting connections on Unix domain socket “/tmp/.s.PGSQL.5432” 没有这样的文件或目录 服务器是否在本地运行并接受 Unix 域套接字“/tmp/.s.PGSQL.5432”上的连接? 在 docker - No such file or directory Is the server running locally and accepting connections on Unix domain socket “/tmp/.s.PGSQL.5432”? at docker 服务器是否在本地运行并接受 Unix 域套接字“/tmp/.s.PGSQL.5432”上的连接? Dockerized Rails - Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? Dockerized Rails Rails PG Unix域套接字“ /tmp/.s.PGSQL.5432”? 问题 - Rails PG Unix domain socket “/tmp/.s.PGSQL.5432”? issue postgresql 数据库错误:服务器是否在本地运行并接受 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接? - error with postgresql datababse : Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”? 问题与Postgresql`initialize` ... Socket .s.PGSQL.5432 - Issue with Postgresql `initialize` … Socket .s.PGSQL.5432
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM