无法连接到服务器:没有此文件或目录。服务器是否正在本地运行,并接受Unix域套接字”/tmp/.s.PGSQL.5432″上的连接?

最初のエラー

请用中文给我翻译一下DeepL所提供的翻译。

无法连接到服务器:找不到该文件或目录。服务器正在本地运行,并接受使用Unix域套接字“/tmp/.s.PGSQL.5432”进行的连接吗?

解决问题

    1. 无法连接服务器

 

    1. 文件或目录不存在

 

    服务器是否在本地运行,域名是否为/tmp/.s.PGSQL.5432

作为一个初学者的工程师,我将按照这个顺序逐步解决问题。

解答问题一

只需一种选择: 无法连接到服务器 => 是否启动了服务器
要确认服务器状态,可以使用systemctl等命令。但是,我当前的Mac无法使用这些命令。
因为我使用Homebrew下载的PostgreSQL,所以需要确认数据库服务器的启动状态。

% brew services list
Name          Status     User         File
emacs         none
mysql@5.7     none
postgresql    error  256 hogehoge ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgresql@12 none
postgresql@13 none
unbound       none

这篇文章

使用Homebrew Services管理服务。

因为在brew services中有所提及,所以进行引用。

在这里,有一个Plist栏,当services start时,plist会被复制到LaunchAgents目录中等,并且以后会在启动时自动加载并执行命令。

因为出现错误,所以停止brew服务的postgresql。

我输入了psql命令。
通过psql -V获知,我知道postgresql版本是psql (PostgreSQL) 14.1。

我从更新Homebrew开始就觉得有些奇怪,想要引入一款看起来使用方便的终端替代品iTerm2,并且添加点幽默感。PostgreSQL 14是新的吧?

スクリーンショット 2022-01-26 20.52.27.png

似乎是因为没有数据库而导致错误发生。
执行 rails db:create 和 rails db:migrate。

我能够无错误地进入Rails服务器,但之前的表格数据不见了。没问题吗?

这是正确的答案吗?

我还要引用文章。

我查了一下Homebrew安装的postgresql无法启动。

首先,我想查看一下 brew info postgresql 这篇文章,它似乎是我以前在升级 postgre 时候曾经查阅过的。

% brew info postgresql
postgresql: stable 14.1 (bottled), HEAD
Object-relational database system
https://www.postgresql.org/
/usr/local/Cellar/postgresql/14.1_1 (3,304 files, 45MB) *
  Poured from bottle on 2022-01-24 at 23:50:17
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgresql.rb
License: PostgreSQL
==> Dependencies
Build: pkg-config ✔
Required: icu4c ✔, krb5 ✔, openssl@1.1 ✔, readline ✔
==> Options
--HEAD
    Install HEAD version
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /usr/local/var/postgres
For more details, read:
  https://www.postgresql.org/docs/14/app-initdb.html

To restart postgresql after an upgrade:
  brew services restart postgresql
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres
==> Analytics
install: 90,012 (30 days), 351,492 (90 days), 1,536,916 (365 days)
install-on-request: 86,592 (30 days), 338,228 (90 days), 1,470,528 (365 days)
build-error: 38 (30 days)

这里写着重要的事情呢。 de ne.)

==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

要從以前的主要版本的PostgreSQL遷移現有數據,請執行以下操作:
brew postgresql-upgrade-database

这个方法能完成数据迁移吗?希望能解决之前没有表的问题。
在那之前,也可以在正在运行的postgresql@13上执行info命令。

% brew info postgresql@13
postgresql@13: stable 13.5 (bottled) [keg-only]
Object-relational database system
https://www.postgresql.org/
/usr/local/Cellar/postgresql@13/13.5_1 (3,233 files, 42.8MB)
  Poured from bottle on 2022-01-26 at 08:06:31
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgresql@13.rb
License: PostgreSQL
==> Dependencies
Build: pkg-config ✔
Required: icu4c ✔, krb5 ✔, openssl@1.1 ✔, readline ✔
==> Caveats
Previous versions of this formula used the same data directory as
the regular PostgreSQL formula. This causes a conflict if you
try to use both at the same time.

In order to avoid this conflict, you should make sure that the
postgresql@13 data directory is located at:
  /usr/local/var/postgresql@13

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /usr/local/var/postgresql@13
For more details, read:
  https://www.postgresql.org/docs/13/app-initdb.html

postgresql@13 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have postgresql@13 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/postgresql@13/bin:$PATH"' >> ~/.zshrc

For compilers to find postgresql@13 you may need to set:
  export LDFLAGS="-L/usr/local/opt/postgresql@13/lib"
  export CPPFLAGS="-I/usr/local/opt/postgresql@13/include"

For pkg-config to find postgresql@13 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/postgresql@13/lib/pkgconfig"


To restart postgresql@13 after an upgrade:
  brew services restart postgresql@13
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/postgresql@13/bin/postgres -D /usr/local/var/postgresql@13
==> Analytics
install: 8,844 (30 days), 36,310 (90 days), 50,579 (365 days)
install-on-request: 8,821 (30 days), 36,261 (90 days), 50,507 (365 days)
build-error: 1 (30 days)

我本来是在使用postgresql@13进行启动的,但现在我计划尝试一下通过已经配置好了Path的14.1版本进行启动。
一旦通过brew服务停止postgresql@13,那么在Rails应用程序中将回到初始屏幕截图的状态。

我将运行brew postgresql-upgrade-database。

(Wǒ brew postgresql-upgrade-database.)

% brew postgresql-upgrade-database
Error: /usr/local/var/postgres.old already exists!
Remove it if you want to upgrade data automatically.

发生了错误。看起来应该删除postgres.old,参考文章:PostgreSQL数据库升级很方便通过brew postgresql-upgrade-database。从这里看,重命名也是可能的,所以先重命名一下。

再次运行brew postgresql-upgrade-database。

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
    /usr/local/opt/postgresql/bin/vacuumdb --all --analyze-in-stages

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh
==> Upgraded postgresql data from 13 to 14!
==> Your postgresql 13 data remains at /usr/local/var/postgres.old

我省略了日志,但据看起来数据迁移顺利完成。

重命名的文件仍然存在。

% ls
cache           log             postgres        postgres_re.old postgresql@13
homebrew        mysql           postgres.old    postgresql@12
广告
将在 10 秒后关闭
bannerAds