{"Entry":{"collection":"sql","key":"drop-role","name":"DROP ROLE","aliases":["droprole"],"metadata":{"aliases":["droprole"],"changed_in":["8.2"],"changes":[{"from":"8.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"8.1"},{"from":"8.1","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","parameters"],"removed":[]},"status":"changed","synopsis":{"added":["DROP ROLE [ IF EXISTS ] name [, ...]"],"removed":[]},"to":"8.2"},{"from":"9.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"9.1"},{"from":"9.5","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"9.6"},{"from":"13","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"14"},{"from":"15","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"16"},{"from":"16","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"17"}],"content_hash":"cf12a9229f6b75d02e1d09e4da4211b0e88a810e23ae1752970d6dfe5dede8ef","editorial":{},"first_version":"8.1","group":"role","imported_at":"2026-09-30T17:43:38.252165+08:00","last_version":"20","name":"DROP ROLE","object":"ROLE","position":5014,"present_in":["8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"remove a database role","purpose_zh":"","related":["create-role","alter-role","set-role"],"slug":"drop-role","source_rev":"a709ab85","synopsis":"DROP ROLE [ IF EXISTS ] name [, ...]","verb":"DROP"}},"Definition":{"Collection":"sql","Key":"drop-role","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"drop-role","SourceRevision":"a709ab85","Facts":{"anchor":"SQL-DROPROLE","file":"sql-droprole.html","lang":"en","name":"DROP ROLE","purpose":"remove a database role","purpose_zh":"","related":["create-role","alter-role","set-role"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eDROP ROLE\u003c/code\u003e removes the specified role(s). To drop a superuser role, you must be a superuser yourself; to drop non-superuser roles, you must have \u003ccode class=\"literal\"\u003eCREATEROLE\u003c/code\u003e privilege and have been granted \u003ccode class=\"literal\"\u003eADMIN OPTION\u003c/code\u003e on the role.\u003c/p\u003e\u003cp\u003eA role cannot be removed if it is still referenced in any database of the cluster; an error will be raised if so. Before dropping the role, you must drop all the objects it owns (or reassign their ownership) and revoke any privileges the role has been granted on other objects. The \u003ca href=\"/docs/18/sql-reassign-owned.html\" title=\"REASSIGN OWNED\"\u003e\u003ccode class=\"command\"\u003eREASSIGN OWNED\u003c/code\u003e\u003c/a\u003e and \u003ca href=\"/docs/18/sql-drop-owned.html\" title=\"DROP OWNED\"\u003e\u003ccode class=\"command\"\u003eDROP OWNED\u003c/code\u003e\u003c/a\u003e commands can be useful for this purpose; see \u003ca href=\"/docs/18/role-removal.html\" title=\"21.4. Dropping Roles\"\u003eSection 21.4\u003c/a\u003e for more discussion.\u003c/p\u003e\u003cp\u003eHowever, it is not necessary to remove role memberships involving the role; \u003ccode class=\"command\"\u003eDROP ROLE\u003c/code\u003e automatically revokes any memberships of the target role in other roles, and of other roles in the target role. The other roles are not dropped nor otherwise affected.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eIF EXISTS\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eDo not throw an error if the role does not exist. A notice is issued in this case.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of the role to remove.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003e\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e includes a program \u003ca href=\"/docs/18/app-dropuser.html\" title=\"dropuser\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003edropuser\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e that has the same functionality as this command (in fact, it calls this command) but can be run from the command shell.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eTo drop a role:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eDROP ROLE jonathan;\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThe SQL standard defines \u003ccode class=\"command\"\u003eDROP ROLE\u003c/code\u003e, but it allows only one role to be dropped at a time, and it specifies different privilege requirements than \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e uses.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-role/?v=18\" title=\"CREATE ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE ROLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/alter-role/?v=18\" title=\"ALTER ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER ROLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/set-role/?v=18\" title=\"SET ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eSET ROLE\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"DROP ROLE [ IF EXISTS ] \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e [, ...]","synopsis_text":"DROP ROLE [ IF EXISTS ] name [, ...]"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"drop-role","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"DROP ROLE","Summary":"移除一个数据库角色","BodyHTML":"\u003cpre\u003eDROP ROLE [ IF EXISTS ] name [, ...]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eDROP ROLE\u003c/code\u003e移除指定的角色。要删除超级用户角色，你自己也必须是超级用户；要删除非超级用户角色，你必须拥有\u003ccode\u003eCREATEROLE\u003c/code\u003e权限，并且已被授予该角色上的\u003ccode\u003eADMIN OPTION\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e如果某角色仍在该集簇的任何数据库中被引用，则不能移除该角色；若是如此将引发错误。在删除该角色之前，你必须删除它拥有的所有对象（或者重新分配这些对象的拥有关系），并撤销该角色在其他对象上被授予的任何权限。\u003ca href=\"/docs/18/sql-reassign-owned.html\" title=\"REASSIGN OWNED\" rel=\"nofollow\"\u003e\u003ccode\u003eREASSIGN OWNED\u003c/code\u003e\u003c/a\u003e 和\u003ca href=\"/docs/18/sql-drop-owned.html\" title=\"DROP OWNED\" rel=\"nofollow\"\u003e\u003ccode\u003eDROP OWNED\u003c/code\u003e\u003c/a\u003e 命令可用于此目的；更详细的讨论见\u003ca href=\"/docs/18/role-removal.html\" rel=\"nofollow\"\u003e第 21.4 节\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e不过，不必手工移除与该角色相关的角色成员资格；\u003ccode\u003eDROP ROLE\u003c/code\u003e会自动撤销目标角色在其他角色中的任何成员资格，以及其他角色在目标角色中的任何成员资格。其他角色不会被删除，也不会受到影响。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eIF EXISTS\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e如果该角色不存在，则不要抛出错误。这种情况下会发出一个提示。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e要移除的角色名称。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e\u003cspan\u003ePostgreSQL\u003c/span\u003e包含一个程序\u003ca href=\"/docs/18/app-dropuser.html\" title=\"dropuser\" rel=\"nofollow\"\u003e\u003cspan\u003e\u003cspan\u003edropuser\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e，它与此命令具有相同功能（实际上它就是调用此命令），但可以从命令 shell 中运行。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e删除一个角色：\u003c/p\u003e\u003cpre\u003eDROP ROLE jonathan;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003eSQL 标准定义了\u003ccode\u003eDROP ROLE\u003c/code\u003e，但它一次只允许删除一个角色，并且规定的权限要求也不同于\u003cspan\u003ePostgreSQL\u003c/span\u003e。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/create-role/?v=18\" title=\"CREATE ROLE\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE ROLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/alter-role/?v=18\" title=\"ALTER ROLE\" rel=\"nofollow\"\u003e\u003cspan\u003eALTER ROLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/set-role/?v=18\" title=\"SET ROLE\" rel=\"nofollow\"\u003e\u003cspan\u003eSET ROLE\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"1b5ca64c","ContentHash":"77a576df1b0684b63be90b87372d747655f52fd553e77384489897ecaf852c2b","Payload":{"purpose_zh":"移除一个数据库角色","sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eDROP ROLE\u003c/code\u003e移除指定的角色。要删除超级用户角色，你自己也必须是超级用户；要删除非超级用户角色，你必须拥有\u003ccode class=\"literal\"\u003eCREATEROLE\u003c/code\u003e权限，并且已被授予该角色上的\u003ccode class=\"literal\"\u003eADMIN OPTION\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e如果某角色仍在该集簇的任何数据库中被引用，则不能移除该角色；若是如此将引发错误。在删除该角色之前，你必须删除它拥有的所有对象（或者重新分配这些对象的拥有关系），并撤销该角色在其他对象上被授予的任何权限。\u003ca href=\"/docs/18/sql-reassign-owned.html\" title=\"REASSIGN OWNED\"\u003e\u003ccode class=\"command\"\u003eREASSIGN OWNED\u003c/code\u003e\u003c/a\u003e 和\u003ca href=\"/docs/18/sql-drop-owned.html\" title=\"DROP OWNED\"\u003e\u003ccode class=\"command\"\u003eDROP OWNED\u003c/code\u003e\u003c/a\u003e 命令可用于此目的；更详细的讨论见\u003ca href=\"/docs/18/role-removal.html\" title=\"21.4. 删除角色\"\u003e第 21.4 节\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e不过，不必手工移除与该角色相关的角色成员资格；\u003ccode class=\"command\"\u003eDROP ROLE\u003c/code\u003e会自动撤销目标角色在其他角色中的任何成员资格，以及其他角色在目标角色中的任何成员资格。其他角色不会被删除，也不会受到影响。\u003c/p\u003e","key":"description","title":"描述"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eIF EXISTS\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e如果该角色不存在，则不要抛出错误。这种情况下会发出一个提示。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e要移除的角色名称。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"参数"},{"html":"\u003cp\u003e\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e包含一个程序\u003ca href=\"/docs/18/app-dropuser.html\" title=\"dropuser\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003edropuser\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e，它与此命令具有相同功能（实际上它就是调用此命令），但可以从命令 shell 中运行。\u003c/p\u003e","key":"notes","title":"注解"},{"html":"\u003cp\u003e删除一个角色：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eDROP ROLE jonathan;\n\u003c/pre\u003e","key":"examples","title":"示例"},{"html":"\u003cp\u003eSQL 标准定义了\u003ccode class=\"command\"\u003eDROP ROLE\u003c/code\u003e，但它一次只允许删除一个角色，并且规定的权限要求也不同于\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e。\u003c/p\u003e","key":"compatibility","title":"兼容性"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-role/?v=18\" title=\"CREATE ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE ROLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/alter-role/?v=18\" title=\"ALTER ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER ROLE\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/set-role/?v=18\" title=\"SET ROLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eSET ROLE\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"另见"}],"sections_same_as":"","synopsis_html":"DROP ROLE [ IF EXISTS ] \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e [, ...]","synopsis_text":"DROP ROLE [ IF EXISTS ] name [, ...]"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
