tablespace.pp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. if ($owner == undef) {
  32. $owner_section = ''
  33. }
  34. else {
  35. $owner_section = "OWNER ${owner}"
  36. }
  37. $create_tablespace_command = "CREATE TABLESPACE ${spcname} ${owner_section} LOCATION '${location}'"
  38. file { $location:
  39. ensure => directory,
  40. owner => 'postgres',
  41. group => 'postgres',
  42. mode => '0700',
  43. }
  44. postgresql_psql { "Create tablespace '${spcname}'":
  45. command => $create_tablespace_command,
  46. unless => "SELECT spcname FROM pg_tablespace WHERE spcname='${spcname}'",
  47. cwd => $postgresql::params::datadir,
  48. require => [Class['postgresql::server'], File[$location]],
  49. }
  50. }