Postgres无法连接到服务器

Gar*_*Lai 384 database postgresql macos homebrew ruby-on-rails

在我做了brew更新和brew升级之后,我的postgres遇到了一些问题.我试图卸载postgres并重新安装,但它也没有用.

这是错误消息.(当我尝试执行rake db:migrate时,我也收到此错误消息)

$ psql
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

Mac版:山狮.

自制版:0.9.3

postgres版本:psql(PostgreSQL)9.2.1

这就是我所做的.

12:30 ~/D/works$ brew uninstall postgresql
Uninstalling /usr/local/Cellar/postgresql/9.2.1...
12:31 ~/D/works$ brew uninstall postgresql
Uninstalling /usr/local/Cellar/postgresql/9.1.4...
12:31 ~/D/works$ psql --version
bash: /usr/local/bin/psql: No such file or directory
12:33 ~/D/works$ brew install postgresql
==> Downloading http://ftp.postgresql.org/pub/source/v9.2.1/postgresql-9.2.1.tar.bz2
Already downloaded: /Library/Caches/Homebrew/postgresql-9.2.1.tar.bz2
......
......
==> Summary
/usr/local/Cellar/postgresql/9.2.1: 2814 files, 38M, built in 2.7 minutes
12:37 ~/D/works$ initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user "laigary".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".

initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
12:39 ~/D/works$ mkdir -p ~/Library/LaunchAgents
12:39 ~/D/works$   cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
12:39 ~/D/works$   launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
homebrew.mxcl.postgresql: Already loaded
12:39 ~/D/works$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
server starting
12:39 ~/D/works$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.14.1
1 gem installed
12:42 ~/D/works$ psql --version
psql (PostgreSQL) 9.2.1
12:42 ~/D/works$ psql
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud)

现在,在我重新安装了问题之后,当我使用时$ psql,它没有显示任何错误消息.

但我rake db:migrate在我的rails应用程序中运行,它显示:

could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `initialize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `new'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `connect'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:329:in `initialize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in `new_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in `checkout_new_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in `block (2 levels) in checkout'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `loop'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `block in checkout'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in `checkout'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `block in connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in `retrieve_connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in `connection'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:107:in `rescue in create_database'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:51:in `create_database'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `block (3 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `each'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `block (2 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/usr/local/bin/rake:32:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"riy_development", "pool"=>5, "username"=>nil, "password"=>nil}
Run Code Online (Sandbox Code Playgroud)

最后我找到了解决方案.

$ sudo mkdir /var/pgsql_socket/
$ sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
Run Code Online (Sandbox Code Playgroud)

这个解决方案有点棘手,但它确实有效.希望有人有更好的解决方案

更新

这对我也有用.

rm /usr/local/var/postgres/postmaster.pid
Run Code Online (Sandbox Code Playgroud)

小智 754

有类似的问题; 一个pid文件阻止postgres启动.要解决这个问题:

rm /usr/local/var/postgres/postmaster.pid

然后一切都很好.

  • 这对小牛队来说不起作用:`rm:/usr/local/var/postgres/postmaster.pid:没有这样的文件或目录` (172认同)
  • 这对我有用,擦除后我不得不开始发布postgres.#pg_ctl -D/usr/local/var/postgres -l /usr/local/var/postgres/server.log start (15认同)
  • 我建议拖尾服务器日志以确保这实际上是问题:`tail/usr/local/var/postgres/server.log` (11认同)
  • 在更新/重启后看到此问题后,这对OSX Mavericks起作用了. (4认同)
  • @jstafford谢谢,我已经解决了!:)解决办法是通过homebew卸载然后立即重启我的电脑,这样我就可以重新安装postgres了.旧版本在后台运行,每次我尝试重新安装postgres时都会创建文件和冲突. (3认同)
  • 接下来是'brew services restart postgresql`为我工作 (3认同)
  • 有些人忘记了版本,所以他们会得到“没有这样的文件或目录”。它们应该更具体:“rm /usr/local/var/postgresql\@9.5/postmaster.pid”,然后“brew services restart postgresql@9.5” (3认同)
  • 使用Yosemite它没有用.仍然存在相同的错误,文件不再存在.但它曾经为我的OSX版本工作,但是......有什么帮助吗?"无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受Unix域套接字上的连接"/tmp/.s.PGSQL.5432"?" (2认同)
  • @BetuUuUu 请参阅这篇文章以获取 Yosemite 上的解决方案。它不漂亮,但很有效。http://stackoverflow.com/questions/25970132/pg-tblspc-missing-after-installation-of-os-x-yosemite (2认同)
  • 正如@MIA 所说,有时您需要特定于版本。我需要 `rm /opt/homebrew/var/postgresql@12/postmaster.pid` 和 `postgresql@12` (M1 上的 macOS Big Sur) (2认同)

