How to configure every (postgresql) db connection?

I would like to set some db session variables specific to my
application on the database connection that rails uses. They can be
set by issuing an SQL command like "SET statement_timeout = 1000"
once - it will be in effect for every subsequent SQL statement that
uses this connection.

So I tried to put the following into an initializer:

ActiveRecord::Base.connection.execute("SET statement_timeout = 1000")

but this does not have the desired effect - it is not set for all
connections. I assume this has to do with the connection pool rails
uses - the code above just sets it for a single one.

The PostgreSQLAdapter issues some SET statements itself for each new
connection - is there a good way to add your own configuration
statements, either specific to the PostgreSQLAdapter or in a general


In SqlServer, in the context of a Model, you can do this:

('CommandTimeout', 300)

Perhaps there is something similar for Postgres.

I used to do this in the context of a model which I assume has a
similar effect:

self.connection.execute("SET statement_timeout 300")

but I doubt that this is reliably configuring _all_ connections of the
AR connection pool, and I'd rather do it in an app-wide configuration
file and not in a model.