Skip to content

add parameter "version" to postgresql::server::extension to update the extension version #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2017

Conversation

georgehansper
Copy link
Contributor

@georgehansper georgehansper commented Jul 7, 2017

MODULES-5635
This change adds the parameter "version" to the defined type postgresql::server::extension

If unspecified, the module behaviour is unchanged.

If specified, the module will invoke the PostgreSQL-specific ALTER EXTENSION...

version may be set to latest, in which case the SQL ALTER EXTENSION "extension" UPDATE is applied to this database (only).

version may be set to a specific version, in which case the extension is updated using ALTER EXTENSION "extension" UPDATE TO 'version'

When an extension package is updated, this does not automatically change the effective version in each database. The ALTER EXTENSION... takes care of this on a per-database basis.

@sammcj
Copy link

sammcj commented Jul 10, 2017

Thanks, this would be very useful to have George, let us know if there's anything we can do to help get this merged @puppetlabs

@sammcj
Copy link

sammcj commented Sep 18, 2017

Hi @puppetlabs, just wondering if this could please be merged in as we're trying not to run off long-existing forks of official modules.

Thanks,

@georgehansper
Copy link
Contributor Author

Issue is MODULES-5635

@tphoney
Copy link
Contributor

tphoney commented Sep 28, 2017

Fantastic PR many thanks @georgehansper !!!

@tphoney tphoney merged commit fe5f278 into puppetlabs:master Sep 28, 2017
@georgehansper
Copy link
Contributor Author

Thank you very much for merging this PR.

@georgehansper georgehansper deleted the extension_upgrade branch September 28, 2017 11:50
@antgel
Copy link

antgel commented Oct 12, 2017

@georgehansper Hi, I think that this PR is causing the behaviour seen at example42/psick#193, specifically:

Debug: Executing with uid=postgres gid=postgres: '/usr/bin/psql -d puppetdb -t -c "SELECT COUNT(*) FROM (SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'pg_trgm') as t WHERE t.count = 1) count"'
Error: /Stage[main]/Puppetdb::Database::Postgresql/Postgresql::Server::Extension[pg_trgm]/Postgresql_psql[Add pg_trgm extension to puppetdb]: Could not evaluate: Error evaluating 'unless' clause, returned pid 9730 exit 1: ''

It seems that it's quite possible for the psql command to run before the postgresql server is installed, let alone running. Downgrading from 5.2.0 to 5.1.0, which didn't contain this PR, fixed the problem. Any thoughts?

@georgehansper
Copy link
Contributor Author

It is possible for the psql command to run before postgres is started, but I don't think that the code in PR #896 is the cause of this problem.
For this to happen, it would be necessary to specify:
database => undef
in the type declaration of postgresql::server::extension

This is definitely not the case here, because the psql command which is failing explicitly includes the DB puppetdb.

/usr/bin/psql -d puppetdb -t -c "SELECT COUNT(*) FROM (SELECT t.count FROM (SELECT count(extname) FROM pg_extension WHERE extname = 'pg_trgm') as t WHERE t.count = 1) count"

The question I would ask is: Does the puppet run succeed because the version was rolled back, or just because it was run a second time (regardless of the version)?

I have tried to reproduce the issue using:

include stdlib

class { 'postgresql::globals':
  encoding => 'UTF-8',
  locale   => 'en_AU.UTF-8',
  version  => '9.6',
  datadir  => '/var/lib/pgsql/9.6/data',
  user     => 'postgres',
  group    => 'postgres',
} ->
class { 'postgresql::server':
  listen_addresses => '*',
}

postgresql::server::database { 'db_with_pg_trgm':
}

postgresql::server::extension { 'add extension pg_trgm to db_with_pg_trgm':
  extension => 'pg_trgm',
  database  => 'db_with_pg_trgm',
}

But puppet always gets the ordering right.
The ordering is derived from the dependancies, which state that the extension requires the nominated database to exist (and be managed under puppet).
For puppet to be able to check that the DB exists, postgresql needs to be running.
ie puppet starts postgresql before the extension is applied, or the unless clause is executed.

I suspect the problem is more likely related to the subsequent error message:

  Error: /Stage[main]/Postgresql::Server::Reload/Exec[postgresql_reload]: Failed to call refresh: invalid byte sequence in US-ASCII

which might account for postgresql not being started, or failing soon after being started.
Note that applying an extension does not require a reload, so the reload is due to something else.

FYI: Specifying database=>undef allows puppet to apply an extension to the DB postgres.

@justinstoller
Copy link
Member

So, I'm seeing a similar issue when running the PuppetDB module now, but only on hosts that have pulled in the new postgresql module. I think the problem is that the check

and defined(Postgresql::Server::Database[$database])

is dependent on the manifest order.

For example the puppetdb module defines the extension to be installed and then defines the database to install them into here.

The PDB ordering is admittedly weird, but I do think that this causes a change in behavior by not complete auto-requiring dependent databases.

@antgel
Copy link

antgel commented Oct 25, 2017

Thanks @justinstoller for clarifying. @georgehansper Any thoughts?

@georgehansper
Copy link
Contributor Author

I suspect @justinstoller is right, and that using defined(Postgresql::Server::Database[$database]) may not be the right approach. I will try something else.

@georgehansper
Copy link
Contributor Author

Hello @justinstoller @antgel

I can reproduce the error message using the module puppetlabs-puppetdb

I have created a new branch extension_upgrade_fixdep in the repository https://github.com/infoxchange/puppetlabs-postgresql
which I believe will resolve this issue.

Before I create a pull-request, could you please verify that this branch also resolves the issue in your environment?

Regards,
George Hansper

antgel pushed a commit to graduway/psick that referenced this pull request Oct 31, 2017
antgel pushed a commit to graduway/psick that referenced this pull request Nov 6, 2017
antgel pushed a commit to graduway/psick that referenced this pull request Nov 6, 2017
@antgel
Copy link

antgel commented Nov 7, 2017

@georgehansper Works for me, hope you can create a PR soon! :)

antgel pushed a commit to graduway/psick that referenced this pull request Nov 7, 2017
@justinstoller
Copy link
Member

Hi! Sorry, I've gotten a bit swamped, the change in your branch looks fine to me, but I don't have time to functionally test it. I've pinged the modules folks to see if they can work with you to get this across the line.

@georgehansper
Copy link
Contributor Author

Hi @justinstoller , @antgel

I have submitted PR #932 to merge the code from https://github.com/infoxchange/puppetlabs-postgresql branch extension_upgrade_fixdep

cegeka-jenkins pushed a commit to cegeka/puppet-postgresql that referenced this pull request Feb 3, 2022
add parameter "version" to postgresql::server::extension to update the extension version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants