Removes a subscription from the database cluster.
Prerequisites
Before you begin, ensure that you have:
Superuser privileges on the database cluster
Synopsis
DROP SUBSCRIPTION [ IF EXISTS ] name [ CASCADE | RESTRICT ]Parameters
| Parameter | Description |
|---|---|
name | The name of the subscription to drop. |
CASCADE | RESTRICT | No effect. These keywords are accepted for SQL compatibility but perform no action, as subscriptions have no dependencies. |
Usage notes
Replication slot handling
When you drop a subscription that is associated with a replication slot on the remote host (the normal state), DROP SUBSCRIPTION connects to the remote host and drops the replication slot and any remaining table synchronization slots. This releases the resources allocated for the subscription on the remote host.
The command fails if any of the following conditions are true:
The remote host is unreachable.
The remote replication slot cannot be dropped.
The remote replication slot does not exist or never existed.
Transaction block restriction
DROP SUBSCRIPTION cannot run inside a transaction block when the subscription is associated with a replication slot. To disassociate the subscription from the slot before dropping, first disable the subscription by running ALTER SUBSCRIPTION ... DISABLE, and then disassociate it from the replication slot by running ALTER SUBSCRIPTION ... SET (slot_name = NONE).
If orphaned replication slots are left on the remote host, they continue to reserve Write-Ahead Log (WAL) space and can eventually fill the disk.
Drop a subscription when the remote host is unreachable
If DROP SUBSCRIPTION fails because the remote host is unreachable or the replication slot cannot be dropped, follow these steps:
Disable the subscription.
ALTER SUBSCRIPTION <subscription_name> DISABLE;Disassociate the subscription from the replication slot.
ALTER SUBSCRIPTION <subscription_name> SET (slot_name = NONE);Drop the subscription.
DROP SUBSCRIPTION <subscription_name>;
After step 3, DROP SUBSCRIPTION no longer attempts any actions on the remote host. However, if the remote replication slot still exists, drop it and any related table synchronization slots manually to prevent WAL accumulation.
Example
Drop a subscription:
DROP SUBSCRIPTION mysub;See also
ALTER SUBSCRIPTION — disable a subscription or modify its replication slot configuration before dropping
CREATE SUBSCRIPTION — create a new subscription for logical replication