Install the whpg-cjk package on each host in your WarehousePG cluster, as it doesn't ship as part of the WarehousePG server package.
Supported platforms
whpg-cjk is available for WarehousePG 7:
| WarehousePG version | Architecture | Operating systems |
|---|---|---|
| 7 | x86_64, ppc64le | RHEL 8, 9 |
Prerequisites
The database where you register whpg-cjk must use UTF8 encoding.
To check the encoding of your databases, run:
SELECT datname, pg_encoding_to_char(encoding) AS encoding FROM pg_database;
You can't change the encoding of an existing database. If your data is in a database that uses a different encoding, create a database with UTF8 encoding, and load the data into it:
CREATE DATABASE <database_name> ENCODING 'UTF8' TEMPLATE template0;
Where <database_name> is a name for the new database.
Installing the package
Refer to Downloading and installing an extension for instructions on downloading the package and installing it on every host. The package name is edb-whpg7-cjk.
Registering whpg-cjk
Create the extension in each database where you want to use it:
CREATE EXTENSION whpg_cjk;
The command adds the korean, japanese, and chinese text search configurations. See Using whpg-cjk.
Verifying the installation
Confirm that whpg-cjk is registered in the database:
\dx whpg_cjk
Confirm that the text search configurations exist. The query returns three rows:
SELECT cfgname FROM pg_ts_config WHERE cfgname IN ('korean', 'japanese', 'chinese');
cfgname ---------- korean japanese chinese
Preloading whpg-cjk
Optionally, preload whpg-cjk to build the analyzers once at server start, instead of in each session. Without preloading, the first use of the Korean or Japanese analyzer in a session takes a few milliseconds, and the first use of the Chinese analyzer takes about 120 ms and uses about 50 MB of private memory per backend. To preload, load whpg_cjk as a shared library:
Check for existing shared libraries:
gpconfig -s shared_preload_librariesUse the output of the previous command to enable the extension, along with any other shared libraries:
gpconfig -c shared_preload_libraries -v '<other_libraries>, whpg_cjk'
Where
<other_libraries>is the list of libraries from the previous step.Restart WarehousePG:
gpstop -ar
On restart, the server builds the analyzers for the languages listed in the whpg_cjk.preload_languages configuration parameter, which defaults to korean, japanese, chinese. Every backend on every segment inherits them, so the first-use delay and the per-backend memory copy disappear.
Upgrading whpg-cjk
Upgrade whpg-cjk by installing the new package on every host, restarting the cluster, updating the extension in each database, and rebuilding the objects that depend on it. Don't drop and re-create the extension to upgrade, because dropping it cascades to the text search configurations and to every index built on them. Check the release notes to find out whether a release changes how text is analyzed. If it does, rebuild those objects, as described in step 4, so that indexed text and queries are analyzed the same way.
Note
Plan a maintenance window. From the restart until you finish rebuilding the dependent objects, new documents and queries are analyzed by the new version, while existing indexes still hold the old analysis.
Upgrade the whpg-cjk package on every host in the cluster, including the coordinator and every segment host. Refer to Upgrading an extension for downloading and distributing the new package. The package name is
edb-whpg7-cjk.Restart WarehousePG to load the new library:
gpstop -arThe restart makes every process load the new library. A process that still runs the old library analyzes text with the old version, and
ALTER EXTENSIONfails if you run it from that process, with the errorcould not find function "ts_cjk_headline".If you didn't preload whpg-cjk, you can close every existing session instead, including the connections in connection pools.
From a new session, update the extension in every database where you registered it:
ALTER EXTENSION whpg_cjk UPDATE;
Note
In whpg-cjk 1.1.0, the update switches the parsers to the new headline function,
ts_cjk_headline, on the coordinator and on all segments. It also raises aWARNINGthat names the objects built with whpg-cjk:- Indexes
- Generated columns
- Column defaults
CHECKconstraints- Materialized views
The objects include those that use
cjk_normalize(). The warning appears only if the database has such objects. A database with none completes the update without a warning.The warning doesn't list
tsvectorcolumns that triggers or your application fill. In a database that doesn't use UTF8, a secondWARNINGnames the objects that depend oncjk_normalize(). Writes andREINDEXon those objects now fail. Move the data to a UTF8 database, or drop those objects.Rebuild the indexes, stored
tsvectorcolumns, and materialized views that are built withto_tsvectorand a whpg-cjk configuration, and the objects that are built oncjk_normalize(). Configurations that you created withPARSER = cjk_ko,cjk_ja, orcjk_zh, and configurations that map a token type to acjk_templatedictionary, such ascjk_japanese_stemunder the default parser, count as whpg-cjk configurations. For more information about storedtsvectorcolumns, see Indexing large tables.REINDEX TABLE <table_name>; UPDATE <table_name> SET <text_column> = <text_column>; REFRESH MATERIALIZED VIEW <view_name>;
Where:
<table_name>is a table with an index, a generated column, or a trigger-filledtsvectorcolumn that depends on whpg-cjk. RunREINDEX INDEX <index_name>instead to rebuild only the indexes that the warning names.<text_column>is a text column that atsvectorcolumn is built from. TheUPDATErecomputes generated columns and runsUPDATEtriggers. Your application must rewrite any column that it fills itself.<view_name>is a materialized view that the warning names.
Revalidate the
CHECKconstraints that the warning names. WarehousePG doesn't check a validCHECKconstraint again, so the constraint keeps its old result. Look for rows that fail the constraint against the new analysis, then re-add the constraint and validate it in a transaction:SELECT count(*) FROM <table_name> WHERE NOT (<check_expression>); BEGIN; ALTER TABLE <table_name> DROP CONSTRAINT <constraint_name>, ADD CONSTRAINT <constraint_name> CHECK (<check_expression>) NOT VALID; ALTER TABLE <table_name> VALIDATE CONSTRAINT <constraint_name>; COMMIT;
Where:
<table_name>is the table that has the constraint.<check_expression>is the expression of the constraint, for examplecjk_normalize(body) <> ''.<constraint_name>is the name of the constraint.
If a row fails,
VALIDATEraises an error and the transaction rolls back to the old constraint.To re-add the constraint of a domain, use
ALTER DOMAIN ... DROP CONSTRAINT,ADD CONSTRAINT ... NOT VALID, andVALIDATE CONSTRAINTthe same way.