6

When I put postgres -D /usr/local/var/postgres in terminal, I get this back:

FATAL: data directory "/usr/local/var/postgres" has wrong ownership HINT: The server must be started by the user that owns the data directory.

How could I fix with that? Thanks~

bfontaine
  • 18,169
  • 13
  • 73
  • 107
Echo0831
  • 307
  • 2
  • 5
  • 14

1 Answers1

11

Check the what the owner is of that dir by doing

ls -l /usr/local/var/ | grep postgres

You should see something like

-rw-r--r-- 1 postgresuser postgresuser  285659 Sep  1 18:05 postgres

Assuming it's "postgresuser", then run your database with

sudo -u postgresuser postgres -D /usr/local/var/postgres
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
  • I try the first line, but the result I got was drwxr--r--+ 27 root admin 918 1 28 23:31 postgres – Echo0831 Jan 29 '16 at 06:44
  • but it says "root" execution of the PostgreSQL server is not permitted. The server must be started under an unprivileged user ID to prevent possible system security compromise. – Echo0831 Jan 29 '16 at 06:46
  • 1
    Run `sudo chown -R YYY /usr/local/var/postgres` replacing `YYY` with your user name. Then you should be able to run `postgres -D /usr/local/var/postgres`. – Martin Konecny Jan 29 '16 at 06:50
  • 1
    and then I got FATAL: data directory "/usr/local/var/postgres" has group or world access DETAIL: Permissions should be u=rwx (0700). how could I change it.... – Echo0831 Jan 29 '16 at 06:54
  • 28
    `sudo chmod -R 700 /usr/local/var/postgres` – Martin Konecny Jan 29 '16 at 06:54
  • but FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 7671) running in data directory "/usr/local/var/postgres"? – Echo0831 Jan 29 '16 at 06:56
  • It's mentioning that postgresql may already be running, check if `ps -e | grep 7671` returns anything. – Martin Konecny Jan 29 '16 at 06:58
  • It returns "7671 ?? 0:00.02 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log 7685 ttys000 0:00.00 grep 7671" what does it mean? – Echo0831 Jan 29 '16 at 07:01
  • It means your database is running - you should be able to use it – Martin Konecny Jan 29 '16 at 07:03