IT

PostgreSQL 오류 '서버에 연결할 수 없습니다 : 해당 파일 또는 디렉토리가 없습니다'

lottoking 2020. 6. 29. 07:38
반응형

PostgreSQL 오류 '서버에 연결할 수 없습니다 : 해당 파일 또는 디렉토리가 없습니다'


다른 프로젝트와 마찬가지로 프로젝트에서 rake db : migrate를 실행하거나 Ruby on Rails 3.2 응용 프로그램 대한 대부분의 데이터베이스 작업을 시도 할 때이 오류가 발생 합니다.

PGError (서버에 연결할 수 없습니다 : 해당 파일 또는 디렉토리가 없습니다. 서버가 로컬로 실행 중이고 Unix 도메인 소켓 "/tmp/.s.PGSQL.5432"에서 연결을 수락합니까?

오래 전에 Homebrew 와 함께 PostgreSQL설치 했으며 MongoDB를 설치 한 후에 최근 PostgreSQL 설치가 동일하지 않았습니다. OS X v10.6 Snow Leopard를 실행하고 있습니다.

무엇이 잘못되었고 PostgreSQL이 Mac에서 어떻게 설정되어 있어야하는지 어떻게 더 잘 이해합니까?

지금까지는 PostgreSQL이 실행되고 있지 않다고 생각합니다 (?).

ps -aef|grep postgres                                                                                                   (ruby-1.9.2-p320@jct-ana) (develop) ✗
  501 17604 11329   0   0:00.00 ttys001    0:00.00 grep postgres

그러나 이것이 PostgreSQL이 실행 중임을 알려줍니까?

✪ launchctl load -w /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist                                                        (ruby-1.9.2-p136) 
homebrew.mxcl.postgresql: Already loaded

이 문제를 어떻게 해결합니까? 내가 뭘 보지 못합니까?

PS : ~/Library/LaunchAgents두 개의 PostgreSQL .plist 파일이 포함되어 있습니다. 그것이 관련이 있는지 확실하지 않습니다.

org.postgresql.postgres.plist
homebrew.mxcl.postgresql.plist

나는 다음을 시도하고 아래와 같이 결과를 얻었다.

$ psql -p 5432 -h localhost

psql: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (fe80::1) and accepting
    TCP/IP connections on port 5432?

OS X가 자체 버전의 PostgreSQL을 설치하고 Homebrew가 다른 위치에 다른 버전을 설치하고 PostgreSQL 명령이 / tmp / 디렉토리를보고 있기 때문에 이것이 발생했기 때문에 읽었습니다. 스택 오버플로에서 더 많은 것을 검색해야하지만 기본적으로 PostgreSQL을 symlink하여 해당 tmp 경로를 찾는 것이 실제로 실제 경로를 찾을 수 있도록하십시오.

이것은 내가 시도 할 몇 가지 더 많은 것을 발견 한 링크입니다. 특히 위의 링크를 수행하면 Mac OSX Lion Postgres는 /tmp/.s.PGSQL.5432의 연결을 허용하지 않습니다 . 나는 여전히 누군가 누군가 OS X에 PostgreSQL을 설치하는 개념과 그것이 왜 그렇게 어려운지에 대해 잘 설명하기를 바랍니다.

문제 해결에 도움이되는 최신 정보 :

$ which psql // This tells you which PostgreSQL you are using when you run $ psql. 

그런 다음 다음을 실행하십시오.

$ echo $PATH

고려해야 할 핵심 사항은 다음과 같습니다.

OS X 시스템의 PostgreSQL에 대한 경로 전에 실행하려는 PostgreSQL 사본의 경로 항목이 COMES인지 확인하십시오.

이것은 어떤 PostgreSQL이 실행될지를 결정하는 핵심 요구 사항이며, 내가 들었던 것은 대부분의 문제를 유발합니다.


postgres 디렉토리에 postmaster.pid가 없는지 확인하십시오. /usr/local/var/postgres/

이것을 제거하고 서버를 시작하십시오.

확인 - https://github.com/mperham/lunchy가 launchctl을위한 훌륭한 래퍼입니다.


업데이트 : OSX를 사용하는 경우 더 나은 문제가 있습니다 ...

http://postgresapp.com/


기존 답변 :

다음은 수정 사항입니다. 자세한 정보는 다음과 같습니다.

https://github.com/mxcl/homebrew/issues/5004

먼저 db를 중지 한 다음

  1. cd / var
  2. rm -r pgsql_socket
  3. ln -s / tmp pgsql_socket
  4. chown _postgres : _postgres pgsql_socket
  5. 컴퓨터가 아닌 postgres를 다시 시작하십시오.

나를 위해, 이것은 작동합니다

rm /usr/local/var/postgres/postmaster.pid

위에서 언급 한 오류에 대해서는이 문제가 해결됩니다.

1) 설치 중에 기본 포트 번호 5432 이외의 다른 포트를 언급 한 경우 postgres.conf 파일에 지정된 기본 포트 번호를 변경하십시오.

