From 298a9e2e9c0c768b5e3c0749c1e8b5a915b5d198 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 9 Dec 2024 16:11:03 -0500 Subject: [PATCH] Add missing index for GC in Postgres --- internal/datastore/postgres/gc.go | 2 +- .../zz_migration.0023_add_missing_gc_index.go | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 internal/datastore/postgres/migrations/zz_migration.0023_add_missing_gc_index.go diff --git a/internal/datastore/postgres/gc.go b/internal/datastore/postgres/gc.go index 4be068c23c..ee012269ed 100644 --- a/internal/datastore/postgres/gc.go +++ b/internal/datastore/postgres/gc.go @@ -45,7 +45,7 @@ func (pgd *pgDatastore) LockGCRun(ctx context.Context, timeout time.Duration, gc }) if err != nil { if errors.Is(err, pglock.ErrNotAcquired) { - log.Debug().Err(err).Msg("did not acquire lock for GC run; GC is likely being run by another node") + log.Trace().Err(err).Msg("did not acquire lock for GC run; GC is likely being run by another node") return false, nil } return false, err diff --git a/internal/datastore/postgres/migrations/zz_migration.0023_add_missing_gc_index.go b/internal/datastore/postgres/migrations/zz_migration.0023_add_missing_gc_index.go new file mode 100644 index 0000000000..952572301e --- /dev/null +++ b/internal/datastore/postgres/migrations/zz_migration.0023_add_missing_gc_index.go @@ -0,0 +1,25 @@ +package migrations + +import ( + "context" + "fmt" + + "github.com/jackc/pgx/v5" +) + +const addGCIndexForRelationTupleTransaction = `CREATE INDEX CONCURRENTLY + IF NOT EXISTS ix_relation_tuple_transaction_xid_desc_timestamp + ON relation_tuple_transaction (xid DESC, timestamp);` + +func init() { + if err := DatabaseMigrations.Register("add-missing-gc-index", "add-gc-lock-table", + func(ctx context.Context, conn *pgx.Conn) error { + if _, err := conn.Exec(ctx, addGCIndexForRelationTupleTransaction); err != nil { + return fmt.Errorf("failed to add missing GC index: %w", err) + } + return nil + }, + noTxMigration); err != nil { + panic("failed to register migration: " + err.Error()) + } +}