<p>I would like to generate dump from a remote PostgreSQL database (PGAAS) with commands or Python code.</p>
<p>Firstly I tried locally to do the work but I have an error :</p>
<pre><code>pg_dump: error: server version: 13.9; pg_dump version: 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1)
</code></pre>
<p>I tried this code :</p>
<pre><code>import subprocess

dump_file = &quot;database_dump.sql&quot;

with open(dump_file, &quot;w&quot;) as f:
    print(f)
    subprocess.call([&quot;pg_dump&quot;, &quot;-Fp&quot;, &quot;-d&quot;, &quot;dbdev&quot;, &quot;-U&quot;, &quot;pgsqladmin&quot;, &quot;-h&quot;, &quot;hostname&quot;-p&quot;, &quot;32000&quot;], stdout=f)
</code></pre>
<p>How can I do to have a pod (container) doing this work and where version is the same that server version, without entering pgaas password manually ?</p>

lbened
<p><code>pg_dump: error: server version: 13.9; pg_dump version: 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1)</code></p>
<p>As you can see this error is caused because of a version mismatch checking the version of your PGaaS database and the database version you are using on your local machine. If your local version is lower than that of the server version you can upgrade the local version. Follow this <a href="https://www.postgresql.org/docs/current/pgupgrade.html" rel="nofollow noreferrer">document</a> for upgrading your pg version.</p>
<p>If you want to take dumps at regular intervals in an easy way you can have a cron job scheduled on your vm for running your code. Since you want to use kubernetes, build a docker image with your code in it and create a kubernetes job and run it with kube-scheduler and you can use environment variables for encrypting your password.</p>
