Files
zulip/puppet/zulip/manifests/postgresql_base.pp
Alex Vandiver 2dfc0463bd pgroonga: Run upgrade SQL when pgroonga package is updated.
Updating the pgroonga package is not sufficient to upgrade the
extension in PostgreSQL -- an `ALTER EXTENSION pgroonga UPDATE` must
explicitly be run[^1].  Failure to do so can lead to unexpected behavior,
including crashes of PostgreSQL.

Expand on the existing `pgroonga_setup.sql.applied` file, to track
which version of the PostgreSQL extension has been configured.  If the
file exists but is empty, we run `ALTER EXTENSION pgroonga UPDATE`
regardless -- if it is a no-op, it still succeeds with a `NOTICE`:

```
zulip=# ALTER EXTENSION pgroonga UPDATE;
NOTICE:  version "3.0.8" of extension "pgroonga" is already installed
ALTER EXTENSION
```

The simple `ALTER EXTENSION` is sufficient for the
backwards-compatible case[^1] -- which, for our usage, is every
upgrade since 0.9 -> 1.0.  Since version 1.0 was released in 2015,
before pgroonga support was added to Zulip in 2016, we can assume for
the moment that all pgroonga upgrades are backwards-compatible, and
not bother regenerating indexes.

Fixes: #25989.

[^1]: https://pgroonga.github.io/upgrade/

(cherry picked from commit c8ec3dfcf6)
2023-07-03 18:50:14 +00:00

108 lines
4.0 KiB
Puppet

# Minimal shared configuration needed to run a Zulip PostgreSQL database.
class zulip::postgresql_base {
include zulip::postgresql_common
include zulip::process_fts_updates
case $::os['family'] {
'Debian': {
$postgresql = "postgresql-${zulip::postgresql_common::version}"
$postgresql_sharedir = "/usr/share/postgresql/${zulip::postgresql_common::version}"
$postgresql_confdirs = [
"/etc/postgresql/${zulip::postgresql_common::version}",
"/etc/postgresql/${zulip::postgresql_common::version}/main",
]
$postgresql_confdir = $postgresql_confdirs[-1]
$postgresql_datadir = "/var/lib/postgresql/${zulip::postgresql_common::version}/main"
$tsearch_datadir = "${postgresql_sharedir}/tsearch_data"
$pgroonga_setup_sql_path = "${postgresql_sharedir}/pgroonga_setup.sql"
$setup_system_deps = 'setup_apt_repo'
$postgresql_restart = "pg_ctlcluster ${zulip::postgresql_common::version} main restart"
$postgresql_dict_dict = '/var/cache/postgresql/dicts/en_us.dict'
$postgresql_dict_affix = '/var/cache/postgresql/dicts/en_us.affix'
}
'RedHat': {
$postgresql = "postgresql${zulip::postgresql_common::version}"
$postgresql_sharedir = "/usr/pgsql-${zulip::postgresql_common::version}/share"
$postgresql_confdirs = [
"/var/lib/pgsql/${zulip::postgresql_common::version}",
"/var/lib/pgsql/${zulip::postgresql_common::version}/data",
]
$postgresql_confdir = $postgresql_confdirs[-1]
$postgresql_datadir = "/var/lib/pgsql/${zulip::postgresql_common::version}/data"
$tsearch_datadir = "${postgresql_sharedir}/tsearch_data/"
$pgroonga_setup_sql_path = "${postgresql_sharedir}/pgroonga_setup.sql"
$setup_system_deps = 'setup_yum_repo'
$postgresql_restart = "systemctl restart postgresql-${zulip::postgresql_common::version}"
# TODO Since we can't find the PostgreSQL dicts directory on CentOS yet, we
# link directly to the hunspell directory.
$postgresql_dict_dict = '/usr/share/myspell/en_US.dic'
$postgresql_dict_affix = '/usr/share/myspell/en_US.aff'
}
default: {
fail('osfamily not supported')
}
}
file { "${tsearch_datadir}/en_us.dict":
ensure => link,
require => Package[$postgresql],
target => $postgresql_dict_dict,
}
file { "${tsearch_datadir}/en_us.affix":
ensure => link,
require => Package[$postgresql],
target => $postgresql_dict_affix,
}
file { "${tsearch_datadir}/zulip_english.stop":
ensure => file,
require => Package[$postgresql],
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/zulip/postgresql/zulip_english.stop',
}
file { "${zulip::common::nagios_plugins_dir}/zulip_postgresql":
require => Package[$zulip::common::nagios_plugins],
recurse => true,
purge => true,
owner => 'root',
group => 'root',
mode => '0755',
source => 'puppet:///modules/zulip/nagios_plugins/zulip_postgresql',
}
$pgroonga = zulipconf('machine', 'pgroonga', false)
if $pgroonga {
# Needed for optional our full text search system
# Removed 2020-12 in version 4.0; these lines can be removed when
# we drop support for upgrading from Zulip 3 or older.
package{"${postgresql}-pgroonga":
ensure => purged,
}
package{"${postgresql}-pgdg-pgroonga":
ensure => latest,
require => [
Package[$postgresql],
Exec[$setup_system_deps]
],
}
exec { 'pgroonga-config':
require => Package["${postgresql}-pgdg-pgroonga"],
unless => @("EOT"/$),
test -f ${pgroonga_setup_sql_path}.applied &&
test "$(dpkg-query --show --showformat='\${Version}' "${postgresql}-pgdg-pgroonga")" \
= "$(cat ${pgroonga_setup_sql_path}.applied)"
| EOT
command => "${::zulip_scripts_path}/setup/pgroonga-config ${postgresql_sharedir}",
}
}
$s3_backups_bucket = zulipsecret('secrets', 's3_backups_bucket', '')
if $s3_backups_bucket != '' {
include zulip::postgresql_backups
}
}