# Error while deleting Mattermost User through API

**URL:** <https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181>\
**Category:** Troubleshooting\
**Created:** [February 23, 2023, 1:02pm UTC](https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181 "2023-02-23T13:02:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![praseeb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/praseeb/32/5230_2.png) [@praseeb](https://forum.mattermost.com/u/praseeb)\
**Post date:** [February 23, 2023, 1:02pm UTC](https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181/1 "2023-02-23T13:02:15Z")

</div>

We are trying to delete a user from Mattermost server through API,

```auto

```

curl --location --request DELETE '[https://xxxxxx/api/v4/users/ **USERID**?permanent=true’](https://xxxxxx/api/v4/users/ **USERID**?permanent=true%27)   
–header 'Authorization: Bearer **TOKEN**

```auto

```

’  
We were getting below error

"`id": "app.post.permanent_delete_by_user.app_error", "message": "Unable to select the posts to delete for the user.", "detailed_error": "MError:\nfailed to fetch Posts with userId= **TOKEN** : context deadline exceeded\ndriver: bad connection\n2 errors total.\n", "request_id": "qo1hxxcjopydzfbx4zw7ind85h", "status_code": 500`

```auto
### **Mattermost Team Edition**

Mattermost Version: 7.7.1

Database Schema Version: 100

Database: postgres

```

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [February 23, 2023, 1:48pm UTC](https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181/2 "2023-02-23T13:48:17Z")

</div>

Hi @praseeb ,

the message `context deadline exceeded` usually indicates, that the SQL query was running too long and has therefore been intercepted.  
It seems as if this user account has quite a lot of posts and therefore the cleanup process might take a while.  
You could try to increase the `SqlSettings.QueryTimeout` value in your server’s `config.json` (I think the change requires a server restart then) and see if that helps.  
Did you track the time that elapses when you start the query until you receive the HTTP 500? If it’s near to the current `QueryTimeout` setting, this should be a solid guess then.

---

<div class="post-metadata">

**Author:** ![praseeb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/praseeb/32/5230_2.png) [@praseeb](https://forum.mattermost.com/u/praseeb)\
**Post date:** [February 24, 2023, 12:25pm UTC](https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181/3 "2023-02-24T12:25:02Z")

</div>

@agriesser Please find the below in our config.json

```auto
    "SqlSettings": {
        "DriverName": "postgres",
        "DataSource": "postgres://username:password@endpointurl:5432/dbname?sslmode=disable\u0026connect_timeout=10",
        "DataSourceReplicas": [],
        "DataSourceSearchReplicas": [],
        "MaxIdleConns": 20,
        "ConnMaxLifetimeMilliseconds": 3600000,
        "ConnMaxIdleTimeMilliseconds": 300000,
        "MaxOpenConns": 300,
        "Trace": false,
        "AtRestEncryptKey": "ENCRYPTKEY",
        "QueryTimeout": 30,
        "DisableDatabaseSearch": false,
        "MigrationsStatementTimeoutSeconds": 100000,
        "ReplicaLagSettings": []

```

Can you please suggest the idle QueryTimeout which we can set.

---

<div class="post-metadata">

**Author:** ![praseeb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/praseeb/32/5230_2.png) [@praseeb](https://forum.mattermost.com/u/praseeb)\
**Post date:** [February 24, 2023, 12:28pm UTC](https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181/4 "2023-02-24T12:28:49Z")

</div>

@agriesser please find the below config.json values

```auto
    "SqlSettings": {
        "DriverName": "postgres",
        "DataSource": "postgres://username:password@endpointurl:5432/dbname?sslmode=disable\u0026connect_timeout=10",
        "DataSourceReplicas": [],
        "DataSourceSearchReplicas": [],
        "MaxIdleConns": 20,
        "ConnMaxLifetimeMilliseconds": 3600000,
        "ConnMaxIdleTimeMilliseconds": 300000,
        "MaxOpenConns": 300,
        "Trace": false,
        "AtRestEncryptKey": "ENCRYPTYKEY",
        "QueryTimeout": 30,
        "DisableDatabaseSearch": false,
        "MigrationsStatementTimeoutSeconds": 100000,
        "ReplicaLagSettings": []

```

Kindly suggest us the Idle value to update in QueryTimeout

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [February 26, 2023, 5:49am UTC](https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181/5 "2023-02-26T05:49:00Z")

</div>

Hi @praseeb ,

hard to tell since I don’t know how long the query would run on your system, but set it to 180 for testing purposes and check again if that fixes the problem.  
Increasing the timeout doesn’t really hurt if it’s done in a controlled environment.

---

<div class="post-metadata">

**Author:** ![praseeb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/praseeb/32/5230_2.png) [@praseeb](https://forum.mattermost.com/u/praseeb)\
**Post date:** [February 27, 2023, 1:32pm UTC](https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181/6 "2023-02-27T13:32:45Z")

</div>

@agriesser Thanks, it worked for us now 🙂

---

<div class="post-metadata">

**Author:** ![agriesser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/agriesser/32/5644_2.png) [@agriesser](https://forum.mattermost.com/u/agriesser)\
**Post date:** [March 1, 2023, 6:25am UTC](https://forum.mattermost.com/t/error-while-deleting-mattermost-user-through-api/15181/7 "2023-03-01T06:25:04Z")

</div>

Awesome, thanks for reporting back - glad to hear you’re up and running now 🙂
