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


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:

Or you could use the Postgres Terraform provider instead:

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

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

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

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel