{"Entry":{"collection":"sql","key":"drop-subscription","name":"DROP SUBSCRIPTION","aliases":["dropsubscription"],"metadata":{"aliases":["dropsubscription"],"changed_in":[],"changes":[{"from":"9.6","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"10"},{"from":"10","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"11"},{"from":"11","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"12"},{"from":"13","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters","notes"],"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":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"17"},{"from":"19","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"20"}],"content_hash":"7898e847576cbd5e5f1d1121fb88c12066fc24c54aa54d0fdfd1b2f7f4dc3cc1","editorial":{},"first_version":"10","group":"replication","imported_at":"2026-09-30T17:43:38.978086+08:00","last_version":"20","name":"DROP SUBSCRIPTION","object":"SUBSCRIPTION","position":10005,"present_in":["10","11","12","13","14","15","16","17","18","19","20"],"purpose":"remove a subscription","purpose_zh":"","related":["create-subscription","alter-subscription"],"slug":"drop-subscription","source_rev":"a709ab85","synopsis":"DROP SUBSCRIPTION [ IF EXISTS ] name [ CASCADE | RESTRICT ]","verb":"DROP"}},"Definition":{"Collection":"sql","Key":"drop-subscription","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"drop-subscription","SourceRevision":"a709ab85","Facts":{"anchor":"SQL-DROPSUBSCRIPTION","file":"sql-dropsubscription.html","lang":"en","name":"DROP SUBSCRIPTION","purpose":"remove a subscription","purpose_zh":"","related":["create-subscription","alter-subscription"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e removes a subscription from the database cluster.\u003c/p\u003e\u003cp\u003eTo execute this command the user must be the owner of the subscription.\u003c/p\u003e\u003cp\u003e\u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e cannot be executed inside a transaction block if the subscription is associated with a replication slot. (You can use \u003ca href=\"/docs/18/sql-altersubscription.html\" title=\"ALTER SUBSCRIPTION\"\u003e\u003ccode class=\"command\"\u003eALTER SUBSCRIPTION\u003c/code\u003e\u003c/a\u003e to unset the slot.)\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 subscription 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 a subscription to be dropped.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eCASCADE\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eRESTRICT\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThese key words do not have any effect, since there are no dependencies on subscriptions.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eWhen dropping a subscription that is associated with a replication slot on the remote host (the normal state), \u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e will connect to the remote host and try to drop the replication slot (and any remaining table synchronization slots) as part of its operation. This is necessary so that the resources allocated for the subscription on the remote host are released. If this fails, either because the remote host is not reachable or because the remote replication slot cannot be dropped or does not exist or never existed, the \u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e command will fail. To proceed in this situation, first disable the subscription by executing \u003ca href=\"/docs/18/sql-altersubscription.html#SQL-ALTERSUBSCRIPTION-PARAMS-DISABLE\"\u003e\u003ccode class=\"literal\"\u003eALTER SUBSCRIPTION ... DISABLE\u003c/code\u003e\u003c/a\u003e, and then disassociate it from the replication slot by executing \u003ca href=\"/docs/18/sql-altersubscription.html#SQL-ALTERSUBSCRIPTION-PARAMS-SET\"\u003e\u003ccode class=\"literal\"\u003eALTER SUBSCRIPTION ... SET (slot_name = NONE)\u003c/code\u003e\u003c/a\u003e. After that, \u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e will not attempt to drop the subscription's own replication slot. It may still connect to the publisher to drop internally-created table synchronization slots if some table synchronization is left unfinished; if the publisher is unreachable, those slots (and the main slot, if it still exists) must be dropped manually. Otherwise it/they will continue to reserve WAL and might eventually cause the disk to fill up. See also \u003ca href=\"/docs/18/logical-replication-subscription.html#LOGICAL-REPLICATION-SUBSCRIPTION-SLOT\" title=\"29.2.1. Replication Slot Management\"\u003eSection 29.2.1\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eIf a subscription is associated with a replication slot, then \u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e cannot be executed inside a transaction block.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eDrop a subscription:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eDROP SUBSCRIPTION mysub;\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e is a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extension.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-subscription/?v=18\" title=\"CREATE SUBSCRIPTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SUBSCRIPTION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/alter-subscription/?v=18\" title=\"ALTER SUBSCRIPTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER SUBSCRIPTION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"DROP SUBSCRIPTION [ IF EXISTS ] \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e [ CASCADE | RESTRICT ]","synopsis_text":"DROP SUBSCRIPTION [ IF EXISTS ] name [ CASCADE | RESTRICT ]"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"drop-subscription","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"DROP SUBSCRIPTION","Summary":"移除一个订阅","BodyHTML":"\u003cpre\u003eDROP SUBSCRIPTION [ IF EXISTS ] name [ CASCADE | RESTRICT ]\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eDROP SUBSCRIPTION\u003c/code\u003e从数据库集簇中移除一个订阅。\u003c/p\u003e\u003cp\u003e要执行此命令，用户必须是该订阅的拥有者。\u003c/p\u003e\u003cp\u003e如果该订阅与复制槽相关联，则不能在事务块内执行 \u003ccode\u003eDROP SUBSCRIPTION\u003c/code\u003e。（可以使用\u003ca href=\"/docs/18/sql-altersubscription.html\" title=\"ALTER SUBSCRIPTION\" rel=\"nofollow\"\u003e\u003ccode\u003eALTER SUBSCRIPTION\u003c/code\u003e\u003c/a\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\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eCASCADE\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003eRESTRICT\u003c/code\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删除一个与远端主机上的复制槽相关联的订阅时（这通常是正常状态），\u003ccode\u003eDROP SUBSCRIPTION\u003c/code\u003e会连接到远端主机，并在执行过程中尝试删除该复制槽（以及任何剩余的表同步槽）。这样做是必要的，以便释放远端主机上为该订阅分配的资源。如果此操作失败，无论是因为远端主机不可达，还是因为远端复制槽无法删除、不存在或者从未存在，\u003ccode\u003eDROP SUBSCRIPTION\u003c/code\u003e命令都会失败。要在这种情况下继续，首先执行 \u003ca href=\"/docs/18/sql-altersubscription.html#SQL-ALTERSUBSCRIPTION-PARAMS-DISABLE\" rel=\"nofollow\"\u003e\u003ccode\u003eALTER SUBSCRIPTION ... DISABLE\u003c/code\u003e\u003c/a\u003e 禁用订阅，然后执行 \u003ca href=\"/docs/18/sql-altersubscription.html#SQL-ALTERSUBSCRIPTION-PARAMS-SET\" rel=\"nofollow\"\u003e\u003ccode\u003eALTER SUBSCRIPTION ... SET (slot_name = NONE)\u003c/code\u003e\u003c/a\u003e 将其与复制槽解除关联。此后，\u003ccode\u003eDROP SUBSCRIPTION\u003c/code\u003e将不会尝试删除订阅自身的复制槽。如果还有某些表同步尚未完成，它仍可能连接到发布者，以删除由系统内部创建的表同步槽；如果发布者不可达，则必须手工删除这些槽（以及仍然存在的主复制槽）。否则，这些槽会继续保留 WAL，并最终可能导致磁盘被占满。另见\u003ca href=\"/docs/18/logical-replication-subscription.html#LOGICAL-REPLICATION-SUBSCRIPTION-SLOT\" rel=\"nofollow\"\u003e第 29.2.1 节\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e如果订阅与复制槽相关联，则不能在事务块内执行 \u003ccode\u003eDROP SUBSCRIPTION\u003c/code\u003e。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e删除一个订阅：\u003c/p\u003e\u003cpre\u003eDROP SUBSCRIPTION mysub;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eDROP SUBSCRIPTION\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-subscription/?v=18\" title=\"CREATE SUBSCRIPTION\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE SUBSCRIPTION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/alter-subscription/?v=18\" title=\"ALTER SUBSCRIPTION\" rel=\"nofollow\"\u003e\u003cspan\u003eALTER SUBSCRIPTION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"1b5ca64c","ContentHash":"dc59ce4289864a3a884da7cbd604fa5d9f1e59ccfb2c49cd3e35644ffb69cd86","Payload":{"purpose_zh":"移除一个订阅","sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e从数据库集簇中移除一个订阅。\u003c/p\u003e\u003cp\u003e要执行此命令，用户必须是该订阅的拥有者。\u003c/p\u003e\u003cp\u003e如果该订阅与复制槽相关联，则不能在事务块内执行 \u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e。（可以使用\u003ca href=\"/docs/18/sql-altersubscription.html\" title=\"ALTER SUBSCRIPTION\"\u003e\u003ccode class=\"command\"\u003eALTER SUBSCRIPTION\u003c/code\u003e\u003c/a\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\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eCASCADE\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eRESTRICT\u003c/code\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删除一个与远端主机上的复制槽相关联的订阅时（这通常是正常状态），\u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e会连接到远端主机，并在执行过程中尝试删除该复制槽（以及任何剩余的表同步槽）。这样做是必要的，以便释放远端主机上为该订阅分配的资源。如果此操作失败，无论是因为远端主机不可达，还是因为远端复制槽无法删除、不存在或者从未存在，\u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e命令都会失败。要在这种情况下继续，首先执行 \u003ca href=\"/docs/18/sql-altersubscription.html#SQL-ALTERSUBSCRIPTION-PARAMS-DISABLE\"\u003e\u003ccode class=\"literal\"\u003eALTER SUBSCRIPTION ... DISABLE\u003c/code\u003e\u003c/a\u003e 禁用订阅，然后执行 \u003ca href=\"/docs/18/sql-altersubscription.html#SQL-ALTERSUBSCRIPTION-PARAMS-SET\"\u003e\u003ccode class=\"literal\"\u003eALTER SUBSCRIPTION ... SET (slot_name = NONE)\u003c/code\u003e\u003c/a\u003e 将其与复制槽解除关联。此后，\u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e将不会尝试删除订阅自身的复制槽。如果还有某些表同步尚未完成，它仍可能连接到发布者，以删除由系统内部创建的表同步槽；如果发布者不可达，则必须手工删除这些槽（以及仍然存在的主复制槽）。否则，这些槽会继续保留 WAL，并最终可能导致磁盘被占满。另见\u003ca href=\"/docs/18/logical-replication-subscription.html#LOGICAL-REPLICATION-SUBSCRIPTION-SLOT\" title=\"29.2.1. 复制槽管理\"\u003e第 29.2.1 节\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e如果订阅与复制槽相关联，则不能在事务块内执行 \u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\u003c/code\u003e。\u003c/p\u003e","key":"notes","title":"注解"},{"html":"\u003cp\u003e删除一个订阅：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eDROP SUBSCRIPTION mysub;\n\u003c/pre\u003e","key":"examples","title":"示例"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eDROP SUBSCRIPTION\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-subscription/?v=18\" title=\"CREATE SUBSCRIPTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SUBSCRIPTION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/alter-subscription/?v=18\" title=\"ALTER SUBSCRIPTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER SUBSCRIPTION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"另见"}],"sections_same_as":"","synopsis_html":"DROP SUBSCRIPTION [ IF EXISTS ] \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e [ CASCADE | RESTRICT ]","synopsis_text":"DROP SUBSCRIPTION [ IF EXISTS ] name [ CASCADE | RESTRICT ]"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
