PostgreSQL 13 업데이트

:warning: 경고! 데이터베이스가 매우 크다면, 상당한 추가 디스크 공간(데이터베이스 크기의 2배)이 필요하며, 이 업그레이드 시 매우 주의해야 합니다!

Docker 이미지를 PostgreSQL 13으로 업그레이드하는 변경 사항이 적용되었습니다. 명령줄에서 Discourse를 다시 빌드하는 사이트 관리자는 이전 PostgreSQL 12에서 PostgreSQL 13으로 업그레이드됩니다. 참고로, 5월에 PostgreSQL 12 업데이트가 실시되었을 때 업그레이드를 보류했다면, 해당 업그레이드를 건너뛰고 바로 PostgreSQL 13으로 진행할 수 있습니다.

이전에 업그레이드를 보류했다면, app.yml의 PostgreSQL 템플릿을 templates/postgres.10.template.yml에서 templates/postgres.template.yml로 변경하십시오.

어떤 업그레이드와 마찬가지로, 작업을 수행하기 전에 백업을 만드는 것이 강력히 권장됩니다.

업데이트

공식 설치 가이드 (단일 컨테이너)

다음 재빌드 시, 끝에 다음과 같은 메시지가 표시됩니다:

-------------------------------------------------------------------------------------
UPGRADE OF POSTGRES COMPLETE

Old 12 database is stored at /shared/postgres_data_old

To complete the upgrade, rebuild again using:

./launcher rebuild app
-------------------------------------------------------------------------------------

이는 업그레이드가 잘 완료되었음을 의미합니다! 사이트를 다시 실행하려면 새로운 재빌드를 수행하기만 하면 됩니다.

데이터 컨테이너 설치

discourse_docker 저장소에 제공된 샘플을 기반으로 한 전용 데이터 컨테이너가 포함된 설정을 사용 중이라면, PostgreSQL을 안전하고 깔끔하게 종료하는 것이 중요합니다.

요즘에는 수 분 동안 실행되는 쿼리를 수행하는 백그라운드 작업이 있으므로, 웹 컨테이너를 종료하면 데이터 컨테이너가 안전하게 종료되는 데 도움이 됩니다.

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

데이터 컨테이너에 대한 첫 번째 재빌드를 수행하기 전에, PostgreSQL 로그를 tail하여 제대로 종료되었는지 확인할 수 있습니다.

tail -f shared/data/log/var-log/postgres/current를 실행하면, 깔끔하게 종료된 경우 다음과 같은 로그가 표시됩니다:

2020-05-13 18:33:33.457 UTC [36] LOG:  received smart shutdown request
2020-05-13 18:33:33.464 UTC [36] LOG:  worker process: logical replication launcher (PID 52) exited with exit code 1
2020-05-13 18:33:33.465 UTC [47] LOG:  shutting down
2020-05-13 18:33:33.479 UTC [36] 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 \
	-v /var/discourse/shared/standalone/postgres_data:/var/lib/postgresql/12/data \
	-v /var/discourse/shared/standalone/postgres_data_new:/var/lib/postgresql/13/data \
	tianon/postgres-upgrade:12-to-13
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
./launcher rebuild app #(또는 해당 환경에 따라 먼저 data를 재빌드한 후 web_only)

제 테스트에서 이 절차는 현재 데이터베이스 크기의 1배 미만의 자유 공간이 필요합니다.

업데이트 보류

다음 재빌드 시 업데이트를 보류해야 하는 경우, app.yml 파일에서 "templates/postgres.template.yml"을 "templates/postgres.12.template.yml"로 변경하여 PostgreSQL 템플릿을 교체할 수 있습니다.

이것은 권장되지 않습니다. 일부 사이트 관리자가 나중에 변경 사항을 되돌리는 것을 잊기 때문입니다.

업데이트 후 선택적 작업

PostgreSQL 통계 최적화

업데이트 후, 새 PostgreSQL에는 테이블 통계가 없습니다. 다음을 사용하여 생성할 수 있습니다:

cd /var/discourse
./launcher enter app
su postgres
psql
\connect discourse
VACUUM VERBOSE ANALYZE;
\q
exit
exit

또는 위의 내용을 한 줄로 작성한 버전:

/var/discourse/launcher run app "echo 'vacuum verbose analyze;' | su postgres -c 'psql discourse'"

인덱스 재작성

이 업그레이드의 주요 기능은 모든 인스턴스에서 가장 큰 테이블인 post_timings 테이블 및 그 인덱스에서 파일 용량을 크게 절감하는 것입니다. 성공적인 업데이트를 수행한 후에는 인덱스를 재빌드하고 이 이점을 누리기 위해 명령을 실행해야 합니다.

cd /var/discourse
./launcher enter app
su postgres
psql
\connect discourse
REINDEX SCHEMA CONCURRENTLY public;
\q
exit
exit

REINDEX 전후의 post_timings 크기를 확인하여 그 차이를 공유해 주시면 멋진 통계가 될 것입니다!

아래 쿼리를 사용하여 20개의 가장 큰 데이터 오브젝트를 확인할 수 있으며, 인덱스 재작성 전후로 실행해 보세요:

WITH RECURSIVE pg_inherit(inhrelid, inhparent) AS
    (select inhrelid, inhparent
    FROM pg_inherits
    UNION
    SELECT child.inhrelid, parent.inhparent
    FROM pg_inherit child, pg_inherits parent
    WHERE child.inhparent = parent.inhrelid),
