{
    "mode": "man",
    "parameter": "CREATE_ROLE",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/CREATE_ROLE/7/json",
    "generated": "2026-10-05T15:39:07Z",
    "synopsis": "CREATE ROLE name [ [ WITH ] option [ ... ] ]\nwhere option can be:\nSUPERUSER | NOSUPERUSER\n| CREATEDB | NOCREATEDB\n| CREATEROLE | NOCREATEROLE\n| INHERIT | NOINHERIT\n| LOGIN | NOLOGIN\n| REPLICATION | NOREPLICATION\n| BYPASSRLS | NOBYPASSRLS\n| CONNECTION LIMIT connlimit\n| [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL\n| VALID UNTIL 'timestamp'\n| IN ROLE rolename [, ...]\n| IN GROUP rolename [, ...]\n| ROLE rolename [, ...]\n| ADMIN rolename [, ...]\n| USER rolename [, ...]\n| SYSID uid",
    "sections": {
        "NAME": {
            "content": "CREATEROLE - define a new database role\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "CREATE ROLE name [ [ WITH ] option [ ... ] ]\n\nwhere option can be:\n\nSUPERUSER | NOSUPERUSER\n| CREATEDB | NOCREATEDB\n| CREATEROLE | NOCREATEROLE\n| INHERIT | NOINHERIT\n| LOGIN | NOLOGIN\n| REPLICATION | NOREPLICATION\n| BYPASSRLS | NOBYPASSRLS\n| CONNECTION LIMIT connlimit\n| [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL\n| VALID UNTIL 'timestamp'\n| IN ROLE rolename [, ...]\n| IN GROUP rolename [, ...]\n| ROLE rolename [, ...]\n| ADMIN rolename [, ...]\n| USER rolename [, ...]\n| SYSID uid\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "CREATE ROLE adds a new role to a PostgreSQL database cluster. A role is an entity that can\nown database objects and have database privileges; a role can be considered a “user”, a\n“group”, or both depending on how it is used. Refer to Chapter 22 and Chapter 21 for\ninformation about managing users and authentication. You must have CREATEROLE privilege or be\na database superuser to use this command.\n\nNote that roles are defined at the database cluster level, and so are valid in all databases\nin the cluster.\n\nDuring role creation it is possible to immediately assign the newly created role to be a\nmember of an existing role, and also assign existing roles to be members of the newly created\nrole. The rules for which initial role membership options are enabled are described below in\nthe IN ROLE, ROLE, and ADMIN clauses. The GRANT(7) command has fine-grained option control\nduring membership creation, and the ability to modify these options after the new role is\ncreated.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "name\nThe name of the new role.\n\nSUPERUSER\nNOSUPERUSER\nThese clauses determine whether the new role is a “superuser”, who can override all\naccess restrictions within the database. Superuser status is dangerous and should be used\nonly when really needed. You must yourself be a superuser to create a new superuser. If\nnot specified, NOSUPERUSER is the default.\n\nCREATEDB\nNOCREATEDB\nThese clauses define a role's ability to create databases. If CREATEDB is specified, the\nrole being defined will be allowed to create new databases. Specifying NOCREATEDB will\ndeny a role the ability to create databases. If not specified, NOCREATEDB is the default.\nOnly superuser roles or roles with CREATEDB can specify CREATEDB.\n\nCREATEROLE\nNOCREATEROLE\nThese clauses determine whether a role will be permitted to create, alter, drop, comment\non, and change the security label for other roles. See role creation for more details\nabout what capabilities are conferred by this privilege. If not specified, NOCREATEROLE\nis the default.\n\nINHERIT\nNOINHERIT\nThis affects the membership inheritance status when this role is added as a member of\nanother role, both in this and future commands. Specifically, it controls the inheritance\nstatus of memberships added with this command using the IN ROLE clause, and in later\ncommands using the ROLE clause. It is also used as the default inheritance status when\nadding this role as a member using the GRANT command. If not specified, INHERIT is the\ndefault.\n\nIn PostgreSQL versions before 16, inheritance was a role-level attribute that controlled\nall runtime membership checks for that role.\n\nLOGIN\nNOLOGIN\nThese clauses determine whether a role is allowed to log in; that is, whether the role\ncan be given as the initial session authorization name during client connection. A role\nhaving the LOGIN attribute can be thought of as a user. Roles without this attribute are\nuseful for managing database privileges, but are not users in the usual sense of the\nword. If not specified, NOLOGIN is the default, except when CREATE ROLE is invoked\nthrough its alternative spelling CREATE USER.\n\nREPLICATION\nNOREPLICATION\nThese clauses determine whether a role is a replication role. A role must have this\nattribute (or be a superuser) in order to be able to connect to the server in replication\nmode (physical or logical replication) and in order to be able to create or drop\nreplication slots. A role having the REPLICATION attribute is a very highly privileged\nrole, and should only be used on roles actually used for replication. If not specified,\nNOREPLICATION is the default. Only superuser roles or roles with REPLICATION can specify\nREPLICATION.\n\nBYPASSRLS\nNOBYPASSRLS\nThese clauses determine whether a role bypasses every row-level security (RLS) policy.\nNOBYPASSRLS is the default. Only superuser roles or roles with BYPASSRLS can specify\nBYPASSRLS.\n\nNote that pgdump will set rowsecurity to OFF by default, to ensure all contents of a\ntable are dumped out. If the user running pgdump does not have appropriate permissions,\nan error will be returned. However, superusers and the owner of the table being dumped\nalways bypass RLS.\n\nCONNECTION LIMIT connlimit\nIf role can log in, this specifies how many concurrent connections the role can make. -1\n(the default) means no limit. Note that only normal connections are counted towards this\nlimit. Neither prepared transactions nor background worker connections are counted\ntowards this limit.\n\n[ ENCRYPTED ] PASSWORD 'password'\nPASSWORD NULL\nSets the role's password. (A password is only of use for roles having the LOGIN\nattribute, but you can nonetheless define one for roles without it.) If you do not plan\nto use password authentication you can omit this option. If no password is specified, the\npassword will be set to null and password authentication will always fail for that user.\nA null password can optionally be written explicitly as PASSWORD NULL.\n\nNote\nSpecifying an empty string will also set the password to null, but that was not the\ncase before PostgreSQL version 10. In earlier versions, an empty string could be\nused, or not, depending on the authentication method and the exact version, and libpq\nwould refuse to use it in any case. To avoid the ambiguity, specifying an empty\nstring should be avoided.\nThe password is always stored encrypted in the system catalogs. The ENCRYPTED keyword has\nno effect, but is accepted for backwards compatibility. The method of encryption is\ndetermined by the configuration parameter passwordencryption. If the presented password\nstring is already in MD5-encrypted or SCRAM-encrypted format, then it is stored as-is\nregardless of passwordencryption (since the system cannot decrypt the specified\nencrypted password string, to encrypt it in a different format). This allows reloading of\nencrypted passwords during dump/restore.\n\nVALID UNTIL 'timestamp'\nThe VALID UNTIL clause sets a date and time after which the role's password is no longer\nvalid. If this clause is omitted the password will be valid for all time.\n\nIN ROLE rolename\nThe IN ROLE clause causes the new role to be automatically added as a member of the\nspecified existing roles. The new membership will have the SET option enabled and the\nADMIN option disabled. The INHERIT option will be enabled unless the NOINHERIT option is\nspecified.\n\nIN GROUP rolename\nIN GROUP is an obsolete spelling of IN ROLE.\n\nROLE rolename\nThe ROLE clause causes one or more specified existing roles to be automatically added as\nmembers, with the SET option enabled. This in effect makes the new role a “group”. Roles\nnamed in this clause with the role-level INHERIT attribute will have the INHERIT option\nenabled in the new membership. New memberships will have the ADMIN option disabled.\n\nADMIN rolename\nThe ADMIN clause has the same effect as ROLE, but the named roles are added as members of\nthe new role with ADMIN enabled, giving them the right to grant membership in the new\nrole to others.\n\nUSER rolename\nThe USER clause is an obsolete spelling of the ROLE clause.\n\nSYSID uid\nThe SYSID clause is ignored, but is accepted for backwards compatibility.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Use ALTER ROLE to change the attributes of a role, and DROP ROLE to remove a role. All the\nattributes specified by CREATE ROLE can be modified by later ALTER ROLE commands.\n\nThe preferred way to add and remove members of roles that are being used as groups is to use\nGRANT and REVOKE.\n\nThe VALID UNTIL clause defines an expiration time for a password only, not for the role per\nse. In particular, the expiration time is not enforced when logging in using a\nnon-password-based authentication method.\n\nThe role attributes defined here are non-inheritable, i.e., being a member of a role with,\ne.g., CREATEDB will not allow the member to create new databases even if the membership grant\nhas the INHERIT option. Of course, if the membership grant has the SET option the member role\nwould be able to SET ROLE to the createdb role and then create a new database.\n\nThe membership grants created by the IN ROLE, ROLE, and ADMIN clauses have the role executing\nthis command as the grantor.\n\nThe INHERIT attribute is the default for reasons of backwards compatibility: in prior\nreleases of PostgreSQL, users always had access to all privileges of groups they were members\nof. However, NOINHERIT provides a closer match to the semantics specified in the SQL\nstandard.\n\nPostgreSQL includes a program createuser(1) that has the same functionality as CREATE ROLE\n(in fact, it calls this command) but can be run from the command shell.\n\nThe CONNECTION LIMIT option is only enforced approximately; if two new sessions start at\nabout the same time when just one connection “slot” remains for the role, it is possible that\nboth will fail. Also, the limit is never enforced for superusers.\n\nCaution must be exercised when specifying an unencrypted password with this command. The\npassword will be transmitted to the server in cleartext, and it might also be logged in the\nclient's command history or the server log. The command createuser(1), however, transmits the\npassword encrypted. Also, psql(1) contains a command \\password that can be used to safely\nchange the password later.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Create a role that can log in, but don't give it a password:\n\nCREATE ROLE jonathan LOGIN;\n\nCreate a role with a password:\n\nCREATE USER davide WITH PASSWORD 'jw8s0F4';\n\n(CREATE USER is the same as CREATE ROLE except that it implies LOGIN.)\n\nCreate a role with a password that is valid until the end of 2004. After one second has\nticked in 2005, the password is no longer valid.\n\nCREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';\n\nCreate a role that can create databases and manage roles:\n\nCREATE ROLE admin WITH CREATEDB CREATEROLE;\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "The CREATE ROLE statement is in the SQL standard, but the standard only requires the syntax\n\nCREATE ROLE name [ WITH ADMIN rolename ]\n\nMultiple initial administrators, and all the other options of CREATE ROLE, are PostgreSQL\nextensions.\n\nThe SQL standard defines the concepts of users and roles, but it regards them as distinct\nconcepts and leaves all commands defining users to be specified by each database\nimplementation. In PostgreSQL we have chosen to unify users and roles into a single kind of\nentity. Roles therefore have many more optional attributes than they do in the standard.\n\nThe behavior specified by the SQL standard is most closely approximated creating SQL-standard\nusers as PostgreSQL roles with the NOINHERIT option, and SQL-standard roles as PostgreSQL\nroles with the INHERIT option.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "SET ROLE (SETROLE(7)), ALTER ROLE (ALTERROLE(7)), DROP ROLE (DROPROLE(7)), GRANT(7),\nREVOKE(7), createuser(1), createroleselfgrant\n\nPostgreSQL 16.14                                2026                                  CREATE ROLE(7)",
            "subsections": []
        }
    },
    "summary": "CREATEROLE - define a new database role",
    "flags": [],
    "examples": [
        "Create a role that can log in, but don't give it a password:",
        "CREATE ROLE jonathan LOGIN;",
        "Create a role with a password:",
        "CREATE USER davide WITH PASSWORD 'jw8s0F4';",
        "(CREATE USER is the same as CREATE ROLE except that it implies LOGIN.)",
        "Create a role with a password that is valid until the end of 2004. After one second has",
        "ticked in 2005, the password is no longer valid.",
        "CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01';",
        "Create a role that can create databases and manage roles:",
        "CREATE ROLE admin WITH CREATEDB CREATEROLE;"
    ],
    "see_also": [
        {
            "name": "SETROLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/SETROLE/7/json"
        },
        {
            "name": "ALTERROLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ALTERROLE/7/json"
        },
        {
            "name": "DROPROLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPROLE/7/json"
        },
        {
            "name": "GRANT",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/GRANT/7/json"
        },
        {
            "name": "REVOKE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/REVOKE/7/json"
        },
        {
            "name": "createuser",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/createuser/1/json"
        },
        {
            "name": "ROLE",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ROLE/7/json"
        }
    ]
}