comparison roundup/backends/back_postgresql.py @ 4514:f6c49df25048

PostgreSQL backend minor improvement: database creation less likely to fail for PostgreSQL versions >= 8.1 as the table "postgres" is used by default. Closes issue2550543. Thanks to Kai Storbeck for the patch.
author Bernhard Reiter <Bernhard.Reiter@intevation.de>
date Fri, 01 Jul 2011 15:05:09 +0000
parents 4f353d71d716
children 6467fd9a3afd
comparison
equal deleted inserted replaced
4513:6a32a2fb95b4 4514:f6c49df25048
48 db_command(config, command) 48 db_command(config, command)
49 49
50 if os.path.exists(config.DATABASE): 50 if os.path.exists(config.DATABASE):
51 shutil.rmtree(config.DATABASE) 51 shutil.rmtree(config.DATABASE)
52 52
53 def db_command(config, command): 53 def db_command(config, command, database='postgres'):
54 '''Perform some sort of database-level command. Retry 10 times if we 54 '''Perform some sort of database-level command. Retry 10 times if we
55 fail by conflicting with another user. 55 fail by conflicting with another user.
56
57 Since PostgreSQL version 8.1 there is a database "postgres",
58 before "template1" seems to habe been used, so we fall back to it.
59 Compare to issue2550543.
56 ''' 60 '''
57 template1 = connection_dict(config) 61 template1 = connection_dict(config)
58 template1['database'] = 'template1' 62 template1['database'] = database
59 63
60 try: 64 try:
61 conn = psycopg.connect(**template1) 65 conn = psycopg.connect(**template1)
62 except psycopg.OperationalError, message: 66 except psycopg.OperationalError, message:
67 if str(message).find('database "postgres" does not exist') >= 0:
68 return db_command(config, command, database='template1')
63 raise hyperdb.DatabaseError(message) 69 raise hyperdb.DatabaseError(message)
64 70
65 conn.set_isolation_level(0) 71 conn.set_isolation_level(0)
66 cursor = conn.cursor() 72 cursor = conn.cursor()
67 try: 73 try:

Roundup Issue Tracker: http://roundup-tracker.org/