summaryrefslogtreecommitdiff
path: root/src/docs/src/api/server/common.rst
blob: 95478bf102b466f6fbbd915cd498e26a2110a68f (plain)
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
.. Licensed under the Apache License, Version 2.0 (the "License"); you may not
.. use this file except in compliance with the License. You may obtain a copy of
.. the License at
..
..   http://www.apache.org/licenses/LICENSE-2.0
..
.. Unless required by applicable law or agreed to in writing, software
.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
.. License for the specific language governing permissions and limitations under
.. the License.

.. _api/server/root:

=====
``/``
=====

.. http:get:: /
    :synopsis: Returns the welcome message and version information

    Accessing the root of a CouchDB instance returns meta information about the
    instance. The response is a JSON structure containing information about the
    server, including a welcome message and the version of the server.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :code 200: Request completed successfully

    **Request**:

    .. code-block:: http

        GET / HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 179
        Content-Type: application/json
        Date: Sat, 10 Aug 2013 06:33:33 GMT
        Server: CouchDB (Erlang/OTP)

        {
            "couchdb": "Welcome",
            "uuid": "85fb71bf700c17267fef77535820e371",
            "vendor": {
                "name": "The Apache Software Foundation",
                "version": "1.3.1"
            },
            "version": "1.3.1"
        }

.. _api/server/active_tasks:

==================
``/_active_tasks``
==================

.. versionchanged:: 2.1.0 Because of how the scheduling replicator works, continuous replication jobs could be periodically stopped and then started later. When they are not running they will not appear in the ``_active_tasks`` endpoint

.. versionchanged:: 3.3 Added `"bulk_get_attempts"` and `"bulk_get_docs"` fields for replication jobs.

.. http:get:: /_active_tasks
    :synopsis: Obtains a list of the tasks running in the server

    List of running tasks, including the task type, name, status
    and process ID. The result is a JSON array of the currently running tasks,
    with each task being described with a single object. Depending on operation
    type set of response object fields might be different.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :>json number changes_done: Processed changes
    :>json string database: Source database
    :>json string pid: Process ID
    :>json number progress: Current percentage progress
    :>json number started_on: Task start time as unix timestamp
    :>json string status: Task status message
    :>json string task: Task name
    :>json number total_changes: Total changes to process
    :>json string type: Operation Type
    :>json number updated_on: Unix timestamp of last operation update
    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    **Request**:

    .. code-block:: http

        GET /_active_tasks HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 1690
        Content-Type: application/json
        Date: Sat, 10 Aug 2013 06:37:31 GMT
        Server: CouchDB (Erlang/OTP)

        [
            {
                "changes_done": 64438,
                "database": "mailbox",
                "pid": "<0.12986.1>",
                "progress": 84,
                "started_on": 1376116576,
                "total_changes": 76215,
                "type": "database_compaction",
                "updated_on": 1376116619
            },
            {
                "changes_done": 14443,
                "database": "mailbox",
                "design_document": "c9753817b3ba7c674d92361f24f59b9f",
                "pid": "<0.10461.3>",
                "progress": 18,
                "started_on": 1376116621,
                "total_changes": 76215,
                "type": "indexer",
                "updated_on": 1376116650
            },
            {
                "changes_done": 5454,
                "database": "mailbox",
                "design_document": "_design/meta",
                "pid": "<0.6838.4>",
                "progress": 7,
                "started_on": 1376116632,
                "total_changes": 76215,
                "type": "indexer",
                "updated_on": 1376116651
            },
            {
                "checkpointed_source_seq": 68585,
                "continuous": false,
                "doc_id": null,
                "doc_write_failures": 0,
                "bulk_get_attempts": 4524,
                "bulk_get_docs": 4524,
                "docs_read": 4524,
                "docs_written": 4524,
                "missing_revisions_found": 4524,
                "pid": "<0.1538.5>",
                "progress": 44,
                "replication_id": "9bc1727d74d49d9e157e260bb8bbd1d5",
                "revisions_checked": 4524,
                "source": "mailbox",
                "source_seq": 154419,
                "started_on": 1376116644,
                "target": "http://mailsrv:5984/mailbox",
                "type": "replication",
                "updated_on": 1376116651
            }
        ]

.. _api/server/all_dbs:

=============
``/_all_dbs``
=============

.. http:get:: /_all_dbs
    :synopsis: Returns a list of all the databases

    Returns a list of all the databases in the CouchDB instance.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :query boolean descending: Return the databases in descending order by key.
      Default is ``false``.
    :query json endkey: Stop returning databases when the specified key is
      reached.
    :query json end_key: Alias for ``endkey`` param
    :query number limit: Limit the number of the returned databases to the
      specified number.
    :query number skip: Skip this number of databases before starting to return
      the results. Default is ``0``.
    :query json startkey: Return databases starting with the specified key.
    :query json start_key: Alias for ``startkey``.
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :code 200: Request completed successfully

    **Request**:

    .. code-block:: http

        GET /_all_dbs HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 52
        Content-Type: application/json
        Date: Sat, 10 Aug 2013 06:57:48 GMT
        Server: CouchDB (Erlang/OTP)

        [
           "_users",
           "contacts",
           "docs",
           "invoices",
           "locations"
        ]

.. _api/server/dbs_info:

==============
``/_dbs_info``
==============

.. versionadded:: 3.2

.. http:get:: /_dbs_info
    :synopsis: Returns all databases information

    Returns a list of all the databases information in the CouchDB instance.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :query boolean descending: Return databases information in descending order
      by key. Default is ``false``.
    :query json endkey: Stop returning databases information when the specified
      key is reached.
    :query json end_key: Alias for ``endkey`` param
    :query number limit: Limit the number of the returned databases information
      to the specified number.
    :query number skip: Skip this number of databases before starting to return
      the results. Default is ``0``.
    :query json startkey: Return databases information starting with the
      specified key.
    :query json start_key: Alias for ``startkey``.
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :code 200: Request completed successfully

    **Request**:

    .. code-block:: http

        GET /_dbs_info HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Type: application/json
        Date: Thu, 18 Nov 2021 14:37:35 GMT
        Server: CouchDB (Erlang OTP/23)

        [
          {
            "key": "animals",
            "info": {
              "db_name": "animals",
              "update_seq": "52232",
              "sizes": {
                "file": 1178613587,
                "external": 1713103872,
                "active": 1162451555
              },
              "purge_seq": 0,
              "doc_del_count": 0,
              "doc_count": 52224,
              "disk_format_version": 6,
              "compact_running": false,
              "cluster": {
                "q": 8,
                "n": 3,
                "w": 2,
                "r": 2
              },
              "instance_start_time": "0"
            }
          }
        ]

.. versionadded:: 2.2

