Skip to content

Commit 53c2173

Browse files
Bernhard ReiterBernhard Reiter
authored andcommitted
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.
1 parent 02f8f76 commit 53c2173

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Features:
99

1010
- Xapian indexing improved: Slightly faster and slightly smaller database.
1111
Closes issue2550687. Thanks to Olly Betts for the patch. (Bernhard Reiter)
12+
- PostgreSQL backend minor improvement: database creation less likely to fail
13+
for PostgreSQL versions >= 8.1 as the table "postgres" is used by default.
14+
Closes issue2550543. Thanks to Kai Storbeck for the patch. (Bernhard Reiter)
1215

1316
Fixed:
1417

roundup/backends/back_postgresql.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,22 @@ def db_nuke(config, fail_ok=0):
5050
if os.path.exists(config.DATABASE):
5151
shutil.rmtree(config.DATABASE)
5252

53-
def db_command(config, command):
53+
def db_command(config, command, database='postgres'):
5454
'''Perform some sort of database-level command. Retry 10 times if we
5555
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.
5660
'''
5761
template1 = connection_dict(config)
58-
template1['database'] = 'template1'
62+
template1['database'] = database
5963

6064
try:
6165
conn = psycopg.connect(**template1)
6266
except psycopg.OperationalError, message:
67+
if str(message).find('database "postgres" does not exist') >= 0:
68+
return db_command(config, command, database='template1')
6369
raise hyperdb.DatabaseError(message)
6470

6571
conn.set_isolation_level(0)

0 commit comments

Comments
 (0)