Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

PG_TERMINATE_BACKEND

Focus mode
PG_TERMINATE_BACKEND - Amazon Redshift

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

Syntax

pg_terminate_backend( pid )

Arguments

pid

The process ID of the session to be terminated. Requires an INTEGER value.

Return type

None

Usage notes

If you are close to reaching the limit for concurrent connections, use PG_TERMINATE_BACKEND to terminate idle sessions and free up the connections. For more information, see Limits in Amazon Redshift.

If queries in multiple sessions hold locks on the same table, you can use PG_TERMINATE_BACKEND to terminate one of the sessions, which forces any currently running transactions in the terminated session to release all locks and roll back the transaction. Query the PG_LOCKS catalog table to view currently held locks.

If a query is not in a transaction block (BEGIN … END), you can cancel the query by using the CANCEL command or the PG_CANCEL_BACKEND function.

Examples

To query the SVV_TRANSACTIONS table to view all locks in effect for current transactions, use the following example.

SELECT * FROM svv_transactions; +-----------+--------+-------+------+---------------------+-----------------+----------------------+----------+---------+ | txn_owner | txn_db | xid | pid | txn_start | lock_mode | lockable_object_type | relation | granted | +-----------+--------+-------+------+---------------------+-----------------+----------------------+----------+---------+ | rsuser | dev | 96178 | 8585 | 2017-04-12 20:13:07 | AccessShareLock | relation | 51940 | true | | rsuser | dev | 96178 | 8585 | 2017-04-12 20:13:07 | AccessShareLock | relation | 52000 | true | | rsuser | dev | 96178 | 8585 | 2017-04-12 20:13:07 | AccessShareLock | relation | 108623 | true | | rsuser | dev | 96178 | 8585 | 2017-04-12 20:13:07 | ExclusiveLock | transactionid | | true | +-----------+--------+-------+------+---------------------+-----------------+----------------------+----------+---------+

TO terminate the session holding the locks, use the following example.

SELECT PG_TERMINATE_BACKEND(8585);
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.