Add actual postgresl module from puppetlabs
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / manifests / tablespace.pp
1 # Define: postgresql::tablespace
2 #
3 # This module creates tablespace
4 #
5 # Parameters:
6 #   [*title*]       - the name of a tablespace to be created. The name cannot begin with pg_, as such names are reserved for system tablespaces.
7 #   [*owner*]       - the name of the user who will own the tablespace. If omitted, defaults to the user executing the command.
8 #                     Only superusers can create tablespaces, but they can assign ownership of tablespaces to non-superusers.
9 #   [*location*]    - The directory that will be used for the tablespace. The directory should be empty and must be owned by the PostgreSQL
10 #                     system user. The directory must be specified by an absolute path name.
11 #
12 # Actions:
13 #
14 # Requires:
15 #
16 #   class postgresql::server
17 #
18 # Sample Usage:
19 #
20 #  postgresql::tablespace { 'dbspace':
21 #    location => '/data/dbs',
22 #  }
23 #
24 #
25 define postgresql::tablespace(
26   $location,
27   $owner = undef,
28   $spcname  = $title)
29 {
30   include postgresql::params
31
32   Postgresql_psql {
33     psql_user    => $postgresql::params::user,
34     psql_group   => $postgresql::params::group,
35     psql_path    => $postgresql::params::psql_path,
36   }
37
38   if ($owner == undef) {
39     $owner_section = ''
40   }
41   else {
42     $owner_section = "OWNER \"${owner}\""
43   }
44
45   $create_tablespace_command = "CREATE TABLESPACE \"${spcname}\" ${owner_section} LOCATION '${location}'"
46
47   file { $location:
48     ensure => directory,
49     owner  => $postgresql::params::user,
50     group  => $postgresql::params::group,
51     mode   => '0700',
52   }
53
54   postgresql_psql { "Create tablespace '${spcname}'":
55     command => $create_tablespace_command,
56     unless  => "SELECT spcname FROM pg_tablespace WHERE spcname='${spcname}'",
57     require => [Class['postgresql::server'], File[$location]],
58   }
59 }