From 909f2be99d0c699f506f463bb6238378f12c0dc1 Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 19 Mar 2021 03:23:58 +0000 Subject: Fix postgres ID sequences broken by recreate-table (#15015) (#15029) Backport #15015 Unfortunately there is a subtle problem with recreatetable on postgres which leads to the sequences not being renamed and not being left at 0. Fix #14725 Signed-off-by: Andrew Thornton --- cmd/doctor.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'cmd') diff --git a/cmd/doctor.go b/cmd/doctor.go index 2ca2bb5e70..5ba0451110 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -670,6 +670,23 @@ func runDoctorCheckDBConsistency(ctx *cli.Context) ([]string, error) { } } + if setting.Database.UsePostgreSQL { + count, err = models.CountBadSequences() + if err != nil { + return nil, err + } + if count > 0 { + if ctx.Bool("fix") { + err := models.FixBadSequences() + if err != nil { + return nil, err + } + results = append(results, fmt.Sprintf("%d sequences updated", count)) + } else { + results = append(results, fmt.Sprintf("%d sequences with incorrect values", count)) + } + } + } //ToDo: function to recalc all counters return results, nil -- cgit v1.2.3