.. http:post:: /_dbs_info
    :synopsis: Returns information of a list of the specified databases

    Returns information of a list of the specified databases in the CouchDB
    instance. This enables you to request information about multiple databases
    in a single request, in place of multiple :get:`/{db}` requests.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`
    :<json array keys: Array of database names to be requested
    :code 200: Request completed successfully
    :code 400: Missing keys or exceeded keys in request

    **Request**:

    .. code-block:: http

        POST /_dbs_info HTTP/1.1
        Accept: application/json
        Host: localhost:5984
        Content-Type: application/json

        {
            "keys": [
                "animals",
                "plants"
            ]
        }

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Type: application/json
        Date: Sat, 20 Dec 2017 06:57:48 GMT
        Server: CouchDB (Erlang/OTP)

        [
          {
            "key": "animals",
            "info": {
              "db_name": "animals",
              "update_seq": "52232",
              "sizes": {
                "file": 1178613587,
                "external": 1713103872,
                "active": 1162451555
              },
              "purge_seq": 0,
              "doc_del_count": 0,
              "doc_count": 52224,
              "disk_format_version": 6,
              "compact_running": false,
              "cluster": {
                "q": 8,
                "n": 3,
                "w": 2,
                "r": 2
              },
              "instance_start_time": "0"
            }
          },
          {
            "key": "plants",
            "info": {
              "db_name": "plants",
              "update_seq": "303",
              "sizes": {
                "file": 3872387,
                "external": 2339,
                "active": 67475
              },
              "purge_seq": 0,
              "doc_del_count": 0,
              "doc_count": 11,
              "disk_format_version": 6,
              "compact_running": false,
              "cluster": {
                "q": 8,
                "n": 3,
                "w": 2,
                "r": 2
              },
              "instance_start_time": "0"
            }
          }
        ]

.. note::
    The supported number of the specified databases in the list can be limited
    by modifying the `max_db_number_for_dbs_info_req` entry in configuration
    file. The default limit is 100. Increasing the limit, while possible, creates
    load on the server so it is advisable to have more requests with 100 dbs,
    rather than a few requests with 1000s of dbs at a time.

.. _api/server/cluster_setup:

===================
``/_cluster_setup``
===================

.. versionadded:: 2.0
.. http:get:: /_cluster_setup
    :synopsis: Return the status of the cluster setup wizard

    Returns the status of the node or cluster, per the cluster setup wizard.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :query array ensure_dbs_exist: List of system databases to ensure exist
        on the node/cluster. Defaults to
        ``["_users","_replicator"]``.
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :>json string state: Current ``state`` of the node and/or cluster (see
        below)
    :code 200: Request completed successfully

    The ``state`` returned indicates the current node or cluster state, and
    is one of the following:

    - ``cluster_disabled``: The current node is completely unconfigured.
    - ``single_node_disabled``: The current node is configured as a single
      (standalone) node (``[cluster] n=1``), but either does not have a
      server-level admin user defined, or does not have the standard system
      databases created. If the ``ensure_dbs_exist`` query parameter is
      specified, the list of databases provided overrides the default list
      of standard system databases.
    - ``single_node_enabled``: The current node is configured as a single
      (standalone) node, has a server-level admin user defined, and has
      the ``ensure_dbs_exist`` list (explicit or default) of databases
      created.
    - ``cluster_enabled``: The current node has ``[cluster] n`` > 1, is not
      bound to ``127.0.0.1`` and has a server-level admin user defined.
      However, the full set of standard system databases have not been
      created yet. If the ``ensure_dbs_exist`` query parameter is
      specified, the list of databases provided overrides the default list
      of standard system databases.
    - ``cluster_finished``: The current node has ``[cluster] n`` > 1, is not
      bound to ``127.0.0.1``, has a server-level admin user defined *and*
      has the ``ensure_dbs_exist`` list (explicit or default) of databases
      created.

    **Request**:

    .. code-block:: http

        GET /_cluster_setup HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        X-CouchDB-Body-Time: 0
        X-Couch-Request-ID: 5c058bdd37
        Server: CouchDB/2.1.0-7f17678 (Erlang OTP/17)
        Date: Sun, 30 Jul 2017 06:33:18 GMT
        Content-Type: application/json
        Content-Length: 29
        Cache-Control: must-revalidate

        {"state":"cluster_enabled"}

.. http:post:: /_cluster_setup
    :synopsis: Sets up a node as a single node or as part of a cluster.

    Configure a node as a single (standalone) node, as part of a cluster,
    or finalise a cluster.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :<header Content-Type: :mimetype:`application/json`
    :<json string action: - **enable_single_node**: Configure the current node
                            as a single, standalone CouchDB server.
                          - **enable_cluster**: Configure the local or remote
                            node as one node, preparing it to be joined to a
                            new CouchDB cluster.
                          - **add_node**: Add the specified remote node to
                            this cluster's list of nodes, joining it to the
                            cluster.
                          - **finish_cluster**: Finalise the cluster by
                            creating the standard system databases.
    :<json string bind_address: The IP address to which to bind the current
        node. The special value ``0.0.0.0`` may be specified to bind to all
        interfaces on the host. (enable_cluster and enable_single_node only)
    :<json string username: The username of the server-level administrator to
        create. (enable_cluster and enable_single_node only), or the remote
        server's administrator username (add_node)
    :<json string password: The password for the server-level administrator to
        create. (enable_cluster and enable_single_node only), or the remote
        server's administrator username (add_node)
    :<json number port: The TCP port to which to bind this node
        (enable_cluster and enable_single_node only) or the TCP port to which
        to bind a remote node (add_node only).
    :<json number node_count: The total number of nodes to be joined into
        the cluster, including this one. Used to determine the value of the
        cluster's ``n``, up to a maximum of 3. (enable_cluster only)
    :<json string remote_node: The IP address of the remote node to setup as
        part of this cluster's list of nodes. (enable_cluster only)
    :<json string remote_current_user: The username of the server-level
        administrator authorized on the remote node. (enable_cluster only)
    :<json string remote_current_password: The password of the server-level
        administrator authorized on the remote node. (enable_cluster only)
    :<json string host: The remote node IP of the node to add to the cluster.
        (add_node only)
    :<json array ensure_dbs_exist: List of system databases to ensure exist
        on the node/cluster. Defaults to
        ``["_users","_replicator"]``.

    *No example request/response included here. For a worked example, please
    see* :ref:`cluster/setup/api`.

.. _api/server/db_updates:

================
``/_db_updates``
================

.. versionadded:: 1.4

.. http:get:: /_db_updates
    :synopsis: Return the server changes of databases

    Returns a list of all database events in the CouchDB instance. The
    existence of the ``_global_changes`` database is required to use this
    endpoint.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :query string feed: - **normal**: Returns all historical DB changes, then
                          closes the connection. *Default.*
                        - **longpoll**: Closes the connection after the first
                          event.
                        - **continuous**: Send a line of JSON per event.
                          Keeps the socket open until ``timeout``.
                        - **eventsource**: Like, ``continuous``, but sends
                          the events in `EventSource
                          <http://dev.w3.org/html5/eventsource/>`_ format.
    :query number timeout: Number of *milliseconds* until CouchDB closes the
      connection. Default is ``60000``.
    :query number heartbeat: Period in *milliseconds* after which an empty
        line is sent in the results. Only applicable for ``longpoll``,
        ``continuous``, and ``eventsource`` feeds. Overrides any timeout to
        keep the feed alive indefinitely. Default is ``60000``. May be ``true``
        to use default value.
    :query string since: Return only updates since the specified sequence ID.
        If the sequence ID is specified but does not exist, all changes are returned.
        May be the string ``now`` to begin showing only new updates.
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :>header Transfer-Encoding: ``chunked``
    :>json array results: An array of database events. For ``longpoll`` and
        ``continuous`` modes, the entire response is the contents of the
        ``results`` array.
    :>json string last_seq: The last sequence ID reported.
    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    The ``results`` field of database updates:

    :json string db_name: Database name.
    :json string type: A database event is one of ``created``, ``updated``,
      ``deleted``.
    :json json seq: Update sequence of the event.

    **Request**:

    .. code-block:: http

        GET /_db_updates HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Type: application/json
        Date: Sat, 18 Mar 2017 19:01:35 GMT
        Etag: "C1KU98Y6H0LGM7EQQYL6VSL07"
        Server: CouchDB/2.0.0 (Erlang OTP/17)
        Transfer-Encoding: chunked
        X-Couch-Request-ID: ad87efc7ff
        X-CouchDB-Body-Time: 0

        {
            "results":[
                {"db_name":"mailbox","type":"created","seq":"1-g1AAAAFReJzLYWBg4MhgTmHgzcvPy09JdcjLz8gvLskBCjMlMiTJ____PyuDOZExFyjAnmJhkWaeaIquGIf2JAUgmWQPMiGRAZcaB5CaePxqEkBq6vGqyWMBkgwNQAqobD4h"},
                {"db_name":"mailbox","type":"deleted","seq":"2-g1AAAAFReJzLYWBg4MhgTmHgzcvPy09JdcjLz8gvLskBCjMlMiTJ____PyuDOZEpFyjAnmJhkWaeaIquGIf2JAUgmWQPMiGRAZcaB5CaePxqEkBq6vGqyWMBkgwNQAqobD4hdQsg6vYTUncAou4-IXUPIOpA7ssCAIFHa60"},
            ],
            "last_seq": "2-g1AAAAFReJzLYWBg4MhgTmHgzcvPy09JdcjLz8gvLskBCjMlMiTJ____PyuDOZEpFyjAnmJhkWaeaIquGIf2JAUgmWQPMiGRAZcaB5CaePxqEkBq6vGqyWMBkgwNQAqobD4hdQsg6vYTUncAou4-IXUPIOpA7ssCAIFHa60"
        }

.. _api/server/membership:

================
``/_membership``
================

.. versionadded:: 2.0

.. http:get:: /_membership
    :synopsis: Returns a list of nodes

    Displays the nodes that are part of the cluster as ``cluster_nodes``. The
    field ``all_nodes`` displays all nodes this node knows about, including the
    ones that are part of the cluster. The endpoint is useful when setting up a
    cluster, see :ref:`cluster/nodes`

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :code 200: Request completed successfully

    **Request**:

    .. code-block:: http

        GET /_membership HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Type: application/json
        Date: Sat, 11 Jul 2015 07:02:41 GMT
        Server: CouchDB (Erlang/OTP)
        Content-Length: 142

        {
            "all_nodes": [
                "node1@127.0.0.1",
                "node2@127.0.0.1",
                "node3@127.0.0.1"
            ],
            "cluster_nodes": [
                "node1@127.0.0.1",
                "node2@127.0.0.1",
                "node3@127.0.0.1"
            ]
        }

.. _api/server/replicate:

===============
``/_replicate``
===============

.. versionchanged:: 3.3 Added `"bulk_get_attempts"` and `"bulk_get_docs"`  fields to the replication history response object.

.. http:post:: /_replicate
    :synopsis: Starts or cancels the replication

    Request, configure, or stop, a replication operation.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :<header Content-Type: :mimetype:`application/json`
    :<json boolean cancel: Cancels the replication
    :<json boolean continuous: Configure the replication to be continuous
    :<json boolean create_target: Creates the target database.
      Required administrator's privileges on target server.
    :<json object create_target_params: An object that contains parameters
      to be used when creating the target database. Can include the
      standard ``q`` and ``n`` parameters.
    :<json boolean winning_revs_only: Replicate winning revisions only.
    :<json array doc_ids: Array of document IDs to be synchronized.
      ``doc_ids``, ``filter``, and ``selector`` are mutually exclusive.
    :<json string filter: The name of a :ref:`filter function <filterfun>`.
      ``doc_ids``, ``filter``, and ``selector`` are mutually exclusive.
    :<json json selector: A :ref:`selector <find/selectors>` to filter
      documents for synchronization. Has the same behavior as the
      :ref:`selector objects <selectorobj>` in replication documents.
      ``doc_ids``, ``filter``, and ``selector`` are mutually exclusive.
    :<json string source_proxy: Address of a proxy server through which
      replication from the source should occur (protocol can be "http" or
      "socks5")
    :<json string target_proxy: Address of a proxy server through which
      replication to the target should occur (protocol can be "http" or
      "socks5")
    :<json string/object source: Fully qualified source database URL or an
      object which contains the full URL of the source database with additional
      parameters like headers. Eg: 'http://example.com/source_db_name' or
      {"url":"url in here", "headers": {"header1":"value1", ...}} . For
      backwards compatibility, CouchDB 3.x will auto-convert bare database
      names by prepending the address and port CouchDB is listening on, to
      form a complete URL. This behaviour is deprecated in 3.x and will be
      removed in CouchDB 4.0.
    :<json string/object target: Fully qualified target database URL or an
      object which contains the full URL of the target database with additional
      parameters like headers. Eg: 'http://example.com/target_db_name' or
      {"url":"url in here", "headers": {"header1":"value1", ...}} . For
      backwards compatibility, CouchDB 3.x will auto-convert bare database
      names by prepending the address and port CouchDB is listening on, to
      form a complete URL. This behaviour is deprecated in 3.x and will be
      removed in CouchDB 4.0.
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :>json array history: Replication history (see below)
    :>json boolean ok: Replication status
    :>json number replication_id_version: Replication protocol version
    :>json string session_id: Unique session ID
    :>json number source_last_seq: Last sequence number read from source
      database
    :code 200: Replication request successfully completed
    :code 202: Continuous replication request has been accepted
    :code 400: Invalid JSON data
    :code 401: CouchDB Server Administrator privileges required
    :code 404: Either the source or target DB is not found or attempt to
      cancel unknown replication task
    :code 500: JSON specification was invalid

    The specification of the replication request is controlled through the
    JSON content of the request. The JSON should be an object with the
    fields defining the source, target and other options.

    The `Replication history` is an array of objects with following structure:

    :json number doc_write_failures: Number of document write failures
    :json number docs_read:  Number of documents read
    :json number docs_written:  Number of documents written to target
    :json number bulk_get_attempts: The total count of attempted doc revisions
        fetched with ``_bulk_get``.
    :json number bulk_get_docs: The total count of successful docs fetched with
        ``_bulk_get``.
    :json number end_last_seq:  Last sequence number in changes stream
    :json string end_time:  Date/Time replication operation completed in
      :rfc:`2822` format
    :json number missing_checked:  Number of missing documents checked
    :json number missing_found:  Number of missing documents found
    :json number recorded_seq:  Last recorded sequence number
    :json string session_id:  Session ID for this replication operation
    :json number start_last_seq:  First sequence number in changes stream
    :json string start_time:  Date/Time replication operation started in
      :rfc:`2822` format

