Forum OpenACS Q&A: Connecting to 2 or more DB Pool using -dbn of db_* API

Hello!

Can Anyone here guide me on the right way of connecting to a different database pool other than the default pool. I'm really sorry if there's already a thread that answers my question, I guess I didn't searched hard enough. How does the -dbn switch of a db_* API work? What's the magic behind it? I could deduce that it is not the database pool defined in the "ns/db/pools" section of the AOLServer config file. I always keep getting this error message everytime I run the little script below:

"no such key: pool4"

What am I doing wrong?
Here's the sample code I was working with:

================================================

set tbl [db_tables -pattern "dc_" -dbn "pool4"]                                                                                                          set html [join $tbl "<br>"]

ns_return 200 text/html $html

================================================

And here's the snippet from the AOLserver config file:

ns_section ns/db/pools
ns_param  pool1              "Pool 1"
ns_param  pool2              "Pool 2"
ns_param  pool3              "Pool 3"
ns_param  pool4              "Pool 4"

ns_section ns/db/pool/pool1
ns_param  maxidle            1000000000
ns_param  maxopen            1000000000
ns_param  connections        5
ns_param  verbose            $debug
ns_param  extendedtableinfo  true
ns_param  logsqlerrors      $debug
if { $database == "oracle" } {
    ns_param  driver            ora8
    ns_param  datasource        {}
    ns_param  user              $db_name
    ns_param  password          $db_password
} else {
    ns_param  driver            postgres
    ns_param  datasource        ${db_host}:${db_port}:${db_name}
    ns_param  user              $db_user
    ns_param  password          ""
}

ns_section ns/db/pool/pool2
ns_param  maxidle            1000000000
ns_param  maxopen            1000000000
ns_param  connections        5
ns_param  verbose            $debug
ns_param  extendedtableinfo  true
ns_param  logsqlerrors      $debug
if { $database == "oracle" } {
    ns_param  driver            ora8
    ns_param  datasource        {}
    ns_param  user              $db_name
    ns_param  password          $db_password
} else {
    ns_param  driver            postgres
    ns_param  datasource        ${db_host}:${db_port}:${db_name}
    ns_param  user              nsadmin
    ns_param  password          ""
}

ns_section ns/db/pool/pool3
ns_param  maxidle            1000000000
ns_param  maxopen            1000000000
ns_param  connections        5
ns_param  verbose            $debug
ns_param  extendedtableinfo  true
ns_param  logsqlerrors      $debug
if { $database == "oracle" } {
    ns_param  driver            ora8
    ns_param  datasource        {}
    ns_param  user              $db_name
    ns_param  password          $db_password
} else {
    ns_param  driver            postgres
    ns_param  datasource        ${db_host}:${db_port}:${db_name}
    ns_param  user              $db_user
    ns_param  password          ""
}

ns_section ns/db/pool/pool4
ns_param  maxidle            1000000000
ns_param  maxopen            1000000000
ns_param  connections        5
ns_param  verbose            $debug
ns_param  extendedtableinfo  true
ns_param  logsqlerrors      $debug
if { $database == "oracle" } {
    ns_param  driver            ora8
    ns_param  datasource        {}
    ns_param  user              $db_name
    ns_param  password          $db_password
} else {
    ns_param  driver            postgres
    ns_param  datasource        127.0.0.1::thor
    ns_param  user              nsadmin
    ns_param  password          ""
}

ns_section ns/server/${server}/db
ns_param  pools              "*"
ns_param  defaultpool        pool1

Sorry for the long post. And TIA

Jason,

Hi!

I’m sorry for about this post but I’ve already solved the problem.

There was a typo error on the 00-database-procs.tcl comments.

<snippet from 00-database-procs.tcl>

# To define what databases exist, and what pools belong to what

# databases, you need to put something like this in your nsd.tcl

# AOLserver config file:

#

#  ns_section ns/server/$server_name/acs/database

#

#    ns_param databases  [list ora pg foo]

#    ns_param pools_ora  [list main subquery log]

#    ns_param pools_pg  [list pg-main pg-subquery pg-log]

#    ns_param pools_foo  [list foo1 foo2]

#

#    ## Optional, see comments:

#    #ns_param driverkey_ora  {oracle}

#    #ns_param driverkey_pg  {postgresql}

#    #ns_param driverkey_foo  {bar}

The line that says: ns_param databases  [list ora pg foo]

Should have been written as: ns_param database_names  [list ora pg foo]

Have a nice day!

Collapse
Posted by Jade Rubick on
I've committed this on HEAD.