PostgreSQL 15のアップデート

:warning: 警告! データベースが非常に大きい場合、大量の追加ディスク容量(データベースサイズの2倍)が必要となり、このアップグレードには細心の注意が必要です!

DockerイメージをPostgreSQL 15にアップグレードする変更を適用しました。コマンドラインからDiscourseを再構築するサイト管理者は、以前のPostgreSQL 13からPostgreSQL 15にアップグレードされます。PostgreSQL 13のアップデートが2020年にあった際にアップグレードを見送った場合は、そのアップグレードをスキップして直接PostgreSQL 15に移行できます。

以前にアップグレードを見送った場合は、app.ymlのPostgreSQLテンプレートをtemplates/postgres.12.template.ymlからtemplates/postgres.template.ymlに変更してください。

すべてのアップグレードと同様に、何かを行う前にバックアップを取ることが強く推奨されます。

アップデート

公式インストールガイド (シングルコンテナ)

次回の再構築時に、最後にこのメッセージが表示されます。

-------------------------------------------------------------------------------------
POSTGRESのアップグレード完了
古い13データベースは /shared/postgres_data_old に保存されています
アップグレードを完了するには、次を使用して再度再構築してください:
./launcher rebuild app
-------------------------------------------------------------------------------------

これは、アップグレードがすべて正常に進んだことを意味します!サイトを再開するには、新しい再構築を発行するだけです。

データコンテナインストール

Discourse Dockerリポジトリのサンプルに基づいた専用データコンテナを使用している場合は、PostgreSQLを安全かつクリーンにシャットダウンすることを確認してください。

現在、数分に及ぶクエリを実行するバックグラウンドジョブが実行されているため、Webコンテナをシャットダウンすると、データコンテナも安全にシャットダウンできます。

./launcher stop web_only
./launcher stop data
./launcher rebuild data
./launcher rebuild data
./launcher rebuild web_only

データコンテナへの最初の再構築を発行する前に、PostgreSQLログをtailして、正常にシャットダウンされたかどうかを確認できます。

shared/standalone/log/var-log/postgres/current をtailすると、正常にシャットダウンされた場合は次のログが表示されるはずです。

2025-01-24 09:19:06.437 UTC [37] LOG:  received smart shutdown request
2025-01-24 09:19:06.444 UTC [37] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
2025-01-24 09:19:06.446 UTC [49] LOG:  shutting down
2025-01-24 09:19:06.468 UTC [37] LOG:  database system is shut down

手動アップデート / スペース制約のある環境

:warning::warning::warning:
これを試す前に、POSTGRES_DATAを必ずバックアップしてください
:warning::warning::warning:

スペースが制約されており、追加のスペースを確保できない環境の場合は、次の方法を試してください。

./launcher stop app #(または、該当する場合は web_only と data の両方)
mkdir -p /var/discourse/shared/standalone/postgres_data_new
docker run --rm \
	--entrypoint=/bin/bash \
	-v /var/discourse/shared/standalone/postgres_data:/var/lib/postgresql/13/data \
	-v /var/discourse/shared/standalone/postgres_data_new:/var/lib/postgresql/15/data \
	tianon/postgres-upgrade:13-to-15 \
	-c "apt-get update && apt-get install -y postgresql-13-pgvector postgresql-15-pgvector &&
	docker-upgrade"
mv /var/discourse/shared/standalone/postgres_data /var/discourse/shared/standalone/postgres_data_old
mv /var/discourse/shared/standalone/postgres_data_new /var/discourse/shared/standalone/postgres_data
docker run --rm -v /var/discourse/shared/standalone:/shared local_discourse/app \
	chown -R postgres:postgres /shared/postgres_data #(または local_discourse/data)
./launcher rebuild app #(または、該当する場合はまず data、次に web_only)

私のテストでは、この手順で現在のデータベースサイズの1倍未満の空き容量で済みました。

デフォルト以外のロケールを使用している場合は、最初のdockerコマンドを次のように置き換えてみてください。

# 'en_US.UTF-8' をお使いのロケールに変更してください
docker run --rm \
	--entrypoint=/bin/bash \
	-e LANG='en_US.UTF-8' \
	-v /var/discourse/shared/standalone/postgres_data:/var/lib/postgresql/13/data \
	-v /var/discourse/shared/standalone/postgres_data_new:/var/lib/postgresql/15/data \
	tianon/postgres-upgrade:13-to-15 \
	-c 'sed -i "s/^# $LANG/$LANG/" /etc/locale.gen && locale-gen &&
	apt-get update && apt-get install -y postgresql-13-pgvector postgresql-15-pgvector &&
	docker-upgrade'