.. note::
    As of CouchDB 2.0.0, fully qualified URLs are required for both the
    replication ``source`` and ``target`` parameters.

    **Request**

    .. code-block:: http

        POST /_replicate HTTP/1.1
        Accept: application/json
        Content-Length: 80
        Content-Type: application/json
        Host: localhost:5984

        {
            "source": "http://adm:pass@127.0.0.1:5984/db_a",
            "target": "http://adm:pass@127.0.0.1:5984/db_b"
        }

    **Response**

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 692
        Content-Type: application/json
        Date: Sun, 11 Aug 2013 20:38:50 GMT
        Server: CouchDB (Erlang/OTP)

        {
            "history": [
                {
                    "doc_write_failures": 0,
                    "docs_read": 10,
                    "bulk_get_attempts": 10,
                    "bulk_get_docs": 10,
                    "docs_written": 10,
                    "end_last_seq": 28,
                    "end_time": "Sun, 11 Aug 2013 20:38:50 GMT",
                    "missing_checked": 10,
                    "missing_found": 10,
                    "recorded_seq": 28,
                    "session_id": "142a35854a08e205c47174d91b1f9628",
                    "start_last_seq": 1,
                    "start_time": "Sun, 11 Aug 2013 20:38:50 GMT"
                },
                {
                    "doc_write_failures": 0,
                    "docs_read": 1,
                    "bulk_get_attempts": 1,
                    "bulk_get_docs": 1,
                    "docs_written": 1,
                    "end_last_seq": 1,
                    "end_time": "Sat, 10 Aug 2013 15:41:54 GMT",
                    "missing_checked": 1,
                    "missing_found": 1,
                    "recorded_seq": 1,
                    "session_id": "6314f35c51de3ac408af79d6ee0c1a09",
                    "start_last_seq": 0,
                    "start_time": "Sat, 10 Aug 2013 15:41:54 GMT"
                }
            ],
            "ok": true,
            "replication_id_version": 3,
            "session_id": "142a35854a08e205c47174d91b1f9628",
            "source_last_seq": 28
        }

Replication Operation
=====================

The aim of the replication is that at the end of the process, all active
documents on the source database are also in the destination database and all
documents that were deleted in the source databases are also deleted (if they
exist) on the destination database.

Replication can be described as either push or pull replication:

- *Pull replication* is where the ``source`` is the remote CouchDB instance,
  and the ``target`` is the local database.

  Pull replication is the most useful solution to use if your source database
  has a permanent IP address, and your destination (local) database may have a
  dynamically assigned IP address (for example, through DHCP). This is
  particularly important if you are replicating to a mobile or other device
  from a central server.

- *Push replication* is where the ``source`` is a local database, and
  ``target`` is a remote database.

Specifying the Source and Target Database
=========================================

You must use the URL specification of the CouchDB database if you want to
perform replication in either of the following two situations:

- Replication with a remote database (i.e. another instance of CouchDB on the
  same host, or a different host)

- Replication with a database that requires authentication

For example, to request replication between a database local to the CouchDB
instance to which you send the request, and a remote database you might use the
following request:

.. code-block:: http

    POST http://couchdb:5984/_replicate HTTP/1.1
    Content-Type: application/json
    Accept: application/json

    {
        "source" : "recipes",
        "target" : "http://coucdb-remote:5984/recipes",
    }

In all cases, the requested databases in the ``source`` and ``target``
specification must exist. If they do not, an error will be returned within the
JSON object:

.. code-block:: javascript

    {
        "error" : "db_not_found"
        "reason" : "could not open http://couchdb-remote:5984/ol1ka/",
    }

You can create the target database (providing your user credentials allow it)
by adding the ``create_target`` field to the request object:

.. code-block:: http

    POST http://couchdb:5984/_replicate HTTP/1.1
    Content-Type: application/json
    Accept: application/json

    {
        "create_target" : true
        "source" : "recipes",
        "target" : "http://couchdb-remote:5984/recipes",
    }

The ``create_target`` field is not destructive. If the database already
exists, the replication proceeds as normal.

Single Replication
==================

You can request replication of a database so that the two databases can be
synchronized. By default, the replication process occurs one time and
synchronizes the two databases together. For example, you can request a single
synchronization between two databases by supplying the ``source`` and
``target`` fields within the request JSON content.

.. code-block:: http

    POST http://couchdb:5984/_replicate HTTP/1.1
    Accept: application/json
    Content-Type: application/json

    {
        "source" : "recipes",
        "target" : "recipes-snapshot",
    }

In the above example, the databases ``recipes`` and ``recipes-snapshot`` will
be synchronized. These databases are local to the CouchDB instance where the
request was made. The response will be a JSON structure containing the success
(or failure) of the synchronization process, and statistics about the process:

.. code-block:: javascript

    {
        "ok" : true,
        "history" : [
            {
                "docs_read" : 1000,
                "bulk_get_attempts": 1000,
                "bulk_get_docs": 1000,
                "session_id" : "52c2370f5027043d286daca4de247db0",
                "recorded_seq" : 1000,
                "end_last_seq" : 1000,
                "doc_write_failures" : 0,
                "start_time" : "Thu, 28 Oct 2010 10:24:13 GMT",
                "start_last_seq" : 0,
                "end_time" : "Thu, 28 Oct 2010 10:24:14 GMT",
                "missing_checked" : 0,
                "docs_written" : 1000,
                "missing_found" : 1000
            }
        ],
        "session_id" : "52c2370f5027043d286daca4de247db0",
        "source_last_seq" : 1000
    }

Continuous Replication
======================

Synchronization of a database with the previously noted methods happens only
once, at the time the replicate request is made. To have the target database
permanently replicated from the source, you must set the ``continuous`` field
of the JSON object within the request to true.

With continuous replication changes in the source database are replicated to
the target database in perpetuity until you specifically request that
replication ceases.

.. code-block:: http

    POST http://couchdb:5984/_replicate HTTP/1.1
    Accept: application/json
    Content-Type: application/json

    {
        "continuous" : true
        "source" : "recipes",
        "target" : "http://couchdb-remote:5984/recipes",
    }

Changes will be replicated between the two databases as long as a network
connection is available between the two instances.

.. note::
    Two keep two databases synchronized with each other, you need to set
    replication in both directions; that is, you must replicate from ``source``
    to ``target``, and separately from ``target`` to ``source``.

Canceling Continuous Replication
================================

You can cancel continuous replication by adding the ``cancel`` field to the
JSON request object and setting the value to true. Note that the structure of
the request must be identical to the original for the cancellation request to
be honoured. For example, if you requested continuous replication, the
cancellation request must also contain the ``continuous`` field.

For example, the replication request:

.. code-block:: http

    POST http://couchdb:5984/_replicate HTTP/1.1
    Content-Type: application/json
    Accept: application/json

    {
        "source" : "recipes",
        "target" : "http://couchdb-remote:5984/recipes",
        "create_target" : true,
        "continuous" : true
    }

Must be canceled using the request:

.. code-block:: http

    POST http://couchdb:5984/_replicate HTTP/1.1
    Accept: application/json
    Content-Type: application/json

    {
        "cancel" : true,
        "continuous" : true
        "create_target" : true,
        "source" : "recipes",
        "target" : "http://couchdb-remote:5984/recipes",
    }

Requesting cancellation of a replication that does not exist results in a 404
error.

.. _api/server/_scheduler/jobs:

====================
``/_scheduler/jobs``
====================

