DISCONNECT is a control statement defined in the SQL standard for clients that can maintain multiple open sessions at once. It cleanly terminates a specified connection, the current connection, or all connections. Before the session is closed, the database performs an implicit COMMIT of any outstanding transaction, thereby making all changes permanent (some vendors instead perform an implicit ROLLBACK – always verify). After a connection is disconnected, any cursor, prepared statement, or session state tied to it becomes invalid. Attempting to issue further SQL statements on that connection raises an error until a new CONNECT statement is executed. DISCONNECT does not shut down the database server itself; it only affects the client session(s).
connection_name
(identifier) - Name of an open connection established with CONNECTCURRENT
(keyword) - Closes only the active connectionALL
(keyword) - Closes every open connection held by the clientSQL-92 (ISO/IEC 9075:1992)
Most engines commit pending work before closing the session, but a few roll back. Verify your database to avoid surprises.
Use DISCONNECT CURRENT. The command terminates the active session while leaving others open.
All cursors, prepared statements, and session context tied to that connection are automatically dropped and become unusable.
No. psql uses the meta-command \q to exit the client. DISCONNECT applies to standards-compliant multi-connection environments or embedded SQL.