Skip to content

Commit 1706fb3

Browse files
authored
Merge pull request #1451 from SimonHoenscheid/initdb_parameters
add missing parameters to initdb
2 parents 9534a43 + 7d5b118 commit 1706fb3

File tree

3 files changed

+95
-56
lines changed

3 files changed

+95
-56
lines changed

manifests/server.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
# @param version Deprecated. Use postgresql::globals instead. Sets PostgreSQL version
8888
#
8989
# @param extra_systemd_config Adds extra config to systemd config file, can for instance be used to add extra openfiles. This can be a multi line string
90+
# @param auth_host auth method used by default for host authorization
91+
# @param auth_local auth method used by default for local authorization
92+
# @param lc_messages locale used for logging and system messages
93+
# @param username username of user running the postgres instance
9094
#
9195
class postgresql::server (
9296
Optional[Variant[String[1], Sensitive[String[1]], Integer]] $postgres_password = undef,
@@ -136,9 +140,13 @@
136140

137141
Boolean $needs_initdb = $postgresql::params::needs_initdb,
138142

143+
Optional[String[1]] $auth_host = undef,
144+
Optional[String[1]] $auth_local = undef,
139145
Optional[String[1]] $encoding = $postgresql::params::encoding,
140146
Optional[String[1]] $locale = $postgresql::params::locale,
147+
Optional[String[1]] $lc_messages = undef,
141148
Optional[Boolean] $data_checksums = $postgresql::params::data_checksums,
149+
Optional[String[1]] $username = undef,
142150
Optional[String[1]] $timezone = $postgresql::params::timezone,
143151

144152
Boolean $manage_pg_hba_conf = $postgresql::params::manage_pg_hba_conf,

manifests/server/initdb.pp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# @api private
22
class postgresql::server::initdb {
33
postgresql::server::instance::initdb { 'main':
4-
needs_initdb => $postgresql::server::needs_initdb,
5-
initdb_path => $postgresql::server::initdb_path,
4+
auth_host => $postgresql::server::auth_host,
5+
auth_local => $postgresql::server::auth_local,
6+
data_checksums => $postgresql::server::data_checksums,
67
datadir => $postgresql::server::datadir,
7-
xlogdir => $postgresql::server::xlogdir,
8+
encoding => $postgresql::server::encoding,
9+
group => $postgresql::server::group,
10+
initdb_path => $postgresql::server::initdb_path,
11+
lc_messages => $postgresql::server::lc_messages,
12+
locale => $postgresql::server::locale,
813
logdir => $postgresql::server::logdir,
914
manage_datadir => $postgresql::server::manage_datadir,
1015
manage_logdir => $postgresql::server::manage_logdir,
1116
manage_xlogdir => $postgresql::server::manage_xlogdir,
12-
encoding => $postgresql::server::encoding,
13-
locale => $postgresql::server::locale,
14-
data_checksums => $postgresql::server::data_checksums,
15-
group => $postgresql::server::group,
16-
user => $postgresql::server::user,
1717
module_workdir => $postgresql::server::module_workdir,
18+
needs_initdb => $postgresql::server::needs_initdb,
19+
user => $postgresql::server::user,
20+
username => $postgresql::server::username,
21+
xlogdir => $postgresql::server::xlogdir,
1822
}
1923
}

manifests/server/instance/initdb.pp

Lines changed: 75 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,56 @@
11
# lint:ignore:140chars
2-
# @param needs_initdb Explicitly calls the initdb operation after server package is installed
3-
# and before the PostgreSQL service is started.
4-
# @param initdb_path Specifies the path to the initdb command.
2+
# @param auth_host auth method used by default for host authorization
3+
# @param auth_local auth method used by default for local authorization
4+
# @param data_checksums Boolean. Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent.
55
# @param datadir PostgreSQL data directory
6-
# @param xlogdir PostgreSQL xlog directory
7-
# @param logdir PostgreSQL log directory
8-
# @param manage_datadir Set to false if you have file{ $datadir: } already defined
9-
# @param manage_logdir Set to false if you have file{ $logdir: } already defined
10-
# @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined
116
# @param encoding Sets the default encoding for all databases created with this module.
127
# On certain operating systems this is also used during the template1 initialization, so it becomes a default outside of the module as well.
8+
# @param group Overrides the default postgres user group to be used for related files in the file system.
9+
# @param initdb_path Specifies the path to the initdb command.
10+
# @param lc_messages locale used for logging and system messages
1311
# @param locale Sets the default database locale for all databases created with this module.
1412
# On certain operating systems this is used during the template1 initialization as well, so it becomes a default outside of the module.
15-
# @param data_checksums Boolean. Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent.
1613
# Warning: This option is used during initialization by initdb, and cannot be changed later. If set, checksums are calculated for all objects, in all databases.
17-
# @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system.
18-
# @param group Overrides the default postgres user group to be used for related files in the file system.
14+
# @param logdir PostgreSQL log directory
15+
# @param manage_datadir Set to false if you have file{ $datadir: } already defined
16+
# @param manage_logdir Set to false if you have file{ $logdir: } already defined
17+
# @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined
1918
# @param module_workdir Working directory for the PostgreSQL module
19+
# @param needs_initdb Explicitly calls the initdb operation after server package is installed
20+
# and before the PostgreSQL service is started.
21+
# @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system.
22+
# @param username username of user running the postgres instance
23+
# @param xlogdir PostgreSQL xlog/WAL directory
2024
# lint:endignore:140chars
2125
define postgresql::server::instance::initdb (
22-
Boolean $needs_initdb = $postgresql::server::needs_initdb,
23-
Variant[String[1], Stdlib::Absolutepath] $initdb_path = $postgresql::server::initdb_path,
26+
Optional[String[1]] $auth_host = $postgresql::server::auth_host,
27+
Optional[String[1]] $auth_local = $postgresql::server::auth_local,
28+
Optional[Boolean] $data_checksums = $postgresql::server::data_checksums,
2429
String[1] $datadir = $postgresql::server::datadir,
25-
Optional[String[1]] $xlogdir = $postgresql::server::xlogdir,
30+
Optional[String[1]] $encoding = $postgresql::server::encoding,
31+
String[1] $group = $postgresql::server::group,
32+
Variant[String[1], Stdlib::Absolutepath] $initdb_path = $postgresql::server::initdb_path,
33+
Optional[String[1]] $lc_messages = $postgresql::server::lc_messages,
34+
Optional[String[1]] $locale = $postgresql::server::locale,
2635
Optional[String[1]] $logdir = $postgresql::server::logdir,
2736
Boolean $manage_datadir = $postgresql::server::manage_datadir,
2837
Boolean $manage_logdir = $postgresql::server::manage_logdir,
2938
Boolean $manage_xlogdir = $postgresql::server::manage_xlogdir,
30-
Optional[String[1]] $encoding = $postgresql::server::encoding,
31-
Optional[String[1]] $locale = $postgresql::server::locale,
32-
Optional[Boolean] $data_checksums = $postgresql::server::data_checksums,
33-
String[1] $group = $postgresql::server::group,
34-
String[1] $user = $postgresql::server::user,
3539
String[1] $module_workdir = $postgresql::server::module_workdir,
40+
Boolean $needs_initdb = $postgresql::server::needs_initdb,
41+
String[1] $user = $postgresql::server::user,
42+
Optional[String[1]] $username = $postgresql::server::username,
43+
Optional[String[1]] $xlogdir = $postgresql::server::xlogdir,
3644
) {
3745
if $facts['os']['family'] == 'RedHat' and $facts['os']['selinux']['enabled'] == true {
3846
$seltype = 'postgresql_db_t'
3947
$logdir_type = 'postgresql_log_t'
40-
}
41-
42-
else {
48+
} else {
4349
$seltype = undef
4450
$logdir_type = undef
4551
}
4652

47-
if($manage_datadir) {
53+
if $manage_datadir {
4854
# Make sure the data directory exists, and has the correct permissions.
4955
file { $datadir:
5056
ensure => directory,
@@ -64,8 +70,11 @@
6470
}
6571
}
6672

67-
if($xlogdir) {
68-
if($manage_xlogdir) {
73+
if $xlogdir {
74+
# The xlogdir need to be present before initdb runs.
75+
# If xlogdir is default it's created by package installer
76+
$require_before_initdb = [$datadir, $xlogdir]
77+
if$manage_xlogdir {
6978
# Make sure the xlog directory exists, and has the correct permissions.
7079
file { $xlogdir:
7180
ensure => directory,
@@ -84,10 +93,12 @@
8493
seltype => $seltype,
8594
}
8695
}
96+
} else {
97+
$require_before_initdb = [$datadir]
8798
}
8899

89-
if($logdir) {
90-
if($manage_logdir) {
100+
if $logdir {
101+
if $manage_logdir {
91102
# Make sure the log directory exists, and has the correct permissions.
92103
file { $logdir:
93104
ensure => directory,
@@ -106,43 +117,59 @@
106117
}
107118
}
108119

109-
if($needs_initdb) {
120+
if $needs_initdb {
110121
# Build up the initdb command.
111122
#
112123
# We optionally add the locale switch if specified. Older versions of the
113124
# initdb command don't accept this switch. So if the user didn't pass the
114125
# parameter, lets not pass the switch at all.
115-
$ic_base = "${initdb_path} --pgdata '${datadir}'"
116-
$ic_xlog = $xlogdir ? {
117-
undef => $ic_base,
118-
default => "${ic_base} -X '${xlogdir}'"
126+
127+
$auth_host_parameter = $auth_host ? {
128+
undef => undef,
129+
default => "--auth-host '${auth_host}'"
119130
}
120131

121-
# The xlogdir need to be present before initdb runs.
122-
# If xlogdir is default it's created by package installer
123-
if($xlogdir) {
124-
$require_before_initdb = [$datadir, $xlogdir]
125-
} else {
126-
$require_before_initdb = [$datadir]
132+
$auth_local_parameter = $auth_local ? {
133+
undef => undef,
134+
default => "--auth-local '${auth_local}'"
135+
}
136+
137+
$data_checksums_parameter = $data_checksums ? {
138+
undef => undef,
139+
false => undef,
140+
default => '--data-checksums'
127141
}
128142

143+
$datadir_parameter = "--pgdata '${datadir}'"
144+
129145
# PostgreSQL 11 no longer allows empty encoding
130-
$ic_encoding = $encoding ? {
131-
undef => $ic_xlog,
132-
default => "${ic_xlog} --encoding '${encoding}'"
146+
$encoding_parameter = $encoding ? {
147+
undef => undef,
148+
default => "--encoding '${encoding}'"
149+
}
150+
151+
$lc_messages_parameter = $locale ? {
152+
undef => undef,
153+
default => "--lc-messages '${lc_messages}'"
133154
}
134155

135-
$ic_locale = $locale ? {
136-
undef => $ic_encoding,
137-
default => "${ic_encoding} --locale '${locale}'"
156+
$locale_parameter = $locale ? {
157+
undef => undef,
158+
default => "--locale '${locale}'"
138159
}
139160

140-
$initdb_command = $data_checksums ? {
141-
undef => $ic_locale,
142-
false => $ic_locale,
143-
default => "${ic_locale} --data-checksums"
161+
$username_parameter = $username ? {
162+
undef => undef,
163+
default => "--username '${username}'"
144164
}
145165

166+
$xlogdir_parameter = $xlogdir ? {
167+
undef => undef,
168+
default => "-X '${xlogdir}'"
169+
}
170+
171+
$initdb_command = squeeze("${initdb_path} ${auth_host_parameter} ${auth_local_parameter} ${data_checksums_parameter} ${datadir_parameter} ${encoding_parameter} ${lc_messages_parameter} ${locale_parameter} ${username_parameter} ${xlogdir_parameter}", ' ') # lint:ignore:140chars
172+
146173
# This runs the initdb command, we use the existance of the PG_VERSION
147174
# file to ensure we don't keep running this command.
148175
exec { 'postgresql_initdb':

0 commit comments

Comments
 (0)