アップグレードの延期

次回の再構築時にアップグレードを延期する必要がある場合は、app.ymlファイルでPostgreSQLテンプレートを"templates/postgres.template.yml"から"templates/postgres.13.template.yml"に変更することで切り替えることができます。

これは推奨されません。なぜなら、一部のサイト管理者は後で変更を元に戻すのを忘れる可能性があるからです。

アップグレード後のオプションタスク

PostgreSQL統計情報の最適化

アップグレード後、新しいPostgreSQLにはテーブル統計情報がありません。これらは次を使用して生成できます。

docker exec -u postgres app \
	/usr/lib/postgresql/15/bin/vacuumdb -d discourse --analyze-in-stages

古いデータのクリーンアップ

標準的なインストールの場合、PG13形式の古いデータは次のコマンドで削除できます。

cd /var/discourse
./launcher cleanup

データコンテナが分離されている場合は、次のようにバックアップコピーを削除する必要があります。

rm -fr /var/discourse/shared/data/postgres_data_old/

FAQ

ソースクラスターがクリーンにシャットダウンされませんでした

上記メッセージでアップグレードが失敗した場合、より良い状態に戻すために、より簡単なアプローチを試すことができます。

古いコンテナを./launcher start appで再起動します。数分待ってから、再度./launcher stop appでシャットダウンします。その後、ログをtailして、クリーンなシャットダウンであったかを確認します。

tail -f shared/standalone/log/var-log/postgres/current
2025-01-24 09:19:06.437 UTC [37] LOG:  received smart shutdown request
2025-01-24 09:19:06.444 UTC [37] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
2025-01-24 09:19:06.446 UTC [49] LOG:  shutting down
2025-01-24 09:19:06.468 UTC [37] LOG:  database system is shut down

ログにデータベースがシャットダウンされたことを示すものがない場合は、古いコンテナを再度起動し、./launcher enter appで入り、次のコマンドを実行してから、完了後に再度ログをtailしてください。

export SVWAIT=300
sv stop nginx
sv stop unicorn
sv stop postgres
exit

ログが上記のように表示されたら、./launcher rebuild appを使用して再度アップグレードを試すことができます。

データベース「postgres」のlc_collate値が一致しません

このエラーは、データベースでデフォルト以外のロケールを使用している場合に発生します。成功するには3つの変数が必要であると報告されています。app.ymlファイルのenv:セクションに次の3行が含まれていることを確認してください。

  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8

en_US.UTF-8をお使いのロケールに変更してください。

すべての再構築でアップグレードが再度実行される(アップグレードループ)

この場合、アップグレードログには次のような内容が含まれます。

mv: cannot move '/shared/postgres_data' to '/shared/postgres_data_old/postgres_data': Directory not empty
mv: cannot move '/shared/postgres_data_new' to '/shared/postgres_data/postgres_data_new': Directory not empty

これは、前回のアップグレードのファイルがまだ残っていることを意味します。続行する前に、それらを別の場所に移動してください。

アップグレード完了の提案スクリプト - 何かする必要がありますか?

アップグレードが完了すると、pg_upgradeメッセージからの出力が表示されます。

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
    /usr/lib/postgresql/15/bin/vacuumdb --all --analyze-in-stages

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh

このメッセージは安全に無視できます。

PostgreSQL 13のアップデートをスキップしました、どうすればよいですか?

ガイドの先頭にある標準の手順に従えば、お使いのバージョンから15に問題なくアップグレードできます。

スペース制約のある環境の手順に従っている場合は、バージョン番号を適宜調整してください。

インデックスの再構築は、ディスク容量を大幅に節約できます。アップグレード後、PostgreSQL 13のアップデートの手順に従ってください。

「いいね!」 26

When I visit https://community.ankihub.net/admin/update, I see the following message:

You are running an old version of the Discourse image
Updates via the web UI are disabled until you run the latest image. To do so log in to your server using SSH and run:

cd /var/discourse
git pull
./launcher rebuild app

After following those instructions, I get UPGRADE OF POSTGRES FAILED:

invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Processing triggers for postgresql-common (267.pgdg120+1) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Stopping PostgreSQL 13 database server: main.
Stopping PostgreSQL 15 database server: main.
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for system-defined composite types in user tables  ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for user-defined encoding conversions              ok
Checking for user-defined postfix operators                 ok
Checking for incompatible polymorphic functions             ok
Creating dump of global objects                             ok
Creating dump of database schemas
*failure*

