簡體   English   中英

PG::ConnectionBad - 無法連接到服務器:Mac OS X 上的連接被拒絕

[英]PG::ConnectionBad - could not connect to server: Connection refused on Mac OS X

使用以下rvm install 2.7.1所需的ruby版本: rvm install 2.7.1並安裝所有 gems 后,我計划使用rails db:create數據庫,但出現此錯誤:

could not connect to server: Connection refused
  Is the server running on host "127.0.0.1" and accepting
  TCP/IP connections on port 5442?
Couldn't create 'development' database. Please check the configuration.
rails aborted!
PG::ConnectionBad: could not connect to server: Connection refused
  Is the server running on host "127.0.0.1" and accepting
  TCP/IP connections on port 5442?

我的database.yml

default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 15 } %>
  host: <%= ENV.fetch("DATABASE_HOST") { '127.0.0.1' } %>

development:
  <<: *default
  database: development

test:
  <<: *default
  database: test

production:
  <<: *default
  database: production

似乎它與postgres有關。 它的版本是: postgres (postgreSQL) 12.4

pg gem 版本是1.2.3

重新啟動postgresql沒有幫助

看來我需要創建一個新的 PostgreSQL 數據庫集群。 首先,您需要刪除/usr/local/var/中的postgres目錄

您可以使用此代碼 - cd /usr/local/var/ && rm -rf postgres

之后 - 創建新的postgres文件夾mkdir postgres (在/usr/local/var

並使用 - 初始化新 PostgreSQL 數據庫集群的創建

cd && initdb --locale=C -E UTF-8 /usr/local/var/postgres

最后一件事,重啟postgres—— brew services restart postgresql

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM