簡體   English   中英

Postgresql 無法連接服務器?

[英]Postgresql can't connect to server?

我是 postgresql 和導軌的新手。 我正在嘗試連接到服務器並創建必要的數據庫。 當我運行rake db:create時,我收到以下消息:

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"?
Couldn't create 'ecom_shoppie_development' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: 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"?

但是服務器在端口 5433 上運行。我嘗試更改 postgresql.conf 和 database.yml 中的端口號,但我得到了同樣的錯誤。

我試過卸載並重新安裝 postgresql 但它總是選擇端口 5433 而不是 5432。

我跟着這個教程

Postgresql 日志文件/var/log/postgresql/postgresql-11-main.log:

2019-09-24 06:12:09.951 EDT [3379] LOG:  listening on IPv4 address "127.0.0.1", port 5433
2019-09-24 06:12:10.087 EDT [3379] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2019-09-24 06:12:10.669 EDT [3380] LOG:  database system was shut down at 2019-09-24 05:54:16 EDT
2019-09-24 06:12:11.313 EDT [3379] LOG:  database system is ready to accept connections
2019-09-24 06:12:12.102 EDT [3387] [unknown]@[unknown] LOG:  incomplete startup packet
2019-09-24 06:35:51.836 EDT [3379] LOG:  received fast shutdown request
2019-09-24 06:35:51.887 EDT [3379] LOG:  aborting any active transactions
2019-09-24 06:35:52.001 EDT [3379] LOG:  background worker "logical replication launcher" (PID 3386) exited with exit code 1
2019-09-24 06:35:52.003 EDT [3381] LOG:  shutting down
2019-09-24 06:35:52.842 EDT [3379] LOG:  database system is shut down
2019-09-24 06:35:54.193 EDT [3475] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 06:35:54.193 EDT [3475] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 06:35:54.194 EDT [3475] WARNING:  could not create listen socket for "localhost"
2019-09-24 06:35:54.194 EDT [3475] FATAL:  could not create any TCP/IP sockets
2019-09-24 06:35:54.215 EDT [3475] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 06:36:57.130 EDT [3517] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 06:36:57.130 EDT [3517] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 06:36:57.130 EDT [3517] WARNING:  could not create listen socket for "localhost"
2019-09-24 06:36:57.131 EDT [3517] FATAL:  could not create any TCP/IP sockets
2019-09-24 06:36:57.153 EDT [3517] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 06:38:02.555 EDT [3533] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 06:38:02.555 EDT [3533] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 06:38:02.556 EDT [3533] WARNING:  could not create listen socket for "localhost"
2019-09-24 06:38:02.557 EDT [3533] FATAL:  could not create any TCP/IP sockets
2019-09-24 06:38:02.579 EDT [3533] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 06:42:48.723 EDT [3564] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 06:42:48.723 EDT [3564] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 06:42:48.724 EDT [3564] WARNING:  could not create listen socket for "localhost"
2019-09-24 06:42:48.724 EDT [3564] FATAL:  could not create any TCP/IP sockets
2019-09-24 06:42:48.746 EDT [3564] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 06:44:22.342 EDT [3599] LOG:  listening on IPv4 address "127.0.0.1", port 5433
2019-09-24 06:44:22.463 EDT [3599] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2019-09-24 06:44:23.036 EDT [3600] LOG:  database system was shut down at 2019-09-24 06:35:52 EDT
2019-09-24 06:44:23.772 EDT [3599] LOG:  database system is ready to accept connections
2019-09-24 06:44:24.488 EDT [3607] [unknown]@[unknown] LOG:  incomplete startup packet
2019-09-24 06:49:23.812 EDT [3601] WARNING:  could not flush dirty data: Function not implemented
2019-09-24 08:43:17.387 EDT [3599] LOG:  received fast shutdown request
2019-09-24 08:43:17.446 EDT [3599] LOG:  aborting any active transactions
2019-09-24 08:43:17.693 EDT [3599] LOG:  background worker "logical replication launcher" (PID 3606) exited with exit code 1
2019-09-24 08:43:17.695 EDT [3601] LOG:  shutting down
2019-09-24 08:43:18.620 EDT [3599] LOG:  database system is shut down
2019-09-24 08:43:20.185 EDT [6822] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 08:43:20.185 EDT [6822] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 08:43:20.186 EDT [6822] WARNING:  could not create listen socket for "localhost"
2019-09-24 08:43:20.186 EDT [6822] FATAL:  could not create any TCP/IP sockets
2019-09-24 08:43:20.206 EDT [6822] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 08:44:24.969 EDT [6857] LOG:  could not bind IPv4 address "0.0.0.0": Address already in use
2019-09-24 08:44:24.969 EDT [6857] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 08:44:24.969 EDT [6857] LOG:  could not bind IPv6 address "::": Address already in use
2019-09-24 08:44:24.969 EDT [6857] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 08:44:24.969 EDT [6857] WARNING:  could not create listen socket for "*"
2019-09-24 08:44:24.970 EDT [6857] FATAL:  could not create any TCP/IP sockets
2019-09-24 08:44:24.991 EDT [6857] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 08:48:02.243 EDT [6894] LOG:  listening on IPv4 address "127.0.0.1", port 5433
2019-09-24 08:48:02.396 EDT [6894] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2019-09-24 08:48:03.677 EDT [6895] LOG:  database system was shut down at 2019-09-24 08:43:17 EDT
2019-09-24 08:48:04.398 EDT [6894] LOG:  database system is ready to accept connections
2019-09-24 08:48:05.177 EDT [6902] [unknown]@[unknown] LOG:  incomplete startup packet
2019-09-24 08:53:04.168 EDT [6896] WARNING:  could not flush dirty data: Function not implemented
2019-09-24 15:10:39.731 EDT [7350] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:10:39.731 EDT [7350] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:10:39.926 EDT [7351] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:10:39.926 EDT [7351] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:10:53.402 EDT [7355] tjgrevious@tjgrevious FATAL:  database "tjgrevious" does not exist
2019-09-24 15:11:06.360 EDT [7358] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:11:06.360 EDT [7358] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:11:06.478 EDT [7359] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:11:06.478 EDT [7359] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:11:40.716 EDT [7374] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:11:40.716 EDT [7374] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:11:40.853 EDT [7375] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:11:40.853 EDT [7375] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:12:02.098 EDT [7378] tjgrevious@tjgrevious FATAL:  database "tjgrevious" does not exist

