# PG::ReadOnlySqlTransaction: ERROR: cannot execute SELECT in a read-only transaction

**URL:** https://meta.discourse.org/t/pg-error-cannot-execute-select-in-a-read-only-transaction/130799
**Category:** Self-hosting
**Created:** [October 11, 2019, 4:28pm UTC](https://meta.discourse.org/t/pg-error-cannot-execute-select-in-a-read-only-transaction/130799 "2019-10-11T16:28:07Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![bts](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bts/32/184556_2.png) [@bts](https://meta.discourse.org/u/bts)
#### Post date: [October 11, 2019, 4:36pm UTC](https://meta.discourse.org/t/pg-error-cannot-execute-select-in-a-read-only-transaction/130799/4 "2019-10-11T16:36:47Z")

</div>

I haven’t used it yet but if for running direct SQL queries I believe this is what you’re looking for! —

> [@New official direct SQL access API for Discourse (mini\_sql)](https://meta.discourse.org/t/new-official-direct-sql-access-api-for-discourse-mini-sql/90441):
>
> I just finished “officializing” and “extracting” our direct DB access helpers in Discourse. I would like to cover what was done and what this means to plugin authors and core contributors. From the very first version of Discourse, @eviltrout introduced some helpers internally for safely executing direct SQL in Discourse. It looked like this. ActiveRecord::Base.exec\_sql("select \* from topics where id = :id", id: 1) # or Topic.exec\_sql("select \* from topics where id = :id", id: 1) This is a p…

---

_[View the full topic](https://meta.discourse.org/t/pg-error-cannot-execute-select-in-a-read-only-transaction/130799)._
