<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >CREATE USER</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 8.0.11 Documentation" HREF="index.html"><LINK REL="UP" TITLE="SQL Commands" HREF="sql-commands.html"><LINK REL="PREVIOUS" TITLE="CREATE TYPE" HREF="sql-createtype.html"><LINK REL="NEXT" TITLE="CREATE VIEW" HREF="sql-createview.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"><META NAME="creation" CONTENT="2007-02-02T03:57:22"></HEAD ><BODY CLASS="REFENTRY" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" >PostgreSQL 8.0.11 Documentation</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="sql-createtype.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="sql-createtype.html" >Fast Backward</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="sql-createview.html" >Fast Forward</A ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="sql-createview.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="SQL-CREATEUSER" ></A >CREATE USER</H1 ><DIV CLASS="REFNAMEDIV" ><A NAME="AEN41407" ></A ><H2 >Name</H2 >CREATE USER -- define a new database user account</DIV ><A NAME="AEN41410" ></A ><DIV CLASS="REFSYNOPSISDIV" ><A NAME="AEN41412" ></A ><H2 >Synopsis</H2 ><PRE CLASS="SYNOPSIS" >CREATE USER <TT CLASS="REPLACEABLE" ><I >name</I ></TT > [ [ WITH ] <TT CLASS="REPLACEABLE" ><I >option</I ></TT > [ ... ] ] where <TT CLASS="REPLACEABLE" ><I >option</I ></TT > can be: SYSID <TT CLASS="REPLACEABLE" ><I >uid</I ></TT > | CREATEDB | NOCREATEDB | CREATEUSER | NOCREATEUSER | IN GROUP <TT CLASS="REPLACEABLE" ><I >groupname</I ></TT > [, ...] | [ ENCRYPTED | UNENCRYPTED ] PASSWORD '<TT CLASS="REPLACEABLE" ><I >password</I ></TT >' | VALID UNTIL '<TT CLASS="REPLACEABLE" ><I >abstime</I ></TT >' </PRE ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN41421" ></A ><H2 >Description</H2 ><P > <TT CLASS="COMMAND" >CREATE USER</TT > adds a new user to a <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > database cluster. Refer to <A HREF="user-manag.html" >Chapter 17</A > and <A HREF="client-authentication.html" >Chapter 19</A > for information about managing users and authentication. You must be a database superuser to use this command. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN41428" ></A ><H2 >Parameters</H2 ><P ></P ><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="REPLACEABLE" ><I >name</I ></TT ></DT ><DD ><P > The name of the new user. </P ></DD ><DT ><TT CLASS="REPLACEABLE" ><I >uid</I ></TT ></DT ><DD ><P > The <TT CLASS="LITERAL" >SYSID</TT > clause can be used to choose the <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > user ID of the new user. This is normally not necessary, but may be useful if you need to recreate the owner of an orphaned object. </P ><P > If this is not specified, the highest assigned user ID plus one (with a minimum of 100) will be used as default. </P ></DD ><DT ><TT CLASS="LITERAL" >CREATEDB</TT ><BR><TT CLASS="LITERAL" >NOCREATEDB</TT ></DT ><DD ><P > These clauses define a user's ability to create databases. If <TT CLASS="LITERAL" >CREATEDB</TT > is specified, the user being defined will be allowed to create his own databases. Using <TT CLASS="LITERAL" >NOCREATEDB</TT > will deny a user the ability to create databases. If not specified, <TT CLASS="LITERAL" >NOCREATEDB</TT > is the default. </P ></DD ><DT ><TT CLASS="LITERAL" >CREATEUSER</TT ><BR><TT CLASS="LITERAL" >NOCREATEUSER</TT ></DT ><DD ><P > These clauses determine whether a user will be permitted to create new users himself. <TT CLASS="LITERAL" >CREATEUSER</TT > will also make the user a superuser, who can override all access restrictions. If not specified, <TT CLASS="LITERAL" >NOCREATEUSER</TT > is the default. </P ></DD ><DT ><TT CLASS="REPLACEABLE" ><I >groupname</I ></TT ></DT ><DD ><P > A name of an existing group into which to insert the user as a new member. Multiple group names may be listed. </P ></DD ><DT ><TT CLASS="REPLACEABLE" ><I >password</I ></TT ></DT ><DD ><P > Sets the user's password. If you do not plan to use password authentication you can omit this option, but then the user won't be able to connect if you decide to switch to password authentication. The password can be set or changed later, using <A HREF="sql-alteruser.html" ><I >ALTER USER</I ></A >. </P ></DD ><DT ><TT CLASS="LITERAL" >ENCRYPTED</TT ><BR><TT CLASS="LITERAL" >UNENCRYPTED</TT ></DT ><DD ><P > These key words control whether the password is stored encrypted in the system catalogs. (If neither is specified, the default behavior is determined by the configuration parameter <A HREF="runtime-config.html#GUC-PASSWORD-ENCRYPTION" >password_encryption</A >.) If the presented password string is already in MD5-encrypted format, then it is stored encrypted as-is, regardless of whether <TT CLASS="LITERAL" >ENCRYPTED</TT > or <TT CLASS="LITERAL" >UNENCRYPTED</TT > is specified (since the system cannot decrypt the specified encrypted password string). This allows reloading of encrypted passwords during dump/restore. </P ><P > Note that older clients may lack support for the MD5 authentication mechanism that is needed to work with passwords that are stored encrypted. </P ></DD ><DT ><TT CLASS="REPLACEABLE" ><I >abstime</I ></TT ></DT ><DD ><P > The <TT CLASS="LITERAL" >VALID UNTIL</TT > clause sets an absolute time after which the user's password is no longer valid. If this clause is omitted the password will be valid for all time. </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN41491" ></A ><H2 >Notes</H2 ><P > Use <A HREF="sql-alteruser.html" ><I >ALTER USER</I ></A > to change the attributes of a user, and <A HREF="sql-dropuser.html" ><I >DROP USER</I ></A > to remove a user. Use <A HREF="sql-altergroup.html" ><I >ALTER GROUP</I ></A > to add the user to groups or remove the user from groups. </P ><P > <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > includes a program <A HREF="app-createuser.html" ><I ><I >createuser</I ></I ></A > that has the same functionality as <TT CLASS="COMMAND" >CREATE USER</TT > (in fact, it calls this command) but can be run from the command shell. </P ><P > The <TT CLASS="LITERAL" >VALID UNTIL</TT > clause defines an expiration time for a password only, not for the user account <I CLASS="FOREIGNPHRASE" >per se</I >. In particular, the expiration time is not enforced when logging in using a non-password-based authentication method. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN41504" ></A ><H2 >Examples</H2 ><P > Create a user with no password: </P><PRE CLASS="PROGRAMLISTING" >CREATE USER jonathan;</PRE ><P> </P ><P > Create a user with a password: </P><PRE CLASS="PROGRAMLISTING" >CREATE USER davide WITH PASSWORD 'jw8s0F4';</PRE ><P> </P ><P > Create a user with a password that is valid until the end of 2004. After one second has ticked in 2005, the password is no longer valid. </P><PRE CLASS="PROGRAMLISTING" >CREATE USER miriam WITH PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';</PRE ><P> </P ><P > Create an account where the user can create databases: </P><PRE CLASS="PROGRAMLISTING" >CREATE USER manuel WITH PASSWORD 'jw8s0F4' CREATEDB;</PRE ><P> </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN41514" ></A ><H2 >Compatibility</H2 ><P > The <TT CLASS="COMMAND" >CREATE USER</TT > statement is a <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > extension. The SQL standard leaves the definition of users to the implementation. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN41519" ></A ><H2 >See Also</H2 ><A HREF="sql-alteruser.html" ><I >ALTER USER</I ></A >, <A HREF="sql-dropuser.html" ><I >DROP USER</I ></A >, <A HREF="app-createuser.html" ><SPAN CLASS="APPLICATION" >createuser</SPAN ></A ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="sql-createtype.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="sql-createview.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >CREATE TYPE</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="sql-commands.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >CREATE VIEW</TD ></TR ></TABLE ></DIV ></BODY ></HTML >