# Can we safely insert users directly into separate Discourse databases?

**URL:** https://meta.discourse.org/t/can-we-safely-insert-users-directly-into-separate-discourse-databases/362851
**Category:** Support
**Created:** [April 21, 2025, 7:55pm UTC](https://meta.discourse.org/t/can-we-safely-insert-users-directly-into-separate-discourse-databases/362851 "2025-04-21T19:55:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![emonunix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emonunix/32/485652_2.png) [@emonunix](https://meta.discourse.org/u/emonunix)
#### Post date: [April 21, 2025, 7:55pm UTC](https://meta.discourse.org/t/can-we-safely-insert-users-directly-into-separate-discourse-databases/362851/1 "2025-04-21T19:55:58Z")

</div>

Hey everyone,

We’re running multiple Discourse forums as isolated instances on the same virtual machine. Each forum has its own separate Postgres database, but they’re all managed by a shared script that runs on the host machine.

We’re looking to automate the creation of initial users during setup. Rather than using the API or CSV importer, we’re wondering:

> 💡 Is it possible (and safe) to insert user records directly into each instance’s database?

Since our script already interacts with the databases, this could streamline the provisioning process significantly.

Has anyone attempted direct DB user creation before? Or is this a bad idea due to risks with data integrity, sessions, or other Discourse-specific mechanisms?

Appreciate any advice or experience you can share!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [April 21, 2025, 8:13pm UTC](https://meta.discourse.org/t/can-we-safely-insert-users-directly-into-separate-discourse-databases/362851/3 "2025-04-21T20:13:13Z")

</div>

It’s a bit safer having Rails do it than modifying the database yourself, but you can do it if you want. Note that you have to touch at least the user and user\_emails tables, and see that the user\_ids match.

Have a look at [discourse/db/fixtures/009\_users.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/db/fixtures/009_users.rb) and then create a plugin that similarly adds a fixture (maybe ./discourse-salesforce/db/fixtures/001\_groups.rb).

You could also use an import script as an example.

---

<div class="post-metadata">

### Author: ![emonunix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emonunix/32/485652_2.png) [@emonunix](https://meta.discourse.org/u/emonunix)
#### Post date: [April 22, 2025, 12:51am UTC](https://meta.discourse.org/t/can-we-safely-insert-users-directly-into-separate-discourse-databases/362851/4 "2025-04-22T00:51:50Z")

</div>

Thanks, @pfaffman — really appreciate the guidance!

Just to clarify: one of the main reasons we’re exploring this route is that both the CSV and API-based methods are too slow for what we’re trying to do. We’re spinning up lots of isolated instances and need to populate each one with a batch of users quickly during provisioning.

Would the fixtures/plugin approach you mentioned allow for significantly faster user creation compared to the API or CSV methods? Specifically, we’re hoping to reduce wait time during setup — ideally something that executes instantly or near-instantly along with the initial DB setup.

Thanks again!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [April 22, 2025, 2:34am UTC](https://meta.discourse.org/t/can-we-safely-insert-users-directly-into-separate-discourse-databases/362851/5 "2025-04-22T02:34:04Z")

</div>

You can look at the bulk import scripts for examples of updating the database directly. The import script does have some overhead, so maybe the example in the fixtures chilly be some faster?

How many users are you adding? Do you have the same users for each site?