.. http:get:: /_scheduler/jobs
    :synopsis: Retrieve information about replication jobs

    List of replication jobs. Includes replications created via
    :ref:`api/server/replicate` endpoint as well as those created from
    replication documents. Does not include replications which have completed
    or have failed to start because replication documents were malformed. Each
    job description will include source and target information, replication id,
    a history of recent event, and a few other things.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`
    :query number limit: How many results to return
    :query number skip: How many result to skip starting at the beginning,
                        ordered by replication ID
    :>json number offset: How many results were skipped
    :>json number total_rows: Total number of replication jobs
    :>json string id: Replication ID.
    :>json string database: Replication document database
    :>json string doc_id: Replication document ID
    :>json list history: Timestamped history of events as a list of objects
    :>json string pid: Replication process ID
    :>json string node: Cluster node where the job is running
    :>json string source: Replication source
    :>json string target: Replication target
    :>json string start_time: Timestamp of when the replication was started
    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    **Request**:

    .. code-block:: http

        GET /_scheduler/jobs HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 1690
        Content-Type: application/json
        Date: Sat, 29 Apr 2017 05:05:16 GMT
        Server: CouchDB (Erlang/OTP)

        {
            "jobs": [
                {
                    "database": "_replicator",
                    "doc_id": "cdyno-0000001-0000003",
                    "history": [
                        {
                            "timestamp": "2017-04-29T05:01:37Z",
                            "type": "started"
                        },
                        {
                            "timestamp": "2017-04-29T05:01:37Z",
                            "type": "added"
                        }
                    ],
                    "id": "8f5b1bd0be6f9166ccfd36fc8be8fc22+continuous",
                    "info": {
                        "changes_pending": 0,
                        "checkpointed_source_seq": "113-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE01ygQLsZsYGqcamiZjKcRqRxwIkGRqA1H-oSbZgk1KMLCzTDE0wdWUBAF6HJIQ",
                        "doc_write_failures": 0,
                        "docs_read": 113,
                        "docs_written": 113,
                        "bulk_get_attempts": 113,
                        "bulk_get_docs": 113,
                        "missing_revisions_found": 113,
                        "revisions_checked": 113,
                        "source_seq": "113-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE01ygQLsZsYGqcamiZjKcRqRxwIkGRqA1H-oSbZgk1KMLCzTDE0wdWUBAF6HJIQ",
                        "through_seq": "113-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE01ygQLsZsYGqcamiZjKcRqRxwIkGRqA1H-oSbZgk1KMLCzTDE0wdWUBAF6HJIQ"
                    },
                    "node": "node1@127.0.0.1",
                    "pid": "<0.1850.0>",
                    "source": "http://myserver.com/foo",
                    "start_time": "2017-04-29T05:01:37Z",
                    "target": "http://adm:*****@localhost:15984/cdyno-0000003/",
                    "user": null
                },
                {
                    "database": "_replicator",
                    "doc_id": "cdyno-0000001-0000002",
                    "history": [
                        {
                            "timestamp": "2017-04-29T05:01:37Z",
                            "type": "started"
                        },
                        {
                            "timestamp": "2017-04-29T05:01:37Z",
                            "type": "added"
                        }
                    ],
                    "id": "e327d79214831ca4c11550b4a453c9ba+continuous",
                    "info": {
                        "changes_pending": null,
                        "checkpointed_source_seq": 0,
                        "doc_write_failures": 0,
                        "docs_read": 12,
                        "docs_written": 12,
                        "bulk_get_attempts": 12,
                        "bulk_get_docs": 12,
                        "missing_revisions_found": 12,
                        "revisions_checked": 12,
                        "source_seq": "12-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE1lzgQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSexgk4yMkhITjS0wdWUBADfEJBg",
                        "through_seq": "12-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE1lzgQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSexgk4yMkhITjS0wdWUBADfEJBg"
                    },
                    "node": "node2@127.0.0.1",
                    "pid": "<0.1757.0>",
                    "source": "http://myserver.com/foo",
                    "start_time": "2017-04-29T05:01:37Z",
                    "target": "http://adm:*****@localhost:15984/cdyno-0000002/",
                    "user": null
                }
            ],
            "offset": 0,
            "total_rows": 2
         }

.. _api/server/_scheduler/docs:

====================
``/_scheduler/docs``
====================

.. versionchanged:: 2.1.0 Use this endpoint to monitor the state of
                    document-based replications. Previously needed to poll both
                    documents and ``_active_tasks`` to get a complete state
                    summary

.. versionchanged:: 3.0.0 In error states the `"info"` field switched
                    from being a string to being an object

.. versionchanged:: 3.3 Added `"bulk_get_attempts"` and `"bulk_get_docs"` the
                    `"info"` object.

.. http:get:: /_scheduler/docs
    :synopsis: Retrieve information about replication documents from the
               ``_replicator`` database.

    List of replication document states. Includes information about all the
    documents, even in ``completed`` and ``failed`` states. For each document
    it returns the document ID, the database, the replication ID, source and
    target, and other information.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`
    :query number limit: How many results to return
    :query number skip: How many result to skip starting at the beginning, if
                        ordered by document ID
    :>json number offset: How many results were skipped
    :>json number total_rows: Total number of replication documents.
    :>json string id: Replication ID, or ``null`` if state is ``completed`` or
                      ``failed``
    :>json string state: One of following states (see :ref:`replicator/states`
                         for descriptions): ``initializing``, ``running``,
                         ``completed``, ``pending``, ``crashing``, ``error``,
                         ``failed``
    :>json string database: Database where replication document came from
    :>json string doc_id: Replication document ID
    :>json string node: Cluster node where the job is running
    :>json string source: Replication source
    :>json string target: Replication target
    :>json string start_time: Timestamp of when the replication was started
    :>json string last_updated: Timestamp of last state update
    :>json object info: Will contain additional information about the
                        state. For errors, this will be an object with
                        an ``"error"`` field and string value. For
                        success states, see below.
    :>json number error_count: Consecutive errors count. Indicates how many
                               times in a row this replication has crashed.
                               Replication will be retried with an exponential
                               backoff based on this number. As soon as the
                               replication succeeds this count is reset to 0.
                               To can be used to get an idea why a particular
                               replication is not making progress.
    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    The ``info`` field of a scheduler doc:

    :json number revisions_checked: The count of revisions which have been
        checked since this replication began.
    :json number missing_revisions_found: The count of revisions which were
        found on the source, but missing from the target.
    :json number docs_read: The count of docs which have been read from the
        source.
    :json number docs_written: The count of docs which have been written to the
        target.
    :json number bulk_get_attempts: The total count of attempted doc revisions
        fetched with ``_bulk_get``.
    :json number bulk_get_docs: The total count of successful docs fetched with
        ``_bulk_get``.
    :json number changes_pending: The count of changes not yet replicated.
    :json number doc_write_failures: The count of docs which failed to be
        written to the target.
    :json object checkpointed_source_seq: The source sequence id which was last
        successfully replicated.

    **Request**:

    .. code-block:: http

        GET /_scheduler/docs HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json
        Date: Sat, 29 Apr 2017 05:10:08 GMT
        Server: Server: CouchDB (Erlang/OTP)
        Transfer-Encoding: chunked

        {
            "docs": [
                {
                    "database": "_replicator",
                    "doc_id": "cdyno-0000001-0000002",
                    "error_count": 0,
                    "id": "e327d79214831ca4c11550b4a453c9ba+continuous",
                    "info": {
                        "changes_pending": 15,
                        "checkpointed_source_seq": "60-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYEyVygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSSpgk4yMkhITjS0wdWUBAENCJEg",
                        "doc_write_failures": 0,
                        "docs_read": 67,
                        "bulk_get_attempts": 67,
                        "bulk_get_docs": 67,
                        "docs_written": 67,
                        "missing_revisions_found": 67,
                        "revisions_checked": 67,
                        "source_seq": "67-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE2VygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSepgk4yMkhITjS0wdWUBAEVKJE8",
                        "through_seq": "67-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE2VygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSepgk4yMkhITjS0wdWUBAEVKJE8"
                    },
                    "last_updated": "2017-04-29T05:01:37Z",
                    "node": "node2@127.0.0.1",
                    "source_proxy": null,
                    "target_proxy": null,
                    "source": "http://myserver.com/foo",
                    "start_time": "2017-04-29T05:01:37Z",
                    "state": "running",
                    "target": "http://adm:*****@localhost:15984/cdyno-0000002/"
                },
                {
                    "database": "_replicator",
                    "doc_id": "cdyno-0000001-0000003",
                    "error_count": 0,
                    "id": "8f5b1bd0be6f9166ccfd36fc8be8fc22+continuous",
                    "info": {
                        "changes_pending": null,
                        "checkpointed_source_seq": 0,
                        "doc_write_failures": 0,
                        "bulk_get_attempts": 12,
                        "bulk_get_docs": 12,
                        "docs_read": 12,
                        "docs_written": 12,
                        "missing_revisions_found": 12,
                        "revisions_checked": 12,
                        "source_seq": "12-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE1lzgQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSexgk4yMkhITjS0wdWUBADfEJBg",
                        "through_seq": "12-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE1lzgQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSexgk4yMkhITjS0wdWUBADfEJBg"
                    },
                    "last_updated": "2017-04-29T05:01:37Z",
                    "node": "node1@127.0.0.1",
                    "source_proxy": null,
                    "target_proxy": null,
                    "source": "http://myserver.com/foo",
                    "start_time": "2017-04-29T05:01:37Z",
                    "state": "running",
                    "target": "http://adm:*****@localhost:15984/cdyno-0000003/"
                }
            ],
            "offset": 0,
            "total_rows": 2
        }

