DATABASE_NAME=your_database_name
, where your_database_name
is the name of your original unsharded keyspace, you will need to update your configuration code so that all queries don’t go straight to that keyspace.
The preferred way to do this is to just leave off the database name completely in your application configuration code. PlanetScale will be able to route traffic correctly just using the connection username and password.
While this is the preferred way, it’s sometimes not possible. For example, many frameworks and ORMs require that you include a database name.
In those cases, you should use @primary
. This will send any incoming queries first to our Global Edge Network, which will see that you’re targeting a primary. Edge will then send the request to the VTGate(s)/load balancer. We typically will use Vitess’s Global Routing to direct the query to the correct keyspace and, optionally, correct shard.
NoteIf you explicitly wish to target a replica for some or all reads, using
@replica
will have the same effect as @primary
in that it will automatically route the request to the correct keyspace.@replica
, but it will not automatically route the query to the closest replica.
Framework examples
Using@primary
is simple, but there are slight variations for each framework. The following code snippets show how to target @primary
in some of the popular languages/frameworks. If you don’t see your framework on here and are unsure of how to proceed, please reach out to support.