ProgrammingError:关系django_session的权限被拒绝

时间:2014-06-29 07:21:08

标签: python django django-sessions

我最近在网站上收到了500个错误。错误是ProgrammingError: permission denied for relation django_session

有时会发生update_disable() ajax函数。

这是函数

def update_disable(request, song_pk, dj_name=None, view=None, genre=None):
    song = Song.objects.get(pk=song_pk)
    song.votes = song.votes + 1
    song.save()
    dajax = Dajax()
    dajax.assign('.vote', 'disabled', 'disabled')
    if dj_name:
        request.session[dj_name] = True
    elif genre:
        print genre
        request.session[genre] = True
    else:
        if view=="month":
            request.session['month_voted'] = True
        else:
            request.session['trending_voted'] = True
    request.session.set_expiry(604800)
    visitor = get_obj_or_none(Visitor, last_session_key=request.session._session_key)
    if visitor:
        voter = get_obj_or_none(Voter, visitor=visitor)
        if voter:
            voter.vote_count += 1
            voter.save()
        else:
            voter = Voter(visitor=visitor)
            voter.save()
    return dajax.json()

我似乎无法理解是什么引发了这个错误。有什么想法吗?

这是整个追溯

Traceback (most recent call last):

  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 201, in get_response
    response = middleware_method(request, response)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/sessions/middleware.py", line 38, in process_response
    request.session.save()

  File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py", line 63, in save
    obj.save(force_insert=must_create, using=using)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 545, in save
    force_update=force_update, update_fields=update_fields)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 573, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 654, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 687, in _do_insert
    using=using, raw=raw)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py", line 232, in _insert
    return insert_query(self.model, objs, fields, **kwargs)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 1511, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 899, in execute_sql
    cursor.execute(sql, params)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)

ProgrammingError: permission denied for relation django_session



<WSGIRequest
path:/dajaxice/hunt.update_disable/,
GET:<QueryDict: {}>,
POST:<QueryDict: {u'argv': [u'{"song_pk":"680","dj_name":"Tiesto"}']}>,
COOKIES:{'_ga': 'GA1.2.1299003573.1404006039',
'csrftoken': '**masked**'},
META:{'CONTENT_LENGTH': '67',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
u'CSRF_COOKIE': u'**masked**',
'HTTP_ACCEPT': '*/*',
'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',
'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8',
'HTTP_CONNECTION': 'close',
'HTTP_COOKIE': 'csrftoken=**masked**; _ga=GA1.2.1299003573.1404006039',
'HTTP_HOST': 'www.edmhunters.com',
'HTTP_ORIGIN': 'http://www.edmhunters.com',
'HTTP_REFERER': 'http://www.edmhunters.com/top100/tiesto/',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
'HTTP_X_CSRFTOKEN': '**masked**',
'HTTP_X_FORWARDED_FOR': '110.32.33.39',
'HTTP_X_FORWARDED_PORT': '80',
'HTTP_X_FORWARDED_PROTO': 'http',
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
'HTTP_X_REQUEST_ID': 'ebadfe5f-d375-460d-8bdf-8a879f8fb13b',
'HTTP_X_REQUEST_START': '1404006080594',
'PATH_INFO': u'/dajaxice/hunt.update_disable/',
'QUERY_STRING': '',
'RAW_URI': '/dajaxice/hunt.update_disable/',
'REMOTE_ADDR': '10.122.102.62',
'REMOTE_PORT': '34465',
'REQUEST_METHOD': 'POST',
'SCRIPT_NAME': u'',
'SERVER_NAME': 'www.edmhunters.com',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.1',
'SERVER_SOFTWARE': 'gunicorn/18.0',
'gunicorn.socket': <socket._socketobject object at 0x35882f0>,
'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7fcd37a971e0>,
'wsgi.file_wrapper': <class gunicorn.http.wsgi.FileWrapper at 0x244e1f0>,
'wsgi.input': <gunicorn.http.body.Body object at 0x35bc550>,
'wsgi.multiprocess': False,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>

2 个答案:

答案 0 :(得分:0)

如果您使用Heroku PostgreSQL作为数据库,则可能已达到行数限制。使用命令行工具进行验证:

heroku pg:info -a <your_app>

=== HEROKU_POSTGRESQL_MAUVE_URL, DATABASE_URL
Plan:                  Hobby-dev
Status:                Available
Connections:           0/20
PG Version:            10.6
Created:               2018-03-14 22:04 UTC
Data Size:             20.3 MB
Tables:                90
Rows:                  13764/10000 (Write access revoked)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Billing App:           xxxxxxxxx
Add-on:                postgresql-silhouetted-xxx

Rows:行告诉您写访问权限已被撤销:(Write access revoked)

答案 1 :(得分:0)

如果您使用的是 Heroku、DJANGO、PostgreSQL

此错误说明by Heroku here

heroku 提供的所有解决此问题的方法都需要您更新您的帐户。 为了避免这一切,我想向您展示如何解决这个问题

1.在本地机器上安装 POSTGRESSQL Heroku devcenter tutorial

2.获取您的 BATABASE 信息

$ heroku pg:info -a your-app-name

=== DATABASE_URL
Plan:                  Hobby-dev
Status:                Available
Connections:           6/20
PG Version:            11.12
Created:               2019-09-10 23:20 UTC
Data Size:             11.8 MB
Tables:                33
Rows:                  1064/10000 (In compliance)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Add-on:                postgresql-********

注意最后一行(附加组件),我们将使用它

3.打开您的在线 PSQL 命令提示符

$ heroku pg:psql postgresql-******** --app sleento

用附加组件的内容替换 '********'

如果一切顺利,您已经到达了应用程序的 pqsl 命令提示符

4.删除 django_session 表

your-app-name::DATABASE=> DROP TABLE django_session;

5.创建一个新的 django_session 表

your-app-name::DATABASE=> CREATE TABLE django_session (
   session_key     varchar(40),
   session_data   text,
   expire_date timestamptz );

6.退出

your-app-name::DATABASE=> \q