首页 > 解决方案 > PostgreSQL 端口 5432 已在使用 // 忘记用户密码

问题描述

这几天我在使用 postgreSQL 时遇到了一些麻烦(macos 版本:10.15.4)

  1. 我丢失了用户密码,因此无法登录 psql 控制台
  2. 我尝试启动 PosgreSQL 12 应用程序以更好地可视化我的数据库,并且不知何故我的端口一直在使用中

我的第一个问题是:

我已经尝试 brew uninstall postgresqlbrew remove postgresql

在那方面没有任何作用

第二个问题和第二种可能性

启动应用程序时,它告诉我端口 5432 已在使用中

我遇到了一个奇怪的行为:

lsof -i TCP:5432

给了我两行在端口中侦听的进程我试图杀死它工作的相关 pid 但是随后另一个新的 pid 出现并使用端口 5432 并且 pid 号增加,就好像无论发生什么我的 postgres cammand 都重新生成了我的端口5432 正在使用中。

有了这个,我被一个我无法使用的应用程序和一个我无法连接的命令行所困。

您知道如何重置或解决问题吗?

编辑似乎每10秒我的postgre日志文件就会增加这个

    2020-04-28 19:28:52.579 CEST [12186] LOG:  starting PostgreSQL 12.2 on x86_64-apple-darwin19.4.0, compiled by Apple clang version 11.0.3 (clang-1103.0.32.59), 64-bit
2020-04-28 19:28:52.626 CEST [12186] LOG:  could not bind IPv6 address "::1": Address already in use
2020-04-28 19:28:52.626 CEST [12186] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2020-04-28 19:28:52.626 CEST [12186] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2020-04-28 19:28:52.626 CEST [12186] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2020-04-28 19:28:52.626 CEST [12186] WARNING:  could not create listen socket for "localhost"
2020-04-28 19:28:52.626 CEST [12186] FATAL:  could not create any TCP/IP sockets
2020-04-28 19:28:52.649 CEST [12186] LOG:  database system is shut down

感谢您对此的任何建议!干杯,

标签: postgresqlmacos

解决方案


重新启动计算机后,有时即使端口 5432 上没有运行任何进程,我也会收到端口 5432 已在使用错误。

什么对我有用:

ps -ef | grep postgres

这显示了在 postgres 用户下运行的所有进程。

sudo pkill -u postgres

这会杀死那些进程


推荐阅读