1

I'm using Postgres 9.5 on Mac Sierra. My postgres db suddenly died, and so I need to restart it, but I'm getting some errors when I try and run

/usr/local/var/postgres start

below tells the saga ...

localhost:myproject davea$ sudo pg_ctl -D /usr/local/var/postgres start
Password:
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
localhost:myproject davea$ sudo su - postgres pg_ctl -D /usr/local/var/postgres start
-bash: pg_ctl: No such file or directory
localhost:myproject davea$ ls /usr/local/var/postgres
PG_VERSION  global   pg_commit_ts  pg_hba.conf    pg_logical    pg_notify    pg_serial     pg_stat  pg_subtrans  pg_twophase  postgresql.auto.conf
base        pg_clog  pg_dynshmem   pg_ident.conf  pg_multixact  pg_replslot  pg_snapshots  pg_stat_tmp  pg_tblspc    pg_xlog      postgresql.conf

What is the right way to start up my Postgres server on my Mac?

Edit: In response to comments, this is how I attempted to impersonate the postgres user and restart the server

localhost:myproject davea$ sudo su - postgres
Password:
localhost:~ postgres$ pg_ctl -D /usr/local/var/postgres start
pg_ctl: could not access directory "/usr/local/var/postgres": Permission denied
localhost:~ postgres$ ls -al
total 128
drwxr-xr-x+ 24 postgres  staff     816 Apr 19  2016 .
drwxr-xr-x   3 root      daemon    102 Oct 26  2016 ..
drwx------+  3 postgres  staff     102 Apr 19  2016 Desktop
drwx------+  3 postgres  staff     102 Apr 19  2016 Documents
drwx------+  3 postgres  staff     102 Apr 19  2016 Downloads
drwx------+  5 postgres  staff     170 Oct 26  2016 Library
drwx------+  3 postgres  staff     102 Apr 19  2016 Movies
drwx------+  3 postgres  staff     102 Apr 19  2016 Music
drwx------+  3 postgres  staff     102 Apr 19  2016 Pictures
drwxr-xr-x+  3 postgres  staff     102 Apr 19  2016 Sites
drwxr-xr-x  40 root      daemon   1360 Mar  4  2016 bin
drwx------  27 postgres  daemon    918 May 26 08:35 data
drwxr-xr-x   6 root      daemon    204 Mar  4  2016 doc
drwxr-xr-x  33 root      daemon   1122 Mar  4  2016 include
drwxr-xr-x   3 root      daemon    102 Mar  4  2016 installer
drwxr-xr-x  61 root      daemon   2074 Mar  4  2016 lib
-rw-rw-r--   1 root      daemon   2476 Jan 11  2016 license.txt
drwxr-xr-x   3 root      daemon    102 Mar  4  2016 pgAdmin3.app
-rwxr-xr-x   1 root      daemon    373 Mar  4  2016 pg_env.sh
drwxr-xr-x  12 root      daemon    408 Mar  4  2016 scripts
-rw-r--r--   1 root      daemon  53807 Feb  8  2016 server_3rd_party_licenses.txt
drwxr-xr-x   4 root      daemon    136 Mar  4  2016 share
drwxr-xr-x   3 root      daemon    102 Mar  4  2016 stackbuilder.app
drwxr-xr-x   3 root      daemon    102 Mar  4  2016 uninstall-postgresql.app
6
  • You normally want to impersonate user "postgres".
    – joanolo
    Jun 22, 2017 at 18:18
  • Doesn't the "sudo su - postgres" in my command above do that?
    – Dave
    Jun 22, 2017 at 18:33
  • No, it doesn't, otherwise it wouldn't tell you: pg_ctl: cannot be run as root.
    – joanolo
    Jun 22, 2017 at 18:34
  • 1
    Yes. Now you have to let the postgres user read and write access to "/usr/local/var/postgres", or otherwise find which is the owner of those files and use sudo with that one.
    – joanolo
    Jun 22, 2017 at 20:30
  • 1
    With postgresql provided by homebrew (which you seem to use based on the paths), you don't use the postgres user, or sudo, or su or anything like that, but your own user. Run brew info postgresql and follow the instructions it displays on how to start. Jun 23, 2017 at 11:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.