-
[yongggg's] psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket?Error 관련 2025. 1. 7. 14:10
docker container에 설치
(저는 docker hub의 postgre official 15.10 (ubuntu 22.04.4) 버전을 이용했습니다.)
이번 장에서는 postgre 최초 설정시 다음과 같은 에러에 대해 알아보도록 하겠습니다.
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?해당 문구는 기존 docker container를 run할 때, 5432 포트를 열어주지 않아서 생긴 문제로 추측된다.
따라서 다음과 같이 5432 포트를 열어주면, 정상적으로 사용할 수 있다.
docker run -p 8300:5432 --name postgre-gozyo -e POSTGRES_PASSWORD=1q2w3e4r -d -v pgdata:/var/lib/postgresql/data postgres
이 때, -e를 통해 Postgre database의 PASSWORD를 미리 설정하는 것이 권장된다고 한다.
또 몇가지 시도를 통해 알게된 것은,
- 맨 뒤에 /bin/bash 옵션을 추가하면, container가 정상적으로 실행되지 않았고
- volumne 마운트를 진행시, /data/yong 과 같은 폴더의 폴더 구조로 했을 때, container가 정상 작동하지 않았다.
$\rightarrow$ 위의 예제처럼 pgdata (절대 경로의 폴더 name)을 볼륨마운트로 지정해주었을 때, container가 정상 작동하였다.
위의 명령어로 docker container를 구성해주었다면, 다음의 명령어로 postgre container에 붙을 수 있다.
docker exec -it postgre-gozyo /bin/bash
Make sample database & example table
위처럼 postgre container에 붙었다면 다음의 명령어로 postgre 명령어를 활성화할 수 있는 상태로 넘어갈 수 있다.
psql -U postgres
그럼 아래와 같이 왼쪽에 posrgre 명령어를 입력할 수 있게되는 쉘로 바뀌게 될것이다.
여기서 위 명령어의 상세 설명은 다음과 같고, 꼭 postgres가 아니더라도 정의된 User로 접속할 수 있다.
- psql: PostgreSQL의 CLI (Command Line Interface) 도구입니다. 이를 통해 데이터베이스와 상호 작용할 수 있다.
- -U: --username의 약어로, 연결할 데이터베이스 사용자 이름을 지정한다.
- postgres: 위의 -U 옵션에 따라 사용할 사용자 이름입니다. PostgreSQL을 설치할 때 기본으로 생성되는 슈퍼유저 계정이 postgres이다.
'Error 관련' 카테고리의 다른 글
[yongggg's] json, jsonl 파일 read & write (0) 2025.01.23 [yongggg's] scp 전송시 Broken pipe error / 서버 무한 렉 error (2) 2025.01.16 [yongggg's] sglang.Engine error (0) 2024.12.04 [yongggg's] huggingface-cli download error (0) 2024.12.03 axolotl : resume_from_checkpoint 시, save checkpoint 및 resume train error (1) 2024.08.30