Optimize Database
Much of the Plex metadata is stored in a database that is stored on the server. Over time as media items are added or deleted from the Plex server, the database can become fragmented, and contain old data. To cleanup the database, Plex provides the Optimize Database command through both the Web app and the API.
This command is the same one that is run from the Optimize Database option in Plex.
URL
PUT http://{ip_address}:32400/library/optimize?async={async}&X-Plex-Token={plex_token}
Parameters
Name | Description |
---|---|
ip_address | The IP address of the Plex Media server. |
plex_token | The Plex token. |
async | A flag indicating if the API command will be run async. 1 for async, otherwise 0. |
Return Status
HTTP Code | Description |
---|---|
200 | Success - The request was successful. |
401 | Unauthorized - The Plex token provided was not valid. |
Response
No response is returned. You will be able to see the optimize database API command run from the Plex console.
Remarks
When the async parameter is set to 1, the status code will be returned immediately, but the command will still be running on the server. By setting the async parameter to 0, the status won't be returned until the command has completed running on the server.
There is also an API command to run the optimize database scheduled task.
Examples
curl -X PUT http://{ip_address}:32400/library/optimize?async={async}&X-Plex-Token={plex_token}
import requests plex_url = http://{ip_address}:32400/library/optimize?async={async}&X-Plex-Token={plex_token} response = requests.put(plex_url) print(response.text)
$response = Invoke-RestMethod 'http://{ip_address}:32400/library/optimize?async={async}&X-Plex-Token={plex_token}' -Method 'PUT' Write-Output $response