(또는)

2) postgresql.conf 파일에서 포트 번호를 변경하고 DB 서버를 다시 시작하십시오.

(또는)

3) psql type full command 대신

"psql -p 5432 -h localhost"

  • 서버 이름과 포트 번호

If you are running Homebrew, uninstall Postgresql end pg gems:*

$ gem uninstall pg
$ brew uninstall postgresql

Download and run the following script to fix permission on /usr/local:* https://gist.github.com/rpavlik/768518

$ ruby fix_homebrew.rb

Then install Postgres again and pg gem:*

$ brew install postgresql  
$ initdb /usr/local/var/postgres -E utf8

To have launchd start postgresql at login run:

$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents 

Or start manually.

Install pg gem

$ gem install pg

I hope have helped


I had that problem when I upgraded Postgres to 9.3.x. The quick fix for me was to downgrade to whichever 9.2.x version I had before (no need to install a new one).

$ ls /usr/local/Cellar/postgresql/
9.2.4
9.3.2
$ brew switch postgresql 9.2.4
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
<open a new Terminal tab or window to reload>
$ psql

This answer offers a much more comprehensive explanation along with alternative ways to fix the problem.


So for a lot of the issues here, it seems that people were already running psql and had to remove postmaster.pid. However, I did not have that issue as I never even had postgres installed in my system properly.

Here's a solution that worked for me in MAC OSX Yosemite

  1. I went to http://postgresapp.com/ and downloaded the app.
  2. I moved the app to Application/ directory
  3. I added it to $PATH by adding this to .bashrc or .bash_profile or .zshrc : export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
  4. I ran the postgres from the Applications directory and ran the command again and it worked.

Hope this helps! Toodles!

Also, this answer helped me the most: https://stackoverflow.com/a/21503349/3173748


When you run: psql -p 5432 -h localhost it does not use the loopback driver but uses a real socket and hence you need to configure postgres to accept socket connections. Hence even though pgadmin and other clients may work, psql will not.

You need to change both the postgresql.conf file and the pg_hba.conf files so allow connection over a real socket. This will also allow connection from a remote ip which is why it is disabled by default.

These files are in the data directory but the actual location can be different depending on how postgres was installed. With postgres running, run the command:

ps -ef | grep postmaster

These two files are the -D directory (maybe /usr/local/pgsql/data).

For the postgresql.conf file, uncomment the listen_address and change it to be:

listen_address = '*'

For the pg_hba.conf add the line:

host all all 0.0.0.0/0 md5

I fixed this by upgrading postgres.

brew update
brew upgrade

Then I had to also upgrade the databases to be compatible with the new major version, because I upgraded from 10 to 11.

brew postgresql-upgrade-database

