module-postgresql/manifests/tablespace.pp

55 lines
1.6 KiB
ObjectPascal
Raw Normal View History

2013-01-28 18:01:11 +01:00
# 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 {
2013-01-29 14:05:15 +01:00
$owner_section = "OWNER ${owner}"
2013-01-28 18:01:11 +01:00
}
2013-01-29 14:05:15 +01:00
$create_tablespace_command = "CREATE TABLESPACE ${spcname} ${owner_section} LOCATION '${location}'"
2013-01-28 18:01:11 +01:00
2013-01-29 14:05:15 +01:00
file { "${location}":
ensure => directory,
owner => 'postgres',
group => 'postgres',
mode => 700,
}
2013-01-28 18:01:11 +01:00
2013-01-29 14:05:15 +01:00
postgresql_psql { "Create tablespace '${spcname}'":
2013-01-28 18:01:11 +01:00
command => $create_tablespace_command,
2013-01-29 14:05:15 +01:00
unless => "SELECT spcname FROM pg_tablespace WHERE spcname='${spcname}'",
2013-01-28 18:01:11 +01:00
cwd => $postgresql::params::datadir,
2013-01-29 14:05:15 +01:00
require => [Class['postgresql::server'], File["${location}"]],
2013-01-28 18:01:11 +01:00
}
}