Skip to content
On this page

資料庫設置

PostgreSQL

安裝

執行 apt install postgresql 安裝 postgres 資料庫,並執行 apt install libpq-dev 安裝 libpq ,往後編譯時才能鏈接到。

設定

  1. 設定 postgres 用戶的密碼
sh
sudo -iu postgres                             # 轉換成 postgres 使用者。
psql                                          # 進入 postgresql 的客戶端
> ALTER USER postgres PASSWORD 'mypassword';  # 設定 postgres 用戶的密碼
  1. 修改 carbonbond.toml 或 carbonbond.dev.toml [database] 的 password 欄位

  2. 將 postgres 用戶的登入方式改為使用密碼

sh
sudo vim  /etc/postgresql/<postgresql版本>/main/pg_hba.conf
# 將
# local all postgres peer
# 改為
# local all postgres md5 
  1. 啟動/重啟 postgresql
sh
sudo service postgresql restart

資料庫遷移

第一次使用,執行以下指令以創建資料庫及表格

cargo run --bin prepare --features=prepare -- -m

後續遷移資料庫時可執行

cargo run --bin prepare --features=prepare -- -cm

redis

sudo apt install redis
sudo service redis-server start