{
    "content": [
        {
            "type": "text",
            "text": "# CREATE_ROLE (man)\n\n## NAME\n\nCREATEROLE - define a new database role\n\n## SYNOPSIS\n\nCREATE 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\n\n## DESCRIPTION\n\nCREATE 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\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "CREATE_ROLE",
        "section": "",
        "mode": "man",
        "summary": "CREATEROLE - define a new database role",
        "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",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "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"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 116,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 42,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 15,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            }
        ],
        "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",
                "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.\n\nCREATEROLE\nNOCREATEROLE\nThese clauses determine whether a role will be permitted to create, alter, drop, comment\non, change the security label for, and grant or revoke membership in other roles. See\nrole creation for more details about what capabilities are conferred by this privilege.\nIf not specified, NOCREATEROLE is the default.\n\nINHERIT\nNOINHERIT\nThese clauses determine whether a role “inherits” the privileges of roles it is a member\nof. A role with the INHERIT attribute can automatically use whatever database privileges\nhave been granted to all roles it is directly or indirectly a member of. Without INHERIT,\nmembership in another role only grants the ability to SET ROLE to that other role; the\nprivileges of the other role are only available after having done so. If not specified,\nINHERIT is the default.\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. You must be a superuser to create a new role having the\nREPLICATION attribute.\n\nBYPASSRLS\nNOBYPASSRLS\nThese clauses determine whether a role bypasses every row-level security (RLS) policy.\nNOBYPASSRLS is the default. You must be a superuser to create a new role having the\nBYPASSRLS attribute.\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 lists one or more existing roles to which the new role will be\nimmediately added as a new member. (Note that there is no option to add the new role as\nan administrator; use a separate GRANT command to do that.)\n\nIN GROUP rolename\nIN GROUP is an obsolete spelling of IN ROLE.\n\nROLE rolename\nThe ROLE clause lists one or more existing roles which are automatically added as members\nof the new role. (This in effect makes the new role a “group”.)\n\nADMIN rolename\nThe ADMIN clause is like ROLE, but the named roles are added to the new role WITH ADMIN\nOPTION, giving them the right to grant membership in this role 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 INHERIT attribute governs inheritance of grantable privileges (that is, access privileges\nfor database objects and role memberships). It does not apply to the special role attributes\nset by CREATE ROLE and ALTER ROLE. For example, being a member of a role with CREATEDB\nprivilege does not immediately grant the ability to create databases, even if INHERIT is set;\nit would be necessary to become that role via SET ROLE before creating a database.\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\nBe careful with the CREATEROLE privilege. There is no concept of inheritance for the\nprivileges of a CREATEROLE-role. That means that even if a role does not have a certain\nprivilege but is allowed to create other roles, it can easily create another role with\ndifferent privileges than its own (except for creating roles with superuser privileges). For\nexample, if the role “user” has the CREATEROLE privilege but not the CREATEDB privilege,\nnonetheless it can create a new role with the CREATEDB privilege. Therefore, regard roles\nthat have the CREATEROLE privilege as almost-superuser-roles.\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 by giving users the\nNOINHERIT attribute, while roles are given the INHERIT attribute.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "SET ROLE (SETROLE(7)), ALTER ROLE (ALTERROLE(7)), DROP ROLE (DROPROLE(7)), GRANT(7),\nREVOKE(7), createuser(1)\n\n\n\nPostgreSQL 14.23                                2026                                  CREATE ROLE(7)",
                "subsections": []
            }
        }
    }
}