Defined Type: postgresql::server::tablespace

Defined in:
manifests/server/tablespace.pp

Summary

This module creates tablespace.

Overview

Parameters:

  • location (Any)

    Specifies the path to locate this tablespace.

  • manage_location (Any) (defaults to: true)

    Set to false if you have file{ $location: } already defined

  • owner (Any) (defaults to: undef)

    Specifies the default owner of the tablespace.

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

    Specifies the name of the tablespace.

  • connect_settings (Any) (defaults to: $postgresql::server::default_connect_settings)

    Specifies a hash of environment variables used when connecting to a remote server.



8
9
10
11
12
13
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'manifests/server/tablespace.pp', line 8

define postgresql::server::tablespace (
  $location,
  $manage_location = true,
  $owner   = undef,
  $spcname = $title,
  $connect_settings = $postgresql::server::default_connect_settings,
) {
  $user           = $postgresql::server::user
  $group          = $postgresql::server::group
  $psql_path      = $postgresql::server::psql_path
  $module_workdir = $postgresql::server::module_workdir

  # If the connection settings do not contain a port, then use the local server port
  if $connect_settings != undef and has_key( $connect_settings, 'PGPORT') {
    $port = undef
  } else {
    $port = $postgresql::server::port
  }

  Postgresql_psql {
    psql_user        => $user,
    psql_group       => $group,
    psql_path        => $psql_path,
    port             => $port,
    connect_settings => $connect_settings,
    cwd              => $module_workdir,
  }

  if($manage_location) {
    file { $location:
      ensure  => directory,
      owner   => $user,
      group   => $group,
      mode    => '0700',
      seluser => 'system_u',
      selrole => 'object_r',
      seltype => 'postgresql_db_t',
      require => Class['postgresql::server'],
    }
  } else {
    File <| title == $location |> {
      ensure  => directory,
      owner   => $user,
      group   => $group,
      mode    => '0700',
      seluser => 'system_u',
      selrole => 'object_r',
      seltype => 'postgresql_db_t',
      require => Class['postgresql::server'],
    }
  }

  postgresql_psql { "CREATE TABLESPACE \"${spcname}\"":
    command => "CREATE TABLESPACE \"${spcname}\" LOCATION '${location}'",
    unless  => "SELECT 1 FROM pg_tablespace WHERE spcname = '${spcname}'",
    require => File[$location],
  }

  if $owner {
    postgresql_psql { "ALTER TABLESPACE \"${spcname}\" OWNER TO \"${owner}\"":
      unless  => "SELECT 1 FROM pg_tablespace JOIN pg_roles rol ON spcowner = rol.oid WHERE spcname = '${spcname}' AND rolname = '${owner}'",
      require => Postgresql_psql["CREATE TABLESPACE \"${spcname}\""],
    }

    if defined(Postgresql::Server::Role[$owner]) {
      Postgresql::Server::Role[$owner]->Postgresql_psql["ALTER TABLESPACE \"${spcname}\" OWNER TO \"${owner}\""]
    }
  }
}