Index: django/conf/project_template/settings.py
===================================================================
--- django/conf/project_template/settings.py	(revision 1510)
+++ django/conf/project_template/settings.py	(working copy)
@@ -15,6 +15,7 @@
 DATABASE_PASSWORD = ''         # Not used with sqlite3.
 DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
 DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+DATABASE_CLIENT_CHARSET = ''   # Set to empty string to guess from DEFAULT_CHARSET. Not used with sqlite3.
 
 # Local time zone for this installation. All choices can be found here:
 # http://www.postgresql.org/docs/current/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
Index: django/conf/global_settings.py
===================================================================
--- django/conf/global_settings.py	(revision 1510)
+++ django/conf/global_settings.py	(working copy)
@@ -78,6 +78,7 @@
 DATABASE_PASSWORD = ''         # Not used with sqlite3.
 DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
 DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+DATABASE_CLIENT_CHARSET = ''   # Set to empty string to guess from DEFAULT_CHARSET. Not used with sqlite3.
 
 # Host for sending e-mail.
 EMAIL_HOST = 'localhost'
Index: django/core/db/backends/postgresql.py
===================================================================
--- django/core/db/backends/postgresql.py	(revision 1510)
+++ django/core/db/backends/postgresql.py	(working copy)
@@ -13,9 +13,18 @@
     def __init__(self):
         self.connection = None
         self.queries = []
+        self.charset_mappings = {
+            'utf-8':'UNICODE',
+            'windows-1251':'WINDOWS1251',
+            'windows-1250':'WINDOWS1250',
+            'shift-jis':'SJIS',
+            'koi8-r':'KOI8',
+            'koi8-u':'KOI8',
+        }
 
     def cursor(self):
-        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG, TIME_ZONE
+        from django.conf.settings import DEFAULT_CHARSET, DATABASE_USER, DATABASE_NAME, DATABASE_HOST, \
+                                         DATABASE_PORT, DATABASE_PASSWORD, DATABASE_CLIENT_CHARSET, DEBUG, TIME_ZONE
         if self.connection is None:
             if DATABASE_NAME == '':
                 from django.core.exceptions import ImproperlyConfigured
@@ -33,6 +42,20 @@
             self.connection.set_isolation_level(1) # make transactions transparent to all cursors
         cursor = self.connection.cursor()
         cursor.execute("SET TIME ZONE %s", [TIME_ZONE])
+        
+        try:
+            charset = self.charset_mappings[DEFAULT_CHARSET.lower()]
+        except KeyError:
+            if (not DATABASE_CLIENT_CHARSET):
+                from django.core.exceptions import ImproperlyConfigured
+                raise ImproperlyConfigured, 'You need to specify DATABASE_CHARSET in your Django settings \
+                    file because Django cannot determine it automatically. You should set it to the name \
+                    that PostgreSQL uses for the character set "'+DEFAULT_CHARSET+'"'
+            else:
+                charset = DATABASE_CLIENT_CHARSET
+
+        self.connection.cursor().execute("SET ENCODING "+charset)
+        
         if DEBUG:
             return base.CursorDebugWrapper(cursor, self)
         return cursor
Index: django/core/db/backends/mysql.py
===================================================================
--- django/core/db/backends/mysql.py	(revision 1510)
+++ django/core/db/backends/mysql.py	(working copy)
@@ -51,9 +51,23 @@
     def __init__(self):
         self.connection = None
         self.queries = []
+        self.charset_mappings = {
+            'utf-8':'utf8',
+            'windows-1251':'cp1251',
+            'windows-1250':'cp1250',
+            'shift-jis':'sjis',
+            'utf-16':'ucs2',
+            'koi8-r':'koi8r',
+            'koi8-u':'koi8u',
+        }
 
     def cursor(self):
-        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG
+        from django.conf.settings import DEFAULT_CHARSET, DATABASE_USER, DATABASE_NAME, DATABASE_HOST, \
+                                         DATABASE_PORT, DATABASE_PASSWORD, DATABASE_CLIENT_CHARSET, DEBUG
+        
+        # additionally import charset-related settings that might not be present
+        from django.conf.settings import DEFAULT_CHARSET
+        
         if self.connection is None:
             kwargs = {
                 'user': DATABASE_USER,
@@ -65,6 +79,22 @@
             if DATABASE_PORT:
                 kwargs['port'] = DATABASE_PORT
             self.connection = Database.connect(**kwargs)
+
+            try:
+                charset = self.charset_mappings[DEFAULT_CHARSET.lower()]
+            except KeyError:
+                if (not DATABASE_CLIENT_CHARSET):
+                    from django.core.exceptions import ImproperlyConfigured
+                    raise ImproperlyConfigured, 'You need to specify DATABASE_CHARSET in your Django settings \
+                        file because Django cannot determine it automatically. You should set it to the name \
+                        that MySQL uses for the character set "'+DEFAULT_CHARSET+'"'
+                else:
+                    charset = DATABASE_CLIENT_CHARSET
+            try:
+                self.connection.cursor().execute("SET NAMES "+charset)
+            except Database.OperationalError: # this is MySQL older than 4.1
+                pass
+                
         if DEBUG:
             return base.CursorDebugWrapper(MysqlDebugWrapper(self.connection.cursor()), self)
         return self.connection.cursor()
