Editing PostgreSQL: CREATE USER

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
<code>[[create user]]</code>, creates a new user in PostgreSQL
 
* Official documentation: https://www.postgresql.org/docs/current/sql-createuser.html
 
  
 +
* https://www.postgresql.org/docs/13/sql-createuser.html
  
* <code>[[CREATE]] USER "your_username";</code>
+
* <code>create user <username></code>
* <code>CREATE USER your_username WITH ENCRYPTED PASSWORD 'your_pass';</code>
 
* <code>CREATE USER username WITH CREATEUSER;</code>
 
* <code>CREATE USER username WITH CREATEROLE;</code>
 
  
 
+
  create user YOUR_USERNAME;
== Synopsys ==
 
CREATE USER name [ [ WITH ] option [ ... ] ]
 
 
where option can be:
 
 
      SUPERUSER | NOSUPERUSER
 
    | CREATEDB | NOCREATEDB
 
    | CREATEROLE | NOCREATEROLE
 
    | INHERIT | NOINHERIT
 
    | LOGIN | NOLOGIN
 
    | REPLICATION | NOREPLICATION
 
    | BYPASSRLS | NOBYPASSRLS
 
    | CONNECTION LIMIT connlimit
 
    | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
 
    | VALID UNTIL 'timestamp'
 
    | [[IN ROLE]] role_name [, ...]
 
    | [[IN GROUP]] role_name [, ...]
 
    | [[ROLE]] role_name [, ...]
 
    | ADMIN role_name [, ...]
 
    | USER role_name [, ...]
 
    | SYSID uid
 
 
 
 
 
== Examples ==
 
* <code>create user your_username</code>
 
 
 
=== Create a new user ===
 
  create user your_username;
 
Output:
 
[[CREATE ROLE]]
 
 
 
create user your_username;
 
Output:
 
ERROR: [[permission]] denied to create role
 
 
 
=== Create a new user with errors ===
 
create user your.username;
 
Output:
 
ERROR:  syntax error at or near "."
 
 
 
create user your_username;
 
ERROR:  cannot execute [[CREATE ROLE]] in a read-only transaction
 
 
 
=== Create a new user and assign a password ===
 
CREATE USER your_username WITH ENCRYPTED PASSWORD 'your_pass';
 
 
  Output:
 
  Output:
 
  [[CREATE ROLE]]
 
  [[CREATE ROLE]]
  
CREATE USER your_username WITH ENCRYPTED PASSWORD 'your_pass';
 
Output:
 
ERROR:  role "your_username" already exists
 
Solution:
 
[[ALTER USER]] user_name WITH PASSWORD 'new_password';
 
  
Assign a role with <code>[[GRANT]]</code> command:
 
GRANT [[your_defined_role]] TO your_username;
 
Output:
 
[[GRANT ROLE]]
 
  
* [[List users]]: <code>[[\du]]</code>
+
* List users: <code>\du</code>
  
 
== Related terms ==
 
== Related terms ==
* <code>[[GRANT]]</code>
 
 
* [[Create database (PostgreSQL)]]
 
* [[Create database (PostgreSQL)]]
 
* <code>[[ALTER USER]] YOUR_USER WITH PASSWORD 'your_new_password';</code>
 
* <code>[[ALTER USER]] YOUR_USER WITH PASSWORD 'your_new_password';</code>
 
* <code>[[sudo]] -u postgres [[psql]]</code>
 
* <code>[[sudo]] -u postgres [[psql]]</code>
* <code>[[CREATE]]</code>
 
* <code>[[SUPERUSER]]</code>
 
* [[community.postgresql.postgresql_query]]
 
* <code>[[community.postgresql.postgresql_privs]]</code>
 
  
 
== See also ==
 
== See also ==
* {{Role}}
+
* {{PostgreSQL}}
* {{CREATE}}
 
* {{SQL}}
 
  
  
 
[[Category:PostgreSQL]]
 
[[Category:PostgreSQL]]

Please note that all contributions to wikieduonline may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Wikieduonline:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Templates used on this page:

Advertising: