settings and switching to external pgsql db I am working with Drupal 7.3.4 and attempting to follow the instructions of changing settings.php so that I can switch to a pgsql DB within a module and then switch back to the default mysql after doing a query.

I have set up in the settings.php file with the following format:

$databases = array (
  'default' =&gt; 
  array (
    'default' =&gt; 
    array (
      'database' =&gt; '',
      'username' =&gt; '',
      'password' =&gt; '',
      'host' =&gt; 'localhost',
      'port' =&gt; '',
      'driver' =&gt; 'mysql',
      'prefix' =&gt; '',
    ),
  ),
  'custom_db' =&gt;
  array (
    'default' =&gt;
    array (
      'database' =&gt; 'custom_db',
      'username' =&gt; 'dbuser',
      'password' =&gt; 'pass',
      'host' =&gt; 'urltoservice',
      'port' =&gt; '5432',
      'driver' =&gt; 'pgsql',
      'prefix' =&gt; '',
    ),
  ),
);


Now I am trying the process of switching to this DB in a module and verifying that the driver is changing.

db_set_active('custom_db');
//Get the currently active DB driver
drupal_set_message(db_driver());
db_set_active();


But, when I print the driver it is not switching to pgsql as expected.  I am pretty sure it is still pointing to the default mysql db.  Any ideas of what I may be doing wrong here would be greatly appreciated.

Thanks, 
Derek
first check whether you are executing your query before  doing db_set_active(); because this function call will set your db to default drupal db.

so you should go like this:

db_set_active('custom_db');


// execute your query related stuff here

then at last switch to your default db by db_set_active();