Add optional VERSION clause to CREATE EXTENSION#1654
Open
aba-malu wants to merge 4 commits into
Open
Conversation
b78b558 to
7769f8a
Compare
4f90186 to
5d39ac5
Compare
smortex
reviewed
May 20, 2026
Collaborator
smortex
left a comment
There was a problem hiding this comment.
Some unit test that ensure this feature does not break in the future would be cool. Other that that, that feels good to me.
smortex
reviewed
May 20, 2026
| case $ensure { | ||
| 'present': { | ||
| $command = "CREATE EXTENSION \"${extension}\"" | ||
| $command = "CREATE EXTENSION \"${extension}\"${if $version and $version != 'latest' { " VERSION \"${version}\"" } else { '' }}" |
Collaborator
There was a problem hiding this comment.
Looks like the code in the ${} confuse the linter. While this is syntactically correct, that is quite uncommon and I would rather avoid this.
Switching to inline epp would be a valid alternative, something like (untested):
Suggested change
| $command = "CREATE EXTENSION \"${extension}\"${if $version and $version != 'latest' { " VERSION \"${version}\"" } else { '' }}" | |
| $command = inline_epp('CREATE EXTENSION "<%= $extension %>"<% if $version and $version != 'latest' { %> VERSION "<%= $version %>"<% } %>', { extension => $extension, version => $version }) |
Author
There was a problem hiding this comment.
It works as expected, I just had to replace the quotation marks for 'latest' , but it works.
$command = inline_epp('CREATE EXTENSION "<%= $extension %>"<% if $version and $version != "latest" { %> VERSION "<%= $version %>"<% } %>', { extension => $extension, version => $version })
My output:
...
Notice: /Stage[main]/Profile::Postgresql/Postgresql::Server::Grant[monitoring_execute_pg_ls_waldir]/Postgresql_psql[grant:monitoring_execute_pg_ls_waldir]/command: command changed 'notrun' to 'GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO "monitoring"'
Notice: /Stage[main]/Zabbix::Database/Postgresql::Server::Db[zabbix]/Postgresql::Server::Role[zabbix]/Postgresql_psql[CREATE ROLE zabbix ENCRYPTED PASSWORD ****]/command: changed [redacted] to [redacted]
Notice: /Stage[main]/Zabbix::Database/Postgresql::Server::Db[zabbix]/Postgresql::Server::Database[zabbix]/Postgresql_psql[CREATE DATABASE "zabbix"]/command: command changed 'notrun' to 'CREATE DATABASE "zabbix" WITH TEMPLATE = "template0" ENCODING = \'UTF-8\' LC_COLLATE = \'en_US.UTF-8\' LC_CTYPE = \'en_US.UTF-8\' '
Info: /Stage[main]/Zabbix::Database/Postgresql::Server::Db[zabbix]/Postgresql::Server::Database[zabbix]/Postgresql_psql[CREATE DATABASE "zabbix"]: Scheduling refresh of Postgresql_psql[REVOKE CONNECT ON DATABASE "zabbix" FROM public]
Notice: /Stage[main]/Zabbix::Database/Postgresql::Server::Db[zabbix]/Postgresql::Server::Database[zabbix]/Postgresql_psql[REVOKE CONNECT ON DATABASE "zabbix" FROM public]: Triggered 'refresh' from 1 event
Notice: /Stage[main]/Zabbix::Database/Postgresql::Server::Db[zabbix]/Postgresql::Server::Database[zabbix]/Postgresql_psql[ALTER DATABASE "zabbix" OWNER TO "zabbix"]/command: command changed 'notrun' to 'ALTER DATABASE "zabbix" OWNER TO "zabbix"'
Notice: /Stage[main]/Profile::Postgresql/Postgresql::Server::Extension[timescaledb]/Postgresql_psql[zabbix: CREATE EXTENSION "timescaledb" VERSION "2.23.1"]/command: command changed 'notrun' to 'CREATE EXTENSION "timescaledb" VERSION "2.23.1"'
Notice: /Stage[main]/Profile::Postgresql/Postgresql::Server::Extension[pg_repack]/Postgresql_psql[zabbix: CREATE EXTENSION "pg_repack" VERSION "1.5.3"]/command: command changed 'notrun' to 'CREATE EXTENSION "pg_repack" VERSION "1.5.3"'
...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request adds support for specifying an explicit extension version when using CREATE EXTENSION. Allowing users to control which extension version is installed instead of relying on the default.
Additional Context
I recently encountered this issue with TimescaleDB 2.23.1 and PostgreSQL 18 on Debian 12 using the official TimescaleDB APT repository. The package timescaledb-2-loader-postgresql-18 (dependency of timescaledb-2-2.23.1-postgresql-18) sets the default to 2.24.0 in
/usr/share/postgresql/18/extension/timescaledb.control. When creating a new database, Puppet wants to create the extension withCREATE EXTENSION "timescaledb" ;. In the next stepALTER EXTENSION "timescaledb" UPDATE TO "2.23.1" ;is executed and fails with following error:If no version is specified, the default from the file
/usr/share/postgresql/18/extension/timescaledb.controlis used. Since the “version” is already implemented, I would like to use it in CREATE as well.Related Issues (if any)
Mention any related issues or pull requests.
Checklist
puppet apply)