Schema changes are treated differently than other SQL queries. You can use SHOW JOBS to monitor the progress of schema changes and CANCEL JOB to cancel schema changes that are taking longer than expected.
In rare cases where a query is close to completion when a cancellation request is issued, the query may run to completion.
In addition to the CANCEL QUERY statement, CockroachDB also supports query cancellation by client drivers and ORMs using the PostgreSQL wire protocol (pgwire). This allows CockroachDB to stop executing queries that your application is no longer waiting for, thereby reducing load on the cluster. pgwire query cancellation differs from the CANCEL QUERY statement in the following ways:
Members of the admin role (including root, which belongs to admin by default) can cancel any currently active queries. User that are not members of the admin role can cancel only their own currently active queries. To view and cancel another non-admin user’s query, the user must be a member of the admin role or must have the VIEWACTIVITYsystem privilege (or the legacy VIEWACTIVITYrole option) and the CANCELQUERYsystem privilege (or the legacy CANCELQUERYrole option) defined.
CANCEL QUERY accepts a single query ID. If a subquery is used and returns multiple IDs, the CANCEL QUERY statement will fail. To cancel multiple queries, use CANCEL QUERIES.
In this example, we nest a SELECT clause that retrieves the ID of a query inside the CANCEL QUERY statement:
> CANCEL QUERY (WITH x AS (SHOW CLUSTER STATEMENTS) SELECT query_id FROM x WHERE client_address = '127.0.0.1:55212' AND user_name = 'demo' AND query = 'SELECT * FROM rides ORDER BY revenue');
CANCEL QUERIES 1
CANCEL QUERY accepts a single query ID. If a subquery is used and returns multiple IDs, the CANCEL QUERY statement will fail. To cancel multiple queries, use CANCEL QUERIES.