You can do it without changing the source

db = DAL(...,driver_args={'unix_sock':'/tmp/.s.PGSQL.5432'})

How common is this scenario?

On Thursday, September 13, 2012 3:55:22 AM UTC-5, Liam wrote:
>
> Hi all,
>
> Due to a strange Postgresql setup by my systems admin, I can not specify 
> the host as "localhost" to connect to my production database. Instead, I 
> have to specify the unix socket. This is currently unsupported in web2py, 
> but I came up with a temporary workaround for the time being. In a connect 
> function in gluon/dal.py I inserted the following lines
>
> @@ -2458,6 +2458,8 @@ class PostgreSQLAdapter(BaseAdapter):
>          # choose diver according uri
>          self.__version__ = "%s %s" % (self.driver.__name__, self.driver.
> __version__)
>          def connect(msg=msg,driver_args=driver_args):
> +            if host.startswith('/'):
> +                driver_args['unix_sock'] = host
>              return self.driver.connect(msg,**driver_args)
>          self.pool_connection(connect)
>          self.after_connection()
>
> Connection strings that have a host name starting with a forward slash 
> will be interpreted as a unix socket instead.
> eg. postgres://user:password@/tmp/.s.PGSQL.5432/database
> where the unix socket is /tmp/.s.PGSQL.5432.
> I don't know how well this plays with different types of connection 
> strings (eg. port also specified).
>
> If anyone has a better solution, I'd like to hear about it.
>
> By the way, there's a typo (diver -> driver) in the comment :) 
>
> Cheers,
> Liam
>

-- 



Reply via email to