Resource Type: pg_exec

Defined in:
lib/puppet/type/pg_exec.rb
Providers:
psql

Overview

This type allows you run a specific SQL statement or an sql file on a specified instance db.

pg_exec{"drop table application_users/db@instance":
  role     => 'app_user',
  password => 'password,'
}

This statement will execute the sql statement ‘drop table application_users` on the database named `db` in the instance named `instance`.

You can use the ‘unless` parameter to only execute the statement in certain states. If the query specified in the `unless` parameter returns one or more records, the main statement is skipped.

pg_exec{ "create synonym ${user}.${synonym} for USER.${synonym}":
  unless  => "select * from all_synonyms where owner='${user}' and synonym_name='${synonym}'",
}

You can also execute a script.

pg_exec{"@/tmp/do_some_stuff.sql/db@instance":
  role      => 'app_user',
  password  => 'password,'
  logoutput => on_failure,  # can be true, false or on_failure
}

This statement will run the sqlscript ‘/tmp/do_some_stuff.sql` on the db named `db`. Use the `unless` parameter to just execute the script in certain situations.

When you don’t specify the rolw and the password, the type will connect as ‘sysdba`.

Parameters

  • provider

    The specific backend to use for this ‘pg_exec` resource. You will seldom need to specify this — Puppet will usually discover the appropriate provider for your platform.