]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/libpq-ldap.html
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / html / libpq-ldap.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>32.18. LDAP Lookup of Connection Parameters</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="libpq-pgservice.html" title="32.17. The Connection Service File" /><link rel="next" href="libpq-ssl.html" title="32.19. SSL Support" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">32.18. LDAP Lookup of Connection Parameters</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="libpq-pgservice.html" title="32.17. The Connection Service File">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="libpq.html" title="Chapter 32. libpq — C Library">Up</a></td><th width="60%" align="center">Chapter 32. <span class="application">libpq</span> — C Library</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="libpq-ssl.html" title="32.19. SSL Support">Next</a></td></tr></table><hr /></div><div class="sect1" id="LIBPQ-LDAP"><div class="titlepage"><div><div><h2 class="title" style="clear: both">32.18. LDAP Lookup of Connection Parameters <a href="#LIBPQ-LDAP" class="id_link">#</a></h2></div></div></div><a id="id-1.7.3.25.2" class="indexterm"></a><p>
3    If <span class="application">libpq</span> has been compiled with LDAP support (option
4    <code class="literal"><code class="option">--with-ldap</code></code> for <code class="command">configure</code>)
5    it is possible to retrieve connection options like <code class="literal">host</code>
6    or <code class="literal">dbname</code> via LDAP from a central server.
7    The advantage is that if the connection parameters for a database change,
8    the connection information doesn't have to be updated on all client machines.
9   </p><p>
10    LDAP connection parameter lookup uses the connection service file
11    <code class="filename">pg_service.conf</code> (see <a class="xref" href="libpq-pgservice.html" title="32.17. The Connection Service File">Section 32.17</a>).  A line in a
12    <code class="filename">pg_service.conf</code> stanza that starts with
13    <code class="literal">ldap://</code> will be recognized as an LDAP URL and an
14    LDAP query will be performed. The result must be a list of
15    <code class="literal">keyword = value</code> pairs which will be used to set
16    connection options.  The URL must conform to
17    <a class="ulink" href="https://datatracker.ietf.org/doc/html/rfc1959" target="_top">RFC 1959</a>
18    and be of the form
19 </p><pre class="synopsis">
20 ldap://[<em class="replaceable"><code>hostname</code></em>[:<em class="replaceable"><code>port</code></em>]]/<em class="replaceable"><code>search_base</code></em>?<em class="replaceable"><code>attribute</code></em>?<em class="replaceable"><code>search_scope</code></em>?<em class="replaceable"><code>filter</code></em>
21 </pre><p>
22    where <em class="replaceable"><code>hostname</code></em> defaults to
23    <code class="literal">localhost</code> and <em class="replaceable"><code>port</code></em>
24    defaults to 389.
25   </p><p>
26    Processing of <code class="filename">pg_service.conf</code> is terminated after
27    a successful LDAP lookup, but is continued if the LDAP server cannot
28    be contacted.  This is to provide a fallback with further LDAP URL
29    lines that point to different LDAP servers, classical <code class="literal">keyword
30    = value</code> pairs, or default connection options.  If you would
31    rather get an error message in this case, add a syntactically incorrect
32    line after the LDAP URL.
33   </p><p>
34    A sample LDAP entry that has been created with the LDIF file
35 </p><pre class="programlisting">
36 version:1
37 dn:cn=mydatabase,dc=mycompany,dc=com
38 changetype:add
39 objectclass:top
40 objectclass:device
41 cn:mydatabase
42 description:host=dbserver.mycompany.com
43 description:port=5439
44 description:dbname=mydb
45 description:user=mydb_user
46 description:sslmode=require
47 </pre><p>
48    might be queried with the following LDAP URL:
49 </p><pre class="programlisting">
50 ldap://ldap.mycompany.com/dc=mycompany,dc=com?description?one?(cn=mydatabase)
51 </pre><p>
52   </p><p>
53    You can also mix regular service file entries with LDAP lookups.
54    A complete example for a stanza in <code class="filename">pg_service.conf</code>
55    would be:
56 </p><pre class="programlisting">
57 # only host and port are stored in LDAP, specify dbname and user explicitly
58 [customerdb]
59 dbname=customer
60 user=appuser
61 ldap://ldap.acme.com/cn=dbserver,cn=hosts?pgconnectinfo?base?(objectclass=*)
62 </pre><p>
63   </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="libpq-pgservice.html" title="32.17. The Connection Service File">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="libpq.html" title="Chapter 32. libpq — C Library">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="libpq-ssl.html" title="32.19. SSL Support">Next</a></td></tr><tr><td width="40%" align="left" valign="top">32.17. The Connection Service File </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 32.19. SSL Support</td></tr></table></div></body></html>