Consult the last few lines of "/shared/postgres_data_new/pg_upgrade_output.d/20250129T103738.877/log/pg_upgrade_dump_16384.log" for
the probable cause of the failure.
Failure, exiting
-------------------------------------------------------------------------------------
UPGRADE OF POSTGRES FAILED

Please visit https://meta.discourse.org/t/postgresql-15-update/349515 for support.

You can run ./launcher start app to restart your app in the meanwhile
-------------------------------------------------------------------------------------



FAILED
--------------------
Pups::ExecError: if [ -f /root/install_postgres ]; then
  /root/install_postgres && rm -f /root/install_postgres
elif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then
  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi
 failed with return #<Process::Status: pid 18 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"tag"=>"db", "cmd"=>"if [ -f /root/install_postgres ]; then\n  /root/install_postgres && rm -f /root/install_postgres\nelif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then\n  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1\nfi\n"}
bootstrap failed with exit code 1

Nothing at here or in this somewhat related topic addresses my issue, afaict.

Here are the logs from /shared/postgres_data_new/pg_upgrade_output.d/20250129T103738.877/log/pg_upgrade_dump_16384.log:

command: "/usr/lib/postgresql/15/bin/pg_dump" --host /var/lib/postgresql --port 50432 --username postgres --schema-only --quote-all-identifiers --binary-upgrade --format=custom  --file="/shared/postgres_data_new/pg_upgrade_output.d/20250129T103738.877/dump/pg_upgrade_dump_16384.custom" 'dbname=discourse' >> "/shared/postgres_data_new/pg_upgrade_output.d/20250129T103738.877/log/pg_upgrade_dump_16384.log" 2>&1
pg_dump: error: query failed: ERROR:  could not access file "$libdir/vector": No such file or directory
pg_dump: detail: Query was: SELECT t.tableoid, t.oid, i.indrelid, t.relname AS indexname, pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, i.indkey, i.indisclustered, c.contype, c.conname, c.condeferrable, c.condeferred, c.tableoid AS contableoid, c.oid AS conoid, pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, (SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, t.reloptions AS indreloptions, i.indisreplident, inh.inhparent AS parentidx, i.indnkeyatts AS indnkeyatts, i.indnatts AS indnatts, (SELECT pg_catalog.array_agg(attnum ORDER BY attnum)   FROM pg_catalog.pg_attribute   WHERE attrelid = i.indexrelid AND     attstattarget >= 0) AS indstatcols, (SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum)   FROM pg_catalog.pg_attribute   WHERE attrelid = i.indexrelid AND     attstattarget >= 0) AS indstatvals, false AS indnullsnotdistinct FROM unnest('{16805,16813,16823,16835,16846,16858,16940,16948,16963,16973,16996,17006,17029,17061,17071,17085,17095,17101,17112,17136,17151,17159,17168,17266,17280,17321,17334,17345,17354,17368,17382,17398,17412,17420,17428,17519,17532,17543,17562,17570,17620,17687,17710,17724,17738,17754,17775,17788,17803,17824,17851,17864,17898,17917,17932,17944,17958,17980,17993,18006,18019,18030,18041,18055,18069,18092,18101,18134,18145,18166,18177,18214,18241,18263,18276,18298,18324,18338,18358,18368,18403,18426,18449,18458,18470,18496,18510,18525,18534,18543,18569,18596,18607,18625,18643,18655,18663,18676,18686,18698,18710,18719,18734,18742,18757,18768,18786,18798,18802,18806,18846,18864,18879,18891,18910,18920,18932,18946,18988,19003,19014,19039,19059,19073,19085,19097,19103,19116,19140,19192,19206,19227,19250,19266,19300,19309,19328,19343,19354,19367,19389,19402,19417,19430,19497,19521,19544,19559,19569,19597,19605,19637,19687,19703,19721,19742,19771,19807,19821,19830,19839,19862,19874,19890,19904,19917,19932,19942,19951,19960,19981,20005,20021,20044,20052,20061,20073,20082,20133,20146,20157,20178,20191,20203,20217,20231,20263,20276,20297,20309,20320,28805,28951,28964,28976,28986,28997,32824,32833,32843,32852,32862,32875,32887,32899,32910,32930,32967,35131,35141,38401,38413,38437,38445,38461,38482,38495,42870,46125,46138,130133,191445,191457,191471,191486,191497,191603,191637,243875,606663,606675,606693,606707,779182,779197,779213,779225,779237,779252,779265,968985,968993,969004,969017,969027,1004239,1004251,1004263,1004276,1004295,1091838,1091849,1091860,1336877,1336884,1336891,1566392,2169846,2169852,2169858,2169864,2169870,2169876,2169882,2169888,2169894,2169900,2169906,2169912,2169918,2169924,2169930,2169936,2169942,2169948,2169954,2169960,2169966,2169972,2169978,2169984}'::pg_catalog.oid[]) AS src(tbloid)
JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) LEFT JOIN pg_catalog.pg_constraint c ON (i.indrelid = c.conrelid AND i.indexrelid = c.conindid AND c.contype IN ('p','u','x')) LEFT JOIN pg_catalog.pg_inherits inh ON (inh.inhrelid = indexrelid) WHERE (i.indisvalid OR t2.relkind = 'p') AND i.indisready ORDER BY i.indrelid, indexname
/shared/postgres_data_new/pg_upgrade_output.d/20250129T103738.877/log/pg_upgrade_dump_16384.log

