2个月后无法连接到Docker上的现有数据库

发布于 2025-02-03 08:36:56 字数 2297 浏览 3 评论 0原文

因此,就像标题中一样,我无法连接到Docker上的数据库。我创建了新容器,以查看一个问题。在新容器上,一切正常工作,旧容器是一个问题。它们都以相同的方式创建。

d7289b0bb93f   postgres   "docker-entrypoint.s…"   24 minutes ago   Up 14 minutes   0.0.0.0:5544->5432/tcp, :::5544->5432/tcp
bc4118c3356c postgres   "docker-entrypoint.s…"   2 months ago     Up 14 minutes 0.0.0.0:5437->5432/tcp, :::5437->5432/tcp

5437刚随机停止。我使用psql -H localhost -p 5437 -u Postgres,我会收到以下错误:

psql:在“ localhost”(:: 1)上连接到服务器,端口5437失败: 服务器意外关闭连接

这可能意味着服务器在或何时终止 处理请求。

当我连接到新创建的容器psql -H localhost -p 5544 -u Postgres一切正常。

端口也一样:

> root@:/var/lib/docker/containers# netstat -tunlp | grep 5437

tcp 0 0 0.0.0.0:5437 0.0.0.0.0 :*听16161/docker-proxy

tcp6 0 0 :::: 5437 :::*听16167/docker-proxy

> root@:/var/lib/docker/containers# netstat -tunlp | grep 5544

tcp 0 0 0.0.0.0:5544 0.0.0.0.0 :*听16426/docker-proxy

tcp6 0 0 ::: 5544 :::*听16434/docker-proxy

在日志中发现了一些奇怪的东西,我不明白。

PostgreSQL Database directory appears to contain a database; Skipping initialization

 2022-05-30 13:08:27.890 GMT [1] LOG:  starting PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
 2022-05-30 13:08:27.891 GMT [1] LOG:  listening on IPv4 address "127.0.0.1", port 5432
 2022-05-30 13:08:27.891 GMT [1] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
 2022-05-30 13:08:27.893 GMT [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
 2022-05-30 13:08:27.899 GMT [26] LOG:  database system was shut down at 2022-05-30 13:08:25 GMT
 2022-05-30 13:08:27.904 GMT [1] LOG:  database system is ready to accept connections
 2022-05-30 13:12:43.197 GMT [1] LOG:  received fast shutdown request
 2022-05-30 13:12:43.198 GMT [1] LOG:  aborting any active transactions
 2022-05-30 13:12:43.200 GMT [1] LOG:  background worker "logical replication launcher" (PID 32) exited with exit code 1
 2022-05-30 13:12:43.200 GMT [27] LOG:  shutting down
 2022-05-30 13:12:43.210 GMT [1] LOG:  database system is shut down

So, as in title I cannot connect to database on docker. I created new container to see where is a problem. On new container everything is working just fine, on old one is a problem. Both of them are created in the same way.

d7289b0bb93f   postgres   "docker-entrypoint.s…"   24 minutes ago   Up 14 minutes   0.0.0.0:5544->5432/tcp, :::5544->5432/tcp
bc4118c3356c postgres   "docker-entrypoint.s…"   2 months ago     Up 14 minutes 0.0.0.0:5437->5432/tcp, :::5437->5432/tcp

The one on 5437 just randomly stoped. I use psql -h localhost -p 5437 -U postgres and I get following error:

psql: connection to server at "localhost" (::1), port 5437 failed:
server closed the connection unexpectedly

This probably means the server terminated abnormally before or while
processing the request.

When I connect to newly created container psql -h localhost -p 5544 -U postgres everything works just fine.

Also the same with ports:

> root@:/var/lib/docker/containers# netstat -tunlp | grep 5437

tcp 0 0 0.0.0.0:5437 0.0.0.0:* LISTEN 16161/docker-proxy

tcp6 0 0 :::5437 :::* LISTEN 16167/docker-proxy

> root@:/var/lib/docker/containers# netstat -tunlp | grep 5544

tcp 0 0 0.0.0.0:5544 0.0.0.0:* LISTEN 16426/docker-proxy

tcp6 0 0 :::5544 :::* LISTEN 16434/docker-proxy

Found something strange in logs, I do not understand it tho.

PostgreSQL Database directory appears to contain a database; Skipping initialization

 2022-05-30 13:08:27.890 GMT [1] LOG:  starting PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
 2022-05-30 13:08:27.891 GMT [1] LOG:  listening on IPv4 address "127.0.0.1", port 5432
 2022-05-30 13:08:27.891 GMT [1] LOG:  could not bind IPv6 address "::1": Cannot assign requested address
 2022-05-30 13:08:27.893 GMT [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
 2022-05-30 13:08:27.899 GMT [26] LOG:  database system was shut down at 2022-05-30 13:08:25 GMT
 2022-05-30 13:08:27.904 GMT [1] LOG:  database system is ready to accept connections
 2022-05-30 13:12:43.197 GMT [1] LOG:  received fast shutdown request
 2022-05-30 13:12:43.198 GMT [1] LOG:  aborting any active transactions
 2022-05-30 13:12:43.200 GMT [1] LOG:  background worker "logical replication launcher" (PID 32) exited with exit code 1
 2022-05-30 13:12:43.200 GMT [27] LOG:  shutting down
 2022-05-30 13:12:43.210 GMT [1] LOG:  database system is shut down

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清浅ˋ旧时光 2025-02-10 08:36:56

所以...在我操作容器后,然后访问/var/lib/postgresql/data/postgresql.conf到我的冲击文件是空的。我的意思是什么都没有...我不知道到底发生了什么!恢复文件,一切都很好。

So... After I opend container and went to /var/lib/postgresql/data/postgresql.conf to my shock file was empty. I mean nothing inside... I dunno what the heck happend! Recoverd file, all is good as new.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文