Fre*_*der 235

这有时可能是postgres升级的问题.

在我的情况下,它发生在从9.3升级到9.4.

http://www.postgresql.org/docs/9.4/static/upgrading.html

OS X/Homebrew:

尝试运行postgres -D /usr/local/var/postgres- 如果postgres无法启动,它将为您提供更详细的输出.

在我的例子中,运行rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8删除我的旧数据库,然后重新初始化postgres数据库架构.

感谢https://github.com/Homebrew/homebrew/issues/35240获得该解决方案.

在重新生成我的数据库之后,rake db:create一切都恢复正常.

  • 如果运行`postgres -D/usr/local/var/postgres`告诉你数据目录是用较旧的,不兼容的Postgres版本初始化的,而你*不想*丢失你的本地数据,你可能会尝试[这个主题](http://stackoverflow.com/q/24379373/4376) (7认同)
  • 在OSX上使用`brew services start postgres`在背景上启动postgres而不是`postgres -D/usr/local/var/postgres` (5认同)

小智 67

找到了一个适合我的解决方案:

https://dba.stackexchange.com/questions/75214/psql-could-not-connect-to-server-no-such-file-or-directory

您基本上运行以下命令来手动启动服务器:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Run Code Online (Sandbox Code Playgroud)

  • 在所有答案中,这是唯一对我有用的答案.使用El Capitan (8认同)

Rya*_*lah 33

在Yosemite上,如果pid文件阻止Postgres启动并且你有一个launchctl守护进程尝试(并且失败)加载数据库守护进程,那么你需要卸载plist文件:

$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Run Code Online (Sandbox Code Playgroud)

然后删除pid文件

$ rm /usr/local/var/postgres/postmaster.pid
Run Code Online (Sandbox Code Playgroud)

然后重新加载launchctl守护进程

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Run Code Online (Sandbox Code Playgroud)


Sso*_*esS 33

如果使用brew安装和卸载postgres不起作用,请查看postgresql安装的日志或:

postgres -D /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)

如果你看到这种输出:

LOG:  skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.4, which is not compatible with this version 9.6.1.
Run Code Online (Sandbox Code Playgroud)

然后尝试以下方法:

rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8
Run Code Online (Sandbox Code Playgroud)

然后启动服务器:

pg_ctl -D /usr/local/var/postgres -l logfile start
Run Code Online (Sandbox Code Playgroud)

资源

  • 当原因不同于接受的答案(即数据库文件与当前版本不兼容)时,此方法有效。既然那一直是我的问题,我赞成。 (2认同)
  • 这应该是公认的答案,就像魅力一样! (2认同)

Dav*_*cki 28

对于阅读此内容并使用Postgres.app的任何人,您可能需要host: localhost在您的database.yml中.http://postgresapp.com/documentation#toc_3


rld*_*rld 18

brew services start postgres 
Run Code Online (Sandbox Code Playgroud)

为我工作!


小智 18

升级数据库对我有用

brew postgresql-upgrade-database

  • ✅⭐️谢谢托默!这对我 2020 年 6 月 2 日在 macOS Mojave 10.14.6 上从 9.4 升级到 12 有效 (2认同)

jrw*_*ren 16

检查套接字文件是否存在.

$ ls -l /tmp/.s.PGSQL.5432
srwxrwxrwx  1 you  wheel  0 Nov 16 09:22 /tmp/.s.PGSQL.5432
Run Code Online (Sandbox Code Playgroud)

