Cannot create PostgreSQL database through Terraform


I am trying to deploy a new pgsql database through terraform.

I am getting the following error :slight_smile:

Could not deploy database '123ae17f-764f-4369-88ac-f878b21d29e6', unexpected error: 500 Internal Server Error - could not execute statement; SQL [n/a]; constraint [deployment_pkey]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement

Here is the Terraform configuration:

resource "qovery_database" "pgsql" {
    environment_id =

    name = "PostgreSQL"
    type = "POSTGRESQL"
    version = "13"
    mode = "CONTAINER

    accessibility = "PRIVATE"

    cpu = 250
    memory = 256
    storage = 10

    state = "RUNNING"

Hi @kerwanp , I put the engineer in charge of our Terraform provider in the loop. @bilel

Hi @kerwanp, I’ll take a look at this to find the root cause of this issue.

But from what I can see at the moment, it look like there were two deployment triggered at the same time which caused an issue while inserting a new row in database (on our side).

In the mean time could you try to terraform apply once again to find out if the issue is still present ?

Hi @bilel @rophilogene,

I made some tests this morning, it appears that the problem only appear when requesting the creation of databases at the same time.

There is one that get successfully created and one that fails.

I also tried with applications and the problem also occurs (with the same error). When creating 3 app at the same time, there are always 2 failing.

1 Like

Hi @kerwanp,

This is something we need to fix on our side, and we will do so on the next version on the provider that will be released in a few weeks.

In the mean time I found a temporary fix that will allow you to deploy you environment.
Since we can’t let multiple deployments be created at the same time, you can add dependencies to your resources. In your case you can say the your second database depends on the first one using the depends_on keyword like this:

resource "qovery_database" "pgsql" {

resource "qovery_database" "redis" {
  depends_on = [

Let me know if this fixed your issue

1 Like