]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/database-roles.html
WIP: toc builder
[ai-pg] / full-docs / src / sgml / html / database-roles.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>21.1. Database Roles</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="user-manag.html" title="Chapter 21. Database Roles" /><link rel="next" href="role-attributes.html" title="21.2. Role Attributes" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">21.1. Database Roles</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="user-manag.html" title="Chapter 21. Database Roles">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="user-manag.html" title="Chapter 21. Database Roles">Up</a></td><th width="60%" align="center">Chapter 21. Database Roles</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="role-attributes.html" title="21.2. Role Attributes">Next</a></td></tr></table><hr /></div><div class="sect1" id="DATABASE-ROLES"><div class="titlepage"><div><div><h2 class="title" style="clear: both">21.1. Database Roles <a href="#DATABASE-ROLES" class="id_link">#</a></h2></div></div></div><a id="id-1.6.8.5.2" class="indexterm"></a><a id="id-1.6.8.5.3" class="indexterm"></a><a id="id-1.6.8.5.4" class="indexterm"></a><a id="id-1.6.8.5.5" class="indexterm"></a><p>
3    Database roles are conceptually completely separate from
4    operating system users. In practice it might be convenient to
5    maintain a correspondence, but this is not required. Database roles
6    are global across a database cluster installation (and not
7    per individual database). To create a role use the <a class="link" href="sql-createrole.html" title="CREATE ROLE"><code class="command">CREATE ROLE</code></a> SQL command:
8 </p><pre class="synopsis">
9 CREATE ROLE <em class="replaceable"><code>name</code></em>;
10 </pre><p>
11    <em class="replaceable"><code>name</code></em> follows the rules for SQL
12    identifiers: either unadorned without special characters, or
13    double-quoted.  (In practice, you will usually want to add additional
14    options, such as <code class="literal">LOGIN</code>, to the command.  More details appear
15    below.)  To remove an existing role, use the analogous
16    <a class="link" href="sql-droprole.html" title="DROP ROLE"><code class="command">DROP ROLE</code></a> command:
17 </p><pre class="synopsis">
18 DROP ROLE <em class="replaceable"><code>name</code></em>;
19 </pre><p>
20   </p><a id="id-1.6.8.5.7" class="indexterm"></a><a id="id-1.6.8.5.8" class="indexterm"></a><p>
21    For convenience, the programs <a class="xref" href="app-createuser.html" title="createuser"><span class="refentrytitle"><span class="application">createuser</span></span></a>
22    and <a class="xref" href="app-dropuser.html" title="dropuser"><span class="refentrytitle"><span class="application">dropuser</span></span></a> are provided as wrappers
23    around these SQL commands that can be called from the shell command
24    line:
25 </p><pre class="synopsis">
26 createuser <em class="replaceable"><code>name</code></em>
27 dropuser <em class="replaceable"><code>name</code></em>
28 </pre><p>
29   </p><p>
30    To determine the set of existing roles, examine the <code class="structname">pg_roles</code>
31    system catalog, for example:
32 </p><pre class="synopsis">
33 SELECT rolname FROM pg_roles;
34 </pre><p>
35    or to see just those capable of logging in:
36 </p><pre class="synopsis">
37 SELECT rolname FROM pg_roles WHERE rolcanlogin;
38 </pre><p>
39    The <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> program's <code class="literal">\du</code> meta-command
40    is also useful for listing the existing roles.
41   </p><p>
42    In order to bootstrap the database system, a freshly initialized
43    system always contains one predefined login-capable role. This role
44    is always a <span class="quote">“<span class="quote">superuser</span>”</span>, and it will have
45    the same name as the operating system user that initialized the
46    database cluster with <code class="command">initdb</code> unless a different name
47    is specified.  This role is often named
48    <code class="literal">postgres</code>. In order to create more roles you
49    first have to connect as this initial role.
50   </p><p>
51    Every connection to the database server is made using the name of some
52    particular role, and this role determines the initial access privileges for
53    commands issued in that connection.
54    The role name to use for a particular database
55    connection is indicated by the client that is initiating the
56    connection request in an application-specific fashion. For example,
57    the <code class="command">psql</code> program uses the
58    <code class="option">-U</code> command line option to indicate the role to
59    connect as.  Many applications assume the name of the current
60    operating system user by default (including
61    <code class="command">createuser</code> and <code class="command">psql</code>).  Therefore it
62    is often convenient to maintain a naming correspondence between
63    roles and operating system users.
64   </p><p>
65    The set of database roles a given client connection can connect as
66    is determined by the client authentication setup, as explained in
67    <a class="xref" href="client-authentication.html" title="Chapter 20. Client Authentication">Chapter 20</a>. (Thus, a client is not
68    limited to connect as the role matching
69    its operating system user, just as a person's login name
70    need not match his or her real name.)  Since the role
71    identity determines the set of privileges available to a connected
72    client, it is important to carefully configure privileges when setting up
73    a multiuser environment.
74   </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="user-manag.html" title="Chapter 21. Database Roles">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="user-manag.html" title="Chapter 21. Database Roles">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="role-attributes.html" title="21.2. Role Attributes">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 21. Database Roles </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"> 21.2. Role Attributes</td></tr></table></div></body></html>