【发布时间】:2021-02-27 12:03:01
【问题描述】:
我需要在正在运行的容器中升级 postgresql 数据库。为此,我需要停止旧服务器,以便启动新服务器。问题是我没有找到如何通过 systemctl、pg_ctl 或服务停止正在运行的 postgres 进程。
pg_ctl:
root@postgres-7ffd788bc9-g2dkv:/# su postgres
$ pg_ctl status
sh: 1: pg_ctl: not found
systemctl:
root@postgres-7ffd788bc9-g2dkv:/# systemctl status postgresql
bash: systemctl: command not found
服务(不返回任何内容):
root@postgres-7ffd788bc9-g2dkv:/# service postgresql status
root@postgres-7ffd788bc9-g2dkv:/#
postgresql 是使用这个 kubernetes yaml 创建的:
spec:
containers:
- name: postgres
image: postgres:10.4
服务器正在运行:
root@postgres-7ffd788bc9-g2dkv:/# psql postgresql://user:pass@127.0.0.1:5432/postgresdb
psql (12.5 (Debian 12.5-1.pgdg90+1), server 10.4 (Debian 10.4-2.pgdg90+1))
Type "help" for help.
postgresdb=# select VERSION();
version
----------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 10.4 (Debian 10.4-2.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
(1 row)
你有什么建议?
【问题讨论】:
-
一个 docker 容器通常应该只执行一个任务。假设您从 docker repo 中获取了默认的 Postgres 容器,这意味着停止容器等同于停止服务。事实上,如果您使用 SSH 登录到容器,您可能会发现停止服务会导致容器停止。所以就像@Marc Salvetti 在他的回答中提到的那样,只需停止容器并重建即可。如果容器内有数据(这不是一个好的做法),则需要先备份所述数据。
标签: postgresql docker kubernetes