diff --git a/patroni/postgresql/__init__.py b/patroni/postgresql/__init__.py
index 69775e4886..da205d7647 100644
--- a/patroni/postgresql/__init__.py
+++ b/patroni/postgresql/__init__.py
@@ -723,6 +723,9 @@ def role(self) -> PostgresqlRole:
     def set_role(self, value: PostgresqlRole) -> None:
         with self._role_lock:
             self._role = value
+        if value not in (PostgresqlRole.PRIMARY, PostgresqlRole.MASTER, PostgresqlRole.PROMOTED) \
+                and hasattr(self, 'sync_handler'):
+            self.sync_handler.reset_state()
 
     @property
     def state(self) -> PostgresqlState:
diff --git a/patroni/postgresql/sync.py b/patroni/postgresql/sync.py
index 727a2402b8..76aa1851df 100644
--- a/patroni/postgresql/sync.py
+++ b/patroni/postgresql/sync.py
@@ -295,6 +295,16 @@ class SyncHandler(object):
 
     def __init__(self, postgresql: 'Postgresql') -> None:
         self._postgresql = postgresql
+        self.reset_state()
+
+    def reset_state(self) -> None:
+        """Forget everything known about ``synchronous_standby_names`` and replicas.
+
+        Must be called when the node stops being a primary. Otherwise values cached during the previous primary
+        tenure would be trusted after the next promotion. For example, if ``synchronous_standby_names`` set before
+        promote is equal to the last value observed by the former primary, replicas would be counted as synchronous
+        without reaching the WAL position of the new primary.
+        """
         self._synchronous_standby_names = ''  # last known value of synchronous_standby_names
         self._ssn_data = deepcopy(_EMPTY_SSN)
         self._primary_flush_lsn = 0
diff --git a/tests/test_sync.py b/tests/test_sync.py
index 99e4f893b2..8919372dfe 100644
--- a/tests/test_sync.py
+++ b/tests/test_sync.py
@@ -7,6 +7,7 @@
 from patroni.dcs import Cluster, ClusterConfig, Status, SyncState
 from patroni.postgresql import Postgresql, PostgresqlState
 from patroni.postgresql.config import ConfigHandler
+from patroni.postgresql.misc import PostgresqlRole
 from patroni.postgresql.slots import SlotsHandler
 
 from . import BaseTestPostgresql, mock_available_gucs, psycopg_connect
@@ -103,6 +104,28 @@ def test_current_state_quorum(self):
                               CaseInsensitiveSet([self.me.name, self.leadermem.name]),
                               CaseInsensitiveSet([self.leadermem.name, self.me.name])))
 
+    @patch('time.sleep', Mock())
+    def test_current_state_after_repromote(self):
+        self.cluster.config.data['synchronous_mode'] = 'quorum'
+        global_config.update(self.cluster)
+        a, b = self.leadermem.name, self.me.name
+        state = {'synchronous_standby_names': 'ANY 1 ({0},"{1}")'.format(a, b), 'synchronous_commit': 'on'}
+        with patch.object(Postgresql, '_cluster_info_state_get', side_effect=lambda name: state[name]), \
+                patch.object(Postgresql, 'last_operation', Mock(return_value=1)) as mock_last_operation:
+            state['pg_stat_replication'] = [
+                {'pid': 100, 'application_name': a, 'sync_state': 'quorum', 'flush_lsn': 1},
+                {'pid': 101, 'application_name': b, 'sync_state': 'quorum', 'flush_lsn': 1}]
+            self.assertEqual(self.s.current_state(self.cluster).sync_confirmed, CaseInsensitiveSet([a, b]))
+
+            # demoted and promoted again, synchronous_standby_names set before promote has the same value
+            self.p.set_role(PostgresqlRole.REPLICA)
+            self.p.set_role(PostgresqlRole.PROMOTED)
+            mock_last_operation.return_value = 3
+            state['pg_stat_replication'] = [
+                {'pid': 200, 'application_name': a, 'sync_state': 'quorum', 'flush_lsn': 2},
+                {'pid': 201, 'application_name': b, 'sync_state': 'quorum', 'flush_lsn': 3}]
+            self.assertEqual(self.s.current_state(self.cluster).sync_confirmed, CaseInsensitiveSet([b]))
+
     @patch.object(Postgresql, 'last_operation', Mock(return_value=1))
     def test_current_state_cascading(self):
         pg_stat_replication = [
