連至 PostgreSQL 資料庫的 localhost 連線不會使用 TLS。若要啟用 TLS,您可以使用 OpenSSL 產生您自己的自我簽署憑證,或者提供您自己的憑證。

  • 若要使用 OpenSSL 產生自我簽署憑證,請執行下列命令:
    openssl req -new -text -out cert.req
     openssl rsa -in privkey.pem -out cert.pem
     openssl req -x509 -in cert.req -text -key cert.pem -out cert.cert
  • 若要提供您自己的憑證,請完成下列步驟:
    • CAcerts.crt 檔案的擁有權修改為 postgres
    • 編輯 postgresql.conf 檔案以包含指令 ssl_ca_file = 'CAcerts.crt

      如果您使用有 CA 鏈結的憑證,則必須將包含中繼和根 CA 憑證的 CAcerts.crt 檔案新增到相同目錄中。