Here is the output of ./discourse-doctor:

./discourse-doctor output
DISCOURSE DOCTOR Wed 29 Jan 2025 10:39:42 AM UTC
OS: Linux forum 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


Found containers/app.yml

==================== YML SETTINGS ====================
DISCOURSE_HOSTNAME=community.ankihub.net
SMTP_ADDRESS=smtp.mailgun.org
DEVELOPER_EMAILS=REDACTED 
SMTP_PASSWORD=REDACTED 
SMTP_PORT=587
SMTP_USER_NAME=postmaster@mg.ankihub.net
LETSENCRYPT_ACCOUNT_EMAIL=REDACTED 

==================== DOCKER INFO ====================
DOCKER VERSION: Docker version 27.2.1, build 9e34c9b

DOCKER PROCESSES (docker ps -a)

CONTAINER ID   IMAGE                           COMMAND        CREATED         STATUS          PORTS                                                                      NAMES
37e2430e1014   local_discourse/app             "/sbin/boot"   4 months ago    Up 33 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   app
260f4c0ed417   local_discourse/mail-receiver   "/sbin/boot"   20 months ago   Up 4 months     0.0.0.0:25->25/tcp, :::25->25/tcp                                          mail-receiver


Discourse container app is running


==================== PLUGINS ====================
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-assign.git
          - git clone https://github.com/discourse/discourse-templates.git
          - git clone https://github.com/discourse/discourse-solved.git
          - git clone https://github.com/discourse/discourse-reactions.git
          - git clone https://github.com/discourse/discourse-chat-integration.git
          - git clone https://github.com/discourse/discourse-code-review.git
          - git clone https://github.com/discourse/discourse-topic-voting.git
          - git clone https://github.com/discourse/discourse-automation.git
          - git clone https://github.com/discourse/discourse-bbcode-color.git
          - git clone https://github.com/discourse/discourse-data-explorer.git
          - git clone https://github.com/discourse/discourse-docs.git
          - git clone https://github.com/discourse/discourse-ai.git
          - git clone https://github.com/discourse/discourse-jira.git

No non-official plugins detected.

See https://github.com/discourse/discourse/blob/main/lib/plugin/metadata.rb for the official list.

========================================
Discourse version at community.ankihub.net: Discourse 3.4.0.beta2 
Discourse version at localhost: Discourse 3.4.0.beta2 


==================== MEMORY INFORMATION ====================
OS: Linux
RAM (MB): 4127

              total        used        free      shared  buff/cache   available
Mem:           3936        1567         158         274        2209        1802
Swap:          2047          67        1980

==================== DISK SPACE CHECK ====================
---------- OS Disk Space ----------
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        78G   50G   28G  65% /

---------- Container Disk Space ----------
Filesystem      Size  Used Avail Use% Mounted on
overlay          78G   50G   28G  65% /
/dev/vda1        78G   50G   28G  65% /shared
/dev/vda1        78G   50G   28G  65% /var/log

==================== DISK INFORMATION ====================
Disk /dev/loop0: 55.68 MiB, 58363904 bytes, 113992 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop1: 91.85 MiB, 96292864 bytes, 188072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop2: 63.71 MiB, 66789376 bytes, 130448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop3: 63.10 MiB, 67080192 bytes, 131016 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop4: 44.45 MiB, 46596096 bytes, 91008 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop5: 91.9 MiB, 96346112 bytes, 188176 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop7: 44.3 MiB, 46448640 bytes, 90720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/vda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 2ED04D82-BA1D-4A75-86B9-9553B7EA5228