pg_inherit_short AS (SELECT * FROM pg_inherit WHERE inhparent NOT IN (SELECT inhrelid FROM pg_inherit))
SELECT table_schema
    , TABLE_NAME
    , row_estimate
    , pg_size_pretty(total_bytes) AS total
    , pg_size_pretty(index_bytes) AS INDEX
    , pg_size_pretty(toast_bytes) AS toast
    , pg_size_pretty(table_bytes) AS TABLE
  FROM (
    SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes
    FROM (
         SELECT c.oid
              , nspname AS table_schema
              , relname AS TABLE_NAME
              , SUM(c.reltuples) OVER (partition BY parent) AS row_estimate
              , SUM(pg_total_relation_size(c.oid)) OVER (partition BY parent) AS total_bytes
              , SUM(pg_indexes_size(c.oid)) OVER (partition BY parent) AS index_bytes
              , SUM(pg_total_relation_size(reltoastrelid)) OVER (partition BY parent) AS toast_bytes
              , parent
          FROM (
                SELECT pg_class.oid
                    , reltuples
                    , relname
                    , relnamespace
                    , pg_class.reltoastrelid
                    , COALESCE(inhparent, pg_class.oid) parent
                FROM pg_class
                    LEFT JOIN pg_inherit_short ON inhrelid = oid
                WHERE relkind IN ('r', 'p')
             ) c
             LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
  ) a
  WHERE oid = parent
) a
ORDER BY total_bytes DESC LIMIT 20;

구버전 데이터 정리

표준 설치인 경우, 다음 명령을 사용하여 PG12 형식의 구버전 데이터를 삭제할 수 있습니다:

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/data/log/var-log/postgres/current
2020-05-13 18:33:33.457 UTC [36] LOG:  received smart shutdown request
2020-05-13 18:33:33.464 UTC [36] LOG:  worker process: logical replication launcher (PID 52) exited with exit code 1
2020-05-13 18:33:33.465 UTC [47] LOG:  shutting down
2020-05-13 18:33:33.479 UTC [36] LOG:  database system is shut down

로그가 위와 같다면, 이제 ./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 so,
once you start the new server, consider running:
    ./analyze_new_cluster.sh

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

이 메시지를 안전하게 무시할 수 있습니다.

PostgreSQL 12 업데이트를 건너뛴 경우, 이제 무엇을 해야 합니까?

이 가이드 상단의 표준 지침을 따르시면 문제없이 현재 버전에서 13으로 업그레이드됩니다.

공간이 제한된 지침을 따르고 있는 경우, 버전 번호를 그에 맞게 조정하십시오.

38개의 좋아요
PostgreSQL Details
Discourse 2.7.0.beta2 Release Notes
Forum offline due to failed rebuilds on Tests-Pass
Nginx upstream timed out (110: Connection timed out)
Help! Problem with firewall/permissions and postgre?
PostgreSQL 13 update from PostgreSQL 10 fails
PostgreSQL 13 update from PostgreSQL 10 fails
Unrecognized error type (ActiveRecord::StatementInvalid: PG::ProgramLimitExceeded
Recover from filesystem backup: can't rebuild nor start
Rebuild error: Errno::ENOENT: No such file or directory @ rb_sysopen - /e tc/postgresql/13/main/pg_hba.conf
Discourse broken after upgrade
Upgrade Failed from 2.7.0.beta1 to 2.7.0.beta3
Invalid location error after update
Upgrade failed!
Upgrade failed: PostgreSQL version 13 ... not compatible with ... version 10.12
Improved Bookmarks with Reminders
Importing old database to latest version
Errors encountered when uploading images
What else do I need to take care of when self hosting?
Rebuild freezing when attempting to stop container
Backup failed due to PG/SQL errors
Restore Failing - Check Free Disk Space
Supported postgresql versions
Wrong Error Message for too short replies for Reply-by-Email
Upgrade Postgres with REALLY limited space
Upgrade Postgres with REALLY limited space
Postgres has 100% CPU for large databases, Discourse 2.7.7
Upgrade failing with FAILED TO BOOTSTRAP
Stuck in an update loop after PostgreSQL 13 update
Problem with rebuild Discourse at Docker
After Rebuild got error: postgres:10/main, Causes CPU to go high
Call AdminDashboardGeneralData.refresh_stats at boot?
Database size/maintenance
Failed to upgrade to v2.9.0beta3
Failed to upgrade to v2.9.0beta3
SMTP Settings in app.yml reset?
Upgrade container - keeping config and data
Site down after failed update: permission denied to create extension "unaccent"
Rebuild fails on db:migrate w/PG12
Update from 2.9.0 beta2 to beta4 failed (my site is down)
Performance optimisation tips
Upgrading from 2.4 to 2.9. Need slight assistance on what order to run the final commands & reboot in
Problem when updating Discourse Forum
Troubleshooting severe performance issues with latest Discourse?
Slow Profile Loads with 100GB+ database
Use Nginx Proxy Manager to manage multiple sites with Discourse
Horizontal loading slider
ERROR: You are running an old version of the Discourse image
PostgreSQL 15 update
Got a lot of "Failed to backfill 'Reader' badge" errors
Trouble updating discourse after some time - UPGRADE OF POSTGRES FAILED
Upgrade gone sideways [deprecated Guest Gate plugin]
Upgrading Discourse from 2.6.0.beta2
Upgrade Issues: Failed Upgrade due to Duplicate Key, Failed Snapshot Restore
2.7.0.beta2 upgrade failed with ERROR: duplicate key
Problem, rebuild to latest version
Urgent, upgraded build failed UniqueViolation
Firewall issue with running multiple containers after upgrade