bytebase/bytebase · error

failed to inspect sample instance setup deletion

Error message

failed to inspect sample instance setup deletion

What it means

This error wraps a failure from result.RowsAffected() after the MarkDeleted UPDATE on sample_instance_setup. The UPDATE executed, but the driver could not report how many rows it changed. This is a driver/protocol-level failure, not a data problem.

Source

Thrown at backend/store/sample_instance.go:316

	if err := tx.Commit(); err != nil {
		return nil, errors.Wrap(err, "failed to commit sample instance cleanup")
	}
	return result, nil
}

// MarkDeleted marks an activated setup physically removed.
func (tx *SampleInstanceSetupTx) MarkDeleted(ctx context.Context, deletedAt time.Time) error {
	result, err := tx.tx.ExecContext(ctx, `
		UPDATE sample_instance_setup SET deleted_at = $1, updated_at = $1
		WHERE workspace = $2 AND replica_id = $3
			AND activated_at IS NOT NULL AND deleted_at IS NULL
	`, deletedAt, tx.workspace, tx.replica)
	if err != nil {
		return errors.Wrap(err, "failed to mark sample instance setup deleted")
	}
	rows, err := result.RowsAffected()
	if err != nil {
		return errors.Wrap(err, "failed to inspect sample instance setup deletion")
	}
	if rows != 1 {
		return errors.Errorf("sample instance setup %q cannot be marked deleted", tx.workspace)
	}
	return nil
}

// DeleteReservation removes the locked pending setup.
func (tx *SampleInstanceSetupTx) DeleteReservation(ctx context.Context) error {
	result, err := tx.tx.ExecContext(ctx, `
		DELETE FROM sample_instance_setup
		WHERE workspace = $1 AND replica_id = $2
			AND activated_at IS NULL AND deleted_at IS NULL
	`, tx.workspace, tx.replica)
	if err != nil {
		return errors.Wrap(err, "failed to delete sample instance setup reservation")
	}
	rows, err := result.RowsAffected()

View on GitHub (pinned to 1870550677)

Solutions

  1. Check DB connection stability; reconnect and retry the cleanup sweep.
  2. If behind PgBouncer or another pooler, ensure a mode that preserves command tags (session/transaction pooling) and server-side affected-row reporting.
  3. Update the Postgres driver to a current version.
  4. Inspect the wrapped error for the driver-level cause.
  5. Retry — the cleanup sweep is idempotent under FOR UPDATE SKIP LOCKED.
Defensive patterns

Strategy: try-catch

Try / catch

if err := tx.MarkDeleted(ctx, now); err != nil {
	if strings.Contains(err.Error(), "failed to inspect sample instance setup deletion") {
		log.Printf("driver could not report rows affected; retry sweep")
	}
	return err
}

Prevention

When it happens

Trigger: Calling MarkDeleted when result.RowsAffected() returns an error from the pq/pgxc driver — typically because the underlying connection was closed or the command tag could not be parsed after a connection-level failure.

Common situations: Connection dropped between the UPDATE and the RowsAffected call; using a driver that does not support RowsAffected for the statement; unusual proxy/pooler (e.g. pgbouncer in statement mode) mangling the command tag.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/f99dd88616d8d074. Report an issue: GitHub.