<p>I have a Postgres pod which has a mounted volume:</p>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: postgres-pv
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 100M
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app: postgres
  name: psql-claim
spec:
  storageClassName: manual
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 100M
</code></pre>

<p>The yaml contains the following:</p>

<pre><code>volumeMounts:
            - mountPath: /docker-entrypoint-initdb.d/
              name: psql-config-map-volume
            - mountPath: /var/lib/postgresql/data
              name: psql-claim 
              subPath: postgres
      volumes:
        - name: psql-config-map-volume
          configMap:
            name: psql-config-map // contains an init.sql
        - name: psql-claim
          persistentVolumeClaim:
            claimName: psql-claim
</code></pre>

<p>It works well, data retain after deployment/pod deletion and redeploy.</p>

<p>The problem appears when I modify the init.sql.
It didn't come into effect and got this message at psql pod startup:</p>

<blockquote>
  <p>PostgreSQL Database directory appears to contain a database; Skipping initialization</p>
</blockquote>

<p>The pod itself starts without any error (just with the old init.sql data)</p>

<p>What I have tried: </p>

<ol>
<li>Deleting the deployment,the pvc and pv. Then redeploy everything. Same result.<br></li>
<li>I searched the hostpath data but /mnt/data is empty.<br></li>
</ol>

<p>What else should I try? How can I force the init.sql to launch? Where the actual old data is stored if not in the hostpath? </p>

<p><strong><em>edit: I have search for pg files and found this:</em></strong><br>
/var/lib/docker/overlay2/6ae2../merged/mnt/data/postgres/pg_ident.conf<br>
/var/lib/docker/overlay2/6ae2../diff/mnt/data/postgres/pg_ident.conf<br>
And it still exists after pvc and pv deletion. How can I gracefully reset its data?</p>

beatrice
<p>I just had a similar situation. It turned out that I had a typo in my <code>initdb.sh</code> script. This results in PG starting, failing to apply the script and crashing. This causes the container to restart, and the next time, PG skips the script.</p>
<p>I finally figured it out because the pod was showing <code>restartCount: 1</code>. Running <code>kubectl logs postgres-0 --previous</code> gave me the logs from <em>before</em> the crash, which pointed to a typo in my script (<code>LC_TYPE</code> instead of <code>LC_CTYPE</code>, in my case).</p>