如果没有,则检查postgresql.conf以获取unix_socket_directory更改.

$ grep unix_socket /usr/local/var/postgres/postgresql.conf
#unix_socket_directory = ''     # (change requires restart)
#unix_socket_group = ''         # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation
Run Code Online (Sandbox Code Playgroud)

  • 最后我找到了解决方案.`$ mkdir/var/pgsql_socket /``$ sudo mkdir/var/pgsql_socket /``$ ln -s /private/tmp/.s.PGSQL.5432/var/pgsql_socket /`这个解决方案有点棘手,但它有效.希望有人有更好的解决方案 (28认同)
  • 这可能会帮助一些人:https://github.com/mxcl/homebrew/issues/14527 (2认同)

rld*_*rld 13

这个问题也可归因于一个崩溃的进程,后面留下了postmaster.pid文件.我这样做并且工作:

$ brew services stop postgresql
$ rm /usr/local/var/postgres/postmaster.pid # adjust path accordingly to your install
$ brew services start postgresql
Run Code Online (Sandbox Code Playgroud)


Han*_*oh. 11

就我而言,问题是由 Mac 操作系统更新引起的。升级 PostgreSQL 解决了这个问题。

\n
# upgrade database version solved the trouble\n$ brew postgresql-upgrade-database\n
Run Code Online (Sandbox Code Playgroud)\n

但是,这个错误很常见,并且有多种可能的原因,您不应该完全依赖我上面的解决方案。

\n


Car*_*mez 10

对于 MacOS BigSur,自制 postgres:

  • rm /opt/homebrew/var/postgres/postmaster.pid
  • brew services restart postgresql


Abd*_*rsu 9

上述解决方案均不适合我.

问题是因为端口5432上已有运行服务,我们无法通过此端口建立psql套接字连接.

我删除了套接字文件

rm -rf /tmp/.s.PGSQL.5432/
Run Code Online (Sandbox Code Playgroud)

然后我重新初始化postgres服务

postgres -D /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)

这对我有用.


小智 9

这对我有用。我不必删除任何文件

brew postgresql-upgrade-database


Joh*_*ohn 7

更改postresql或database.yml配置设置,更改$ PATH或创建符号链接对我来说都是不必要的.我需要做的就是gem uninstall pg然后bundle(或gem install pg).

问题是pg gem已经在自制的postgres之前安装了,所以从MacOS附带的postgres版本中获取了设置.重新安装它(从而重建原生扩展)修复了问题.


stu*_*ujo 7

当我从9.3.4升级到9.5时发生这种情况,因为数据库在没有升级的情况下是不兼容的.

我使用pg_upgrade如下:

停止postgres

$ brew services stop postgresql
Run Code Online (Sandbox Code Playgroud)

升级数据库:

$ pg_upgrade \
   -d /usr/local/var/postgres \
   -D /usr/local/var/postgres9.5 \
   -b /usr/local/Cellar/postgresql/9.3.4/bin/ \
   -B /usr/local/Cellar/postgresql/9.5.0/bin/ \
   -v
Run Code Online (Sandbox Code Playgroud)

存档旧数据库:

 $ mv /usr/local/var/postgres /usr/local/var/postgres9.3.save
 $ mv /usr/local/var/postgres9.5 /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)

重新启动postgres:

 $ brew services start postgresql
Run Code Online (Sandbox Code Playgroud)

更新的Gems(用于rails/active记录):

 $ gem uninstall pg
 $ gem uninstall activerecord-postgresql-adapter
 $ bundle install
Run Code Online (Sandbox Code Playgroud)


小智 7

这实际上是你应该做的:

你应该看一下/usr/local/var/postgres/postmaster.pid

然后查看文件的第一行 - 这是错误的PID

ps aux | grep <PID>
Run Code Online (Sandbox Code Playgroud)

例如:

ps aux | grep 12345
Run Code Online (Sandbox Code Playgroud)

然后做

kill <PID>
Run Code Online (Sandbox Code Playgroud)

例如

