# Nakama's Database Connection Handling (sql.Open with pgx)

**URL:** <https://forum.heroiclabs.com/t/nakamas-database-connection-handling-sql-open-with-pgx/5923>\
**Category:** Local Setup\
**Created:** [January 9, 2025, 12:18pm UTC](https://forum.heroiclabs.com/t/nakamas-database-connection-handling-sql-open-with-pgx/5923 "2025-01-09T12:18:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bachu11](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@bachu11](https://forum.heroiclabs.com/u/bachu11)\
**Post date:** [January 9, 2025, 12:18pm UTC](https://forum.heroiclabs.com/t/nakamas-database-connection-handling-sql-open-with-pgx/5923/1 "2025-01-09T12:18:05Z")

</div>

Hi There,

As far as I understand from the code, Nakama appears to use `sql.Open` to establish the database connection:  
{db, err := sql.Open(“pgx”, parsedURL.String())}

This utilizes Go’s `database/sql` abstraction with the `pgx` driver, which is great for basic connection pooling.

I have a few questions regarding this implementation:

1. Does Heroic Cloud (enterprise version) use `pgxpool` instead of `sql.Open`?
2. Is there any open-source or community-built utility for Nakama that leverages `pgxpool` for database connections?
3. In this [article](https://aws.amazon.com/blogs/gametech/how-heroic-labs-load-tested-nakama-to-two-million-concurrent-players-with-aws/) - an Aurora database cluster was used.

- Was the same `db_Connect` method (as in the open-source Nakama) used in that setup?

1. Are there any benchmark or standard values for `max_open_connections`, `idle_connections`, and `max_lifetime`?

- For example, if Nakama is running on a 1 CPU or 2 CPU machine, and the database is on a CockroachDB standard cluster (2 CPUs), what would be the ideal values?

1. If a query execution fails due to contention or timeout on the database:
  - Does the current implementation perform any retries?
  - Is it possible for Nakama to fail to log such cases?

Thanks in advance for the clarification!

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [January 10, 2025, 2:14pm UTC](https://forum.heroiclabs.com/t/nakamas-database-connection-handling-sql-open-with-pgx/5923/2 "2025-01-10T14:14:35Z")

</div>

Hello @bachu11,

Nakama Enterprise uses a combination of libraries to manage the databases in clustered mode. Aurora is one of the databases available that is Nakama-compatible.

As for the database specifics, Nakama and the topology configuration, feel free to contact [support@heroiclabs.com](mailto:support@heroiclabs.com) and they can help you with your questions as they are very specific to each individual setup and how Heroic Cloud configures the topology.

Best.

---

<div class="post-metadata">

**Author:** ![bachu11](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@bachu11](https://forum.heroiclabs.com/u/bachu11)\
**Post date:** [January 21, 2025, 1:37pm UTC](https://forum.heroiclabs.com/t/nakamas-database-connection-handling-sql-open-with-pgx/5923/3 "2025-01-21T13:37:45Z")

</div>

I believe if i move the database connect to PGXPool and implement a shared session cache I should be able to manage my poor man’s nakama cluster until I get to a stage where I can afford the enterprise. I have evaluated other options like PGBouncer etc… but they are not compatible with cockroach db standard cluster.

I will get in touch with support sooner or later.

Thanks
