Skip to content

Commit f889a46

Browse files
committed
Fix comment detection
On psql 8.1, `pg_catalog.shobj_description` does not exist. Also, if the database to comment is not the current db then this warning will be raised and the comment will not be applied: `WARNING: database comments may only be applied to the current database` This fix uses the pg_* databases to find the comment based on the database oid rather than the shared object description function.
1 parent 6d2b66c commit f889a46

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

manifests/server/database.pp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@
7878
}
7979

8080
if $comment {
81+
# The shobj_description function was only introduced with 8.2
82+
$comment_information_function = $version ? {
83+
'8.1' => 'obj_description',
84+
default => 'shobj_description',
85+
}
8186
Exec[ $createdb_command ]->
8287
postgresql_psql {"COMMENT ON DATABASE ${dbname} IS '${comment}'":
83-
unless => "SELECT description FROM pg_description JOIN pg_database ON objoid = pg_database.oid WHERE datname = '${dbname}' AND description = '${comment}'",
84-
db => $dbname,
88+
unless => "SELECT pg_catalog.${comment_information_function}(d.oid, 'pg_database') as \"Description\" FROM pg_catalog.pg_database d WHERE datname = '${dbname}' AND pg_catalog.${comment_information_function}(d.oid, 'pg_database') = '${comment}'",
89+
db => $dbname,
8590
}
8691
}
8792

spec/acceptance/db_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ class { 'postgresql::server': }
2929
expect(r.stdout).to match(/\(1 row\)/)
3030
end
3131

32-
psql('--command="SELECT pg_catalog.shobj_description(d.oid, \'pg_database\') FROM pg_catalog.pg_database d WHERE datname = \'postgresql_test_db\' AND pg_catalog.shobj_description(d.oid, \'pg_database\') = \'testcomment\'"') do |r|
32+
result = shell('psql --version')
33+
version = result.stdout.match(%r{\s(8\.\d)})[1]
34+
if version > "8.1"
35+
comment_information_function = "shobj_description"
36+
else
37+
comment_information_function = "obj_description"
38+
end
39+
psql("--dbname postgresql_test_db --command=\"SELECT pg_catalog.#{comment_information_function}(d.oid, 'pg_database') FROM pg_catalog.pg_database d WHERE datname = 'postgresql_test_db' AND pg_catalog.#{comment_information_function}(d.oid, 'pg_database') = 'testcomment'\"") do |r|
3340
expect(r.stdout).to match(/\(1 row\)/)
3441
end
3542
ensure

0 commit comments

Comments
 (0)