.. http:get:: /_scheduler/docs/{replicator_db}
    :synopsis: Retrieve information about replication documents from a specific
               replicator database.

    Get information about replication documents from a replicator database.
    The default replicator database is ``_replicator`` but other replicator
    databases can exist if their name ends with the suffix ``/_replicator``.

    .. note:: As a convenience slashes (``/``) in replicator db names do not
       have to be escaped. So ``/_scheduler/docs/other/_replicator`` is valid
       and equivalent to ``/_scheduler/docs/other%2f_replicator``

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`
    :query number limit: How many results to return
    :query number skip: How many result to skip starting at the beginning, if
                        ordered by document ID
    :>json number offset: How many results were skipped
    :>json number total_rows: Total number of replication documents.
    :>json string id: Replication ID, or ``null`` if state is ``completed`` or
                      ``failed``
    :>json string state: One of following states (see :ref:`replicator/states`
                         for descriptions): ``initializing``, ``running``,
                         ``completed``, ``pending``, ``crashing``, ``error``,
                         ``failed``
    :>json string database: Database where replication document came from
    :>json string doc_id: Replication document ID
    :>json string node: Cluster node where the job is running
    :>json string source: Replication source
    :>json string target: Replication target
    :>json string start_time: Timestamp of when the replication was started
    :>json string last_update: Timestamp of last state update
    :>json object info: Will contain additional information about the
                        state. For errors, this will be an object with
                        an ``"error"`` field and string value. For
                        success states, see below.
    :>json number error_count: Consecutive errors count. Indicates how many
                               times in a row this replication has crashed.
                               Replication will be retried with an exponential
                               backoff based on this number. As soon as the
                               replication succeeds this count is reset to 0.
                               To can be used to get an idea why a particular
                               replication is not making progress.
    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    The ``info`` field of a scheduler doc:

    :json number revisions_checked: The count of revisions which have been
        checked since this replication began.
    :json number missing_revisions_found: The count of revisions which were
        found on the source, but missing from the target.
    :json number docs_read: The count of docs which have been read from the
        source.
    :json number docs_written: The count of docs which have been written to the
        target.
    :json number bulk_get_attempts: The total count of attempted doc revisions
        fetched with ``_bulk_get``.
    :json number bulk_get_docs: The total count of successful docs fetched with
        ``_bulk_get``.
    :json number changes_pending: The count of changes not yet replicated.
    :json number doc_write_failures: The count of docs which failed to be
        written to the target.
    :json object checkpointed_source_seq: The source sequence id which was last
        successfully replicated.

    **Request**:

    .. code-block:: http

        GET /_scheduler/docs/other/_replicator HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json
        Date: Sat, 29 Apr 2017 05:10:08 GMT
        Server: Server: CouchDB (Erlang/OTP)
        Transfer-Encoding: chunked

        {
            "docs": [
                {
                    "database": "other/_replicator",
                    "doc_id": "cdyno-0000001-0000002",
                    "error_count": 0,
                    "id": "e327d79214831ca4c11550b4a453c9ba+continuous",
                    "info": {
                        "changes_pending": 0,
                        "checkpointed_source_seq": "60-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYEyVygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSSpgk4yMkhITjS0wdWUBAENCJEg",
                        "doc_write_failures": 0,
                        "docs_read": 67,
                        "bulk_get_attempts": 67,
                        "bulk_get_docs": 67,
                        "docs_written": 67,
                        "missing_revisions_found": 67,
                        "revisions_checked": 67,
                        "source_seq": "67-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE2VygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSepgk4yMkhITjS0wdWUBAEVKJE8",
                        "through_seq": "67-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE2VygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSepgk4yMkhITjS0wdWUBAEVKJE8"
                    },
                    "last_updated": "2017-04-29T05:01:37Z",
                    "node": "node2@127.0.0.1",
                    "source_proxy": null,
                    "target_proxy": null,
                    "source": "http://myserver.com/foo",
                    "start_time": "2017-04-29T05:01:37Z",
                    "state": "running",
                    "target": "http://adm:*****@localhost:15984/cdyno-0000002/"
                }
            ],
            "offset": 0,
            "total_rows": 1
        }

.. http:get:: /_scheduler/docs/{replicator_db}/{docid}
    :synopsis: Retrieve information about a particular replication document

    .. note:: As a convenience slashes (``/``) in replicator db names do not
       have to be escaped. So ``/_scheduler/docs/other/_replicator`` is valid
       and equivalent to ``/_scheduler/docs/other%2f_replicator``

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`
    :>json string id: Replication ID, or ``null`` if state is ``completed`` or
                      ``failed``
    :>json string state: One of following states (see :ref:`replicator/states`
                         for descriptions): ``initializing``, ``running``,
                         ``completed``, ``pending``, ``crashing``, ``error``,
                         ``failed``
    :>json string database: Database where replication document came from
    :>json string doc_id: Replication document ID
    :>json string node: Cluster node where the job is running
    :>json string source: Replication source
    :>json string target: Replication target
    :>json string start_time: Timestamp of when the replication was started
    :>json string last_update: Timestamp of last state update
    :>json object info: Will contain additional information about the
                        state. For errors, this will be an object with
                        an ``"error"`` field and string value. For
                        success states, see below.
    :>json number error_count: Consecutive errors count. Indicates how many
                               times in a row this replication has crashed.
                               Replication will be retried with an exponential
                               backoff based on this number. As soon as the
                               replication succeeds this count is reset to 0.
                               To can be used to get an idea why a particular
                               replication is not making progress.
    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    The ``info`` field of a scheduler doc:

    :json number revisions_checked: The count of revisions which have been
        checked since this replication began.
    :json number missing_revisions_found: The count of revisions which were
        found on the source, but missing from the target.
    :json number docs_read: The count of docs which have been read from the
        source.
    :json number docs_written: The count of docs which have been written to the
        target.
    :json number bulk_get_attempts: The total count of attempted doc revisions
        fetched with ``_bulk_get``.
    :json number bulk_get_docs: The total count of successful docs fetched with
        ``_bulk_get``.
    :json number changes_pending: The count of changes not yet replicated.
    :json number doc_write_failures: The count of docs which failed to be
        written to the target.
    :json object checkpointed_source_seq: The source sequence id which was last
        successfully replicated.

     **Request**:

    .. code-block:: http

        GET /_scheduler/docs/other/_replicator/cdyno-0000001-0000002 HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json
        Date: Sat, 29 Apr 2017 05:10:08 GMT
        Server: Server: CouchDB (Erlang/OTP)
        Transfer-Encoding: chunked

        {
            "database": "other/_replicator",
            "doc_id": "cdyno-0000001-0000002",
            "error_count": 0,
            "id": "e327d79214831ca4c11550b4a453c9ba+continuous",
            "info": {
                "changes_pending": 0,
                "checkpointed_source_seq": "60-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYEyVygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSSpgk4yMkhITjS0wdWUBAENCJEg",
                "doc_write_failures": 0,
                "docs_read": 67,
                "bulk_get_attempts": 67,
                "bulk_get_docs": 67,
                "docs_written": 67,
                "missing_revisions_found": 67,
                "revisions_checked": 67,
                "source_seq": "67-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE2VygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSepgk4yMkhITjS0wdWUBAEVKJE8",
                "through_seq": "67-g1AAAACTeJzLYWBgYMpgTmHgz8tPSTV0MDQy1zMAQsMckEQiQ1L9____szKYE2VygQLsBsZm5pZJJpjKcRqRxwIkGRqA1H-oSepgk4yMkhITjS0wdWUBAEVKJE8"
            },
            "last_updated": "2017-04-29T05:01:37Z",
            "node": "node2@127.0.0.1",
            "source_proxy": null,
            "target_proxy": null,
            "source": "http://myserver.com/foo",
            "start_time": "2017-04-29T05:01:37Z",
            "state": "running",
            "target": "http://adm:*****@localhost:15984/cdyno-0000002/"
        }

.. _api/server/name:

======================
``/_node/{node-name}``
======================

.. http:get:: /_node/{node-name}
    :synopsis: Returns node name

    The ``/_node/{node-name}`` endpoint can be used to confirm the Erlang
    node name of the server that processes the request. This is most useful
    when accessing ``/_node/_local`` to retrieve this information. Repeatedly
    retrieving this information for a CouchDB endpoint can be useful to determine
    if a CouchDB cluster is correctly proxied through a reverse load balancer.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :code 200: Request completed successfully

    **Request**:

    .. code-block:: http

        GET /_node/_local HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

      HTTP/1.1 200 OK
      Cache-Control: must-revalidate
      Content-Length: 27
      Content-Type: application/json
      Date: Tue, 28 Jan 2020 19:25:51 GMT
      Server: CouchDB (Erlang OTP)
      X-Couch-Request-ID: 5b8db6c677
      X-CouchDB-Body-Time: 0

      {"name":"node1@127.0.0.1"}

.. _api/server/stats:

=============================
``/_node/{node-name}/_stats``
=============================

.. http:get:: /_node/{node-name}/_stats
    :synopsis: Returns server statistics

    The ``_stats`` resource returns a JSON object containing the statistics
    for the running server. The object is structured with top-level sections
    collating the statistics for a range of entries, with each individual
    statistic being easily identified, and the content of each statistic is
    self-describing.

    Statistics are sampled internally on a :ref:`configurable interval
    <config/stats>`. When monitoring the ``_stats`` endpoint, you need to use
    a polling frequency of at least twice this to observe accurate results.
    For example, if the :ref:`interval <config/stats>` is 10 seconds,
    poll ``_stats`` at least every 5 seconds.

    The literal string ``_local`` serves as an alias for the local node name, so
    for all stats URLs, ``{node-name}`` may be replaced with ``_local``, to
    interact with the local node's statistics.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :code 200: Request completed successfully

    **Request**:

    .. code-block:: http

        GET /_node/_local/_stats/couchdb/request_time HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 187
        Content-Type: application/json
        Date: Sat, 10 Aug 2013 11:41:11 GMT
        Server: CouchDB (Erlang/OTP)

        {
          "value": {
            "min": 0,
            "max": 0,
            "arithmetic_mean": 0,
            "geometric_mean": 0,
            "harmonic_mean": 0,
            "median": 0,
            "variance": 0,
            "standard_deviation": 0,
            "skewness": 0,
            "kurtosis": 0,
            "percentile": [
              [
                50,
                0
              ],
              [
                75,
                0
              ],
              [
                90,
                0
              ],
              [
                95,
                0
              ],
              [
                99,
                0
              ],
              [
                999,
                0
              ]
            ],
            "histogram": [
              [
                0,
                0
              ]
            ],
            "n": 0
          },
          "type": "histogram",
          "desc": "length of a request inside CouchDB without MochiWeb"
        }

The fields provide the current, minimum and maximum, and a collection of
statistical means and quantities. The quantity in each case is not defined, but
the descriptions below provide sufficient detail to determine units.

Statistics are reported by 'group'.  The statistics are divided into the
following top-level sections:

- ``couch_log``: Logging subsystem
- ``couch_replicator``: Replication scheduler and subsystem
- ``couchdb``: Primary CouchDB database operations
- ``fabric``: Cluster-related operations
- ``global_changes``: Global changes feed
- ``mem3``: Node membership-related statistics
- ``pread``: CouchDB file-related exceptions
- ``rexi``: Cluster internal RPC-related statistics

The type of the statistic is included in the ``type`` field, and is one of
the following:

- ``counter``: Monotonically increasing counter, resets on restart
- ``histogram``: Binned set of values with meaningful subdivisions.
  Scoped to the current :ref:`collection interval <config/stats>`.
- ``gauge``: Single numerical value that can go up and down

