<p>Postgres can't start giving the error:  </p>

<pre><code>PANIC could not locate a valid checkpoint record
</code></pre>

<p>On Google, there is a lot of solution, but all of them need to connect the pod to execute some pg commands.</p>

<p>But, as I use K8S, my pod falls into status: <code>CrashLoopBackOff</code>, so I can't connect anymore to my pod.</p>

<p>How should I do to fix my postgres DB ?</p>

<p>EDIT: </p>

<p>I have tried to run the command: </p>

<pre><code>pg_resetwal /var/lib/postgresql/data
</code></pre>

<p>with:</p>

<pre><code>...
spec:
      containers:
      - args:
        - pg_resetwal
        - /var/lib/postgresql/data
</code></pre>

<p>But I get: </p>

<pre><code>pg_resetwal: cannot be executed by "root"
You must run pg_resetwal as the PostgreSQL superuser.
</code></pre>

<p>Can go further...</p>

<p>EDIT2:</p>

<p>I tried to run a new pod with the same volumes attached, and the same postgres container, but changing the command to : <code>pg_resetwal /var/lib/postgresql/data</code></p>

<p>I also added: </p>

<pre><code>securityContext:
              runAsUser: 0
</code></pre>

<p>Here is the yaml for deployment:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    reloader.stakater.com/auto: "true"
  labels:
    app: metadata-postgres-fix
  name: metadata-postgres-fix
  namespace: metadata
spec:
  selector:
    matchLabels:
      app: metadata-postgres-fix
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: metadata-postgres-fix
    spec:
      containers:
      - args:
        - pg_resetwal
        - /var/lib/postgresql/data
        envFrom:
          - secretRef:
              name: metadata-env
        image: postgres:11.3
        name: metadata-postgres-fix
        securityContext:
          runAsUser: 0
        ports:
        - containerPort: 5432
        imagePullPolicy: Always
        volumeMounts:
        - mountPath: /etc/postgresql/postgresql.conf
          name: metadata-postgres-data
          subPath: postgres.conf
        - mountPath: /docker-entrypoint-initdb.d/init.sh
          name: metadata-postgres-data
          subPath: init.sh
        - mountPath: /var/lib/postgresql/data
          name: metadata-postgres-claim
          subPath: postgres
      restartPolicy: Always
      volumes:
      - name: metadata-postgres-data
        configMap:
          name: cfgmap-metadata-postgres
      - name: metadata-postgres-claim
        persistentVolumeClaim:
          claimName: metadata-postgres-claim
      nodeSelector:
        kops.k8s.io/instancegroup: nodes
</code></pre>

Juliatzin
<p>I solved it changing</p>
<pre><code>- args:
    - pg_resetwal
    - /var/lib/postgresql/data
</code></pre>
<p>with a pause to be able to get UID of postgres:</p>
<pre><code>- args:
    - sleep
    - 1000
</code></pre>
<p>with</p>
<pre><code>cat /etc/passwd
</code></pre>
<p>I could find posgres UID is 999</p>
<p>and finally change <code>runAsUser: 0</code> with <code>runAsUser: 999</code></p>
