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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 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:

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

Your Answer


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.