Python/개발환경 구축

[Error] SCRAM authentication requires libpq version 10 or above 해결 / M1 Mac

뒷골목프로그래머 2023. 2. 9. 15:30
반응형

 안녕하세요. 글쓰는 개발자 입니다.

 

최근 기존 제품의 MSA 화 및 재 개발을 위해 설계를 마치고 그 중 Machine Learning 을 담당하는 Server 를 구축하던 중 발생한 Error 와 해결 과정을 간단히 소개하겠습니다.

 

요약

1. 에러 : FastAPI Server 를 Container로 띄우는 과정에서 발생

psycopg2.OperationalError: SCRAM authentication requires libpq version 10 or above

2. 원인 : m1 based macOS Computer 에서 발생하는 'libpg' error

3. 해결 방법 : Dockerfile 최상단 FROM 영역 '--platform=linux/amd64' 추가

# pull official base image
FROM --platform=linux/amd64 python:3.11-slim-buster

...

 

해결 과정

1. postgres client 문제 일 것이다. (fail)

    mysql 연동 시, mysql-clinet 를 설치 해야하는 것 처럼 postgresql도 똑같이 설치해야 하지 않을까? 하는 생각을 했습니다. 그러나 psycopg2-binary 설치를 통해 의존성 없이 실행 가능한 환경이었기 때문에 잘못된 접근법이었습니다.

2. psycopg2, psycopg2-binary, libpq 등 각종 버전 문제일 것이다. (fail)

    여기서부터 무한 loop 였습니다. 열심히 구글링을 하면서 각종 버전을 확인하고 container 내부에서 직접 설치/버전변경 해보았지만 먹히지 않고 일단 다음 날 출근을 위해 새벽에 분한 마음을 억지로 참아가며 잠을 청했습니다.

3. Docker Image 를 slim 으로 받아오기 때문이다. (fail)

    분한 마음을 안고 출근하여 점심 시간, 동료들과 대화하며 'docker image 를 slim 으로 받은 것 자체가 문제 일 수도 있다.' 는 결론을 내리고 재빠르게 자리로 돌아와 해보았지만 실패했습니다.

4. M1 Chip 이 문제다. (success)

    혼자 커피를 마시고 자리로 돌아와 해결 과정을 복기하면서 갑자기 떠오른 시나리오였고 저는 검색 키워드에 'm1' 을 추가했으며, 아래 참고자료 덕분에 문제를 해결했습니다.

 

참고

https://gitlab.com/glitchtip/glitchtip-backend/-/issues/143

 

Arm docker compose doesn't build locally due to old libpq and psycopg2-binary (#143) · Issues · GlitchTip / GlitchTip Backend

django.db.utils.OperationalError: SCRAM authentication requires libpq version 10 or above postgres 14...

gitlab.com

https://djangoforprofessionals.com/postgresql/

 

Chapter 3: PostgreSQL | Django For Professionals

One of the most immediate differences between working on a “toy app” in Django and a production-ready one is the database. Django ships with SQLite as the default choice for local development because it is small, fast, and file-based which makes it eas

djangoforprofessionals.com

 

반응형