2017-10-18 141 views
0

我的問題原本是我無法使用PostgreSQL,因爲我不知道密碼 - 我也沒有創建過密碼。我正嘗試重置或恢復密碼,並在嘗試執行此操作時遵循了各種建議。無法重置PSQL密碼或編輯mac上的pg_hba.conf文件

起初,我嘗試過編輯pg_hba.conf文件,我定位是通過使用下面的命令:

sudo vim /etc/postgresql/9.3/main/pg_hba.conf 

但是,這只是把我帶到一個空白的屏幕,我可以做什麼用,除了關閉窗口。

有人告訴我嘗試:

sudo nano /etc/postgresql/9.3/main/pg_hba.conf 

...這是更好,因爲這包括在頁面底部的按鍵命令,但該文件是空白的,所以無法進行編輯。

要回這之後,我想造成一些錯誤,如果我回去到現在,我得到這個:

E325: ATTENTION 
Found a swap file by the name "/var/tmp/pg_hba.conf.swp" 
     owned by: root dated: Tue Oct 17 15:57:30 2017 
    file name: /etc/postgresql/9.3/main/pg_hba.conf 
     modified: YES 
    user name: root host name: Roberts-MacBook-Pro.local 
    process ID: 2668 
While opening file "/etc/postgresql/9.3/main/pg_hba.conf" 

(1) Another program may be editing the same file. If this is the case, 
be careful not to end up with two different instances of the same 
file when making changes. Quit, or continue with caution. 
(2) An edit session for this file crashed. 
If this is the case, use ":recover" or "vim -r 
/etc/postgresql/9.3/main/pg_hba.conf" 
to recover the changes (see ":help recovery"). 
If you did this already, delete the swap file 
"/var/tmp/pg_hba.conf.swp" 
to avoid this message. 

Swap file "/var/tmp/pg_hba.conf.swp" already exists! 
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, 
(A)bort: 

我試圖通過鍵入d刪除.SWP文件,但這個沒似乎沒有做任何事情。

我真的很困惑這一切,我真的不知道我怎麼可以學習更多,以瞭解我在做什麼。當我進入PostgreSQL網站時,我讀了pp_hba.conf文件應該是什麼樣子,但是我可以訪問這個文件的唯一方式是完全空的。

我不知道該從哪裏出發,所以我會非常感謝任何能指引我正確方向的人的建議,謝謝。

+0

這可能值得一讀https://stackoverflow.com/questions/7975414/how-to-check-status-of-postgresql-server-mac-os-x –

+0

謝謝,但我已經通過這個階段。我應該提到這一點。 – Robert

+0

你甚至使用PostgreSQL 9.3嗎?你是如何安裝它的?如果配置在Mac OS的'/ etc'中,我會感到驚訝。 –

回答

0

只要PostgreSQL的已啓動,您可以通過運行找出pg_hba.conf你應該編輯:

ps -ef | grep 'postgres -D' 

在我奇怪的設置,這將返回:

/opt/boxen/homebrew/opt/postgresql/bin/postgres -D /opt/boxen/homebrew/var/postgres 

,所以我知道編輯文件:

/opt/boxen/homebrew/var/postgres/pg_hba.conf 

更改哪些連接是全部欠哪些數據庫等。另請參閱pg_hba.conf docs瞭解更多信息。

+0

謝謝,但我已經經歷了這些階段,並且我有了pg_hba.conf文件,我只是在編輯時遇到了麻煩。您提到的文檔讓我相信我會看到文件上的某些內容,但是當我通過VIM或Nano進行操作時,它完全是空白的。所以我正在設法解決這個問題,以便我可以重置我的PSQL密碼。任何想法? – Robert

+0

它是空白的事實意味着文件不存在(vim會顯示'[New File]'),或者你沒有編輯文件的權限(vim會顯示'[Permission Denied]')。 –

+0

其實VIM在底部顯示[新目錄]。在這種情況下我能做些什麼? – Robert