Skip to content

Commit f6b0a9d

Browse files
committed
fix: outbox partition detach with default partition present
2 parents 1eae798 + 5511adf commit f6b0a9d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

internal/adapter/postgres/outbox_repo.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,13 @@ func (r *OutboxRepository) DetachAndDropPartition(ctx context.Context, partition
351351
if !outboxPartitionPattern.MatchString(partitionName) {
352352
return fmt.Errorf("invalid partition name: %s", partitionName)
353353
}
354-
// CONCURRENTLY avoids blocking concurrent DML on the parent table.
355-
detachSQL := fmt.Sprintf("ALTER TABLE public.outbox DETACH PARTITION %s CONCURRENTLY", partitionName)
354+
// Non-concurrent DETACH: public.outbox always has a DEFAULT partition
355+
// (outbox_default), and Postgres forbids DETACH PARTITION ... CONCURRENTLY
356+
// while a default partition exists ("cannot detach partitions concurrently
357+
// when a default partition exists", SQLSTATE 55000). A plain DETACH is a
358+
// fast catalog-only operation; it briefly takes ACCESS EXCLUSIVE on the
359+
// parent, which is acceptable for this infrequent, advisory-locked cleanup.
360+
detachSQL := fmt.Sprintf("ALTER TABLE public.outbox DETACH PARTITION %s", partitionName)
356361
if _, err := r.pool.Exec(ctx, detachSQL); err != nil {
357362
return fmt.Errorf("detach partition %s: %w", partitionName, err)
358363
}

0 commit comments

Comments
 (0)