Device      Start       End   Sectors  Size Type
/dev/vda1  227328 167772126 167544799 79.9G Linux filesystem
/dev/vda14   2048     10239      8192    4M BIOS boot
/dev/vda15  10240    227327    217088  106M Microsoft basic data

Partition table entries are not in disk order.


Disk /dev/loop8: 55.37 MiB, 58052608 bytes, 113384 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

==================== END DISK INFORMATION ====================

==================== MAIL TEST ====================
For a robust test, get an address from http://www.mail-tester.com/
Mail test skipped.

==================== DONE! ====================

Hoping someone can point me in the right direction. Thanks!

「いいね!」 1

私も同じ問題を抱えており、解決策を探しています。

「いいね!」 1

インスタンスのデータベースのサイズを確認するにはどうすればよいですか?

「いいね!」 2

レポートありがとうございます。could not access file \"$libdir/vector\" の問題について調査中です。

標準インストールの場合、次を実行できると思います。

du -sh /var/discourse/shared/standalone/postgres_data

私のテストサイトの結果は次のとおりです。

# du -sh /var/discourse/shared/standalone/postgres_data
237M	/var/discourse/shared/standalone/postgres_data

@mwaniki より良い方法があれば訂正してください!)

「いいね!」 4

はい、これはディスク上のすべての PostgreSQL データファイル(WAL ファイルを含む)の合計サイズを返します。

discourse データベースのサイズのみに興味がある場合は、pg_database_size 関数 または \\list+ メタコマンド を使用できます。

docker exec -u postgres app psql -c "SELECT pg_size_pretty( pg_database_size('discourse') ) AS db_size;"

# または

docker exec -u postgres app psql -c "\list+ discourse"
「いいね!」 6

ちなみに、PostgreSQL が推奨するコマンドではなく、バキューム分析フォームを使用する利点は何ですか?

discourse データベース以外の統計情報を生成する必要がないということだけですか?もしそうなら、次のように使用した場合、非常に大規模なインスタンスにとって analyze-in-stages は利点になりますか?

/var/discourse/launcher run app \"/usr/lib/postgresql/15/bin/vacuumdb -d discourse --analyze-in-stages\"

こんにちは、@aas@NKERIFAC_CLAUD_NBAPNON さん!:wave:

以前のベースイメージで実行されているサイトの launcher rebuild を実行した際に、エラーを再現できませんでした。discourse-ai プラグインがインストールされていても、テストでは正常なアップグレードが確認できました。

エラーは古いデータベースからスキーマをダンプする際に発生するため、問題が解決すると思われるアップデートをプッシュしました。

同じ手順を試して、結果をお知らせください。

cd /var/discourse
git pull
./launcher rebuild app

それでも問題が解決しない場合は、環境に関する詳細情報を共有していただけますでしょうか?特に以下の情報が役立ちます。

  • 現在のベースイメージのバージョン

    docker image inspect --format '{{ .Config.Image }}' local_discourse/app
    
  • インストールされている Discourse プラグイン

    cat containers/app.yml | \\\
    docker run --rm -i -a stdout -a stdin local_discourse/app \\\
    ruby -e \"require 'yaml'; puts YAML.load(STDIN.readlines.join)['hooks']\"
    
  • PostgreSQL の拡張機能とそのバージョン

    docker exec -u postgres app psql discourse -c \"SELECT
      name,
      default_version,
      installed_version
    FROM
      pg_catalog.pg_available_extensions
    WHERE
      installed_version IS NOT NULL;\"
    
「いいね!」 3

postgres.template.yml の気になる行を見つけました。

現在のロジックでは、PostgreSQL が実際に実行されているかどうかに関わらず、ファイル /shared/postgres_run/.s.PGSQL.5432 が存在する場合、スクリプトはすぐに終了します。これにより、アップグレードスクリプトを含む /root/install_postgres の後続のコードはすべてスキップされます。最初の exit 0 は削除すべきだと思います。

「いいね!」 1

Upgrade fails for me, too. The error I see seems to indicate a locale problem (which is a bit weird since the locale of the system always was de_DE.UTF-8).

