Stan Blog

Live well, love lots, and laugh often.

[Rails] (PG::InsufficientPrivilege: ERROR: permission denied for schema public)

在 import 完 .sql 檔到專案的 postgres 後

使用 rails console 操作 db, 出現了以下錯誤訊息:

ActiveRecord::StatementInvalid (PG::InsufficientPrivilege: ERROR:  permission denied for schema public)
LINE 1: SELECT 1 FROM ONLY "public"."users" x WHERE "id" OPERATOR(pg...
                           ^
QUERY:  SELECT 1 FROM ONLY "public"."users" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x

螢幕快照 2019-11-06 11 53 25

解決方法:

  1. 進 pg 看目前所有使用者的權限
$ psql postgres
$ \du

螢幕快照 2019-11-06 11 55 39

發現 root 的 role attribute 是空的

  1. 給 root superuser 的權限, 在重新 \du 查看一次

$ ALTER USER root WITH SUPERUSER;

螢幕快照 2019-11-06 11 57 31

  1. 回到 rails console 重試, 成功

螢幕快照 2019-11-06 11 58 02

Ref:

PG::InsufficientPrivilege: ERROR: permission denied for relation schema_migrations rake db:create

Comments

comments powered by Disqus