ERROR: must be owner of language plpgsql
For new readers, I read this older post after having run into this error in one of my own projects. I strongly feel that giving the app's PostgreSQL a superuser role is a terrible idea and changing the template is not ideal either. Since the referenced PSQL commands that are added by db:structure:dump
are not needed by the Rails app's database, I have written a custom rake task that comments out the problematic lines in structure.sql. I have shared that code publicly on Github as a Gist at https://gist.github.com/rietta/7898366.
I had the same problem. I fixed my template with the commands below
psql template1
template1=# alter role my_user_name with superuser;
read more at http://gilesbowkett.blogspot.com/2011/07/error-must-be-owner-of-language-plpgsql.html
The solution was as follows:
On my installation, there are standard templates template0
and template1
- at least as I understand it postgres will look for the highest numbered templateN
when creating a new database, unless the template is specified.
In this instance, as template0
included plpgsql
, so did template1
… the idea being that you will customise template1
to suite your site specific default needs, and in the case that you blow everything up, you would restore template1
from template0
.
As my site specific requirement was to install plpgsql
as part of the automated build of my web application (a step we had to keep to maintain 8.4 compatibility) - the solution was easy: remove plpgsql
from template1
and the warning/error went away.
In the case that the site-specific defaults would change, and we should need to go back to the default behaviour, we would simply remove template1
and recreate it (which would use template0
)