store.GetSidebarCategories failing on db replicas

Description

Seeing the sidebar not appearing on a cloud test server that's using latest master. The API request to `/api/v4/users/{id}/teams/{id}/channels/categories` is failing on a 500 with this log:

```
{"timestamp":"2021-02-26 17:49:52.725 Z","level":"error","msg":"Failed to insert record to database.","err_details":"begin_transaction: pq: cannot set transaction read-write mode during recovery","err_where":"GetSidebarCategories","http_code":500,"ip_addr":"","method":"GET","path":"/api/v4/users/y57dkzc98byc8df7dzemftgp7h/teams/y17t9ikx6tbozqpox4up1w1qyy/channels/categories","request_id":"56mcrympwjrgubj34pyggc3kqa","user_id":"y57dkzc98byc8df7dzemftgp7h","stacktrace":[{"Function":"github.com/mattermost/logr.Logger.Log","File":"github.com/mattermost/logr@v1.0.13/logger.go","Line":54},{"Function":"github.com/mattermost/logr.Logger.Error","File":"github.com/mattermost/logr@v1.0.13/logger.go","Line":86},{"Function":"github.com/mattermost/mattermost-server/v5/mlog.(*Logger).Error","File":"github.com/mattermost/mattermost-server/v5/mlog/log.go","Line":234},{"Function":"github.com/mattermost/mattermost-server/v5/web.(*Context).LogErrorByCode","File":"github.com/mattermost/mattermost-server/v5/web/context.go","Line":104},{"Function":"github.com/mattermost/mattermost-server/v5/web.Handler.ServeHTTP","File":"github.com/mattermost/mattermost-server/v5/web/handlers.go","Line":279},{"Function":"github.com/NYTimes/gziphandler.GzipHandlerWithOpts.func1.1","File":"github.com/NYTimes/gziphandler@v1.1.1/gzip.go","Line":337},{"Function":"net/http.HandlerFunc.ServeHTTP","File":"net/http/server.go","Line":2042},{"Function":"github.com/gorilla/mux.(*Router).ServeHTTP","File":"github.com/gorilla/mux@v1.8.0/mux.go","Line":210},{"Function":"net/http.serverHandler.ServeHTTP","File":"net/http/server.go","Line":2843},{"Function":"net/http.(*conn).serve","File":"net/http/server.go","Line":1925},{"Function":"runtime.goexit","File":"runtime/asm_amd64.s","Line":1374}]}
```

This is on postgres with two read replicas configured. Seems like the store function `GetSidebarCategories` isn't playing nicely with the replicas. Doesn't reproduce locally where I'm not using any read replicas. Any ideas?

cc @claudio.costa since it looks like you might have touched that code recently

Issue created from a message in Mattermost.

QA Test Steps

No testing required.

Done

Mana

None

Assignee

Claudio Costa

QA Assignee

None

Reporter

Claudio Costa

Epic Link

None

Fix versions

Mattermost Team

Server

Sprint

None

Labels

None

QA Testing Areas

None

GitHub Issue

None

Components

None

Severity

None