Skip to content

Add optional VERSION clause to CREATE EXTENSION#1654

Open
aba-malu wants to merge 4 commits into
puppetlabs:mainfrom
abacusresearch:feature/create-extension-version
Open

Add optional VERSION clause to CREATE EXTENSION#1654
aba-malu wants to merge 4 commits into
puppetlabs:mainfrom
abacusresearch:feature/create-extension-version

Conversation

@aba-malu
Copy link
Copy Markdown

@aba-malu aba-malu commented Dec 17, 2025

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 with CREATE EXTENSION "timescaledb" ;. In the next step ALTER EXTENSION "timescaledb" UPDATE TO "2.23.1" ; is executed and fails with following error:

Error: Error executing SQL; psql returned pid 115701 exit 1: 'ERROR:  extension "timescaledb" has no installation script nor update path for version "2.24.0"
'
Error: /Stage[main]/Profile::Postgresql/Postgresql::Server::Extension[timescaledb]/Postgresql_psql[zabbix: CREATE EXTENSION "timescaledb"]/command: change from 'notrun' to 'CREATE EXTENSION "timescaledb"' failed: Error executing SQL; psql returned pid 115701 exit 1: 'ERROR:  extension "timescaledb" has no installation script nor update path for version "2.24.0"
' (corrective)
Error: Error executing SQL; psql returned pid 115705 exit 1: 'ERROR:  extension "timescaledb" does not exist
'
Error: /Stage[main]/Profile::Postgresql/Postgresql::Server::Extension[timescaledb]/Postgresql_psql[zabbix: ALTER EXTENSION "timescaledb" UPDATE TO '2.23.1']/command: change from 'notrun' to 'ALTER EXTENSION "timescaledb" UPDATE TO \'2.23.1\'' failed: Error executing SQL; psql returned pid 115705 exit 1: 'ERROR:  extension "timescaledb" does not exist
' (corrective)

If no version is specified, the default from the file /usr/share/postgresql/18/extension/timescaledb.control is 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

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 17, 2025

CLA assistant check
All committers have signed the CLA.

@aba-malu aba-malu force-pushed the feature/create-extension-version branch from b78b558 to 7769f8a Compare May 19, 2026 06:15
@aba-malu aba-malu force-pushed the feature/create-extension-version branch from 4f90186 to 5d39ac5 Compare May 19, 2026 07:33
Copy link
Copy Markdown
Collaborator

@smortex smortex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some unit test that ensure this feature does not break in the future would be cool. Other that that, that feels good to me.

Comment thread manifests/server/extension.pp Outdated
case $ensure {
'present': {
$command = "CREATE EXTENSION \"${extension}\""
$command = "CREATE EXTENSION \"${extension}\"${if $version and $version != 'latest' { " VERSION \"${version}\"" } else { '' }}"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 })

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"'
...

@aba-malu aba-malu requested a review from smortex May 22, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants