From a7a1c2d5f81b9d7f01e77739c6f26e9f8effb6a5 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 --- .../zz_migration.0023_add_missing_gc_index.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 internal/datastore/postgres/migrations/zz_migration.0023_add_missing_gc_index.go 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()) + } +}