嘗試這個:

$ rm /usr/local/var/postgres/postmaster.pid
$ brew services restart postgresql

參考: https://stackoverflow.com/a/18832331/13180074

你確定它在 5433 上運行嗎? 您可以使用 netstat 工具查看實際運行的內容(在 OS X、Windows 和 Linux 上可用,命令行語法在這三個工具中有所不同)

如果您在 Mac 上,並且正在使用默認的 postgres 安裝,請丟棄它並通過 homebrew 安裝它。

最終發生的是用戶安裝 Pg 並從一個包啟動服務器,但使用來自不同包的 psql 和 libpq 客戶端。 這通常發生在他們運行 Postgres.app 或 homebrew Pg 並連接操作系統附帶的 psql 時。 不僅這些有時具有不同的默認端口,而且 Mac OS X 附帶的 Pg 具有不同的默認 unix 套接字路徑,因此即使服務器在同一端口上運行,它也不會偵聽相同的 unix 套接字。

大多數 Mac 用戶只需將 tcp/ip 與 psql -h localhost 一起使用即可解決此問題。 如果需要,您還可以指定一個端口,例如 psql -h localhost -p 5433。您可能有多個 PostgreSQL 實例正在運行,因此請確保您使用 select version() 和 SHOW data_directory; 連接到正確的實例。

可以在postgresql 端口混淆 5433 或 5432?

暫無
暫無

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

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