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):
|
174 | 174 | conn_params['port'] = settings_dict['PORT'] |
175 | 175 | self.connection = Database.connect(**conn_params) |
176 | 176 | self.connection.set_client_encoding('UTF8') |
177 | | # Set the time zone in autocommit mode (see #17062) |
178 | 177 | 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: |
180 | 187 | self.connection.set_isolation_level( |
181 | 188 | psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) |
182 | 189 | self.connection.cursor().execute("SET TIME ZONE %s", [tz]) |
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.
|
33 | 33 | .. _known to be faulty: http://archives.postgresql.org/pgsql-bugs/2007-07/msg00046.php |
34 | 34 | .. _Release 8.2.5: http://developer.postgresql.org/pgdocs/postgres/release-8-2-5.html |
35 | 35 | |
| 36 | Changing database's default settings |
| 37 | ------------------------------------ |
| 38 | |
| 39 | It is a good idea to set the defaults for certain variables so that Django |
| 40 | doesn't need to do that for every new connection. The variables in question |
| 41 | are client_encoding, which should be set to 'UTF8', timezone, which should be |
| 42 | set to settings TIME_ZONE if not using USE_TZ, else to 'UTC', and |
| 43 | default_transaction_isolation which should be set to 'read committed'. You can |
| 44 | set these variables directly in postgresql.conf, or more conveniently for the |
| 45 | database user directly using `ALTER ROLE`_ db_user SET variable TO value. |
| 46 | |
| 47 | Django will work just fine if you don't do these changes, but each new |
| 48 | connection will need to do additional queries to set the above mentioned |
| 49 | variables. |
| 50 | |
| 51 | .. _ALTER ROLE: http://www.postgresql.org/docs/current/interactive/sql-alterrole.html |
| 52 | |
36 | 53 | Transaction handling |
37 | 54 | --------------------- |
38 | 55 | |
… |
… |
Autocommit mode
|
48 | 65 | |
49 | 66 | If your application is particularly read-heavy and doesn't make many |
50 | 67 | database 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 |
| 68 | sometimes be noticeable. For those situations, you can configure Django |
| 69 | to use *"autocommit"* behavior for the connection, meaning that each database |
54 | 70 | operation will normally be in its own transaction, rather than having |
55 | 71 | the transaction extend over multiple operations. In this case, you can |
56 | 72 | still manually start a transaction if you're doing something that |