Ask Your Question

create postgresql db from sql file with puppetlabs-postgresql

asked 2016-01-20 07:11:21 -0600

teleivo gravatar image


I would like to create a postgresql db from an sql script.

I am using the puppetlabs-postgresql module to setup postgresql.

Is there a way to to this with the puppetlabs-postgresql module? These resources

dont seem to be able to create a db from a script.

If not I am going to use the exec resource, but just didnt want to do it since its not encouraged

thanks a lot!!

edit retag flag offensive close merge delete


Concider liquibase or some other DB versioning framework.

Iakov GAN gravatar imageIakov GAN ( 2016-01-23 18:17:04 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-01-21 03:56:54 -0600

Grant Croker gravatar image

If you have your own custom SQL script then I think the only way is it use an exec resource. For example:

exec {'postgres_create_db':
    command => "psql -f ${sql_create_db} postgres",
    path    => '/usr/pgsql-9.4/bin:/usr/bin:/bin',
    user    => 'postgres',
    require => File['/tmp/create_db.sql'],
    onlyif  => "test $(psql ${db_name} --command='SELECT version();' ; echo $?) -ne 0",
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-01-20 07:11:21 -0600

Seen: 538 times

Last updated: Jan 21 '16