我有本地的Kubernetes集群,我想在其中部署主从postgres实例,并在它们之间设置流复制.我遵循了下面的Postgres文档来实现这一点:
https://www.postgresql.org/docs/16/warm-standby.html#STREAMING-REPLICATION. https://www.postgresql.org/docs/16/runtime-config-replication.html.
当前情况如下,从postgres实例写入以下错误:database system identifier differs between the primary and standby
.我计算出,为了解决这个问题,从postgres实例需要首先使用pg_basebackup
从主实例复制数据文件夹.我也这样做了,目前我在我的从实例上的以下文件夹/var/lib/postgresql/main
中有该副本.但是,我不理解应该如何更改放置在/var/lib/postgresql/data
中的当前数据文件夹,以及当前由postgres从postgres实例使用的文件夹.请建议一下如何处理这件事.理想情况下,最好将这个新复制的文件夹放在中央位置,并在所有Postgres实例中重复使用它
UPDATE:个 我还try 设置持久化卷并在状态集中使用它,如下所示,但在这种情况下,容器不起作用:
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-data-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /path/to/data/folder/on/my/host/machine
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-data-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
和庄严的设置:
apiVersion: v1
kind: StatefulSet
spec:
containers:
- name: slave-postgres
image: postgres:latest
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-data
persistentVolumeClaim:
claimName: postgres-data-pvc