Is db_set_active a global or local setting? I need to run a new query on another database.

I configured the settings.php

 $databases = array (
      'default' =&gt; 
      array (
        'default' =&gt; 
        array (
          'database' =&gt; 'db_name',
          'username' =&gt; 'db_usr',
          'password' =&gt; '',
          'host' =&gt; 'localhost',
          'port' =&gt; '',
          'driver' =&gt; 'mysql',
          'prefix' =&gt; '',
        ),
      ),
      'slave' =&gt; 
      array (
        'default' =&gt; 
        array (
          'database' =&gt; 'db_name',
          'username' =&gt; 'db_usr',
          'password' =&gt; '',
          'host' =&gt; 'localhost',
          'port' =&gt; '',
          'driver' =&gt; 'mysql',
          'prefix' =&gt; '',
        ),
      ),
    );


and this is my custom function:

    function myModule_test()
{

    db_set_active('slave');

    sleep(90);

    $view = views_get_view('test_view');
    $view-&gt;set_display('page');
    $view-&gt;pre_execute();
    $view-&gt;execute();

    print $view-&gt;render();
    db_set_active();

    }


the query is performed on the second database, what I do not understand is if the database change is local or global, because during the sleep (90) I tried to insert a new 'article' content and it has been inserted into the 'default' database.
It's a per-request global setting. db_set_active calls:

Database::setActiveConnection($key);


Which sets the static $activeKey property of the Database class. 

Database::getConnection(), which is where the connection for all queries comes from, then uses that same static $activeKey.

So once you've used db_set_active, all queries in that request will use the new connection until changed again. 

It doesn't persist across multiple requests.