You can also access individual statistics by quoting the statistics sections
and statistic ID as part of the URL path. For example, to get the
``request_time`` statistics within the ``couchdb`` section for the target
node, you can use:

.. code-block:: http

    GET /_node/_local/_stats/couchdb/request_time HTTP/1.1

This returns an entire statistics object, as with the full request, but
containing only the requested individual statistic.

.. _api/server/prometheus:

==================================
``/_node/{node-name}/_prometheus``
==================================

.. http:get:: /_node/{node-name}/_prometheus
    :synopsis: Returns server statistics in prometheus format

    The ``_prometheus`` resource returns a text/plain response that consolidates our
    :ref:`api/server/stats`, and :ref:`api/server/system` endpoints. The format is
    determined by `Prometheus <https://prometheus.io/docs/introduction/overview/>`_.
    The format version is 2.0.

    **Request**:

    .. code-block:: http

        GET /_node/_local/_prometheus HTTP/1.1
        Accept: text/plain
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 187
        Content-Type: text/plain; version=2.0
        Date: Sat, 10 May 2020 11:41:11 GMT
        Server: CouchDB (Erlang/OTP)

        # TYPE couchdb_couch_log_requests_total counter
        couchdb_couch_log_requests_total{level="alert"} 0
        couchdb_couch_log_requests_total{level="critical"} 0
        couchdb_couch_log_requests_total{level="debug"} 0
        couchdb_couch_log_requests_total{level="emergency"} 0
        couchdb_couch_log_requests_total{level="error"} 0
        couchdb_couch_log_requests_total{level="info"} 8
        couchdb_couch_log_requests_total{level="notice"} 51
        couchdb_couch_log_requests_total{level="warning"} 0
        # TYPE couchdb_couch_replicator_changes_manager_deaths_total counter
        couchdb_couch_replicator_changes_manager_deaths_total 0
        # TYPE couchdb_couch_replicator_changes_queue_deaths_total counter
        couchdb_couch_replicator_changes_queue_deaths_total 0
        # TYPE couchdb_couch_replicator_changes_read_failures_total counter
        couchdb_couch_replicator_changes_read_failures_total 0
        # TYPE couchdb_couch_replicator_changes_reader_deaths_total counter
        couchdb_couch_replicator_changes_reader_deaths_total 0
        # TYPE couchdb_couch_replicator_checkpoints_failure_total counter
        couchdb_couch_replicator_checkpoints_failure_total 0
        # TYPE couchdb_couch_replicator_checkpoints_total counter
        couchdb_couch_replicator_checkpoints_total 0
        # TYPE couchdb_couch_replicator_cluster_is_stable gauge
        couchdb_couch_replicator_cluster_is_stable 1
        # TYPE couchdb_couch_replicator_connection_acquires_total counter
        couchdb_couch_replicator_connection_acquires_total 0
        # TYPE couchdb_couch_replicator_connection_closes_total counter
        couchdb_couch_replicator_connection_closes_total 0
        # TYPE couchdb_couch_replicator_connection_creates_total counter
        couchdb_couch_replicator_connection_creates_total 0
        # TYPE couchdb_couch_replicator_connection_owner_crashes_total counter
        couchdb_couch_replicator_connection_owner_crashes_total 0
        # TYPE couchdb_couch_replicator_connection_releases_total counter
        couchdb_couch_replicator_connection_releases_total 0
        # TYPE couchdb_couch_replicator_connection_worker_crashes_total counter
        couchdb_couch_replicator_connection_worker_crashes_total 0
        # TYPE couchdb_couch_replicator_db_scans_total counter
        couchdb_couch_replicator_db_scans_total 1
        # TYPE couchdb_couch_replicator_docs_completed_state_updates_total counter
        couchdb_couch_replicator_docs_completed_state_updates_total 0
        # TYPE couchdb_couch_replicator_docs_db_changes_total counter
        couchdb_couch_replicator_docs_db_changes_total 0
        # TYPE couchdb_couch_replicator_docs_dbs_created_total counter
        couchdb_couch_replicator_docs_dbs_created_total 0
        # TYPE couchdb_couch_replicator_docs_dbs_deleted_total counter
        couchdb_couch_replicator_docs_dbs_deleted_total 0
        # TYPE couchdb_couch_replicator_docs_dbs_found_total counter
        couchdb_couch_replicator_docs_dbs_found_total 2
        # TYPE couchdb_couch_replicator_docs_failed_state_updates_total counter
        couchdb_couch_replicator_docs_failed_state_updates_total 0
        # TYPE couchdb_couch_replicator_failed_starts_total counter
        couchdb_couch_replicator_failed_starts_total 0
        # TYPE couchdb_couch_replicator_jobs_adds_total counter
        couchdb_couch_replicator_jobs_adds_total 0
        # TYPE couchdb_couch_replicator_jobs_crashed gauge
        couchdb_couch_replicator_jobs_crashed 0
        # TYPE couchdb_couch_replicator_jobs_crashes_total counter
        couchdb_couch_replicator_jobs_crashes_total 0
        # TYPE couchdb_couch_replicator_jobs_duplicate_adds_total counter
        couchdb_couch_replicator_jobs_duplicate_adds_total 0
        # TYPE couchdb_couch_replicator_jobs_pending gauge
        couchdb_couch_replicator_jobs_pending 0
        # TYPE couchdb_couch_replicator_jobs_removes_total counter
        couchdb_couch_replicator_jobs_removes_total 0
        # TYPE couchdb_couch_replicator_jobs_running gauge
        couchdb_couch_replicator_jobs_running 0
        # TYPE couchdb_couch_replicator_jobs_starts_total counter
        couchdb_couch_replicator_jobs_starts_total 0
        # TYPE couchdb_couch_replicator_jobs_stops_total counter
        couchdb_couch_replicator_jobs_stops_total 0
        # TYPE couchdb_couch_replicator_jobs_total gauge
        couchdb_couch_replicator_jobs_total 0
        # TYPE couchdb_couch_replicator_requests_total counter
        couchdb_couch_replicator_requests_total 0
        # TYPE couchdb_couch_replicator_responses_failure_total counter
        couchdb_couch_replicator_responses_failure_total 0
        # TYPE couchdb_couch_replicator_responses_total counter
        couchdb_couch_replicator_responses_total 0
        # TYPE couchdb_couch_replicator_stream_responses_failure_total counter
        couchdb_couch_replicator_stream_responses_failure_total 0
        # TYPE couchdb_couch_replicator_stream_responses_total counter
        couchdb_couch_replicator_stream_responses_total 0
        # TYPE couchdb_couch_replicator_worker_deaths_total counter
        couchdb_couch_replicator_worker_deaths_total 0
        # TYPE couchdb_couch_replicator_workers_started_total counter
        couchdb_couch_replicator_workers_started_total 0
        # TYPE couchdb_auth_cache_requests_total counter
        couchdb_auth_cache_requests_total 0
        # TYPE couchdb_auth_cache_misses_total counter
        couchdb_auth_cache_misses_total 0
        # TYPE couchdb_collect_results_time_seconds summary
        couchdb_collect_results_time_seconds{quantile="0.5"} 0.0
        couchdb_collect_results_time_seconds{quantile="0.75"} 0.0
        couchdb_collect_results_time_seconds{quantile="0.9"} 0.0
        couchdb_collect_results_time_seconds{quantile="0.95"} 0.0
        couchdb_collect_results_time_seconds{quantile="0.99"} 0.0
        couchdb_collect_results_time_seconds{quantile="0.999"} 0.0
        couchdb_collect_results_time_seconds_sum 0.0
        couchdb_collect_results_time_seconds_count 0
        # TYPE couchdb_couch_server_lru_skip_total counter
        couchdb_couch_server_lru_skip_total 0
        # TYPE couchdb_database_purges_total counter
        couchdb_database_purges_total 0
        # TYPE couchdb_database_reads_total counter
        couchdb_database_reads_total 0
        # TYPE couchdb_database_writes_total counter
        couchdb_database_writes_total 0
        # TYPE couchdb_db_open_time_seconds summary
        couchdb_db_open_time_seconds{quantile="0.5"} 0.0
        couchdb_db_open_time_seconds{quantile="0.75"} 0.0
        couchdb_db_open_time_seconds{quantile="0.9"} 0.0
        couchdb_db_open_time_seconds{quantile="0.95"} 0.0
        couchdb_db_open_time_seconds{quantile="0.99"} 0.0
        couchdb_db_open_time_seconds{quantile="0.999"} 0.0
        couchdb_db_open_time_seconds_sum 0.0
        couchdb_db_open_time_seconds_count 0
        # TYPE couchdb_dbinfo_seconds summary
        couchdb_dbinfo_seconds{quantile="0.5"} 0.0
        couchdb_dbinfo_seconds{quantile="0.75"} 0.0
        couchdb_dbinfo_seconds{quantile="0.9"} 0.0
        couchdb_dbinfo_seconds{quantile="0.95"} 0.0
        couchdb_dbinfo_seconds{quantile="0.99"} 0.0
        couchdb_dbinfo_seconds{quantile="0.999"} 0.0
        couchdb_dbinfo_seconds_sum 0.0
        couchdb_dbinfo_seconds_count 0
        # TYPE couchdb_document_inserts_total counter
        couchdb_document_inserts_total 0
        # TYPE couchdb_document_purges_failure_total counter
        couchdb_document_purges_failure_total 0
        # TYPE couchdb_document_purges_success_total counter
        couchdb_document_purges_success_total 0
        # TYPE couchdb_document_purges_total_total counter
        couchdb_document_purges_total_total 0
        # TYPE couchdb_document_writes_total counter
        couchdb_document_writes_total 0
        # TYPE couchdb_httpd_aborted_requests_total counter
        couchdb_httpd_aborted_requests_total 0
        # TYPE couchdb_httpd_all_docs_timeouts_total counter
        couchdb_httpd_all_docs_timeouts_total 0
        # TYPE couchdb_httpd_bulk_docs_seconds summary
        couchdb_httpd_bulk_docs_seconds{quantile="0.5"} 0.0
        couchdb_httpd_bulk_docs_seconds{quantile="0.75"} 0.0
        couchdb_httpd_bulk_docs_seconds{quantile="0.9"} 0.0
        couchdb_httpd_bulk_docs_seconds{quantile="0.95"} 0.0
        couchdb_httpd_bulk_docs_seconds{quantile="0.99"} 0.0
        couchdb_httpd_bulk_docs_seconds{quantile="0.999"} 0.0
        couchdb_httpd_bulk_docs_seconds_sum 0.0
        couchdb_httpd_bulk_docs_seconds_count 0
        ...remaining couchdb metrics from _stats and _system

