8

I need to load the uuid extension on my database, which is being created in runtime. The user that created the db is not superuser, she only has the "CREATEDB" permissions.

Is there a way to do this? Thanks.

1 Answer 1

7

I see two possibilities:

1.

Install the extension into a template database (just a regular database) and use it as template for CREATE DATABASE:

CREATE DATABASE new_db TEMPLATE my_template_db;

That copies all installed extensions into the new database. Your user obviously can do that.

Also, if she created the database she should have the necessary privileges to run CREATE EXTENSION anyway. I quote the manual:

For most extensions this means superuser or database owner privileges are needed.

2.

Create a SECURITY DEFINER function executing all necessary DML statements, owned by a superuser. Revoke all privileges from public and grant EXECUTE to the user role:

CREATE FUNCTION foo() ... SECURITY DEFINER;
REVOKE ALL ON FUNCTION foo() FROM public;
GRANT EXECUTE ON FUNCTION foo() to my_user;

Read the chapter "Writing SECURITY DEFINER Functions Safely" in the manual.

4
  • Thank you, Erwin!! I already got the same answer in #postgres, but I think you deserve the credit. And, btw, the user cannot load the extension, because, as I was explained, to load C extensions you must have superuser privileges.
    – Alex
    Commented Mar 25, 2012 at 21:17
  • @Alex: If you got an answer from a usenet list, it would be nice to add a link to your question. Others coming across your question here may be interested. Commented Mar 25, 2012 at 21:22
  • true, but that happened on FreeNode IRC channel (the one for postgres). I can hardly imagine that someone would read the history of the channel...
    – Alex
    Commented Mar 25, 2012 at 21:29
  • @Alex: I see. I guess my answer will have to do then. Commented Mar 25, 2012 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.