<p>I am trying to set a postgres parameter (shared_buffers) into my postgres database pod. I am trying to set an init container to set the db variable, but it is not working because the init container runs as the root user.</p>

<p>What is the best way to edit the db variable on the pods? I do not have the ability to make the change within the image, because the variable needs to be different for different instances. If it helps, the command I need to run is a "postgres -c" command.</p>

<pre><code>"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.
</code></pre>

mmiara
<p>In my case, the <a href="https://stackoverflow.com/a/60783722/7856777">@Rico answer</a> didn't help me out of the box because I don't use postgres with a persistent storage mount, which means there is no /var/lib/postgresql/data folder and pre-existed database (so both proposed options have failed in my case).</p>
<p>To successfully apply postgres settings, I used only args (without <code>command</code> section).</p>
<p>In that case, k8s will pass these args to the default entrypoint defined in the docker image (<a href="https://kubernetes.io/docs/tasks/inject-data-application/_print/#notes" rel="noreferrer">docs</a>), and as for postgres entrypoint, it is made so that any options passed to the docker command will be passed along to the postgres server daemon (look section <em>Database Configuration</em> at: <a href="https://hub.docker.com/_/postgres" rel="noreferrer">https://hub.docker.com/_/postgres</a>)</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: postgres
spec:
  containers:
    - image: postgres:9.6.8
      name: postgres
      args: [&quot;-c&quot;, &quot;shared_buffers=256MB&quot;, &quot;-c&quot;, &quot;max_connections=207&quot;]
</code></pre>
<p>To check that the settings applied:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl exec -it postgres -- bash
root@postgres:/# su postgres
$ psql -c 'show max_connections;'
 max_connections
-----------------
 207
(1 row)
</code></pre>
