I am on OSX 10.9.2

I am locked out of postgres and trying to modify pg_hba.conf to get back in. https://stackoverflow.com/questions/11919275/can-not-enter-and-change-postgresql-pg-hba-conf-file

I run these commands:

$sudo ls -l /Library/PostgreSQL/9.3/data/pg_hba.conf
-rwx--x--x  1 abramhandler  daemon  4222 Oct  9 20:42 /Library/PostgreSQL/9.3/data/pg_hba.conf
$ whoami
$ sudo subl /Library/PostgreSQL/9.3/data/pg_hba.conf

I make changes and click save and get an error from sublime text 2: Unable to save ~/data/pg_hba.conf

The ls -l command shows that I own the file and have write access. Why can't I save?

Note: I think I am saving to /Library/PostgreSQL/9.3/data/pg_hba.conf even if I get that error message. Data has a little red circle on it -- which probably indicates a problem.

enter image description here

  • 2
    The error from Sublime shows the file at ~/data/pg_hba.conf while in your terminal it looks like the file is at /Library/PostgreSQL/9.3/data/pg_hba.conf. Are you using /Library/PostgreSQL/9.3/ as your home directory? Or do you have one file open in Sublime Text, when you're looking at a completely different file in the terminal? Commented Mar 17, 2014 at 3:52
  • 1
    Please edit your question and 1) tell us what user you are running sublime as 2) what is that user's home directory (echo ~)? 3) Have you tried saving to /Library/PostgreSQL/9.3/data/pg_hba.conf instead of ~/data/pg_hba.conf? 4) post the output of ls -l ~/data/pg_hba.conf
    – terdon
    Commented Mar 17, 2014 at 4:03
  • 1
    he's running Sublime as root, due to the sudo. try changing the owner of the file to root and try again. I think it's denied because root doesn't have access to the file (yes, this is possible - the distinction is that root has the power to get access, whereas normal users don't).
    – strugee
    Commented Mar 17, 2014 at 4:10
  • 1
    Does it work if you try writing to that file from another process, e.g. echo | sudo tee -a /Library/PostgreSQL/9.3/data/pg_hba.conf (don't forget the -a!)? Why are you using sudo? Commented Mar 17, 2014 at 20:12
  • 1
    If you need to do an ls to see the file, then you don't have access to the directory to save it. Confirm that subl is really, really running Sublime Text as root (check Activity Monitor or ps). I suspect it is running it as your user, and the user does not have access to one of the directories in the path. Commented Mar 17, 2014 at 21:18

2 Answers 2


I needed to chown the containing folder -- not just the file itself. Once I chowned the containing folder I was able to save.

$sudo chown abramhandler data

The editor you're using might want to first write out a new file and then rename it to the original name. That way, if something goes wrong in saving the file, the old file is not overwritten before the new one is ready. This minimizes chances for loss of data in case of power interruptions or hardware/filesystem errors, but requires write access to the directory, not just the file itself.

Optionally, the editor might be trying to rename the old file into a backup file (often with a .bak or ~ suffix) before writing out the new version of the file. This also requires write permissions to the directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .