Question

How to provide access to a public scheme in PostgreSQL 15 or 16 using terraform?

PostgreSQL has brought the changes related to a public scheme.

  • Remove PUBLIC creation permission on the public schema (Noah Misch)
  • Change the owner of the public schema to be the new pg_database_owner role (Noah Misch)

The question is how to create a user using resource digitalocean_database_user to be belong to the new role?

I have tested on 16 and have not found such role.

luckyroot=> \du
                                                                List of roles
      Role name      |                         Attributes                         |                         Member of
---------------------+------------------------------------------------------------+-----------------------------------------------------------
 _doadmin_managed    | Cannot login                                               | {pg_read_all_stats,pg_stat_scan_tables,pg_signal_backend}
 _doadmin_monitor    |                                                            | {pg_monitor}
 _dodb               | Superuser, Replication                                     | {}
 doadmin             | Create role, Create DB, Replication, Bypass RLS            | {_doadmin_managed,luckyroot-develop-3}
 luckyroot-develop-3 |                                                            | {}
 postgres            | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 5, 2024
Accepted Answer

Hey!

Any new users created with digitalocean_database_user resource or manually via the DigitalOcean Control Panel, will always have normal role, only the default user that comes with database cluster creation has primary role.

Additional permissions must be managed manually.

You can either do it manually as described here:

https://docs.digitalocean.com/products/databases/postgresql/how-to/modify-user-privileges/

Or you could use the Postgres Terraform provider instead:

https://registry.terraform.io/providers/cyrilgdn/postgresql/latest/docs

Hope that this helps!

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.