root@Ubuntu-2204-jammy-amd64-base /var/discourse # ./launcher rebuild app
x86_64 arch detected.
...
Launcher is up-to-date
Stopping old container
+ /usr/bin/docker stop -t 600 app
app
2.0.20250129-0720: Pulling from discourse/base
Digest: sha256:01b8516e5504c0e9bc3707773015ff4407be03a89154194ff3b5b8699291bc26
Status: Image is up to date for discourse/base:2.0.20250129-0720
docker.io/discourse/base:2.0.20250129-0720
/usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups.rb
/usr/local/bin/pups --stdin
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (de_DE.UTF-8)
I, [2025-01-29T21:35:58.711630 #1]  INFO -- : Reading from stdin
I, [2025-01-29T21:35:58.721321 #1]  INFO -- : File > /etc/service/postgres/run  chmod: +x  chown:
I, [2025-01-29T21:35:58.726551 #1]  INFO -- : File > /etc/service/postgres/log/run  chmod: +x  chown:
I, [2025-01-29T21:35:58.732322 #1]  INFO -- : File > /etc/runit/3.d/99-postgres  chmod: +x  chown:
I, [2025-01-29T21:35:58.737436 #1]  INFO -- : File > /root/install_postgres  chmod: +x  chown:
I, [2025-01-29T21:35:58.742651 #1]  INFO -- : File > /root/upgrade_postgres  chmod: +x  chown:
I, [2025-01-29T21:35:58.742825 #1]  INFO -- : Replacing data_directory = '/var/lib/postgresql/15/main' with data_directory = '/shared/postgres_data' in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.743394 #1]  INFO -- : Replacing (?-mix:#?listen_addresses *=.*) with listen_addresses = '*' in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.743708 #1]  INFO -- : Replacing (?-mix:#?synchronous_commit *=.*) with synchronous_commit = $db_synchronous_commit in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.744003 #1]  INFO -- : Replacing (?-mix:#?shared_buffers *=.*) with shared_buffers = $db_shared_buffers in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.744441 #1]  INFO -- : Replacing (?-mix:#?work_mem *=.*) with work_mem = $db_work_mem in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.744734 #1]  INFO -- : Replacing (?-mix:#?default_text_search_config *=.*) with default_text_search_config = '$db_default_text_search_config' in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.745027 #1]  INFO -- : Replacing (?-mix:#?checkpoint_segments *=.*) with checkpoint_segments = $db_checkpoint_segments in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.747582 #1]  INFO -- : Replacing (?-mix:#?logging_collector *=.*) with logging_collector = $db_logging_collector in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.748035 #1]  INFO -- : Replacing (?-mix:#?log_min_duration_statement *=.*) with log_min_duration_statement = $db_log_min_duration_statement in /etc/postgresql/15/main/postgresql.conf
I, [2025-01-29T21:35:58.748263 #1]  INFO -- : Replacing (?-mix:^#local +replication +postgres +peer$) with local replication postgres  peer in /etc/postgresql/15/main/pg_hba.conf
I, [2025-01-29T21:35:58.748463 #1]  INFO -- : Replacing (?-mix:^host.*all.*all.*127.*$) with host all all 0.0.0.0/0 md5 in /etc/postgresql/15/main/pg_hba.conf
I, [2025-01-29T21:35:58.748657 #1]  INFO -- : Replacing (?-mix:^host.*all.*all.*::1\/128.*$) with host all all ::/0 md5 in /etc/postgresql/15/main/pg_hba.conf
I, [2025-01-29T21:35:58.748844 #1]  INFO -- : > if [ -f /root/install_postgres ]; then
  /root/install_postgres && rm -f /root/install_postgres
elif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then
  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (de_DE.UTF-8)
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
W: https://dl.yarnpkg.com/debian/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
debconf: delaying package configuration, since apt-utils is not installed
I, [2025-01-29T21:37:25.430685 #1]  INFO -- : Generating locales (this might take a while)...
  de_DE.UTF-8... done
  en_US.UTF-8... done
Generation complete.
Upgrading PostgreSQL from version 13 to 15
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "de_DE.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "german".

Data page checksums are disabled.

fixing permissions on existing directory /shared/postgres_data_new ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok


Success. You can now start the database server using:

    /usr/lib/postgresql/15/bin/pg_ctl -D /shared/postgres_data_new -l logfile start

Get:1 http://deb.debian.org/debian bookworm-backports InRelease [59,0 kB]
Get:2 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:3 http://deb.debian.org/debian bookworm-updates InRelease [55,4 kB]
Get:4 https://dl.yarnpkg.com/debian stable InRelease [17,1 kB]
Get:5 http://deb.debian.org/debian-security bookworm-security InRelease [48,0 kB]
Get:6 https://deb.nodesource.com/node_22.x nodistro InRelease [12,1 kB]
Get:7 http://deb.debian.org/debian bookworm-backports/main amd64 Packages [280 kB]
Get:8 http://deb.debian.org/debian bookworm/main amd64 Packages [8.792 kB]
Get:9 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13,5 kB]
Get:10 https://dl.yarnpkg.com/debian stable/main amd64 Packages [10,9 kB]
Get:11 https://dl.yarnpkg.com/debian stable/main all Packages [10,9 kB]
Get:12 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [243 kB]
Get:13 https://deb.nodesource.com/node_22.x nodistro/main amd64 Packages [5.274 B]
Get:14 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg InRelease [129 kB]
Get:15 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 Packages [360 kB]
Fetched 10,2 MB in 2s (6.159 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  postgresql-client-13
Suggested packages:
  postgresql-doc-13
The following NEW packages will be installed:
  postgresql-13 postgresql-13-pgvector postgresql-client-13
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 17,3 MB of archives.
After this operation, 56,7 MB of additional disk space will be used.
Get:1 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-client-13 amd64 13.18-1.pgdg120+1 [1.523 kB]
Get:2 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-13 amd64 13.18-1.pgdg120+1 [15,4 MB]
Get:3 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-13-pgvector amd64 0.8.0-1.pgdg120+1 [297 kB]
Fetched 17,3 MB in 1s (32,1 MB/s)
Selecting previously unselected package postgresql-client-13.
(Reading database ... 33363 files and directories currently installed.)
Preparing to unpack .../postgresql-client-13_13.18-1.pgdg120+1_amd64.deb ...
Unpacking postgresql-client-13 (13.18-1.pgdg120+1) ...
Selecting previously unselected package postgresql-13.
Preparing to unpack .../postgresql-13_13.18-1.pgdg120+1_amd64.deb ...
Unpacking postgresql-13 (13.18-1.pgdg120+1) ...
Selecting previously unselected package postgresql-13-pgvector.
Preparing to unpack .../postgresql-13-pgvector_0.8.0-1.pgdg120+1_amd64.deb ...
Unpacking postgresql-13-pgvector (0.8.0-1.pgdg120+1) ...
Setting up postgresql-client-13 (13.18-1.pgdg120+1) ...
Setting up postgresql-13 (13.18-1.pgdg120+1) ...
Creating new PostgreSQL cluster 13/main ...
/usr/lib/postgresql/13/bin/initdb -D /var/lib/postgresql/13/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/13/main ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Etc/UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctlcluster 13 main start

invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Setting up postgresql-13-pgvector (0.8.0-1.pgdg120+1) ...
Processing triggers for postgresql-common (267.pgdg120+1) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Stopping PostgreSQL 13 database server: main.
Stopping PostgreSQL 15 database server: main.
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for system-defined composite types in user tables  ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for user-defined encoding conversions              ok
Checking for user-defined postfix operators                 ok
Checking for incompatible polymorphic functions             ok
Creating dump of global objects                             ok
Creating dump of database schemas                           ok

lc_collate values for database "template1" do not match:  old "en_US.UTF-8", new "de_DE.UTF-8"
Failure, exiting
-------------------------------------------------------------------------------------
UPGRADE OF POSTGRES FAILED

Please visit https://meta.discourse.org/t/postgresql-15-update/349515 for support.

You can run ./launcher start app to restart your app in the meanwhile
-------------------------------------------------------------------------------------



FAILED
--------------------
Pups::ExecError: if [ -f /root/install_postgres ]; then
  /root/install_postgres && rm -f /root/install_postgres
elif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then
  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi
 failed with return #<Process::Status: pid 18 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"tag"=>"db", "cmd"=>"if [ -f /root/install_postgres ]; then\n  /root/install_postgres && rm -f /root/install_postgres\nelif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then\n  socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1\nfi\n"}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
80933ad1f9a6809c85383c9d512c34340988ab7791b3ff57a6a563fd42fc413f

@mwaniki様、プッシュしていただいたアップデートは正常に動作しました。大変ありがとうございました。

「いいね!」 2

古いスキーマのダンプ時に失敗が発生しているとのことですが、現在のロケール設定を確認していただけますでしょうか?

docker exec -it -u postgres app bash
env
psql -c 'SELECT
  datname,
  datcollate,
  datctype
FROM
  pg_database;'

はい、その通りです!ご指摘ありがとうございます!OPの手順を更新しました。:+1:

確認いただきありがとうございます。

「いいね!」 4

4件の投稿が新しいトピックに分割されました: Problems with Discouse AI embeddings configuration

Oefhh、、このリンクとy/Nのプロンプトでアップデートスクリプトが更新されていれば、もっと良かったのに。今アップデートしましたが、この変更のためにサイトを復旧する必要があるかどうか分かりません。

編集:無事に完了したようです :tada:

サーバーには4つのフォーラムがありますが、そのうち1つはアップグレードに成功しました。次のフォーラムをアップグレードしようとすると、以下のエラーが発生します。

Caused by:
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: Connection refused (PG::ConnectionBad)

復旧させるために ./launcher start app を実行する必要がありました。

以前、PostgreSQL 12 update で同様の問題が発生し、アップグレードを試みる前に他のアプリで ./launcher stop app を実行する必要があったことを思い出しましたが、今回はうまくいきません。(そのスレッドの投稿は自動的に削除されました。モデレーターの方、投稿を確認して、私が実行した操作がそれだったかどうか確認していただけますか?)

他に何か考えはありますか?

「いいね!」 1

discourse-ai チームにコメントを求めるよう依頼しました。

はい、まさにその通りでした。同様のセットアップでテストし、改めてご連絡します。

「いいね!」 3

Mwanikiさん、ありがとうございます。アプリに入り、アップグレードのrebuildsを実行する前にsudo service postgresql stopを入力して、解決しました。

ご協力ありがとうございました :heart:

「いいね!」 1

環境は期待どおりのロケールになっているようです(env の出力は以下のとおりです。メール設定は省略しています)。

LEFTHOOK=0
HOSTNAME=Ubuntu-2204-jammy-amd64-base-app
LANGUAGE=de_DE.UTF-8
UNICORN_WORKERS=8
DISCOURSE_HOSTNAME=[..]
RUBY_GC_HEAP_INIT_SLOTS=400000
DISCOURSE_SMTP_USER_NAME=[...]
DOCKER_HOST_IP=172.17.0.1
DISCOURSE_SMTP_ADDRESS=[...]
RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5
RUBY_VERSION=3.3.6
PWD=/
DISCOURSE_DB_SOCKET=/var/run/postgresql
DISCOURSE_DEVELOPER_EMAILS=[...]
HOME=/var/lib/postgresql
LANG=de_DE.UTF-8
DISCOURSE_SMTP_PORT=587
RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000
DEBIAN_RELEASE=bookworm
DISCOURSE_SMTP_PASSWORD=[...]
DISCOURSE_NOTIFICATION_EMAIL=[...]
PG_MAJOR=13
DISCOURSE_DB_HOST=
TERM=xterm
RUBY_ALLOCATOR=/usr/lib/libjemalloc.so
SHLVL=1
DISCOURSE_DB_PORT=
DISCOURSE_SMTP_DOMAIN=[...]
UNICORN_SIDEKIQS=1
LC_ALL=de_DE.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RAILS_ENV=production
_=/usr/bin/env

しかし、Postgres ステートメントの出力は US ロケールを示しています。

  datname  | datcollate  |  datctype
-----------+-------------+-------------
 postgres  | en_US.UTF-8 | en_US.UTF-8
 template1 | en_US.UTF-8 | en_US.UTF-8
 template0 | en_US.UTF-8 | en_US.UTF-8
 discourse | en_US.UTF-8 | en_US.UTF-8
(4 rows)
「いいね!」 1

そのDiscourseインスタンスはいつ作成されましたか?

これまでのところ、問題を再現できるのは、あるロケールでデータベースを作成し、その後別のロケールを使用して移行しようとした場合のみです。その時期に過去のロケールに関するバグがあったかどうかを確認するために、インスタンスがいつ作成されたのかを理解したいと思います。

「いいね!」 2

私がたどれる限りでは、最初のインストールは2024年2月7日に行われました(サーバーが数日前に稼働したと思いますが、OSはUbuntu 22.04で、Discourseと同様に継続的に更新されていました)。

編集:
それが役立つかどうかわかりませんが、ロケールに関する問題の警告が表示されるようになったのは比較的最近のことだと思います。コンテナを再構築した last time にそれらを見たのを覚えています。しかし、最初からあったとは思えません。

「いいね!」 1