Question

Permission denied for database postgres when creating schemas in dev database

I was able to successfully connect to my app’s dev database, however when I try to create a schema with this script:

client.query(
  `CREATE SCHEMA IF NOT EXISTS ${team};`, (err, res) => {
  if (err) console.log(err.stack);
});

I get the following error:

digitalocean app error: permission denied for database db

I understand that the dev database doesn’t allow me to create databases, but nothing is said about creating schemas which is what I tried to do. It turns out that the default user db doesn’t have that privilege and it seems that there’s no way for me to change it.

What are the default user permissions? Should I be allowed to create PostgreSQL schemas in the dev database? This is what I get, and it looks like the user I have access to has no permissions whatsoever.

Role name Attributes Member of
_dodb Superuser, Replication {}
db {}
doadmin Create role, Create DB, Replication, Bypass RLS {db}
postgres Superuser, Create role, Create DB, Replication, Bypass RLS {}
Show comments

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I had the same issue deploying django multi tenant solution based on django-tenants. After doing some bit of digging i found out that the db_user created from the control panel have minimal permissions based on DO ‘principle of least privilege’ as defined in the documentation.

To fix this you need to connect to the cluster via psql defaultdb=> propt and grant permissions to your user using the following command GRANT CREATE ON DATABASE <your db> TO <your user>;

More on this you can referce the documentation here https://docs.digitalocean.com/products/databases/postgresql/how-to/modify-user-privileges/

Could anyone solve this?

@kamaln7 any news? I’m trying to develop a new API, but I cannot create a new schema on my dev database.

I am also experiencing this issue, and it’s preventing me from moving forward with a project; I’d love to use hosted Postgres instead of maintaining my own, but I need multiple schema to do it.