Development Tip

Psql이 서버에 연결할 수 없습니다 : 해당 파일 또는 디렉터리가 없습니다. 5432 오류?

yourdevel 2020. 11. 23. 20:17
반응형

Psql이 서버에 연결할 수 없습니다 : 해당 파일 또는 디렉터리가 없습니다. 5432 오류?


psqlVagrant 컴퓨터에서 실행하려고 하는데이 오류가 발생합니다.

psql: could not connect to server: No such file or directory

Is the server running locally and accepting connections on 
Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

참고 : Vagrant 1.9.2 상자 : ubuntu / trusty64, https://atlas.hashicorp.com/ubuntu/boxes/trusty64

postgres를 설치하고 실행하기 위해 사용한 편집 명령 :

  • sudo apt-get update
  • sudo apt-get install postgresql
  • sudo su postgres
  • psql -d postgres -U postgres

내 pg_hba.conf 파일 ()의 구성과 관련된 동일한 문제가 발생했습니다 /etc/postgresql/9.6/main. 9.6은 내가 사용중인 postgresql 버전입니다.

오류 자체는 postgresql의 잘못된 구성과 관련이 있으며, 이로 인해 서버가 시작되기 전에 충돌이 발생합니다.

다음 지침을 따르는 것이 좋습니다.

  1. 다음을 사용하여 postgresql 서비스가 실행 중인지 확인합니다. sudo service postgresql start
  2. pg_lsclusters터미널에서 실행
  3. 실행중인 클러스터가 무엇인지 확인합니다. 출력은 다음과 같아야합니다.

    버전-클러스터 포트 상태 소유자 데이터 디렉토리

    9.6 ------- 메인-5432 온라인 postgres /var/lib/postgresql/9.6/main

    '---'기호는 정렬을 위해서만 사용되므로 무시하십시오. 중요한 정보는 버전과 클러스터입니다. 상태 열에서 서버가 실행 중인지 여부를 확인할 수도 있습니다.

  4. 버전 및 클러스터에서 정보를 복사하고 다음과 같이 사용하십시오. pg_ctlcluster <version> <cluster> start, 제 경우에는 버전 9.6 및 클러스터 'main'을 사용하여pg_ctlcluster 9.6 main start
  5. 뭔가 잘못된 경우 postgresql은에서 액세스 할 수있는 로그를 생성 /var/log/postgresql/postgresql-<version>-main.log하므로 제 경우에는 전체 명령이 sudo nano /var/log/postgresql/postgresql-9.6-main.log.
  6. 출력에 오류가 무엇인지 표시되어야합니다.

    2017-07-13 16:53:04 BRT [32176-1] LOG : 잘못된 인증 방법 "all"
    2017-07-13 16:53:04 BRT [32176-2] CONTEXT : 구성 파일의 90 행 "/ etc /postgresql/9.5/main/pg_hba.conf "
    2017-07-13 16:53:04 BRT [32176-3] 치명적 : pg_hba.conf를로드 할 수 없습니다.

  7. 오류를 수정하고 postgresql 서비스를 다시 시작 sudo service postgresql restart하면 괜찮습니다.

나는 이것을 찾기 위해 많은 것을 검색했으며 신용은이 게시물 로 이동합니다 .

행운을 빌어 요!


나는 같은 문제가 있었지만 여기에 대답이 도움이되지 않았습니다.

수정 방법 (Mac)

  • 다음으로 postgresql을 시작하십시오. pg_ctl -D /usr/local/var/postgres start
  • 와 같은 오류 메시지찾으십시오 FATAL: could not open directory "pg_tblspc": No such file or directory.
  • 누락 된 디렉토리 생성 mkdir /usr/local/var/postgres/pg_tblspc
  • 누락 된 모든 디렉토리를 만들 때까지 1 단계부터 반복합니다.
  • 완료되면 postgresql을 다시 시작하려고하면 다음과 같이 말할 수 있습니다 .FATAL: lock file "postmaster.pid" already exists
  • postmaster.pid 삭제 :rm /usr/local/var/postgres/postmaster.pid
  • 다음을 사용하여 postgres를 시작하십시오. pg_ctl -D /usr/local/var/postgres start
  • 완료 ✨

나는이 질문을 발견했을 때처럼 길을 잃고 절망감을 느끼는 사람을 위해 이것을 게시하고 있습니다. 때때로 psotgresql 관련 구성 파일을 편집하면 실수로 파일의 권한을 변경할 수 있습니다.

여기에 이미지 설명 입력

pg_hba.conf가 어떻게 루트에 속해 있는지, 사용자는 그것을 읽을 수도 없습니다. 이로 인해 postgres가이 파일을 열 수 없으므로 서버를 시작할 수 없으며 원래 질문에 표시된 오류가 발생합니다.

달리기

sudo chmod +r pg_hba.conf

이 파일을 postgres 사용자가 다시 한 번 액세스 할 수 있도록 한 다음 실행 한 후

sudo service postgresql start

서버를 다시 실행할 수있었습니다.


Does the /etc/postgresql/9.6/main/postgresql.conf show that port being assigned? On my default Xubuntu Linux install, mine showed port = 5433 for some reason as best as I can remember, but I did comment out the line in that same file that said listen_addresses = 'localhost' and uncommented the line listen_addresses = '*'. So maybe start and check there. Hope that helps.


Use command:

rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

Open your database manager and execute this script

update pg_database set datallowconn = 'true' where datname = 'your_database_name';

The same thing happened to me as I had changed something in the /etc/hosts file. After changing it back to 127.0.0.1 localhost it worked for me.


Within zsh:

rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

This is the only thing that worked for me after countless hours trouble shooting.


This works for me:

pg_ctl -D /usr/local/var/postgresql@9.6 stop;
brew services stop postgresql@9.6;
brew services start postgresql@9.6;

I had the same error when I create the SQL db in a VM. I had changed the default value of /etc/postgresql/9.3/main/postgresql.conf shared_buffers = 200MB to 75% of my total RAM. Well, I forgot to actually allocate that RAM in the VM. When I gave the command to make a new database, I received the same error.

Powered off, gave the baby its bottle (RAM) and presto, it worked.


just reinstall your pgsql with direct version sudo apt-get install postgresql-9.5 (u must remove the package before install new one)


I was able to solve the issue by running:

sudo systemctl start postgresql@9.5-main

I got this error when I restored my database from last pg_basebackup backup file. After that when I tried to connect database(psql), I was getting the same error. The error was resolved, when I updated pg_hba.conf file and wherever "peer" authentication was there I replaced that with "md5" and then restarted postgres services. After that, the problem was resolved.


I had similar problems just a while ago. After trying more than 5 suggestions I decided to go back to the basics and start from the beginning. Which meant removing my postgresql installation and following this guide upon re-installing postgresql. https://help.ubuntu.com/lts/serverguide/postgresql.html

참고URL : https://stackoverflow.com/questions/42653690/psql-could-not-connect-to-server-no-such-file-or-directory-5432-error

반응형