I have a PostgreSQL 9.5 server on which I have scripts that create roles and databases for users automatically. Within these databases it would be helpful to enable specific extensions (e.g. pgcrypto), but as I understand it one must be a superuser to run CREATE EXTENSION
. Is there a way to enable such extensions without manually logging in with a superuser account?
1 Answer 1
From the docs on Extensions,
superuser (boolean) If this parameter is true (which is the default), only superusers can create the extension or update it to a new version. If it is set to false, just the privileges required to execute the commands in the installation or update script are required.
The value isn't set in pgcrypto.control
, so it's defaulting to true which requires a SuperUser.
This means you can not CREATE EXTENSION
as the mere owner of the database, despite what the docs on CREATE EXTENSION lead you to believe.
I tried hard setting it to false
, and no joy. C is an untrusted language and you'll get
ERROR: permission denied for language c
Only superusers can create functions in untrusted languages.
... of course you can make c
trusted with UPDATE pg_language set lanpltrusted = true where lanname = 'c';
as a superuser. Then CREATE EXTENSION pgcrypto
will work fine as a non-superuser. But, that sounds like a bad idea if you have to worry about your users uploading source to your extension directory and then installing it in the database. That is to say, I wouldn't go that far. I'd find another way to skin this cat.
-
Thanks Evan, that's as thorough an answer as I could ask for. I'll probably opt for @Kassandry's cat-skinning proposal to get around this. I did also think about wrapping the CREATE EXTENSION in a stored procedure, but couldn't find a route to making this work in the same database without dblink authentication yuckiness.beldaz– beldaz2017年06月05日 19:38:35 +00:00Commented Jun 5, 2017 at 19:38
-
What's the point, then, of not having any option in
pg_dump
to prevent it from dumping statements regarding extensions? I currently have to use external text processing tools to remove those statements from the SQL dumped bypg_dump
.Claudi– Claudi2018年07月01日 16:03:35 +00:00Commented Jul 1, 2018 at 16:03 -
@Evan Carroll: is it possible to set the superuser to false via psql cli? I have an instance on amazon aws rds and don't have access to pgcrypto.control .ribamar– ribamar2019年01月03日 12:17:45 +00:00Commented Jan 3, 2019 at 12:17
-
2@ribamar no because that would mean that anyone connected to the database could perform literal arbitrary code execution as the db postmaster. that would be a horrible idea.Evan Carroll– Evan Carroll2019年01月03日 19:25:55 +00:00Commented Jan 3, 2019 at 19:25
-
not anybody, the superuser. I understand that this way you differentiate the operating system super from the dbms super user, although if I was making such a decision I would go for enpowering the tool, and if really needed to create yet another more powerful user, i'd implement it inside the tool.ribamar– ribamar2019年01月04日 11:52:07 +00:00Commented Jan 4, 2019 at 11:52
Explore related questions
See similar questions with these tags.
template1
and then creating each user database fromtemplate1
likeCREATE DATABASE foo OWNER=userfoo TEMPLATE=template1
?