Permanently removes a partition and all its data from a partitioned table. This operation is irreversible — dropped data cannot be recovered.
Back up the partition data before running this command. Once dropped, the data cannot be restored.
If you only need to clear data without removing the partition definition, use ALTER TABLE TRUNCATE PARTITION instead. TRUNCATE PARTITION removes all rows from the partition but keeps the partition structure intact, and it does not permanently remove the data in the same way as DROP PARTITION.
Syntax
ALTER TABLE [schema.]table_name DROP PARTITION partition_name;
Parameters
| Parameter | Required | Description | Example |
|---|---|---|---|
table_name |
Yes | The name of the partitioned table from which to drop a partition | sales_records |
partition_name |
Yes | The name of the partition to drop | P_2023_Q1 |
Usage notes
-
Only the table owner or a privileged user can run this command.
-
A partitioned table must have at least one partition. Dropping the last remaining partition is not allowed.
-
DROP PARTITIONacquires a table-levelAccessExclusiveLock, which blocks all Data Manipulation Language (DML) and most Data Definition Language (DDL) operations on the table. Run this command during off-peak hours.
Example
The following example creates a range-partitioned table, runs pre-checks, drops a partition, and verifies the result.
FAQ
Why do I get `partition "..." of relation "..." does not exist`?
The partition name is case-sensitive. Query USER_TAB_PARTITIONS to find the exact name, then use double quotes for an exact match if needed.
Why do I get `permission denied for table ...` or `must be owner of table ...`?
The current user lacks sufficient permissions. Switch to the table owner or a privileged user.
Why do I get `cannot drop partition due to dependent objects`?
Other database objects — such as foreign key constraints or views — depend on this partition. The default RESTRICT behavior prevents the deletion. Identify and remove those dependent objects first, then retry.
Why is the operation taking a long time or appears stuck?
DROP PARTITION acquires an AccessExclusiveLock. If another active long-running transaction is holding a conflicting lock, the operation waits. Use the following query to identify the blocking session by its PID, then decide whether to wait or terminate the blocking transaction.
-- Query user information of the blocking thread based on the PID.
SELECT
pid,
usename AS username, -- Database username
application_name, -- Application name (such as JDBC, psql)
client_addr, -- Client IP address
client_hostname, -- Client hostname
client_port, -- Client port
backend_start, -- Time when the connection started
xact_start, -- Time when the transaction started
query_start, -- Time when the current query started
state_change, -- Time when the status last changed
state, -- Status (active, idle, idle in transaction)
wait_event_type, -- Wait event type (such as Lock, IO)
wait_event, -- Specific wait event
query -- Currently running or most recently run SQL statement
FROM
pg_stat_activity
WHERE
pid in 'blocking_pid';
What's next
-
ALTER TABLE ADD PARTITION: Add a new partition to a partitioned table.
-
ALTER TABLE TRUNCATE PARTITION: Clear all data from a partition while keeping the partition definition.
-
ALTER TABLE SPLIT PARTITION: Split one partition into two.