Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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;

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

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

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

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

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

Be sure to read the chapter "Writing SECURITY DEFINER Functions Safely" in the manual.

share|improve this answer
    
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 Mar 25 '12 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. –  Erwin Brandstetter Mar 25 '12 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 Mar 25 '12 at 21:29
    
@Alex: I see. I guess my answer will have to do then. –  Erwin Brandstetter Mar 25 '12 at 22:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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