-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathdb.killOp.txt
244 lines (161 loc) · 6.98 KB
/
db.killOp.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
===========
db.killOp()
===========
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Description
-----------
.. method:: db.killOp(opid)
Terminates an operation as specified by the operation ID. To find
operations and their corresponding IDs, see :pipeline:`$currentOp`
or :method:`db.currentOp()`.
The :method:`db.killOp()` method has the following parameter:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Parameter
- Type
- Description
* - ``op``
- number
- An operation ID.
.. |command| replace:: :method:`db.killOp()`
.. include:: /includes/extracts/warning-terminating-ops-method.rst
Compatibility
-------------
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. important::
{+atlas+} limits the use of this method to the MongoDB user who ran the
operation. For information on Atlas support for all commands,
see :atlas:`Unsupported Commands </unsupported-commands>`.
.. include:: /includes/fact-environments-onprem-only.rst
Sharded Cluster
---------------
.. _kill-read-ops-sharded-cluster:
Kill Read Operations
~~~~~~~~~~~~~~~~~~~~
The :method:`db.killOp()` method can be run on a
:binary:`~bin.mongos` and can kill queries (read operations) that are running
on more than one shard in a cluster.
For example, to kill a query operation on a sharded cluster:
.. tabs::
tabs:
- id: mongos
name: From the mongos Instance
content: |
#. On the **same** :binary:`~bin.mongos` where the client issued the
query, find the opid of the query operation to kill by running the
aggregation pipeline :pipeline:`$currentOp` with the ``localOps:
true``:
.. code-block:: javascript
use admin
db.aggregate( [
{ $currentOp : { allUsers: true, localOps: true } },
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
// e.g. { op: "getmore", "command.collection": "someCollection" }
] )
.. important::
You must issue this aggregation operation on the **same**
:binary:`~bin.mongos` where the client issued the query.
#. Once you find the query operation to kill, issue
:method:`db.killOp()` with the opid on the :binary:`~bin.mongos`:
.. code-block:: javascript
db.killOp(<opid of the query to kill>)
.. seealso::
The ``localOps`` parameter in :pipeline:`$currentOp`.
- id: mongod
name: From a shard member
content: |
Alternatively, you can find and kill the read operation from a
shard member where the operation is running. MongoDB
propagates the kill operation to the other shards and
:binary:`~bin.mongos` instances:
#. On one of the shards where the operation is running, find the opid
of the query operation to kill:
.. code-block:: javascript
use admin
db.aggregate( [
{ $currentOp : { allUsers: true } },
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
// e.g. { op: "getmore", "command.collection": "someCollection" }
] )
#. Once you find the query operation to kill, issue
:method:`db.killOp()` with the opid on the shard member:
.. code-block:: javascript
db.killOp(<opid of the query to kill>)
MongoDB propagates the kill operation to the
other shards and :binary:`~bin.mongos` instances.
.. _kill-write-ops-sharded-cluster:
Kill Write Operations
~~~~~~~~~~~~~~~~~~~~~
Within a Session
MongoDB drivers associate all operations with a
:ref:`server session <server-sessions>`, with the
exception of unacknowledged writes.
If the write operation is associated with a session, you can use the
:dbcommand:`killSessions` command on the :binary:`~bin.mongos` to
kill the write operation across shards.
#. Run the aggregation pipeline :pipeline:`$currentOp` on
the :binary:`~bin.mongos` to find the
``lsid`` (logical session id).
.. code-block:: javascript
use admin
db.aggregate( [
{ $currentOp : { allUsers: true, localOps: true } },
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
// e.g. { "op" : "update", "ns": "mydb.someCollection" }
] )
#. Using the returned ``lsid`` information, issue the
:dbcommand:`killSessions` command on the
:binary:`~bin.mongos` to kill the operation on the shards.
.. code-block:: javascript
db.adminCommand( { killSessions: [
{ "id" : UUID("80e48c5a-f7fb-4541-8ac0-9e3a1ed224a4"), "uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") }
] } )
Without a Session
If the write operation is **not** associated with a session, you must find and kill the
operation on all the shards associated with the write.
#. From a :binary:`~bin.mongos`, run the aggregation pipeline
:pipeline:`$currentOp` to find the opid(s) of the query operation on
the shards:
.. code-block:: javascript
use admin
db.aggregate( [
{ $currentOp : { allUsers: true } },
{ $match : <filter condition> } // Optional. Specify the condition to find the op.
] )
When run on a :binary:`~bin.mongos`, :pipeline:`$currentOp`
returns the opids in the format of ``"<shardName>:<opid on that
shard>"``; e.g.
.. code-block:: javascript
{
"shard" : "shardB",
..
"opid" : "shardB:79214",
...
},
{
"shard" : "shardA",
..
"opid" : "shardA:100913",
...
},
#. Using the opid information, issue :method:`db.killOp()` on the
:binary:`~bin.mongos` to kill the operation on the shards.
.. code-block:: javascript
db.killOp("shardB:79014");
db.killOp("shardA:100813");
Access Control
--------------
On systems running with :setting:`~security.authorization`, to kill
operations not owned by the user, the user must have access that
includes the :authaction:`killop` privilege action.
On :binary:`~bin.mongod` instances, users can kill their own operations
even without the :authaction:`killop` privilege action.
.. seealso::
:pipeline:`$currentOp`