kill 12345
Run Code Online (Sandbox Code Playgroud)

假设它仍然在运行

https://superuser.com/questions/553045/fatal-lock-file-postmaster-pid-already-exists

不要听到接受的答案它是坏的,会破坏你的数据!


Abh*_*rma 6

解决此问题的最简单方法是

brew reinstall postgresql
Run Code Online (Sandbox Code Playgroud)

这将保留您的用户权限等所有内容,并且所有内容都将重置为新的。一直工作!


Piy*_*ria 6

我遇到了同样的问题psql (PostgreSQL) 9.6.11

什么对我有用 -

删除 postmaster.pid -- rm /usr/local/var/postgresql@9.6/postmaster.pid

重新启动 postgres --brew services restart postgresql@9.6

如果这也不起作用,那么运行—— sudo chmod 700 /usr/local/var/postgresql@9.6


小智 5

Psql 选项

-h 主机名 --host=主机名

:指定运行服务器的计算机的主机名。 如果该值以斜杠开头,则将其用作 Unix 域套接字的目录。

$ grep "port\|unix_socket" /etc/postgresql/9.1/main/postgresql.conf
port = 5433                                         # (change requires restart)
unix_socket_directory = '/var/run/postgresql'       # (change requires resta

$ netstat -nalp | grep postgres
unix  2      [ ACC ]     STREAM     LISTENING     106753   4349/postgres       /tmp/.s.PGSQL.5432
unix  2      [ ACC ]     STREAM     LISTENING     10377 1031/postgres       /var/run/postgresql/.s.PGSQL.5433
Run Code Online (Sandbox Code Playgroud)

使用 -host 选项运行 psql

$ psql -p 5433 -h /var/run/postgresql
Run Code Online (Sandbox Code Playgroud)

不需要做软链接


小智 5

如果 postgres 是使用自制软件安装的,你可以通过运行来解决这个问题:

brew link postgres
Run Code Online (Sandbox Code Playgroud)


Ram*_*ogo 5

这对我有用(作为以前答案的混合):

$ rm /usr/local/var/postgres/postmaster.pid

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Run Code Online (Sandbox Code Playgroud)

资料来源:https : //coderwall.com/p/zf-fww/postgres-on-osx-with-homebrew-not-running-after-osx-crash


dim*_*vrn 5

所以我在rails db:create命令之后偶然发现了这一点。在 macOS Catalina 10.15.3 中设置环境。

我检查的第一件事是让我来到这里的流程。在确保所有事情都顺利进行并且没有任何错误可能逃过我的脑海之后,我尝试了这里最流行的解决方案,但似乎都不起作用。

到目前为止我看到的唯一错误是

$ psql psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

所以我需要一些关于正在发生的事情的更具体的信息。由于这个原因,我决定查看位于的 postgres 日志文件

/usr/local/var/log/postgres.log

所以打开日志后我看到了这个错误

LOG: starting PostgreSQL 12.2 on x86_64-apple-darwin19.3.0, compiled by Apple clang version 11.0.0 (clang-1100.0.33.17), 64-bit LOG: could not translate host name "localhost", service "5432" to address: nodename nor servname provided, or not known WARNING: could not create listen socket for "localhost" FATAL: could not create any TCP/IP sockets LOG: database system is shut down

所以这更具解释性和具体性。问题在于 PostgreSQL 无法“查看”并解析本地主机服务器。

所以我接下来要做的就是检查 /etc/hosts 文件,其默认内容应如下所示:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1          localhost 
Run Code Online (Sandbox Code Playgroud)

在将上面的内容与我的进行比较后,我发现我的这一行有所不同并发表了评论(!)。

#::1             localhost
Run Code Online (Sandbox Code Playgroud)

所以我删除了保存文件的行前面的#符号并重新运行

rails db:create 
Run Code Online (Sandbox Code Playgroud)

并且数据库已成功启动。


Kho*_*Ngo 5

适用于 MacOS M1 蒙特雷的解决方案

rm /opt/homebrew/var/postgres/postmaster.pid
brew services restart postgresql
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

274641 次

最近记录:

6 年,2 月 前