Ticket #17266: 17266.diff

File 17266.diff, 3.3 KB (added by Anssi Kääriäinen, 13 years ago)
  • django/db/backends/postgresql_psycopg2/base.py

    diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
    index c816237..4b5233f 100644
    a b class DatabaseWrapper(BaseDatabaseWrapper):  
    174174                conn_params['port'] = settings_dict['PORT']
    175175            self.connection = Database.connect(**conn_params)
    176176            self.connection.set_client_encoding('UTF8')
    177             # Set the time zone in autocommit mode (see #17062)
    178177            tz = 'UTC' if settings.USE_TZ else settings_dict.get('TIME_ZONE')
    179             if tz:
     178            # Psycopg2 verions prior to 2.0.12 do not have get_parameter_status
     179            # and there doesn't seem to be easy way to get psycog version - so
     180            # guard agains older than 2.0.12 with an AttributeError
     181            try:
     182                conn_tz = self.connection.get_parameter_status('TimeZone')
     183            except AttributeError:
     184                conn_tz = None
     185            # Set the time zone in autocommit mode (see #17062)
     186            if tz and tz <> conn_tz:
    180187                self.connection.set_isolation_level(
    181188                        psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
    182189                self.connection.cursor().execute("SET TIME ZONE %s", [tz])
  • docs/ref/databases.txt

    diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt
    index b914a68..f5f093d 100644
    a b aggregate with a database backend that falls within the affected release range.  
    3333.. _known to be faulty: http://archives.postgresql.org/pgsql-bugs/2007-07/msg00046.php
    3434.. _Release 8.2.5: http://developer.postgresql.org/pgdocs/postgres/release-8-2-5.html
    3535
     36Changing database's default settings
     37------------------------------------
     38
     39It is a good idea to set the defaults for certain variables so that Django
     40doesn't need to do that for every new connection. The variables in question
     41are client_encoding, which should be set to 'UTF8', timezone, which should be
     42set to settings TIME_ZONE if not using USE_TZ, else to 'UTC', and
     43default_transaction_isolation which should be set to 'read committed'. You can
     44set these variables directly in postgresql.conf, or more conveniently for the
     45database user directly using `ALTER ROLE`_ db_user SET variable TO value.
     46
     47Django will work just fine if you don't do these changes, but each new
     48connection will need to do additional queries to set the above mentioned
     49variables.
     50
     51.. _ALTER ROLE: http://www.postgresql.org/docs/current/interactive/sql-alterrole.html
     52
    3653Transaction handling
    3754---------------------
    3855
    Autocommit mode  
    4865
    4966If your application is particularly read-heavy and doesn't make many
    5067database writes, the overhead of a constantly open transaction can
    51 sometimes be noticeable. For those situations, if you're using the
    52 ``postgresql_psycopg2`` backend, you can configure Django to use
    53 *"autocommit"* behavior for the connection, meaning that each database
     68sometimes be noticeable. For those situations, you can configure Django
     69to use *"autocommit"* behavior for the connection, meaning that each database
    5470operation will normally be in its own transaction, rather than having
    5571the transaction extend over multiple operations. In this case, you can
    5672still manually start a transaction if you're doing something that
Back to Top