sijms / go-ora

Pure go oracle client
MIT License
787 stars 174 forks source link

no available servers to connect to in oracle 19c rac #583

Closed lvxiaorun closed 1 day ago

lvxiaorun commented 1 month ago

when use latest go-ora with oracle 19.7 rac,

It has two instance, we called them rac_ins1,rac_ins2

when we use service_name to create connection and run query,

`

  dsn := go_ora.BuildUrl("rac_ins1_addr", 1532, "service_name", "username", "password", nil)
  db, err := sql.Open("oracle", dsn)
   if err != nil {
    panic(err)
    }

    rows, err := db.QueryContext(ctx, "select count(*) from v$sql")

     if err != nil {
    panic(err)
    }

`

It get a error "no available servers to connect to"

I check the go-ora source code,find the error appear in .

I run the code once more with trace log, in the log,I find that, when connect to rac_ins1, it get a redirect reply, the target is rac_ins2, then try to connect to rac_ins2,it get a redirect reply, the target is rac_ins1, finally,it return error.It seems that the two instance mutual redirect. The redirect packet as it (It's the same before every redirect)

Read packet: 00000000 00 0a 00 00 05 02 00 00 01 0e

By the way,if I edit the "AddServer" func as this,(make it redirect more times) `

 func (op *ConnectionOption) AddServer(server ServerAddr) {

    for i := 0; i < len(op.Servers); i++ {

    if server.IsEqual(&op.Servers[i]) && len(op.Servers) >= 8 {
        return
    }
}
       op.Servers = append(op.Servers, server)
}

`

It will redirect between rac_ins1 and rac_ins2 util more than 7 times redirect.Finally get the above error “no available servers to connect to”

I looked it up,This may be related to the following two parameters,“load_balance” and "faliover", but setting them is not currently supported in go-ora.

Looking forward to your reply to the above questions.Thanks.

lvxiaorun commented 1 month ago

I tried to write a connection demo with ojdbc8, and captured the packet, I found that each time only one redirection will successfully establish the connection and execute the statement successfully. I find that there are some parameters in the redirection returned packet, among which I think the parameter INSTANCE_NAME is more critical. The jdk takes these parameters with it when initiating a second connection, but go-ora only changes the connection address without taking these parameters with it.

lvxiaorun commented 4 weeks ago

I tried to solve this problem in this pull request #586