If an additional port config option is specified, then a client can call this API using
that port which does not require authentication. This option is ``false`` (OFF)
by default. When the option is ``true`` (ON), the default ports for a 3 node cluster
are ``17986``, ``27986``, ``37986``.
See :ref:`Configuration of Prometheus Endpoint <config/prometheus>` for details.

.. code-block:: http

        GET /_node/_local/_prometheus HTTP/1.1
        Accept: text/plain
        Host: localhost:17986

.. _api/server/system:

==============================
``/_node/{node-name}/_system``
==============================

.. http:get:: /_node/{node-name}/_system
    :synopsis: Returns system-level server statistics

    The ``_system`` resource returns a JSON object containing various
    system-level statistics for the running server. The object is structured
    with top-level sections collating the statistics for a range of entries,
    with each individual statistic being easily identified, and the content of
    each statistic is self-describing.

    The literal string ``_local`` serves as an alias for the local node name, so
    for all stats URLs, ``{node-name}`` may be replaced with ``_local``, to
    interact with the local node's statistics.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :code 200: Request completed successfully

    **Request**:

    .. code-block:: http

        GET /_node/_local/_system HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 187
        Content-Type: application/json
        Date: Sat, 10 Aug 2013 11:41:11 GMT
        Server: CouchDB (Erlang/OTP)

        {
          "uptime": 259,
          "memory": {}
        }

    These statistics are generally intended for CouchDB developers only.

.. _api/server/restart:

===============================
``/_node/{node-name}/_restart``
===============================

.. http:post:: /_node/{node-name}/_restart
    :synopsis: Restarts CouchDB application on a given node

    This API is to facilitate integration testing only
    it is not meant to be used in production

    :code 200: Request completed successfully

.. _api/server/versions:

================================
``/_node/{node-name}/_versions``
================================

.. http:get:: /_node/{node-name}/_versions
    :synopsis: Returns system-level server version informations

    The ``_versions`` resource returns a JSON object containing various
    system-level informations for the running server.

    The literal string ``_local`` serves as an alias for the local node name, so
    for all stats URLs, ``{node-name}`` may be replaced with ``_local``, to
    interact with the local node's informations.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :>header Content-Type: - :mimetype:`application/json`
    :code 200: Request completed successfully

    **Request**:

    .. code-block:: http

        GET /_node/_local/_versions HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 368
        Content-Type: application/json
        Date: Sat, 03 Sep 2022 08:12:12 GMT
        Server: CouchDB/3.2.2-ea382cf (Erlang OTP/25)

        {
            "javascript_engine": {
                "version": "91",
                "name": "spidermonkey"
            },
            "erlang": {
                "version": "25.0.4",
                "supported_hashes": [
                    "sha",
                    "sha224",
                    "sha256",
                ]
            },
            "collation_driver": {
                "name": "libicu",
                "library_version": "70.1",
                "collator_version": "153.112",
                "collation_algorithm_version": "14"
            }
        }

.. _api/server/search_analyze:

==========================================
``/_search_analyze``
==========================================

.. warning::
    Search endpoints require a running search plugin connected to each cluster
    node. See :ref:`Search Plugin Installation <install/search>` for details.

.. versionadded:: 3.0

.. http:post:: /_search_analyze
    :synopsis: Tests the results of analyzer tokenization

    Tests the results of Lucene analyzer tokenization on sample text.

    :param field: Type of analyzer
    :param text:  Analyzer token you want to test
    :code 200: Request completed successfully
    :code 400: Request body is wrong (malformed or missing one of the mandatory fields)
    :code 500: A server error (or other kind of error) occurred

**Request**:

.. code-block:: http

    POST /_search_analyze HTTP/1.1
    Host: localhost:5984
    Content-Type: application/json

    {"analyzer":"english", "text":"running"}

**Response**:

.. code-block:: javascript

    {
        "tokens": [
            "run"
        ]
    }

.. _api/server/utils:

===========
``/_utils``
===========

.. http:get:: /_utils
    :synopsis: Redirects to /_utils/

    Accesses the built-in Fauxton administration interface for CouchDB.

    :>header Location: New URI location
    :code 301: Redirects to :get:`/_utils/`

.. http:get:: /_utils/
    :synopsis: CouchDB administration interface (Fauxton)

    :>header Content-Type: :mimetype:`text/html`
    :>header Last-Modified: Static files modification timestamp
    :code 200: Request completed successfully

.. _api/server/up:

========
``/_up``
========

.. versionadded:: 2.0

.. http:get:: /_up
    :synopsis: Health check endpoint

    Confirms that the server is up, running, and ready to respond to requests.
    If :config:option:`maintenance_mode <couchdb/maintenance_mode>` is
    ``true`` or ``nolb``, the endpoint will return a 404 response.

    :>header Content-Type: :mimetype:`application/json`
    :code 200: Request completed successfully
    :code 404: The server is unavailable for requests at this time.

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Cache-Control: must-revalidate
        Content-Length: 16
        Content-Type: application/json
        Date: Sat, 17 Mar 2018 04:46:26 GMT
        Server: CouchDB/2.2.0-f999071ec (Erlang OTP/19)
        X-Couch-Request-ID: c57a3b2787
        X-CouchDB-Body-Time: 0

        {"status":"ok"}

.. _api/server/uuids:

===========
``/_uuids``
===========

.. versionchanged:: 2.0.0

.. http:get:: /_uuids
    :synopsis: Generates a list of UUIDs from the server

    Requests one or more Universally Unique Identifiers (UUIDs) from the
    CouchDB instance. The response is a JSON object providing a list of UUIDs.

    :<header Accept: - :mimetype:`application/json`
                     - :mimetype:`text/plain`
    :query number count: Number of UUIDs to return. Default is ``1``.
    :>header Content-Type: - :mimetype:`application/json`
                           - :mimetype:`text/plain; charset=utf-8`
    :>header ETag: Response hash
    :code 200: Request completed successfully
    :code 400: Requested more UUIDs than is :config:option:`allowed
               <uuids/max_count>` to retrieve

    **Request**:

    .. code-block:: http

        GET /_uuids?count=10 HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Length: 362
        Content-Type: application/json
        Date: Sat, 10 Aug 2013 11:46:25 GMT
        ETag: "DGRWWQFLUDWN5MRKSLKQ425XV"
        Expires: Fri, 01 Jan 1990 00:00:00 GMT
        Pragma: no-cache
        Server: CouchDB (Erlang/OTP)

        {
            "uuids": [
                "75480ca477454894678e22eec6002413",
                "75480ca477454894678e22eec600250b",
                "75480ca477454894678e22eec6002c41",
                "75480ca477454894678e22eec6003b90",
                "75480ca477454894678e22eec6003fca",
                "75480ca477454894678e22eec6004bef",
                "75480ca477454894678e22eec600528f",
                "75480ca477454894678e22eec6005e0b",
                "75480ca477454894678e22eec6006158",
                "75480ca477454894678e22eec6006161"
            ]
        }

The UUID type is determined by the :config:option:`UUID algorithm
<uuids/algorithm>` setting in the CouchDB configuration.

The UUID type may be changed at any time through the
:ref:`Configuration API <api/config/section/key>`. For example, the UUID type
could be changed to ``random`` by sending this HTTP request:

