Terraform postgres pq tuple concurrently updated

by Daniel Pham
Published: Updated:

Error: could not execute revoke query: pq: tuple concurrently updated.

Hey guys, today I’m gonna to share with you about a case when using Terraform.

Error: could not execute revoke query: pq: tuple concurrently updated

I’m using Terraform with Postgres provider to create a bunch of database users and grant the permissions to them.

Well, everything looking good until I run the terraform apply . A lot of error logs that scared me. What is that error look likes?

Error: could not execute revoke query: pq: tuple concurrently updated

│   with module.user-rds-postgres-trade.postgresql_grant.rds_postgres_grant_table["user.01"],
│   on ../../modules/user-rds-postgres/main.tf line 90, in resource "postgresql_grant" "rds_postgres_grant_table":
90: resource "postgresql_grant" "rds_postgres_grant_table" {



Error: could not execute revoke query: pq: tuple concurrently updated

│   with module.user-rds-postgres-trade.postgresql_grant.rds_postgres_grant_table["user.02"],
│   on ../../modules/user-rds-postgres/main.tf line 90, in resource "postgresql_grant" "rds_postgres_grant_table":
90: resource "postgresql_grant" "rds_postgres_grant_table" {



Error: could not execute revoke query: pq: tuple concurrently updated

│   with module.user-rds-postgres-trade.postgresql_grant.rds_postgres_grant_table["user.03"],
│   on ../../modules/user-rds-postgres/main.tf line 90, in resource "postgresql_grant" "rds_postgres_grant_table":
90: resource "postgresql_grant" "rds_postgres_grant_table" {


Releasing state lock. This may take a few moments...

Why the error “pq: tuple concurrently updated” happened?

After searched for a while in the internet, finally I got the information from provider’s github https://github.com/cyrilgdn/terraform-provider-postgresql/issues/178

terraform-postgres-pq-tupple-concurrently-updated
Terraform Postgres with error “pq tupple concurrently updated”.

What does the issue means?

They wrote and discussed a lots but I can tell you that simply the Postgres provider doesn’t supporting to run GRANT the permissions for multi users as the same time.

And that’s an issue belong to the provider, nothing wrong with the Terraform code or your Postgres instance.

How we can resolve the error “pq: tuple concurrently updated”?

And now, how we’re gonna to resolve this error?

Really simple with a trick. Use a parameter like -parallelism=1 . How the Terraform command will be?

You like to change from this:

terraform apply

To this:

terraform apply -parallelism=1

What does that parameter means? According to the Terraform docs https://developer.hashicorp.com/terraform/cli/commands/apply then that parameter means “Limit the number of concurrent operation”. Default values is 10 and we down it to 1.

Like at one time, Terraform just run Postgres grant for only 1 user. That’s all, we can passed the problem.

Conclusion

With just a simple trick above, I think you can save a bit time when facing the error exactly like that. Even myself, few months ago, I wrote and applied the Terraform code and faced it. Then I forgot to use -parallelism=1 and faced the problem again. I gotta to write a post to take a note about this case and also hoping it’s helpful to you guys.

5 2 votes
Article Rating

You may also like

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.

SUPPORT US

FOLLOW US

Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

0
Would love your thoughts, please comment.x
()
x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.