Skip to content

add missing parameters to initdb #1451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
# @param version Deprecated. Use postgresql::globals instead. Sets PostgreSQL version
#
# @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
# @param auth_host auth method used by default for host authorization
# @param auth_local auth method used by default for local authorization
# @param lc_messages locale used for logging and system messages
# @param username username of user running the postgres instance
#
class postgresql::server (
Optional[Variant[String[1], Sensitive[String[1]], Integer]] $postgres_password = undef,
Expand Down Expand Up @@ -136,9 +140,13 @@

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

Optional[String[1]] $auth_host = undef,
Optional[String[1]] $auth_local = undef,
Optional[String[1]] $encoding = $postgresql::params::encoding,
Optional[String[1]] $locale = $postgresql::params::locale,
Optional[String[1]] $lc_messages = undef,
Optional[Boolean] $data_checksums = $postgresql::params::data_checksums,
Optional[String[1]] $username = undef,
Optional[String[1]] $timezone = $postgresql::params::timezone,

Boolean $manage_pg_hba_conf = $postgresql::params::manage_pg_hba_conf,
Expand Down
20 changes: 12 additions & 8 deletions manifests/server/initdb.pp
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# @api private
class postgresql::server::initdb {
postgresql::server::instance::initdb { 'main':
needs_initdb => $postgresql::server::needs_initdb,
initdb_path => $postgresql::server::initdb_path,
auth_host => $postgresql::server::auth_host,
auth_local => $postgresql::server::auth_local,
data_checksums => $postgresql::server::data_checksums,
datadir => $postgresql::server::datadir,
xlogdir => $postgresql::server::xlogdir,
encoding => $postgresql::server::encoding,
group => $postgresql::server::group,
initdb_path => $postgresql::server::initdb_path,
lc_messages => $postgresql::server::lc_messages,
locale => $postgresql::server::locale,
logdir => $postgresql::server::logdir,
manage_datadir => $postgresql::server::manage_datadir,
manage_logdir => $postgresql::server::manage_logdir,
manage_xlogdir => $postgresql::server::manage_xlogdir,
encoding => $postgresql::server::encoding,
locale => $postgresql::server::locale,
data_checksums => $postgresql::server::data_checksums,
group => $postgresql::server::group,
user => $postgresql::server::user,
module_workdir => $postgresql::server::module_workdir,
needs_initdb => $postgresql::server::needs_initdb,
user => $postgresql::server::user,
username => $postgresql::server::username,
xlogdir => $postgresql::server::xlogdir,
}
}
123 changes: 75 additions & 48 deletions manifests/server/instance/initdb.pp
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
# lint:ignore:140chars
# @param needs_initdb Explicitly calls the initdb operation after server package is installed
# and before the PostgreSQL service is started.
# @param initdb_path Specifies the path to the initdb command.
# @param auth_host auth method used by default for host authorization
# @param auth_local auth method used by default for local authorization
# @param data_checksums Boolean. Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent.
# @param datadir PostgreSQL data directory
# @param xlogdir PostgreSQL xlog directory
# @param logdir PostgreSQL log directory
# @param manage_datadir Set to false if you have file{ $datadir: } already defined
# @param manage_logdir Set to false if you have file{ $logdir: } already defined
# @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined
# @param encoding Sets the default encoding for all databases created with this module.
# On certain operating systems this is also used during the template1 initialization, so it becomes a default outside of the module as well.
# @param group Overrides the default postgres user group to be used for related files in the file system.
# @param initdb_path Specifies the path to the initdb command.
# @param lc_messages locale used for logging and system messages
# @param locale Sets the default database locale for all databases created with this module.
# On certain operating systems this is used during the template1 initialization as well, so it becomes a default outside of the module.
# @param data_checksums Boolean. Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent.
# 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.
# @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system.
# @param group Overrides the default postgres user group to be used for related files in the file system.
# @param logdir PostgreSQL log directory
# @param manage_datadir Set to false if you have file{ $datadir: } already defined
# @param manage_logdir Set to false if you have file{ $logdir: } already defined
# @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined
# @param module_workdir Working directory for the PostgreSQL module
# @param needs_initdb Explicitly calls the initdb operation after server package is installed
# and before the PostgreSQL service is started.
# @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system.
# @param username username of user running the postgres instance
# @param xlogdir PostgreSQL xlog/WAL directory
# lint:endignore:140chars
define postgresql::server::instance::initdb (
Boolean $needs_initdb = $postgresql::server::needs_initdb,
Variant[String[1], Stdlib::Absolutepath] $initdb_path = $postgresql::server::initdb_path,
Optional[String[1]] $auth_host = $postgresql::server::auth_host,
Optional[String[1]] $auth_local = $postgresql::server::auth_local,
Optional[Boolean] $data_checksums = $postgresql::server::data_checksums,
String[1] $datadir = $postgresql::server::datadir,
Optional[String[1]] $xlogdir = $postgresql::server::xlogdir,
Optional[String[1]] $encoding = $postgresql::server::encoding,
String[1] $group = $postgresql::server::group,
Variant[String[1], Stdlib::Absolutepath] $initdb_path = $postgresql::server::initdb_path,
Optional[String[1]] $lc_messages = $postgresql::server::lc_messages,
Optional[String[1]] $locale = $postgresql::server::locale,
Optional[String[1]] $logdir = $postgresql::server::logdir,
Boolean $manage_datadir = $postgresql::server::manage_datadir,
Boolean $manage_logdir = $postgresql::server::manage_logdir,
Boolean $manage_xlogdir = $postgresql::server::manage_xlogdir,
Optional[String[1]] $encoding = $postgresql::server::encoding,
Optional[String[1]] $locale = $postgresql::server::locale,
Optional[Boolean] $data_checksums = $postgresql::server::data_checksums,
String[1] $group = $postgresql::server::group,
String[1] $user = $postgresql::server::user,
String[1] $module_workdir = $postgresql::server::module_workdir,
Boolean $needs_initdb = $postgresql::server::needs_initdb,
String[1] $user = $postgresql::server::user,
Optional[String[1]] $username = $postgresql::server::username,
Optional[String[1]] $xlogdir = $postgresql::server::xlogdir,
) {
if $facts['os']['family'] == 'RedHat' and $facts['os']['selinux']['enabled'] == true {
$seltype = 'postgresql_db_t'
$logdir_type = 'postgresql_log_t'
}

else {
} else {
$seltype = undef
$logdir_type = undef
}

if($manage_datadir) {
if $manage_datadir {
# Make sure the data directory exists, and has the correct permissions.
file { $datadir:
ensure => directory,
Expand All @@ -64,8 +70,11 @@
}
}

if($xlogdir) {
if($manage_xlogdir) {
if $xlogdir {
# The xlogdir need to be present before initdb runs.
# If xlogdir is default it's created by package installer
$require_before_initdb = [$datadir, $xlogdir]
if$manage_xlogdir {
# Make sure the xlog directory exists, and has the correct permissions.
file { $xlogdir:
ensure => directory,
Expand All @@ -84,10 +93,12 @@
seltype => $seltype,
}
}
} else {
$require_before_initdb = [$datadir]
}

if($logdir) {
if($manage_logdir) {
if $logdir {
if $manage_logdir {
# Make sure the log directory exists, and has the correct permissions.
file { $logdir:
ensure => directory,
Expand All @@ -106,43 +117,59 @@
}
}

if($needs_initdb) {
if $needs_initdb {
# Build up the initdb command.
#
# We optionally add the locale switch if specified. Older versions of the
# initdb command don't accept this switch. So if the user didn't pass the
# parameter, lets not pass the switch at all.
$ic_base = "${initdb_path} --pgdata '${datadir}'"
$ic_xlog = $xlogdir ? {
undef => $ic_base,
default => "${ic_base} -X '${xlogdir}'"

$auth_host_parameter = $auth_host ? {
undef => undef,
default => "--auth-host '${auth_host}'"
}

# The xlogdir need to be present before initdb runs.
# If xlogdir is default it's created by package installer
if($xlogdir) {
$require_before_initdb = [$datadir, $xlogdir]
} else {
$require_before_initdb = [$datadir]
$auth_local_parameter = $auth_local ? {
undef => undef,
default => "--auth-local '${auth_local}'"
}

$data_checksums_parameter = $data_checksums ? {
undef => undef,
false => undef,
default => '--data-checksums'
}

$datadir_parameter = "--pgdata '${datadir}'"

# PostgreSQL 11 no longer allows empty encoding
$ic_encoding = $encoding ? {
undef => $ic_xlog,
default => "${ic_xlog} --encoding '${encoding}'"
$encoding_parameter = $encoding ? {
undef => undef,
default => "--encoding '${encoding}'"
}

$lc_messages_parameter = $locale ? {
undef => undef,
default => "--lc-messages '${lc_messages}'"
}

$ic_locale = $locale ? {
undef => $ic_encoding,
default => "${ic_encoding} --locale '${locale}'"
$locale_parameter = $locale ? {
undef => undef,
default => "--locale '${locale}'"
}

$initdb_command = $data_checksums ? {
undef => $ic_locale,
false => $ic_locale,
default => "${ic_locale} --data-checksums"
$username_parameter = $username ? {
undef => undef,
default => "--username '${username}'"
}

$xlogdir_parameter = $xlogdir ? {
undef => undef,
default => "-X '${xlogdir}'"
}

$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

# This runs the initdb command, we use the existance of the PG_VERSION
# file to ensure we don't keep running this command.
exec { 'postgresql_initdb':
Expand Down