# Using Two Database Connections with the Same User

**URL:** <https://community.auth0.com/t/using-two-database-connections-with-the-same-user/154957>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [November 28, 2024, 12:12pm UTC](https://community.auth0.com/t/using-two-database-connections-with-the-same-user/154957 "2024-11-28T12:12:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![himashya.fonseka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/himashya.fonseka/32/62359_2.png) [@himashya.fonseka](https://community.auth0.com/u/himashya.fonseka)\
**Post date:** [November 28, 2024, 12:12pm UTC](https://community.auth0.com/t/using-two-database-connections-with-the-same-user/154957/1 "2024-11-28T12:12:04Z")

</div>

**Question** :  
How can I use two database connections in Auth0 while sharing the same users having same user\_ids between them? I need this for testing purposes, where one connection is for production users and the other for testing users. At the end of the testing the test database connection is delete, does this affect the users sharing both the databases. Is it possible to achieve this? How does Auth0 handle shared users across connections, and what are the best practices for such a setup?

---

<div class="post-metadata">

**Author:** ![gerald.czifra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gerald.czifra/32/75301_2.png) [@gerald.czifra](https://community.auth0.com/u/gerald.czifra)\
**Post date:** [November 28, 2024, 11:00pm UTC](https://community.auth0.com/t/using-two-database-connections-with-the-same-user/154957/3 "2024-11-28T23:00:09Z")

</div>

Hello @himashya.fonseka,

Thank you for reaching out to us!  
I did some testing on this by exporting the users from one DB using the [Create export users job](https://auth0.com/docs/api/management/v2/jobs/post-users-exports), editing the users data from the json file and then [importing the json file](https://auth0.com/docs/api/management/v2/jobs/post-users-imports) to a separate DB. This allowed me to essentially have 2 sets of users, with the same user\_id, in the same tenant, but comparing the two profiles of one user, both of them were linked to my first DB when I looked under the **Identities** field. It was expected for something to break along the line, as the user\_id is a defining attribute and it’s not allowed to have multiples.

However, this can be accomplished by using multiple tenants, if this fits your usecase. As long as the application can access both DBs that are on different tenants, it will have access to two sets of users with the same user\_id. You will just need to export the users from one DB, setup a second DB on a different tenant and import the users.

You can find more information on our [Bulk User Imports](https://auth0.com/docs/manage-users/user-migration/bulk-user-imports#create-users-json-file) documentation.

Thank you!  
Gerald

---

<div class="post-metadata">

**Author:** ![himashya.fonseka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/himashya.fonseka/32/62359_2.png) [@himashya.fonseka](https://community.auth0.com/u/himashya.fonseka)\
**Post date:** [December 4, 2024, 3:49am UTC](https://community.auth0.com/t/using-two-database-connections-with-the-same-user/154957/4 "2024-12-04T03:49:57Z")

</div>

Hi [gerald.czifra](https://community.auth0.com/t/using-two-database-connections-with-the-same-user/154957/3),

Thank you for the response. Based on your solution, we would need to maintain two tenants—one for the production environment and another solely for smoke testing. This approach would also require modifications to enable switching between tenants.

Instead of pursuing that route, we plan to modify the user\_ids of the new user set in the new database and adjust the application to recognize the updated user\_ids.

It would have been more efficient if Auth0 allowed user\_ids to be unique per database connection rather than across the entire tenant. This limitation complicates the process of maintaining backup database connections and adds unnecessary challenges.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 18, 2024, 3:50am UTC](https://community.auth0.com/t/using-two-database-connections-with-the-same-user/154957/5 "2024-12-18T03:50:07Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