.. code-block:: http

    PUT http://couchdb:5984/_node/nonode@nohost/_config/uuids/algorithm HTTP/1.1
    Content-Type: application/json
    Accept: */*

    "random"

You can verify the change by obtaining a list of UUIDs:

.. code-block:: javascript

    {
        "uuids" : [
            "031aad7b469956cf2826fcb2a9260492",
            "6ec875e15e6b385120938df18ee8e496",
            "cff9e881516483911aa2f0e98949092d",
            "b89d37509d39dd712546f9510d4a9271",
            "2e0dbf7f6c4ad716f21938a016e4e59f"
        ]
    }

.. _api/server/favicon:

================
``/favicon.ico``
================

.. http:get:: /favicon.ico
    :synopsis: Returns the site icon

    Binary content for the `favicon.ico` site icon.

    :>header Content-Type: :mimetype:`image/x-icon`
    :code 200: Request completed successfully
    :code 404: The requested content could not be found

.. _api/server/reshard:

=============
``/_reshard``
=============

.. versionadded:: 2.4

.. http:get:: /_reshard
    :synopsis: Retrieve summary information about resharding on the cluster

    Returns a count of completed, failed, running, stopped, and total jobs
    along with the state of resharding on the cluster.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`

    :>json string state: ``stopped`` or ``running``
    :>json string state_reason: ``null`` or string describing additional
                                information or reason associated with the state
    :>json number completed: Count of completed resharding jobs
    :>json number failed: Count of failed resharding jobs
    :>json number running: Count of running resharding jobs
    :>json number stopped: Count of stopped resharding jobs
    :>json number total: Total count of resharding jobs

    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    **Request**:

    .. code-block:: http

        GET /_reshard HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "completed": 21,
            "failed": 0,
            "running": 3,
            "state": "running",
            "state_reason": null,
            "stopped": 0,
            "total": 24
        }

.. http:get:: /_reshard/state
    :synopsis: Retrieve the state of resharding on the cluster

    Returns the resharding state and optional information about the state.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`

    :>json string state: ``stopped`` or ``running``
    :>json string state_reason: Additional  information  or  reason  associated
                                with the state

    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    **Request**:

    .. code-block:: http

        GET /_reshard/state HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "reason": null,
            "state": "running"
        }

.. http:put:: /_reshard/state
    :synopsis: Change resharding state on the cluster

    Change the resharding state on the cluster. The states are
    ``stopped`` or ``running``. This starts and stops global resharding on all
    the nodes of the cluster. If there are any running jobs, they
    will be stopped when the state changes to ``stopped``. When the state
    changes back to ``running`` those job will continue running.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`

    :<json string state: ``stopped`` or ``running``
    :<json string state_reason: Optional string describing additional
                                information or reason associated with the state

    :>json boolean ok: ``true``

    :code 200: Request completed successfully
    :code 400: Invalid request. Could be a bad or missing state name.
    :code 401: CouchDB Server Administrator privileges required

    **Request**:

    .. code-block:: http

        PUT /_reshard/state HTTP/1.1
        Accept: application/json
        Host: localhost:5984

        {
            "state": "stopped",
            "reason": "Rebalancing in progress"
        }

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "ok": true
        }

.. http:get:: /_reshard/jobs
    :synopsis: Retrieve information about all the resharding jobs on the cluster

    .. note:: The shape of the response and the ``total_rows`` and ``offset``
              field in particular are meant to be consistent with the
              ``_scheduler/jobs`` endpoint.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`

    :>json list jobs: Array of json objects, one for each resharding job. For
                      the fields of each job see the /_reshard/job/{jobid}
                      endpoint.
    :>json number offset: Offset in the list of jobs object. Currently
                          hard-coded at ``0``.
    :>json number total_rows: Total number of resharding jobs on the cluster.

    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    **Request**:

    .. code-block:: http

        GET /_reshard/jobs HTTP/1.1
        Accept: application/json

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "jobs": [
                {
                    "history": [
                        {
                            "detail": null,
                            "timestamp": "2019-03-28T15:28:02Z",
                            "type": "new"
                        },
                        {
                            "detail": "initial_copy",
                            "timestamp": "2019-03-28T15:28:02Z",
                            "type": "running"
                        }
                    ],
                    "id": "001-171d1211418996ff47bd610b1d1257fc4ca2628868def4a05e63e8f8fe50694a",
                    "job_state": "completed",
                    "node": "node1@127.0.0.1",
                    "source": "shards/00000000-1fffffff/d1.1553786862",
                    "split_state": "completed",
                    "start_time": "2019-03-28T15:28:02Z",
                    "state_info": {},
                    "target": [
                        "shards/00000000-0fffffff/d1.1553786862",
                        "shards/10000000-1fffffff/d1.1553786862"
                    ],
                    "type": "split",
                    "update_time": "2019-03-28T15:28:08Z"
                }
            ],
            "offset": 0,
            "total_rows": 24
        }

.. http:get:: /_reshard/jobs/{jobid}
    :synopsis: Retrieve information about a particular resharding job

    Get information about the resharding job identified by ``jobid``.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`

    :>json string id: Job ID.
    :>json string type: Currently only ``split`` is implemented.
    :>json string job_state: The running state of the job. Could be one of
                             ``new``, ``running``, ``stopped``, ``completed``
                             or ``failed``.
    :>json string split_state: State detail specific to shard splitting. It
                               indicates how far has shard splitting
                               progressed, and can be one of ``new``,
                               ``initial_copy``, ``topoff1``,
                               ``build_indices``, ``topoff2``,
                               ``copy_local_docs``, ``update_shardmap``,
                               ``wait_source_close``, ``topoff3``,
                               ``source_delete`` or ``completed``.
    :>json object state_info: Optional additional info associated with the
                              current state.
    :>json string source: For ``split`` jobs this will be the source shard.
    :>json list target: For ``split`` jobs this will be a list of two or more
                        target shards.
    :>json list history: List of json objects recording a job's state
                         transition history.

    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required

    **Request**:

    .. code-block:: http

        GET /_reshard/jobs/001-171d1211418996ff47bd610b1d1257fc4ca2628868def4a05e63e8f8fe50694a HTTP/1.1
        Accept: application/json

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {

            "id": "001-171d1211418996ff47bd610b1d1257fc4ca2628868def4a05e63e8f8fe50694a",
            "job_state": "completed",
            "node": "node1@127.0.0.1",
            "source": "shards/00000000-1fffffff/d1.1553786862",
            "split_state": "completed",
            "start_time": "2019-03-28T15:28:02Z",
            "state_info": {},
            "target": [
                "shards/00000000-0fffffff/d1.1553786862",
                "shards/10000000-1fffffff/d1.1553786862"
            ],
            "type": "split",
            "update_time": "2019-03-28T15:28:08Z",
            "history": [
                {
                    "detail": null,
                    "timestamp": "2019-03-28T15:28:02Z",
                    "type": "new"
                },
                {
                    "detail": "initial_copy",
                    "timestamp": "2019-03-28T15:28:02Z",
                    "type": "running"
                }
            ]
        }

.. http:post:: /_reshard/jobs
    :synopsis: Create one or more resharding jobs

    Depending on what fields are specified in the request, one or more
    resharding jobs will be created. The response is a json array of results.
    Each result object represents a single resharding job for a particular node
    and range. Some of the responses could be successful and some could fail.
    Successful results will have the ``"ok": true`` key and and value, and
    failed jobs will have the ``"error": "{error_message}"`` key and value.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`

    :<json string type: Type of job. Currently only ``"split"`` is accepted.

    :<json string db: Database to split. This is mutually exclusive with the
                      ``"shard``" field.

    :<json string node: Split shards on a particular node. This is an optional
                        parameter. The value should be one of the nodes
                        returned from the ``_membership`` endpoint.

    :<json string range: Split shards copies in the given range. The range
                         format is ``hhhhhhhh-hhhhhhhh`` where ``h`` is a
                         hexadecimal digit. This format is used since this is
                         how the ranges are represented in the file system.
                         This is parameter is optional and is mutually
                         exclusive with the ``"shard"`` field.

    :<json string shard: Split a particular shard. The shard should be
                         specified as ``"shards/{range}/{db}.{suffix}"``. Where
                         ``range`` has the ``hhhhhhhh-hhhhhhhh`` format, ``db``
                         is the database name, and ``suffix`` is the shard
                         (timestamp) creation suffix.

    :>json boolean ok: ``true`` if job created successfully.

    :<json string error: Error message if a job could be not be created.

    :<json string node: Cluster node where the job was created and is running.

    :code 201: One or more jobs were successfully created
    :code 400: Invalid request. Parameter validation might have failed.
    :code 401: CouchDB Server Administrator privileges required
    :code 404: Db, node, range or shard was not found

    **Request**:

    .. code-block:: http

        POST /_reshard/jobs HTTP/1.1
        Accept: application/json
        Content-Type: application/json

        {
           "db": "db3",
           "range": "80000000-ffffffff",
           "type": "split"
        }

    **Response**:

    .. code-block:: http

        HTTP/1.1 201 Created
        Content-Type: application/json

        [
            {
                "id": "001-30d7848a6feeb826d5e3ea5bb7773d672af226fd34fd84a8fb1ca736285df557",
                "node": "node1@127.0.0.1",
                "ok": true,
                "shard": "shards/80000000-ffffffff/db3.1554148353"
            },
            {
                "id": "001-c2d734360b4cb3ff8b3feaccb2d787bf81ce2e773489eddd985ddd01d9de8e01",
                "node": "node2@127.0.0.1",
                "ok": true,
                "shard": "shards/80000000-ffffffff/db3.1554148353"
            }
        ]

.. http:delete:: /_reshard/jobs/{jobid}
    :synopsis: Remove a resharding job

    If the job is running, stop the job and then remove it.

    :>json boolean ok: ``true`` if the job was removed successfully.

    :code 200: The job was removed successfully
    :code 401: CouchDB Server Administrator privileges required
    :code 404: The job was not found

    **Request**:

    .. code-block:: http

        DELETE /_reshard/jobs/001-171d1211418996ff47bd610b1d1257fc4ca2628868def4a05e63e8f8fe50694a HTTP/1.1

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "ok": true
        }

.. http:get:: /_reshard/jobs/{jobid}/state
    :synopsis: Retrieve the state of a single resharding job

    Returns the running state of a resharding job identified by ``jobid``.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`

    :<json string state: One of ``new``, ``running``, ``stopped``,
                         ``completed`` or ``failed``.

    :<json string state_reason: Additional information associated with the
                                state

    :code 200: Request completed successfully
    :code 401: CouchDB Server Administrator privileges required
    :code 404: The job was not found

    **Request**:

    .. code-block:: http

        GET /_reshard/jobs/001-b3da04f969bbd682faaab5a6c373705cbcca23f732c386bb1a608cfbcfe9faff/state HTTP/1.1
        Accept: application/json
        Host: localhost:5984

    **Response**:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "reason": null,
            "state": "running"
        }

.. http:put:: /_reshard/jobs/{jobid}/state
    :synopsis: Change the state of a resharding job

    Change the state of a particular resharding job identified by ``jobid``.
    The state can be changed from ``stopped`` to ``running`` or from
    ``running`` to ``stopped``. If an individual job is ``stopped`` via this
    API it will stay ``stopped`` even after the global resharding state is
    toggled from ``stopped`` to ``running``. If the job is already
    ``completed`` its state will stay ``completed``.

    :<header Accept: - :mimetype:`application/json`
    :>header Content-Type: - :mimetype:`application/json`

    :<json string state: ``stopped`` or ``running``
    :<json string state_reason: Optional string describing additional
                                information or reason associated with the state

    :>json boolean ok: ``true``

    :code 200: Request completed successfully
    :code 400: Invalid request. Could be a bad state name, for example.
    :code 401: CouchDB Server Administrator privileges required
    :code 404: The job was not found

    **Request**:

    .. code-block:: http

        PUT /_reshard/state/001-b3da04f969bbd682faaab5a6c373705cbcca23f732c386bb1a608cfbcfe9faff/state HTTP/1.1
        Accept: application/json
        Host: localhost:5984

        {
            "state": "stopped",
            "reason": "Rebalancing in progress"
        }

    **Response**:

    .. code-block:: http

       HTTP/1.1 200 OK
       Content-Type: application/json

       {
            "ok": true
       }