psql 必须是扩展 plpgsql 的所有者

Posted

技术标签:

【中文标题】psql 必须是扩展 plpgsql 的所有者【英文标题】:psql must be owner of extension plpgsql 【发布时间】:2019-03-01 13:57:00 【问题描述】:

Ubuntu 18.04、Ruby ruby​​ 2.4.1p111(2017-03-22 修订版 58053)[x86_64-linux]、PostgreSQL 9.4.21

我正在尝试为 db create 运行 rake,这就是我得到的结果:

nenad@mycomputer-l:~/someproject/foo$ bundle exec rake db:create db:bar:create db:prepare
**************************************************
⛔️ WARNING: Sidekiq testing API enabled, but this is not the test environment.  Your jobs will not go to Redis.
**************************************************
Database 'foo_development' already exists
Database 'foo_test' already exists
Database 'bar-development' already exists
Database 'bar-test' already exists
 set_config 
------------

(1 row)

psql:/home/nenad/someproject/foo/db/structure.sql:20: ERROR:  must be owner of extension plpgsql
rake aborted!
failed to execute:
psql -v ON_ERROR_STOP=1 -q -f /home/nenad/someproject/foo/db/structure.sql foo_development

Please check the output above for any errors and make sure that `psql` is installed in your PATH and has proper permissions.

/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/postgresql_database_tasks.rb:116:in `run_cmd'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/postgresql_database_tasks.rb:88:in `structure_load'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:234:in `structure_load'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:247:in `load_schema'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:266:in `block in load_schema_current'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:313:in `each'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:265:in `load_schema_current'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.2/lib/active_record/railties/databases.rake:300:in `block (3 levels) in <top (required)>'
/home/nenad/someproject/foo/lib/tasks/db.rake:5:in `block (2 levels) in <top (required)>'
/home/nenad/someproject/foo/vendor/bundle/ruby/2.4.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/home/nenad/.rbenv/versions/2.4.1/bin/bundle:22:in `load'
/home/nenad/.rbenv/versions/2.4.1/bin/bundle:22:in `<main>'
Tasks: TOP => db:structure:load
(See full trace by running task with --trace)

【问题讨论】:

【参考方案1】:

您可能需要在 psql 中更改您的权限。

尝试以 postgres 身份登录

sudo -u postgres psql

user 然后列出你的数据库和相关用户

\du

然后

alter role &lt;your_role_name&gt; superuser;

【讨论】:

以上是关于psql 必须是扩展 plpgsql 的所有者的主要内容,如果未能解决你的问题,请参考以下文章

需要使用 plpgsql 函数截断表

在屏幕套接字中显示 plpgsql 过程的执行时间

plpgsql 专家:(记录集)函数的输入和输出

在 PL/pgSQL 匿名块中引用 psql 参数

通过 RAW plpgsql 中的 UPDATE 语句获取受影响的行

使用 psql 如何列出安装在数据库中的扩展?