1.停掉容器
cd /home/middle/langfuse/langfuse
docker compose stop
2.建立歸檔檔案存放路徑
需要登入容器建立目錄,歸檔目錄必須在容器裡面建立
docker exec -ti langfuse-db-1 /bin/bash
cd /var/lib/postgresql/data
mkdir archivelog
2.修改pg配置檔案
cd /home/middle/langfuse/pgdata
vi postgresql.conf
wal_level=replica
archive_mode=on
##archive_command = 'DATE=`date +%Y%m%d`;DIR="/home/middle/langfuse/pgdata/archivelog/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f'
archive_command = 'cp %p /var/lib/postgresql/data/archivelog/%f'
發現在pg16裡面不能建立日期目錄
2024-12-03 10:04:46.064 UTC [1326] FATAL: invalid value for parameter "archive_command": "DATE=`date +%Y%m%d`;DIR="/home/middle/langfuse/pgdata/archivelog/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f"
2024-12-03 10:04:46.064 UTC [1326] DETAIL: String contains unexpected placeholder "%Y".
3.啟動容器
docker compose start
4.歸檔切換
psql -h localhost -U postgres -p5432
postgres=# show archive_mode;
archive_mode
--------------
on
(1 row)
postgres=# checkpoint;
CHECKPOINT
select pg_switch_wal();
檢視日誌:
docker logs langfuse-db-1