FRiCKLE / ngx_postgres

upstream module that allows nginx to communicate directly with PostgreSQL database.
http://labs.frickle.com/nginx_ngx_postgres/
BSD 2-Clause "Simplified" License
545 stars 122 forks source link

Set session variables #22

Closed c0de9en closed 10 years ago

c0de9en commented 10 years ago

I need different time zones for sites. So I need to set the TimeZone session variable for all queries. It would be great to add optional parameter for postgres_server. For example:

upstream db_site_common {
    postgres_server  127.0.0.1
        dbname=test user=test password=test
        init="
            SET TimeZone TO 'UTC';
            SET client_encoding TO 'UTF8';
        ";
}

upstream db_site_ru {
    postgres_server  127.0.0.1
        dbname=test user=test password=test
        init="
            SET TimeZone TO 'Europe/Moscow';
            SET client_encoding TO 'WIN1251';
        ";
}

It may be a postgres_pass optional parameter. For example:

postgres_pass db_site_ru init="
            SET TimeZone TO 'Europe/Moscow';
            SET client_encoding TO 'WIN1251';
";
buddy-ekb commented 10 years ago

It could be easily done inside your database: create another role, assign a membership of role "test" to it and set any necessary configuration parameters on it.

c0de9en commented 10 years ago

But I can't execute queries there. Such as SELECT true FROM usr WHERE username = $arg_username AND password = $arg_password

buddy-ekb commented 10 years ago

To do so you have to use an application server or a connection pooler (e.g. pgbouncer). ngx_postgres doesn't support web-session management in any way.

c0de9en commented 10 years ago

Thank you, I'll try to find other ways...