错误:必须是语言plpgsql的所有者

Lee*_*ley 23 ruby postgresql activerecord ruby-on-rails plpgsql

我使用的是PostgreSQL v9.0.1Rails(和它的DEPS)@ v2.3.8,由于使用的Postgres的全文能力,我有被定义为表:

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,
);

注意最后一行,这确保了活动记录是无法与标准架构自卸车处理它,所以我必须设置config.active_record.schema_format = :sql./config/environment.rb; 并使用rake db:test:clone_structure而不是rake db:test:clone.

这些都不是太了不起,只是不方便 - 但是rake db:test:clone_structure错误却失败了:

ERROR: must be owner of language plpgsql

因为#16我的结果./db/development_schema.sql:

CREATE OR REPLACE PROCEDURAL LANGUAGE plpgsql;

在超级用户安装PostgreSQL v9.0+的语言下plpsql,初始模板可用于新创建的模式.

我不能在没有解决这个问题的情况下对这个项目进行测试,甚至./db/development_schema.sql手动编辑都是徒劳的,因为每次运行时都会重新生成rake db:test:clone_structure(并被忽略rake db:test:clone).

我希望有人可以对此有所了解吗?

注意:我使用了pg 0.9.0适配器gem和postgres版本中的gem 0.7.9.2008.01.28- 两者都显示相同的行为.

我的队友PostgreSQL v8.4在语言安装是手动步骤的地方运行.

Dav*_*han 22

我有同样的问题.我用下面的命令修复了我的模板

psql template1
template1=# alter role my_user_name with superuser;
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请访问http://gilesbowkett.blogspot.com/2011/07/error-must-be-owner-of-language-plpgsql.html

  • 这适合我; 但是什么`改变角色my_user_name与超级用户;`实际上做什么? (2认同)
  • 这不是一个适当的解决方案。我不想给这个用户超级用户权限。 (2认同)

Fra*_*ank 21

对于新读者,我在我自己的一个项目中遇到此错误后阅读了这篇旧帖子.我强烈认为给应用程序的PostgreSQL一个超级用户角色是一个可怕的想法,改变模板也不理想.由于db:structure:dumpRails应用程序的数据库不需要添加引用的PSQL命令,因此我编写了一个自定义rake任务,用于注释structure.sql中有问题的行.我已经通过https://gist.github.com/rietta/7898366在Github上公开分享了该代码.


Lee*_*ley 8

解决方案如下:

在我的安装,有标准模板template0template1-至少我了解Postgres将查找最高编号templateN创建一个新的数据库时,除非指定的模板.

在这种情况下,作为template0包含plpgsql,所以做了template1...的想法是,您将定制template1适合您的网站特定的默认需求,并在你把这一切搞砸的情况下,你会恢复template1template0.

由于我的网站特定要求是plpgsql作为我的Web应用程序的自动构建的一部分安装(我们必须保持以保持8.4兼容性的一步) - 解决方案很简单:plpgsql从中删除template1并且警告/错误消失了.

如果特定于站点的默认值会发生变化,我们应该回到默认行为,我们只需删除template1并重新创建它(将使用template0)