Defined Type: postgresql::server::db

Defined in:
manifests/server/db.pp

Summary

Define for conveniently creating a role, database and assigning the correctpermissions.

Overview

Parameters:

  • user (Any)

    User to create and assign access to the database upon creation. Mandatory.

  • password (Variant[String, Sensitive[String]])

    Required Sets the password for the created user.

  • comment (Any) (defaults to: undef)

    Defines a comment to be stored about the database using the PostgreSQL COMMENT command.

  • dbname (Any) (defaults to: $title)

    Sets the name of the database to be created.

  • encoding (Any) (defaults to: $postgresql::server::encoding)

    Overrides the character set during creation of the database.

  • locale (Any) (defaults to: $postgresql::server::locale)

    Overrides the locale during creation of the database.

  • grant (Any) (defaults to: 'ALL')

    Specifies the permissions to grant during creation. Default value: ‘ALL’.

  • tablespace (Any) (defaults to: undef)

    Defines the name of the tablespace to allocate the created database to.

  • template (Any) (defaults to: 'template0')

    Specifies the name of the template database from which to build this database. Defaults value: template0.

  • istemplate (Any) (defaults to: false)

    Specifies that the database is a template, if set to true.

  • owner (Any) (defaults to: undef)

    Sets a user as the owner of the database.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'manifests/server/db.pp', line 14

define postgresql::server::db (
  $user,
  Variant[String, Sensitive[String]] $password,
  $comment    = undef,
  $dbname     = $title,
  $encoding   = $postgresql::server::encoding,
  $locale     = $postgresql::server::locale,
  $grant      = 'ALL',
  $tablespace = undef,
  $template   = 'template0',
  $istemplate = false,
  $owner      = undef
) {
  if ! defined(Postgresql::Server::Database[$dbname]) {
    postgresql::server::database { $dbname:
      comment    => $comment,
      encoding   => $encoding,
      tablespace => $tablespace,
      template   => $template,
      locale     => $locale,
      istemplate => $istemplate,
      owner      => $owner,
    }
  }

  if ! defined(Postgresql::Server::Role[$user]) {
    postgresql::server::role { $user:
      password_hash => $password,
      before        => Postgresql::Server::Database[$dbname],
    }
  }

  if ! defined(Postgresql::Server::Database_grant["GRANT ${user} - ${grant} - ${dbname}"]) {
    postgresql::server::database_grant { "GRANT ${user} - ${grant} - ${dbname}":
      privilege => $grant,
      db        => $dbname,
      role      => $user,
    } -> Postgresql_conn_validator<| db_name == $dbname |>
  }

  if($tablespace != undef and defined(Postgresql::Server::Tablespace[$tablespace])) {
    Postgresql::Server::Tablespace[$tablespace]->Postgresql::Server::Database[$name]
  }
}