Puppet Class: postgresql::server

Defined in:
modules/postgresql/manifests/server.pp

Overview

Class: postgresql::server

This class installs postgresql packages, standard configuration

Parameters:

pgversion
    Defaults to 9.6 in Debian Stretch
    FIXME: Just use the unversioned package name and let apt
    do the right thing.
ensure
    Defaults to present
includes
    An array of files that will be included in the config. It is
    the caller's responsibility to provide these
root_dir
    The root directory for postgresql data. The actual directory will be
    "${root_dir}/${pgversion}/main".
use_ssl
    Enable ssl

Actions:

Install/configure postgresql

Requires:

Sample Usage:

include postgresql::server

Parameters:

  • ensure (Wmflib::Ensure) (defaults to: 'present')
  • includes (Array) (defaults to: [])
  • listen_addresses (String) (defaults to: '*')
  • port (Stdlib::Port) (defaults to: 5432)
  • root_dir (Stdlib::Unixpath) (defaults to: '/var/lib/postgresql')
  • use_ssl (Boolean) (defaults to: false)
  • log_line_prefix (String) (defaults to: '%t ')
  • log_min_duration_statement (Optional[Integer[250]]) (defaults to: undef)
  • log_autovacuum_min_duration (Optional[Integer]) (defaults to: undef)
  • pgversion (Optional[Numeric]) (defaults to: undef)
  • ssldir (Optional[Stdlib::Unixpath]) (defaults to: undef)


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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'modules/postgresql/manifests/server.pp', line 29

class postgresql::server(
    Wmflib::Ensure             $ensure                      = 'present',
    Array                      $includes                    = [],
    String                     $listen_addresses            = '*',
    Stdlib::Port               $port                        = 5432,
    Stdlib::Unixpath           $root_dir                    = '/var/lib/postgresql',
    Boolean                    $use_ssl                     = false,
    String                     $log_line_prefix             = '%t ',
    Optional[Integer[250]]     $log_min_duration_statement  = undef,
    Optional[Integer]          $log_autovacuum_min_duration = undef,
    Optional[Numeric]          $pgversion                   = undef,
    Optional[Stdlib::Unixpath] $ssldir                      = undef,
) {

    case debian::codename() {
        'buster': {
            $_pgversion_default = 11
        }
        'bullseye': {
            $_pgversion_default = 13
        }
        default: {
            fail("${title} not supported by: ${debian::codename()})")
        }
    }
    $_pgversion = $pgversion ? {
        undef   => $_pgversion_default,
        default => $pgversion,
    }


    package { [
        "postgresql-${_pgversion}",
        "postgresql-${_pgversion}-debversion",
        "postgresql-client-${_pgversion}",
        'libdbi-perl',
        'libdbd-pg-perl',
        'check-postgres',
        'pgtop',
    ]:
        ensure => $ensure,
    }

    class { 'postgresql::dirs':
        ensure    => $ensure,
        pgversion => $_pgversion,
        root_dir  => $root_dir,
    }

    $data_dir = "${root_dir}/${_pgversion}/main"

    $service_name = 'postgresql'

    exec { 'pgreload':
        command     => "/usr/bin/pg_ctlcluster ${_pgversion} main reload",
        user        => 'postgres',
        refreshonly => true,
    }

    if $use_ssl {
        file { "/etc/postgresql/${_pgversion}/main/ssl.conf":
            ensure  => $ensure,
            source  => 'puppet:///modules/postgresql/ssl.conf',
            owner   => 'root',
            group   => 'root',
            mode    => '0444',
            require => Puppet::Expose_agent_certs['/etc/postgresql'],
            before  => Service[$service_name],
        }

        # TODO: consider using profile::pki::get_cert
        puppet::expose_agent_certs { '/etc/postgresql':
            ensure          => $ensure,
            provide_private => true,
            user            => 'postgres',
            group           => 'postgres',
            ssldir          => $ssldir,
        }
    }

    service { $service_name:
        ensure  => stdlib::ensure($ensure, 'service'),
    }

    file { "/etc/postgresql/${_pgversion}/main/postgresql.conf":
        ensure  => $ensure,
        content => template('postgresql/postgresql.conf.erb'),
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
    }
}