Skip to content

Commit

Permalink
Do not check for enabled triggers / FKs for fallback workflow of PG i…
Browse files Browse the repository at this point in the history
…f session_replication_role session variable is used
  • Loading branch information
priyanshi-yb committed Feb 14, 2025
1 parent 1aa4a47 commit 184ef57
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions yb-voyager/src/tgtdb/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
"golang.org/x/exp/slices"

"github.com/yugabyte/yb-voyager/yb-voyager/src/callhome"
"github.com/yugabyte/yb-voyager/yb-voyager/src/constants"
Expand Down Expand Up @@ -115,6 +116,7 @@ func (pg *TargetPostgreSQL) Init() error {
if err != nil {
return err
}
pg.tconf.SessionVars = getYBSessionInitScript(pg.tconf)
schemas := strings.Split(pg.tconf.Schema, ",")
schemaList := strings.Join(schemas, "','") // a','b','c
checkSchemaExistsQuery := fmt.Sprintf(
Expand Down Expand Up @@ -241,12 +243,11 @@ func (pg *TargetPostgreSQL) InitConnPool() error {
pg.tconf.Parallelism = fetchDefaultParallelJobs(tconfs, PG_DEFAULT_PARALLELISM_FACTOR)
log.Infof("Using %d parallel jobs by default. Use --parallel-jobs to specify a custom value", pg.tconf.Parallelism)
}

params := &ConnectionParams{
NumConnections: pg.tconf.Parallelism,
NumMaxConnections: pg.tconf.Parallelism,
ConnUriList: targetUriList,
SessionInitScript: getYBSessionInitScript(pg.tconf),
SessionInitScript: pg.tconf.SessionVars,
// works fine as we check the support of any session variable before using it in the script.
// So upsert and disable transaction will never be used for PG
}
Expand Down Expand Up @@ -1054,6 +1055,10 @@ func (pg *TargetPostgreSQL) getSchemaList() []string {
}

func (pg *TargetPostgreSQL) GetEnabledTriggersAndFks() (enabledTriggers []string, enabledFks []string, err error) {
if slices.Contains(pg.tconf.SessionVars, SET_SESSION_REPLICATE_ROLE_TO_REPLICA) {
//Not check for any triggers / FKs in case this session parameter is used
return nil, nil, nil
}
querySchemaArray := pg.getSchemaList()
querySchemaList := strings.Join(querySchemaArray, ",")

Expand Down
1 change: 1 addition & 0 deletions yb-voyager/src/tgtdb/tconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type TargetConf struct {
Parallelism int `json:"parallelism"`
EnableYBAdaptiveParallelism utils.BoolStr `json:"enable_adaptive_parallelism"`
MaxParallelism int `json:"max_parallelism"` // in case adaptive parallelism is enabled.
SessionVars []string `json:"session_vars"`
}

func (t *TargetConf) Clone() *TargetConf {
Expand Down
5 changes: 3 additions & 2 deletions yb-voyager/src/tgtdb/yugabytedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (yb *TargetYugabyteDB) Init() error {
if err != nil {
return err
}
yb.tconf.SessionVars = getYBSessionInitScript(yb.tconf)

checkSchemaExistsQuery := fmt.Sprintf(
"SELECT count(nspname) FROM pg_catalog.pg_namespace WHERE nspname = '%s';",
Expand Down Expand Up @@ -241,7 +242,7 @@ func (yb *TargetYugabyteDB) InitConnPool() error {
NumConnections: yb.tconf.Parallelism,
NumMaxConnections: yb.tconf.MaxParallelism,
ConnUriList: targetUriList,
SessionInitScript: getYBSessionInitScript(yb.tconf),
SessionInitScript: yb.tconf.SessionVars,
}
yb.connPool = NewConnectionPool(params)
redactedParams := &ConnectionParams{}
Expand Down Expand Up @@ -1067,7 +1068,7 @@ func checkSessionVariableSupport(tconf *TargetConf, sqlStmt string) bool {
if !utils.AskPrompt("Are you sure you want to proceed?") {
utils.ErrExit("Aborting import.")
}
return true
return false // support is not there even if the target user doesn't have privileges to set this parameter.
}
utils.ErrExit("error while executing sqlStatement: %q: %v", sqlStmt, err)
} else {
Expand Down

0 comments on commit 184ef57

Please sign in to comment.