Skip to content

Commit

Permalink
Set transaction_isolation as conneciton option
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev committed Oct 2, 2024
1 parent 279b6b9 commit 09f2320
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
3 changes: 3 additions & 0 deletions pkg/clients/db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func NewDBClient(host, user, password string, port int, database, application_na
}

func buildConnectionString(host, user, password string, port int, database, sslmode, application_name string) string {
options := "--transaction_isolation=strict\\ serializable"

url := &url.URL{
Scheme: "postgres",
User: url.UserPassword(user, password),
Expand All @@ -41,6 +43,7 @@ func buildConnectionString(host, user, password string, port int, database, sslm
RawQuery: url.Values{
"application_name": {application_name},
"sslmode": {sslmode},
"options": {options},
}.Encode(),
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/utils/provider_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"fmt"
"log"
"strings"

"github.com/MaterializeInc/terraform-provider-materialize/pkg/clients"
Expand Down Expand Up @@ -95,12 +94,6 @@ func GetDBClientFromMeta(meta interface{}, d *schema.ResourceData) (*sqlx.DB, cl
return nil, region, fmt.Errorf("no database client for region: %s", region)
}

// Explicitly set the transaction isolation level to 'strict serializable'
_, err = dbClient.Exec("SET TRANSACTION_ISOLATION TO 'STRICT SERIALIZABLE'")
if err != nil {
log.Printf("[ERROR] Failed to set transaction isolation level for region %s: %v\n", region, err)
}

return dbClient.SQLX(), region, nil
}

Expand Down

0 comments on commit 09f2320

Please sign in to comment.