Development Tip

PGError : ERROR : 관계에 대한 권한이 거부되었습니다 (Heroku 사용시).

yourdevel 2020. 10. 20. 08:14
반응형

PGError : ERROR : 관계에 대한 권한이 거부되었습니다 (Heroku 사용시).


최근에 여기에 설명 된대로 데이터베이스 마이그레이션 프로세스를 거쳤습니다.

https://devcenter.heroku.com/articles/migrating-from-shared-database-to-heroku-postgres

이제 다음과 같은 로그에 여러 오류가 표시됩니다.

PGError : ERROR : 관계에 대한 권한이 거부되었습니다.

문제를 해결하려면 어떻게해야하는지에 대한 아이디어가 있습니까?


비슷한 문제가 있었지만 근본 원인은 내 앱이 10,000 행 제한을 초과 한 이전 dev 데이터베이스를 가리키고 있다는 것입니다.

새로운 Basic db를 만들고 모든 것을 백업했지만 앱은 여전히 ​​이전 dev DB를 가리키고있었습니다.

heroku pg:info

행 확인 : 10300/10000 (그러면 문제가 있음)

당신이 필요합니다

-) 1 (더 행이 기본 또는 "생산"사람을 새로운 DB를 생성>에게 Heroku)는 더 많은 돈을 errrrrr를 만들기 위해 업그레이드를 강요하는 것 같다

: 2) 백업 pgbackups 사용하여 이전 DB heroku pg:backups:capture SMALL_DB_NAME

3)에 백업을 복원을 새 DB : heroku pg:backups:restore BACKUP_ID BIG_DB_NAME(자세한 내용은 아래 링크 참조)

4) 새 DB를 앱의 기본 DB로 승격합니다.heroku pg:promote BIG_DB_NAME

항상 다음을 활용할 수 있습니다.

heroku maintenance:on (업데이트 중 앱 비활성화)


heroku maintenance:off


heroku pg:info (상태 확인)

이것이 문제라면 https://devcenter.heroku.com/articles/heroku-postgres-starter-tier https://devcenter.heroku.com/articles/migrating-from-shared-database 를 확인 하십시오. -to-heroku-postgres


업데이트 : Ashton의 답변은 매우 Heroku에 특화된이 상황에서이를 입증합니다. PostgreSQL 오류 메시지 또는 문제 검색에서 이것을 찾았지만 Heroku를 사용 하지 않는 경우 상황에 적용 할 가능성이 더 높은 다른 질문을 찾아보십시오.


추측에 따르면 연결하려는 PostgreSQL 사용자 ID는 테이블의 소유자가 아니며 테이블에 GRANT대한 액세스 권한을 부여하기 위해 명시적인 명령문을 발행하지 않았습니다 . 마이그레이션 할 때 실행 한 내용을 정확히 보지 않고 는 더 많은 것을 말하기 어렵습니다. 그리고 Heroku는 어쨌든 많은 내부를 숨 깁니다.

현재 상황이 무엇인지 알아 봅시다. 다음 psql연결하여 실행 해보십시오 .

\dp the_problem_table

보고 된 권한을 보여줍니다. 다음 결과도 표시합니다.

SHOW current_user;

에서 실행 psql하고 응용 프로그램 내에서 SQL 쿼리로 실행할 때.

질문을 수정하여 해당 정보와 표시되는 오류 메시지의 정확한 전체 텍스트 를 추가하세요 .


Dev (10k 행 제한)에서 Basic (10M 행 제한)으로 업그레이드하기위한 Ashton의 답변을 기반으로 한 단계

DB 행이 제한을 초과했는지 확인하십시오.

heroku pg:info

db 업그레이드 중에 db가 변경되지 않도록 앱 및 작업자를 비활성화하십시오.

heroku maintenance:on
heroku ps:scale worker=0

pgbackups가없는 경우

heroku addons:add pgbackups

데이터베이스 백업 및 백업 ID 가져 오기

heroku pg:backups:capture

웹 인터페이스로 db 추가

  1. https://addons.heroku.com에 로그인
  2. "Heroku Postgres"검색
  3. 계획 및 응용 프로그램 선택
  4. 그것을 추가

heroku 구성을 보려면 새 db URL이 표시되어야합니다.

heroku config --remote heroku

백업을 새 DB로 복원

heroku pg:backups:restore BACKUP_ID NEW_DB_URL

DATABASE_URL 변경

heroku pg:promote NEW_DB_URL

앱 및 작업자 활성화

heroku maintenance:off
heroku ps:scale worker=1

After deleting the extra rows, you won't get the insert privileges back immediately. In that case, delete the extra rows and just run heroku pg:info after that. This will refresh the privileges of your DB and you will get the access back in few minutes. Its not required to clone the existing DB into a new one and setting the new one as the DB of your app.

$ heroku pg:info

=== HEROKU_POSTGRESQL_BRONZE_URL, DATABASE_URL
Plan:        Hobby-dev
Status:      Available
Connections: 3/20
PG Version:  9.3.6
Created:     2014-03-01 13:47 UTC
Data Size:   1.25 GB
Tables:      4
Rows:        2098/10000 (Write access revoked) - refreshing
Fork/Follow: Unsupported
Rollback:    Unsupported
Add-on:      grinning-busily-5587

I was in a situation where I exceeded row count limit.

This answer explained how to list number of rows in each table: http://stackoverflow.com/questions/12701711/heroku-row-count-incorrect

Very valuable to know.

You can get into the psql console through terminal, the connection settings are listed on heroku dashboard for your app!


I had the similar problem on my Redmine application:

PG::InsufficientPrivilege: ERROR:  permission denied for relation settings
: SELECT  "settings".* FROM "settings"  WHERE "settings"."name" = 'plugin_redmine_wktime' LIMIT 1

My steps were:

  1. I made a backup of old Redmine application and database.
  2. I deployed a new version of Redmine - it worked perfectly
  3. I restored old Redmine as a development server and I got an error when I tried to access the main webpage.

The cause of my problem was just in wrong username in old Redmine's config/database.yml

참고URL : https://stackoverflow.com/questions/11930996/pgerror-error-permission-denied-for-relation-when-using-heroku

반응형