|
| 1 | +# lint:ignore:140chars |
| 2 | +# @summary Manage the default encoding when database initialization is managed by the package |
| 3 | +# @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. |
| 4 | +# @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system. |
| 5 | +# @param group Overrides the default postgres user group to be used for related files in the file system. |
| 6 | +# @param psql_path Specifies the path to the psql command. |
| 7 | +# @param port Specifies the port for the PostgreSQL server to listen on. Note: The same port number is used for all IP addresses the server listens on. Also, for Red Hat systems and early Debian systems, changing the port causes the server to come to a full stop before being able to make the change. |
| 8 | +# @param module_workdir Working directory for the PostgreSQL module |
| 9 | +# lint:endignore:140chars |
| 10 | +define postgresql::server::instance_late_initdb ( |
| 11 | + $encoding = $postgresql::server::encoding, |
| 12 | + $user = $postgresql::server::user, |
| 13 | + $group = $postgresql::server::group, |
| 14 | + $psql_path = $postgresql::server::psql_path, |
| 15 | + $port = $postgresql::server::port, |
| 16 | + $module_workdir = $postgresql::server::module_workdir, |
| 17 | +) { |
| 18 | + # Set the defaults for the postgresql_psql resource |
| 19 | + Postgresql_psql { |
| 20 | + psql_user => $user, |
| 21 | + psql_group => $group, |
| 22 | + psql_path => $psql_path, |
| 23 | + port => $port, |
| 24 | + cwd => $module_workdir, |
| 25 | + } |
| 26 | + |
| 27 | + # [workaround] |
| 28 | + # by default pg_createcluster encoding derived from locale |
| 29 | + # but it do does not work by installing postgresql via puppet because puppet |
| 30 | + # always override LANG to 'C' |
| 31 | + postgresql_psql { "Set template1 encoding to ${encoding}": |
| 32 | + command => "UPDATE pg_database |
| 33 | + SET datistemplate = FALSE |
| 34 | + WHERE datname = 'template1' |
| 35 | + ; |
| 36 | + UPDATE pg_database |
| 37 | + SET encoding = pg_char_to_encoding('${encoding}'), datistemplate = TRUE |
| 38 | + WHERE datname = 'template1'", |
| 39 | + unless => "SELECT datname FROM pg_database WHERE |
| 40 | + datname = 'template1' AND encoding = pg_char_to_encoding('${encoding}')", |
| 41 | + before => Anchor['postgresql::server::service::end'], |
| 42 | + } |
| 43 | +} |
0 commit comments