We recently had an issue with v0.11.0 that led to losing the entire database. I'm still trying to reproduce and better figure out what happened, but this is important enough I need to reach out now.
We have 1 primary with 2 replicas. We had an app server that has been caught consuming all of the connections to the primary. It connects as the postgres superuser. We patched our Postgres Resource to use a usermap for user.conf, setting a higher max_connections This caused the replicas and then the primary to be recreated. After they came up, the database was empty. It was after this that we then also found that the last backup job had been running for more than 13 days, uncompleted.
I haven't been able to reproduce the problem to definitely pin the blame on the app server and its misuse of the superuser account. It seems poor that the replicas would stay running if they weren't connected to the primary and it seems very poor that a replica without data and presumably unable to sync from the primary would become the primary in a leader election. and most poor that a replica that was primary would be ok with not being the primary after knowing it had out of date replicas.
Is there any log information or any other debug information that would be helpful to determine why we lost data?
Something similar has happened with me once, where I saw an empty replica becoming the primary during a rolling update. In our case we first increased the number of replicas in one update and then, before it was able to sync we did another update triggering a rolling update.
But it only happened once and with development data. We wasn't able to reproduce the bug. Adding here because seems to be the very same problem.
Since then we have never ran kubedb's postgres with replicas on production data.
I can also confirm that running Postgres with ReplicaCount > 1 leads to data loss.
We're also working on a reliable repro for this problem, however it happens for us quite often.
Possibly related XRefs: https://github.com/kubedb/project/issues/405 https://github.com/kubedb/project/issues/330 https://github.com/kubedb/project/issues/461
/cc @johannwagner @fin-ger
We are running into the same problem with two databases, where empty replicas are being elected leader. We are not aware of a way to reproduce it consistently, though.
Has anyone experienced this with only a single replica? Or more than two replicas?
We also attempted to replicate in another environment which was in an identical state as the one that lost data and were unable to.
Is anyone actively working on this issue currently?
We are experiencing this issue quite regularly with 3 replicas.
Philip Hutchins notifications@github.com schrieb am Fr., 21. Juni 2019,
14:56:
Has anyone experienced this with only a single replica? Or more than two
replicas?We also attempted to replicate in another environment which was in an
identical state as the one that lost data and were unable to.Is anyone actively working on this issue currently?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/kubedb/project/issues/555?email_source=notifications&email_token=ABKM3AMNIOA3DZUSHIBFIS3P3TFYXA5CNFSM4HZDIMW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYIMLEQ#issuecomment-504415634,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABKM3AKO32F65RHDDAXC353P3TFYXANCNFSM4HZDIMWQ
.
This issue just occurred with me. Updated leaderElection leaseDurationSeconds, and all production data got wiped. Will take a while before we will use KubeDB again.
We are seeing this with a single replica. And I think I can see what happens. The context is rolling reboot of nodes so all the pods get moved and restarted a few time.
a database pod is restarted, declares itself as replica, manages to reach the primary, deletes its data directory - https://github.com/kubedb/postgres/blob/30937fd1c6fb8cf9bf21cf340231709b05a8fc13/hack/docker/postgres/10.6/scripts/replica/run.sh#L37 - and starts reading a backup from the primary
while the backup is in progress the primary is restarted, pg_basebackup fails and we see
I0712 06:32:56.341677 1 [leaderelection.go:187] attempting to acquire leader lease database/FOO-leader-lock...
Running as Replica
Attempting pg_isready on primary
Attempting query on primary
pg_basebackup: could not read COPY data: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
pg_basebackup: removing contents of data directory "/var/pv/data"
I0712 06:33:28.270940 1 logs.go:19] exit status 1
the same secondary is restarted once again (bad node scheduling luck) but this time wins the leader election. The primary now is a server with no data at all.
the original primary comes up as secondary, deletes its data.
This is related #385
The replica/run.sh script contains a race condition between checking it can reach the primary and starting the backup.
It might be a good idea to create the backup into a different directory and only delete the real data directory once the backup has succeeded, but this would only create a less likely race condition.
What I feel would be better was to mark the secondary as "I'm in no state to become a primary" before it deletes the data directory and only remove that marker once done with the backup (a lock file on the persistent volume that also holds the data?). If such a marker exists, the pod should not participate in leader elections after startup.
The problem with creating a full backup of the data is that you need twice the space for the same data, which can be fairly expensive when dealing with large databases. Imagine a 1TB database, so you need two PVCs with 1TB each...
Not having any data is not really a better option ;-)
But yes, understood.
We're also experiencing this problem and getting the database wiped. We're running with one primary and two replicas.
the problem can be avoided by using a wal archiver (wal-g), unfortunatly that is not a solution for many private k8s clusters.
the problem can be avoided by using a wal archiver (wal-g), unfortunatly that is not a solution for many private k8s clusters.
Oh, thanks a million! I will test this out.
Today we faced the very same issue.
There was one primary and one replica. Both were running in hot mode.
All we did is changed the nodeSelector in deployment configuration. And viola, when the both server got up, there is no more database!!! All data got wiped. Unfortunately the the backup was not working due to some mis-configuration. So yeah, we just lost last 2 days data.
This problem is known since January: https://github.com/kubedb/project/issues/385
KubeDB team even started working on it, but the progress unfortunately got stuck by some reason: https://github.com/kubedb/postgres/pull/248
In fact it's a critical issue which makes PostgresDB engine completely unusable for us as soon as we run k8n on AWS EC2 spot instances with autoscaling. Hence individual EC2 instance can be terminated at any moment.
I can now confirm that using WAL-G archiving _does not_ prevent the data loss.
Setup: one primary and two replicas.
This happened to me as well with the last 2 versions of the operator v0.12.0 and v0.13.0-rc.0. In both cases I had a cluster with a master and replica, and edited the pg resource for the db to change the backup configuration just as suggested here - https://kubedb.com/docs/0.8.0-beta.2/guides/postgres/snapshot/scheduled_backup/#create-postgres-with-backupschedule, to disable and enable the backups.
In each case, the replica was terminated and regenerated and wiped out it's data, then the other database pod was also terminated, restarted and wiped out it's data. This is a major flaw and it's a little surprising to me that it's not been addressed yet, if it was known since January. Anyway I will have to discontinue my use of KubeDB Postgres, it is not ready for production.
Just hit the same issue with a primary and one replica.
There should be a red note in the docs pointing here until this gets fixed.
We experienced a full data loss (database wiped)—but we did not change backup settings. Instead, monitoring was added to the Postgres CRD:
spec:
monitor:
agent: prometheus.io/builtin
While I was not able to reproduce it (so far) I'm wondering if all config changes that trigger a rolling restart can hit this issue? All other symptoms match what has been said above.
+1 with one primary and 2 warm standby replicas.
Production (beta) cluster, so not great... I'm pretty surprised that something like this isn't line item one on the issues list. It's a bit like playing Russian roulette...
This issue has been resolved in KubeDB release v2021.03.17 . Please open a new bug if you still see this issue.
Most helpful comment
Just hit the same issue with a primary and one replica.
There should be a red note in the docs pointing here until this gets fixed.