mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
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)
This commit is contained in:
21
scripts/setup/pgroonga-config
Executable file
21
scripts/setup/pgroonga-config
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eux
|
||||
|
||||
dbversion=$(crudini --get /etc/zulip/zulip.conf postgresql version)
|
||||
dbname=$(crudini --get /etc/zulip/zulip.conf postgresql database_name 2>/dev/null || echo zulip)
|
||||
dbuser=$(crudini --get /etc/zulip/zulip.conf postgresql database_user 2>/dev/null || echo zulip)
|
||||
|
||||
sharedir="${1:-/usr/share/postgresql/$dbversion}"
|
||||
applied_file="$sharedir/pgroonga_setup.sql.applied"
|
||||
|
||||
installed_version=$(dpkg-query --show --showformat='${Version}' "postgresql-$dbversion-pgdg-pgroonga")
|
||||
|
||||
if [ ! -f "$applied_file" ]; then
|
||||
sql="CREATE EXTENSION PGROONGA; GRANT USAGE ON SCHEMA pgroonga TO $dbuser"
|
||||
else
|
||||
sql="ALTER EXTENSION pgroonga UPDATE"
|
||||
fi
|
||||
|
||||
echo "$sql" | su postgres -c "psql -v ON_ERROR_STOP=1 $dbname"
|
||||
|
||||
echo "$installed_version" >"$applied_file"
|
||||
Reference in New Issue
Block a user