支援的版本:目前 (17) / 16 / 15 / 14 / 13
開發版本:開發中
不支援的版本:12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2

32.18. LDAP 查閱連線參數 #

如果 libpq 已編譯進 LDAP 支援(configure--with-ldap 選項),則可以透過 LDAP 從中央伺服器檢索連線選項,例如 hostdbname。優點是,如果資料庫的連線參數變更,則不必在所有用戶端機器上更新連線資訊。

LDAP 連線參數查閱使用連線服務檔案 pg_service.conf(請參閱第 32.17 節)。pg_service.conf 節中以 ldap:// 開頭的行會被識別為 LDAP URL,並且將執行 LDAP 查詢。結果必須是 keyword = value 配對的清單,將用於設定連線選項。URL 必須符合 RFC 1959,且格式如下:

ldap://[hostname[:port]]/search_base?attribute?search_scope?filter

其中 hostname 預設為 localhost,而 port 預設為 389。

在成功的 LDAP 查閱後,會終止 pg_service.conf 的處理,但如果無法聯絡到 LDAP 伺服器,則會繼續處理。這是為了提供使用指向不同 LDAP 伺服器、經典的 keyword = value 配對或預設連線選項的其他 LDAP URL 行的後備方案。如果您希望在這種情況下收到錯誤訊息,請在 LDAP URL 後面新增一個語法不正確的行。

使用 LDIF 檔案建立的範例 LDAP 項目

version:1
dn:cn=mydatabase,dc=mycompany,dc=com
changetype:add
objectclass:top
objectclass:device
cn:mydatabase
description:host=dbserver.mycompany.com
description:port=5439
description:dbname=mydb
description:user=mydb_user
description:sslmode=require

可以使用以下 LDAP URL 查詢

ldap://ldap.mycompany.com/dc=mycompany,dc=com?description?one?(cn=mydatabase)

您還可以將常規服務檔案條目與 LDAP 查閱混合使用。pg_service.conf 中節的完整範例如下:

# only host and port are stored in LDAP, specify dbname and user explicitly
[customerdb]
dbname=customer
user=appuser
ldap://ldap.acme.com/cn=dbserver,cn=hosts?pgconnectinfo?base?(objectclass=*)

提交更正

如果您在文件中發現任何不正確、與您使用特定功能的經驗不符或需要進一步澄清的地方,請使用此表單來報告文件問題。