gpt4 book ai didi

postgresql - Postgres/K8S : PANIC could not locate a valid checkpoint record/CrashLoopBackOff

转载 作者:行者123 更新时间:2023-12-02 12:28:55 25 4
gpt4 key购买 nike

Postgres 无法开始给出错误:

PANIC could not locate a valid checkpoint record

在谷歌上,有很多解决方案,但都需要连接pod来执行一些pg命令。

但是,当我使用 K8S 时,我的 pod 处于以下状态: CrashLoopBackOff ,所以我无法再连接到我的 Pod。

我应该如何修复我的 postgres 数据库?

编辑:

我试图运行命令:
pg_resetwal /var/lib/postgresql/data

和:
...
spec:
containers:
- args:
- pg_resetwal
- /var/lib/postgresql/data

但我得到:
pg_resetwal: cannot be executed by "root"
You must run pg_resetwal as the PostgreSQL superuser.

可以更进一步...

编辑2:

我尝试运行一个附加了相同卷和相同 postgres 容器的新 pod,但将命令更改为: pg_resetwal /var/lib/postgresql/data
我还补充道:
securityContext:
runAsUser: 0

这是用于部署的 yaml:
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

最佳答案

我解决了它改变

- args:
- pg_resetwal
- /var/lib/postgresql/data
暂停以获取 postgres 的 UID:
- args:
- sleep
- 1000
cat /etc/passwd
我可以找到 posgres UID 是 999
最后改 runAsUser: 0runAsUser: 999

关于postgresql - Postgres/K8S : PANIC could not locate a valid checkpoint record/CrashLoopBackOff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60604699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com