<p>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.</p>
<p>pg_ctl:</p>
<pre><code>root@postgres-7ffd788bc9-g2dkv:/# su postgres
$ pg_ctl status
sh: 1: pg_ctl: not found
</code></pre>
<p>systemctl:</p>
<pre><code>root@postgres-7ffd788bc9-g2dkv:/# systemctl status postgresql
bash: systemctl: command not found
</code></pre>
<p>service (returns nothing):</p>
<pre><code>root@postgres-7ffd788bc9-g2dkv:/# service postgresql status
root@postgres-7ffd788bc9-g2dkv:/# 
</code></pre>
<p>The postgresql was created using this kubernetes yaml:</p>
<pre><code>    spec:
      containers:
        - name: postgres
          image: postgres:10.4
</code></pre>
<p>The server is running:</p>
<pre><code>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 &quot;help&quot; 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)
</code></pre>
<p>What do you suggest to do?</p>

justadev
<p>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.</p>
<p>Here are the steps one by one:</p>
<ol>
<li><p>Create a parallel postgres service with the new version</p>
</li>
<li><p>In old version pod:</p>
</li>
</ol>
<pre><code>pg_dumpall -U postgresadmin -h localhost -p 5432 &gt; dumpall.sql
</code></pre>
<ol start="3">
<li>In the host:</li>
</ol>
<pre><code>kubectl cp postgres-old-pod:/dumpall.sql dumpall.sql
kubectl cp dumpall.sql postgres2-new-pod:/dumpall.sql
</code></pre>
<ol start="4">
<li><p>ssh to new-pod</p>
</li>
<li><p>extra step that I needed, becuase for some reason new pod didn't had 'postgres' user created:
get into postgres client using your credentials:</p>
</li>
</ol>
<pre><code>psql postgresql://postgresadmin:pass1234@127.0.0.1:5432/postgresdb?sslmode=disable
postgresdb=# CREATE ROLE postgres LOGIN SUPERUSER PASSWORD 'somepassword123';
</code></pre>
<p>then exit postgres and exit to normal user</p>
<ol start="6">
<li>Finally update the database:</li>
</ol>
<pre><code>psql -U postgres -W -f dumpall.sql
</code></pre>
