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:

  • pgversion (Any) (defaults to: $::lsbdistcodename)
  • ensure (Any) (defaults to: 'present')
  • includes (Any) (defaults to: [])
  • listen_addresses (Any) (defaults to: '*')
  • port (Any) (defaults to: '5432')
  • root_dir (Any) (defaults to: '/var/lib/postgresql')
  • use_ssl (Any) (defaults to: false)
  • ssldir (Any) (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
# File 'modules/postgresql/manifests/server.pp', line 29

class postgresql::server(
    $pgversion        = $::lsbdistcodename ? {
        'buster'  => '11',
        'stretch' => '9.6',
    },
    $ensure           = 'present',
    $includes         = [],
    $listen_addresses = '*',
    $port             = '5432',
    $root_dir         = '/var/lib/postgresql',
    $use_ssl          = false,
    $ssldir           = undef,
) {

    package { [
        "postgresql-${pgversion}",
        "postgresql-${pgversion}-debversion",
        "postgresql-client-${pgversion}",
        'libdbi-perl',
        'libdbd-pg-perl',
        $::lsbdistcodename ? {
            'buster' => 'pgtop',
            default  => 'ptop',
        },
        'check-postgres',
    ]:
        ensure => $ensure,
    }

    # The contrib package got dropped from Postgres in 10, it's only a virtual
    # package and not needed starting with Buster
    if os_version('debian < buster') {
        package { "postgresql-contrib-${pgversion}":
            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 => Base::Expose_puppet_certs['/etc/postgresql'],
            before  => Service[$service_name],
        }

        ::base::expose_puppet_certs { '/etc/postgresql':
            ensure          => $ensure,
            provide_private => true,
            user            => 'postgres',
            group           => 'postgres',
            ssldir          => $ssldir,
        }
    }

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

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