module-postgresql/manifests/tablespace.pp
2013-01-28 18:01:11 +01:00

52 lines
1.6 KiB
Puppet

# Define: postgresql::tablespace
#
# This module creates tablespace
#
# Parameters:
# [*title*] - the name of a tablespace to be created. The name cannot begin with pg_, as such names are reserved for system tablespaces.
# [*owner*] - the name of the user who will own the tablespace. If omitted, defaults to the user executing the command.
# Only superusers can create tablespaces, but they can assign ownership of tablespaces to non-superusers.
# [*location*] - The directory that will be used for the tablespace. The directory should be empty and must be owned by the PostgreSQL
# system user. The directory must be specified by an absolute path name.
#
# Actions:
#
# Requires:
#
# class postgresql::server
#
# Sample Usage:
#
# postgresql::tablespace { 'dbspace':
# location => '/data/dbs',
# }
#
#
define postgresql::tablespace(
$location,
$owner = undef,
$spcname = $title)
{
include postgresql::params
if ($owner == undef) {
$owner_section = ''
}
else {
$owner_section = "OWNER $owner"
}
$create_tablespace_command = "CREATE TABLESPACE $spcname ${owner_section} LOCATION '$location'"
postgresql_psql { "Check for existence of tablespace '$spcname'":
command => "SELECT 1",
unless => "SELECT spcname FROM pg_tablespace WHERE spcname='$spcname'",
cwd => $postgresql::params::datadir,
require => Class['postgresql::server']
} ~>
postgresql_psql { "Create tablespace '$spcname'":
command => $create_tablespace_command,
cwd => $postgresql::params::datadir,
}
}