Skip to content

Commit 528bb81

Browse files
authored
first sync wal_level then publications (zalando#2109)
1 parent 2a54e49 commit 528bb81

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pkg/cluster/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const (
4848

4949
getPublicationsSQL = `SELECT p.pubname, string_agg(pt.schemaname || '.' || pt.tablename, ', ' ORDER BY pt.schemaname, pt.tablename)
5050
FROM pg_publication p
51-
JOIN pg_publication_tables pt ON pt.pubname = p.pubname
51+
LEFT JOIN pg_publication_tables pt ON pt.pubname = p.pubname
5252
GROUP BY p.pubname;`
5353
createPublicationSQL = `CREATE PUBLICATION "%s" FOR TABLE %s WITH (publish = 'insert, update');`
5454
alterPublicationSQL = `ALTER PUBLICATION "%s" SET TABLE %s;`

pkg/cluster/streams.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@ func (c *Cluster) syncStreams() error {
273273
return nil
274274
}
275275

276+
// update config to set wal_level: logical
277+
requiredPatroniConfig := c.Spec.Patroni
278+
requiresRestart, err := c.syncPostgresConfig(requiredPatroniConfig)
279+
if err != nil {
280+
return fmt.Errorf("failed to snyc Postgres config for event streaming: %v", err)
281+
}
282+
if requiresRestart {
283+
c.logger.Debugf("updated Postgres config. Server will be restarted and streams will get created during next sync")
284+
return nil
285+
}
286+
276287
// fetch different application IDs from streams section
277288
// there will be a separate event stream resource for each ID
278289
appIds := gatherApplicationIds(c.Spec.Streams)
@@ -282,7 +293,6 @@ func (c *Cluster) syncStreams() error {
282293
slotsToSync := make(map[string]map[string]string)
283294
publications := make(map[string]map[string]acidv1.StreamTable)
284295

285-
requiredPatroniConfig := c.Spec.Patroni
286296
if len(requiredPatroniConfig.Slots) > 0 {
287297
slots = requiredPatroniConfig.Slots
288298
}
@@ -330,15 +340,10 @@ func (c *Cluster) syncStreams() error {
330340
}
331341

332342
// add extra logical slots to Patroni config
333-
c.logger.Debug("syncing Postgres config for logical decoding")
334-
requiresRestart, err := c.syncPostgresConfig(requiredPatroniConfig)
343+
_, err = c.syncPostgresConfig(requiredPatroniConfig)
335344
if err != nil {
336345
return fmt.Errorf("failed to snyc Postgres config for event streaming: %v", err)
337346
}
338-
if requiresRestart {
339-
c.logger.Debugf("updated Postgres config. Server will be restarted and streams will get created during next sync")
340-
return nil
341-
}
342347

343348
// after Postgres was restarted we can create stream CRDs
344349
err = c.createOrUpdateStreams()

0 commit comments

Comments
 (0)