本文介绍了如何停止容器内的postgresql服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要升级正在运行的容器中的postgresql数据库.为此,我需要停止旧服务器,以便启动新服务器.问题是我找不到如何停止正在运行的postgres进程thourgh systemctl,pg_ctl或服务.

I need to upgrade a postgresql database inside a running container. For that I need to stop the old server so I can start the new. The problem is that I didn't find how to stop the running postgres process thourgh systemctl, pg_ctl or service.

pg_ctl:

root@postgres-7ffd788bc9-g2dkv:/# su postgres
$ pg_ctl status
sh: 1: pg_ctl: not found

systemctl:

systemctl:

root@postgres-7ffd788bc9-g2dkv:/# systemctl status postgresql
bash: systemctl: command not found

服务(不返回任何内容):

service (returns nothing):

root@postgres-7ffd788bc9-g2dkv:/# service postgresql status
root@postgres-7ffd788bc9-g2dkv:/# 

postgresql是使用以下kubernetes yaml创建的:

The postgresql was created using this kubernetes yaml:

    spec:
      containers:
        - name: postgres
          image: postgres:10.4

服务器正在运行:

root@postgres-7ffd788bc9-g2dkv:/# psql postgresql://user:[email protected]: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)

您建议做什么?

推荐答案

最后,我要做的是在Kubernetes中创建一个并行的postgres pod,其中包含新版本.然后,我从旧服务器上转储数据库,将其复制到新服务器上,并用它来初始化那里的数据库.

What I did at the end is creating a parallel postgres pod in Kubernetes which holds the new version. Then I dumped database from old server, copied it to the new server, and used it to initialize the data base there.

以下是第一步:

  1. 使用新版本创建并行的postgres服务

  1. Create a parallel postgres service with the new version

在旧版本的pod中:

pg_dumpall -U postgresadmin -h localhost -p 5432 > dumpall.sql
  1. 在主持人中:
kubectl cp postgres-old-pod:/dumpall.sql dumpall.sql
kubectl cp dumpall.sql postgres2-new-pod:/dumpall.sql
  1. ssh到new-pod

  1. ssh to new-pod

额外步骤,因为某些原因,新的pod没有创建"postgres"用户:使用您的凭据进入postgres客户:

extra step that I needed, becuase for some reason new pod didn't had 'postgres' user created:get into postgres client using your credentials:

psql postgresql://postgresadmin:[email protected]:5432/postgresdb?sslmode=disable
postgresdb=# CREATE ROLE postgres LOGIN SUPERUSER PASSWORD 'somepassword123';

然后退出postgres并退出普通用户

then exit postgres and exit to normal user

  1. 最后更新数据库:
psql -U postgres -W -f dumpall.sql

这篇关于如何停止容器内的postgresql服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:07