2012-08-16 42 views
6

我想在我的mac(10.7 Lion)上爲rails應用程序本地獲取postgres設置。試圖在OSX上設置postgres

我安裝postgresapp並啓動它,現在我的狀態欄中有一頭大象告訴我postgres正在運行。

我可以得到它:

psql -h localhost 

但是當我只需運行psql我得到這個錯誤:

psql: could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

我把這個:

PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH" 

~/.bashrc和開了一個新的終端。但沒有骰子。

當我運行which psql我得到/usr/bin/psql

不是真的知道該怎麼做..我還是很新的Unix系統。我應該符號鏈接/usr/bin/psql/Applications/Postgres.app/Contents/MacOS/bin/psql

+1

哪裏另一個'psql'來自'/ usr/bin /'中的'psql'嗎?預裝Mac OS X?來自不同的PostgreSQL包? – 2012-08-16 02:58:30

+0

@CraigRinger我會認爲它已經預裝了。 – 2012-08-16 03:14:22

+0

'/ Applications/Postgres.app/Contents/MacOS/bin'中是否有psql可執行文件?它應該在那裏。如果你嘗試運行那個(指定路徑),會發生什麼? – dezso 2012-08-16 06:30:51

回答

4

這個錯誤是非常具體的,並告訴你什麼是錯誤的,但如果你是unix的新手,那就不那麼明顯了。

我給了一個類似的答案在這裏:

Can not connect to local PostgreSQL

的問題

您沒有訪問( 「套接字」)文件/var/pgsql_socket/.s.PGSQL.5432

修復:

檢查您是否至少可以訪問該目錄。在命令行上使用:

ls -l /var/pgsql_socket/.s.PGSQL.5432 

如果不是,則會導致「權限被拒絕」。很可能你已經有權訪問它,它只是你沒有權限的套接字文件。

套接字文件本身是由postgresql在啓動時創建的。

追蹤postgres的主配置文件(postgresql.conf)。 這本身可能很難,我是一個Linux用戶而不是OSX。您可能需要在Google上花費一些時間。這個鏈接非常古老,但如果您遇到問題,它可能會讓您走上正確的軌道。 http://www.postgresqlformac.com/server/howto_edit_postgresql_confi.html

一旦你找到它,發現在postgresql.conf中,他們應該說類似的線路:

unix_socket_directory = '/var/pgsql_socket' # dont worry if yours is different 
#unix_socket_group = ''      # default is fine here 
unix_socket_permissions = 0777     # check this one 
+4

Mac OSX配置文件位於/ Users/$ USER/Library/Application Support/Postgres/var – SANDeveloper 2013-09-05 14:31:18

11

我對我的新的MacBook Pro運行的山獅類似的問題。我下載了PostgresApp,當我啓動了軌道,我收到以下錯誤:

`initialize': could not connect to server: No such file or directory (PG::Error) 
Is the server running locally and accepting 
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? 

爲了解決這個問題,我不得不明確定義的主機和端口在我database.yml文件像這樣:

development: 
    adapter: postgresql 
    encoding: unicode 
    database: my_app_development 
    pool: 5 
    username: tony 
    password: stark  
    host: localhost 
    port: 5432