?
This document uses PHP Chinese website manual Release
如果libpq已經(jīng)通過LDAP支持(configure的--with-ldap選項)進(jìn)行的編譯, 可以從一個中央服務(wù)器,通過LDAP檢索連接選項,如host或dbname。 這樣做的好處是,如果一個數(shù)據(jù)路連接參數(shù)發(fā)生了改變,在所有客戶端的連接信息不必進(jìn)行改變。
LDAP連接參數(shù)查找使用連接服務(wù)文件pg_service.conf(參閱Section 31.15)。 在pg_service.conf中的以ldap://開始的一行被看做是一個LDAP URL,并且會執(zhí)行一個LDAP查詢。 返回結(jié)果會是一個keyword = value,用于設(shè)置連接選項。URL必須符合RFC 1959,并且是如下形式:
ldap://[hostname[:port]]/search_base?attribute?search_scope?filter
這里localhost和port缺省的hostname缺省為389。
pg_service.conf的處理在LDAP成功查找之后就會被終止,但如果不能成功連接LDAP服務(wù),那么會繼續(xù)。 這是為了進(jìn)一步指向不同的LDAP服務(wù)器的LDAP URL線而提供的一個回滾, 標(biāo)準(zhǔn)的keyword = value格式,或缺省的連接參數(shù)。 如果想在這種情況下獲得一個錯誤信息,可以再LDAP URL后添加一個語法不正確的行。
LDIF文件創(chuàng)建的一個樣本LDAP條目:
version:1 dn:cn=mydatabase,dc=mycompany,dc=com changetype:add objectclass:top objectclass:groupOfUniqueNames cn:mydatabase uniqueMember:host=dbserver.mycompany.com uniqueMember:port=5439 uniqueMember:dbname=mydb uniqueMember:user=mydb_user uniqueMember:sslmode=require
might be queried with the following LDAP URL:
ldap://ldap.mycompany.com/dc=mycompany,dc=com?uniqueMember?one?(cn=mydatabase)
也可以通過LDAP查找來混合日常服務(wù)文件。一個pg_service.conf中完整的一節(jié)的例子如下:
# 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=*)