PostgreSQL 모든 데이터베이스 COLLATION 갱신하기
프로덕션 데이터베이스에서는 사용하지 마세요. 개인 개발용으로 굴리는 PostgreSQL 데이터베이스를 위한 명령어입니다.
PostgreSQL DBMS의 버전을 올리고 나면, DB 접속때 아래와 같은 오류가 발생할 경우가 있습니다.
WARNING: database "gnucash" has a collation version mismatch
DETAIL: The database was created using collation version 2.38, but the operating system provides version 2.39.
HINT: Rebuild all objects in this database that use the default collation and run ALTER DATABASE gnucash REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.아래와 같은 shell one-liner를 사용하면 DBMS에 존재하는 모든 데이터베이스에 대해 COLLATION 갱신을 할 수 있습니다.
sudo -u postgres psql -A -t -c 'SELECT datname FROM pg_database' | xargs -I{} sudo -u postgres psql -c 'ALTER DATABASE {} REFRESH COLLATION VERSION'