如果 libpq 已編譯支援 LDAP (使用 configure
的
選項),則可以透過 LDAP 從中央伺服器檢索連線選項,例如 --with-ldap
host
或 dbname
。 這樣的好處是,如果資料庫的連線參數發生變更,則無需在所有用戶端機器上更新連線資訊。
LDAP 連線參數查詢使用連線服務檔案 pg_service.conf
(請參閱第 32.17 節)。 以 ldap://
開頭的 pg_service.conf
節中的一行將被識別為 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 伺服器的更多 LDAP URL 行、經典的 keyword = value
鍵值對或預設連線選項。 如果您希望在這種情況下收到錯誤訊息,請在 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
中 stanza 的完整範例為
# 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=*)
如果您在文件中發現任何不正確、與您使用特定功能的經驗不符或需要進一步澄清的地方,請使用此表單回報文件問題。