문제

I am trying to write a bash script that does some db2 work. I am facing the issue whereby subshells require db2 connections to be reconnected.

Unfortunately, reconnecting every time is dog slow, as around 1000 new connections will need to be made, each taking around a second. Thus I'm looking to avoid these subshell reconnections.

Googling around this situation, I have found that there is a way to set the default connection schema using the variable DB2DBDFT. Unfortunately, with this set it takes the linux logged in user name to be the DB schema name you are running as, whereas our system has a different DB user name to the user logged in to bash.

1) Is there a way to set the DB2DBDFT variable, but make it so that it can use a "user abc using 123" style syntax, or if there are other variables where you can set these (I have searched but not found them).

2) If there is, will this actually save me any time? Obviously if I find a solution I will benchmark, but I'm not sure that even if I find this, it will be quicker, and surely it will slow down all other subshell spawns.

3) I'm very open to other suggestions, I've tried piping to while statements rather than calling subshells but then remembered this has the same issues.

e.g.

    result=$(call_procedure "$get_sell_price_old_sql")

versus

    call_procedure "$get_sell_price_old_sql" | while read result_
    do
            result=$result_
    done

4) I'm sure there are other avenues I've not considered, any advice and suggestions greatly appreciated.

Many thanks, Mitch.

도움이 되었습니까?

해결책

To answer your 2nd question, no, this is unlikely to make the process faster. DB2DBDFT only specifies the name of the database to connect to if a connection does not exist, so the client will still be connecting each time you run any SQL statement. And no, you cannot specify the user for an implicit connection, it will always be the logged-in OS user.

Typically the database connection should be pretty fast, unless it is the very first connection to an inactive database, in which case what takes most time is the database activation. If you are the only user connecting to the database when the script runs, try issuing the db2 activate db <your db> command before connecting, that will keep it active between connections.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top