Defined Type: postgresql::server::tablespace

Defined in:
manifests/server/tablespace.pp

Overview

This module creates tablespace. See README.md for more details.

Parameters:

  • location (Any)
  • owner (Any) (defaults to: undef)
  • spcname (Any) (defaults to: $title)
  • connect_settings (Any) (defaults to: $postgresql::server::default_connect_settings)


2
3
4
5
6
7
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
# File 'manifests/server/tablespace.pp', line 2

define postgresql::server::tablespace(
  $location,
  $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

  # 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,
  }

  if ($owner == undef) {
    $owner_section = ''
  } else {
    $owner_section = "OWNER \"${owner}\""
  }

  $create_tablespace_command = "CREATE TABLESPACE \"${spcname}\" ${owner_section} LOCATION '${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'],
  }

  $create_ts = "Create tablespace '${spcname}'"
  postgresql_psql { "Create tablespace '${spcname}'":
    command => $create_tablespace_command,
    unless  => "SELECT spcname FROM pg_tablespace WHERE spcname='${spcname}'",
    require => [Class['postgresql::server'], File[$location]],
  }

  if($owner != undef and defined(Postgresql::Server::Role[$owner])) {
    Postgresql::Server::Role[$owner]->Postgresql_psql[$create_ts]
  }
}