I'm using PostgreSQL v9.0.1
with Rails
(and it's deps) @ v2.3.8
, owing to the use of the fulltext capability of postgres, I have a table which is defined as:
CREATE TABLE affiliate_products ( id integer NOT NULL, name character varying(255), model character varying(255), description text, price numeric(9,2), created_at timestamp without time zone, updated_at timestamp without time zone, textsearch_vector tsvector, );
Note the last line, this ensures that active record isn't able to process it with the standard schema dumper, so I have to set config.active_record.schema_format = :sql
in ./config/environment.rb
; and use rake db:test:clone_structure
instead of rake db:test:clone
.
None of this is too remarkable, only inconvenient - however rake db:test:clone_structure
fails with the error:
ERROR: must be owner of language plpgsql
Because of line #16
in my resulting ./db/development_schema.sql
:
CREATE OR REPLACE PROCEDURAL LANGUAGE plpgsql;
Under PostgreSQL v9.0+
the language plpsql
is installed by the superuser, to the initial template, which is then available to the newly created schema.
I cannot run tests on this project without resolving this, and even editing ./db/development_schema.sql
manually is futile as it is regenerated every time I run rake db:test:clone_structure
(and ignored by rake db:test:clone
).
I hope someone can shed some light on this?
Note: I have used both the pg 0.9.0
adapter gem, and the postgres
gem at version 0.7.9.2008.01.28
- both display identical behaviour.
My teammates run PostgreSQL v8.4
where the language installation is a manual step.
A type cast specifies a conversion from one data type to another. PostgreSQL accepts two equivalent syntaxes for type casts, the PostgreSQL-specific value::type and the SQL-standard CAST(value AS type) .
Plpgsql is faster, as you don't have to fetch the data, process them and then submit a new query. All the process is done internally and it is also precompiled which also boosts performance.
Using the PostgreSQL ALTER ROLE to change a role's session default for a configuration variable. In this syntax: First, specify the name of the role that you want to modify the role's session default, or use the CURRENT_USER , or SESSION_USER . You use the ALL option to change the settings for all roles.
Description. CREATE EXTENSION loads a new extension into the current database. There must not be an extension of the same name already loaded. Loading an extension essentially amounts to running the extension's script file.
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
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.
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With