LoginSignup
3
1

Dify on WSL2の起動時にpostgresがエラーを出力する

Last updated at Posted at 2024-05-08

以下の環境で実行中にエラーがでて、Perplexityでだいぶ調べて解決したのでメモを残しておきます

環境
Windows10, WSL2, Ubuntu 22.4

リポジトリから落としてきて、WSL2のUbuntuを起動して、dockerディレクトリにcdし、以下のコマンドをたたく

sudo docker compose up -d

Difyにアクセスできないので起動状況を見る

sudo docker ps

postgresが起動していないのでインスタンスのログを見る

sudo docker logs <container id>

以下のエラーが発生していることがわかる

Data page checksums are disabled.
initdb: error: could not change permissions of directory "/var/lib/postgresql/data/pgdata": Operation not permitted
fixing permissions on existing directory /var/lib/postgresql/data/pgdata ... chmod: /var/lib/postgresql/data/pgdata: Operation not permitted
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

解決方法
もちろん、権限回りなど調べてわかることはいろいろやったが、権限では治らなかった。chmodは15回はやった。

最初のファイル

docker-compose.yaml
  # The postgres database.
  db:
    image: postgres:15-alpine
    restart: always
    environment:
      PGUSER: xxxx
      # The password for the default postgres user.
      POSTGRES_PASSWORD: xxxxx
      # The name of the default postgres database.
      POSTGRES_DB: dify
      # postgres data directory
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - ./volumes/db/data:/var/lib/postgresql/data:z
    # uncomment to expose db(postgresql) port to host
    # ports:
    #   - "9999:9999"
    healthcheck:
      test: [ "CMD", "pg_isready" ]
      interval: 1s
      timeout: 3s
      retries: 30

修正後

new_docker-compose.yaml
  # The postgres database.
  db:
    image: postgres:15-alpine
    restart: always
    environment:
      PGUSER: xxxx
      # The password for the default postgres user.
      POSTGRES_PASSWORD: xxxx
      # The name of the default postgres database.
      POSTGRES_DB: dify
      # postgres data directory
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - db_data:/var/lib/postgresql/data
    # uncomment to expose db(postgresql) port to host
    # ports:
    #   - "9999:9999"
    healthcheck:
      test: [ "CMD", "pg_isready" ]
      interval: 1s
      timeout: 3s
      retries: 30
# Add volume name
volumes:
  db_data:

要は以下を修正し、

volumes:
  - db_data:/var/lib/postgresql/data

以下を追加した。

# Add volume name
volumes:
  db_data:

これにて起動完了

なお、こういうのもある。私のPerplexity調査では引っかからなかった。素晴らしい
https://qiita.com/noppe78/items/40cff5859cec4e6eb526

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1