Skip to content

Commit

Permalink
Add missing index for GC in Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
josephschorr committed Dec 9, 2024
1 parent 49d31c6 commit 298a9e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/datastore/postgres/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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())
}
}

0 comments on commit 298a9e2

Please sign in to comment.