2012-09-01 3 views
2

어떻게 PostgreSQL 성능 문제를 진단합니까? PostgreSQL 데이터베이스 서버 응답이 없습니다

우분투 (12)에 대한 데이터베이스 백엔드로의 PostgreSQL을 사용하여 장고 기반의 웹 애플리케이션이 있고, 부하, 데이터베이스처럼 오류가 장고 인터페이스에 연결할 수 원인과 결과 사라질 것 같다

django.db.utils.DatabaseError: error with no message from the libpq 

django.db.utils.DatabaseError: server closed the connection unexpectedly 
    This probably means the server terminated abnormally 
    before or while processing the request. 

이상한 점은/var/log/postgresql의 로그가 비정상적으로 표시된다는 것입니다. 로그 /var/log/postgresql/postgresql-9.1-main.log 쇼 라인이 많이있는 유일한 것은 좋아 :

2012-09-01 12:24:01 EDT LOG: unexpected EOF on client connection 

top을 실행하면 PostgreSQL을가하더라도, 어떤 CPU를 소모하지 않는 것 보여줍니다 service postgresql status은 아직 실행 중임을 나타냅니다.

'service postgresql restart`를 실행하면 일시적으로 문제가 해결되지만 데이터베이스에 많은로드가 발생하면 문제가 즉시 반환됩니다.

dmesg 및 syslog를 확인했지만 잘못된 점을 설명하는 내용이 표시되지 않습니다. 다른 로그를 확인해야합니까? PostgreSQL 서버의 문제점을 어떻게 판별합니까?

편집 : 내 max_connections는 100으로 설정됩니다. 많은 수작업 트랜잭션을 수행하고 있지만. Django의 ORM 동작을 수동 모드로 PostgreSQL에서 읽는다면 명시 적으로 connection.close()를 수행해야하는 것처럼 보입니다.

+0

아마도 데이터베이스에 대한 최대 연결이 모두 사용되었거나 닫히지 않았을 때 아무것도하지 않는 연결이 너무 많습니다 (시간 초과가 너무 높음). – Jingo

+0

전용 서버 또는 VPS에 있습니까? –

+0

@Catcall, KVM 기반 VPS. – Cerin

답변

4

이것은 멀티 프로세싱과 함께 장고의 버그가있는 Postgres-backend 때문인 것으로 나타났습니다. 본질적으로 장고는 자동으로 연결을 자동으로 닫지 않아서 많은 "유휴 트랜잭션"연결과 같은 이상한 동작을 일으 킵니다. 필자는 다중 처리 기능의 끝 부분에이 오류를 던지는 특정 쿼리가 있기 전에 connection.close()을 추가하여 해결했습니다.

+0

문제는 django와 다르므로 django는 연결을 포크하지 않으므로 실행중인 프로세스가 프로세스 사이에 공유 된 이후로 연결을 성숙하게 닫을 수 있습니다. 이것이 내가 일어난 일이다. 다중 처리하는 동안 데이터베이스를 업데이트하려고하면 나에게 문제가 발생합니다. 업데이트 할 데이터와 다중 처리 부분이 완료되었을 때 데이터를 수집했습니다. 그런 다음 업데이트 쿼리를 실행했습니다. 매력처럼 작동 :) – radtek

1
2012-09-01 12:24:01 EDT LOG: unexpected EOF on client connection 

이 메시지가 표시됩니다, 그래서 몇 가지 문제는 클라이언트 측에 - libpq를 에서 어쩌면 일부 예외? 관련 문제가있을 수 있습니다. 클라이언트가 올바른 로그 아웃없이 중단 한 경우 유휴 연결이 많으며 다른 오류가 일찍 발생합니다.

1

프로그램 pg_ctl에는 일 수도 있고 일 수있는 몇 가지 옵션이 있습니다. (man pg_ctl)

-c 
     Attempt to allow server crashes to produce core files, on platforms 
     where this is possible, by lifting any soft resource limit placed 
     on core files. This is useful in debugging or diagnosing problems 
     by allowing a stack trace to be obtained from a failed server 
     process. 

    -l filename 
     Append the server log output to filename. If the file does not 
     exist, it is created. The umask is set to 077, so access to the log 
     file is disallowed to other users by default. 

프로그램 postgres에는 몇 가지 디버그 옵션이 있습니다. 단면 "세미 내부 옵션"의

-d debug-level 
     Sets the debug level. The higher this value is set, the more 
     debugging output is written to the server log. Values are from 1 to 
     5. It is also possible to pass -d 0 for a specific session, which 
     will prevent the server log level of the parent postgres process 
     from being propagated to this session. 

(man postgres)

. . .