SQL DEALLOCATE is a resource-cleanup command. In PostgreSQL it removes a prepared statement created with PREPARE, freeing the memory and execution plan held on the server. In SQL Server it removes a cursor created with DECLARE CURSOR or sp_cursoropen. DEALLOCATE has no effect on transaction state; it simply releases objects that are no longer needed so they do not consume resources for the rest of the session. If the specified object does not exist or has already been closed, the database returns an error. Using DEALLOCATE ALL in PostgreSQL removes every prepared statement defined in the current session, which is helpful for long-running connections or scripts that open many prepared statements.
name
(identifier) - Required. The name of the prepared statement (PostgreSQL) or cursor (SQL Server) to remove.ALL
(keyword) - Optional (PostgreSQL only). Frees every prepared statement in the current session.PREPARE, EXECUTE, CLOSE, CURSOR, DECLARE, DEALLOCATE PREPARE, FREE
PostgreSQL 7.3 (prepared statements) and SQL Server 2000 (cursor deallocation)
It releases a prepared statement (PostgreSQL) or cursor (SQL Server) so the server no longer holds its execution plan or memory.
The database automatically frees resources when the session ends, but DEALLOCATE is recommended in long-lived sessions or connection pools to avoid leaks.
Yes. In PostgreSQL, use DEALLOCATE ALL to remove every prepared statement created in the current session.
No. It does not commit, roll back, or modify data. It only drops server-side objects tied to your session.