(source https://github.com/facebook/react-native/issues/18760#issuecomment-410533581)


I don't really know Mac or Homebrew, but I know PostgreSQL very well.

You want to figure out where the logs are from PostgreSQL trying to start and what the socket directory is for PostgreSQL. By default when you build PG, the socket directory is /tmp/. If you didn't change that when you built PG and then you started PG, you should be able to see a socket file in /tmp if you do: ls -al /tmp

The socket file starts with a ".", so you won't see it with the '-a' to ls.

If you don't see a socket there, and you don't see anything from ps awux | grep postgres, then PG is probably not running, or maybe it is and it's the OSX-installed one. What might be happening is that you might be getting a conflict on listening on port 5432 on localhost- use netstat -anp to see what, if anything, is listening on 5432. If a Mac OSX PG is already listening on that port then that might be the problem.

Hope that helps. I have heard that homebrew can make things a bit ugly and a lot of people I've talked to encourage using a VM instead.


The Cause

Lion comes with a version of postgres already installed and uses those binaries by default. In general you can get around this by using the full path to the homebrew postgres binaries but there may be still issues with other programs.

The Solution

http://nextmarvel.net/blog/downloads/fixBrewLionPostgres.sh |

통하다

http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/


이 오류가 발생하는 한 가지 이유는 컴퓨터를 다시 시작할 때 로컬 postgres 데이터베이스가 종료되기 때문입니다. 새 터미널 창에서 다음을 입력하십시오.

$psql -h localhost 

서버를 다시 시작합니다.


Hello world :)
나에게 가장 좋지만 이상한 방법은 다음 일을하는 것이 었습니다.

1) postgres93.app 또는 다른 버전을 다운로드하십시오 . 이 응용 프로그램을 / Applications / 폴더에 추가하십시오.

2) 파일 .bash_profile(내 홈 디렉토리에 있음)에 행 (명령)을 추가하십시오 .

내보내기 경로 = / Applications / Postgres93.app / Contents / MacOS / bin / : $ PATH
psqlfrom 의 경로 입니다 Postgres93.app. 콘솔이 시작될 때마다 행 (명령)이 실행됩니다.

3) Launch Postgres93.app from /Applications/ folder. It starts a local server (port is "5432" and host is "localhost").

4) After all of this manipulations I was glad to run $ createuser -SRDP user_name and other commands and to see that it worked! Postgres93.app can be made to run every time your system starts.

5) Also if you wanna see your databases graphically you should install PG Commander.app. It's good way to see your postgres DB as pretty data-tables

Of, course, it's helpful only for local server. I will be glad if this instructions help others who has faced with this problem.


I had PostgreSQL 9.3 and got the same error,

Could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

I fixed this using:

chmod 777  /var/lib/pgsql/9.3/data/pg_hba.conf 
service postgresql-9.3 restart

It works for me.


for what it's worth, I experienced this same error when I had a typo (md4 instead of md5) in my pg_hba.conf file (/etc/postgresql/9.5/main/pg_hba.conf)

If you got here as I did, double-check that file once to make sure there isn't anything ridiculous in there.


There might be different issues with running PostgreSQL locally. I would recommend to clean all versions of postgres installed and start fresh. Once you have it installed, it's very easy to recreate your database if you have your rails project with the up to date db/schema.rb

Here is how I usually install PostgreSQL on a Mac. If you're running your database under the root user locally, you might want to omit the last step that creates a todo user


One of the reason could be that

unix_socket_directories in postgresql.conf file is not listed with the directory it is looking for.

In the question example it is looking for directory /tmp this has to be provided in the postgresql.conf file

something like this:

unix_socket_directories = '/var/run/postgresql,/tmp'    # comma-separated list of directories

This solution worked for me.


If you're on MacOS and using homebrew I found this answer extremely helpful:

https://stackoverflow.com/a/27708774/4062901

For me, my server was running but because of an upgrade I was having issues connecting (note: I use brew services). If Postgres is running, try cat /usr/local/var/postgres/server.log and see what the logs say. My error was a migration, not a connection issue.

Also after the manual migration they propose (which does work but) I found there was no longer a table for my user. Try this command to fix that: createdb (answered via psql: FATAL: database "<user>" does not exist)


Just restart Postgres as soon as error appears by running brew services restart postgresql and then try again


It's very simple. Only add host in your database.yaml file.

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

반응형