Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Official postgresql module from puppetlabs allow granting privileges on specific database.

postgresql::database_grant{'grant to myuser':
    privilege   => 'CREATE',
    db          => 'app_production',
    role        => 'myuser',

this would execute:

 GRANT ${privilege} ON database ${db} TO ${role};

However I'd like to execute query on global permissions for given user:

  ALTER role myuser login createdb;

Is there a way how to do this? Or should I use different puppet module for PostgreSQL?

share|improve this question

The solution that works for me is to use 'postgresql::server::role' with createdb => true instead of 'postgresql::database_grant'. It makes sense as you want to alter user's global behaviour, not the one related to the particular database.

This is an example directive that adds the user along with createdb privileges:

postgresql::server::role { 'username':
  password_hash => postgresql_password('username', 'password'),
  createdb  => true

Given 'vagrant' as the user name, this is the expected output:

Role[vagrant]/Postgresql_psql[ALTER ROLE "vagrant" CREATEDB]/command: command changed '' to 'ALTER ROLE "vagrant" CREATEDB'

Important: If you use version 2 of the module, you can use postgresql::role instead of postgresql::server::role. See

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.