14

I receive error

FATAL:  could not create lock file "postmaster.pid": Permission denied

when trying to execute command

pg_ctl restart --pgdata "D:\Program Files\PostgreSQL\8.3\data"

Full rights for postgres user to D:\, D:\Program Files\, D:\Program Files\PostgreSQL\ and D:\Program Files\PostgreSQL\8.3\data are set. What else I need to do?

Milen A. Radev
  • 60,241
  • 22
  • 105
  • 110
DSblizzard
  • 4,007
  • 7
  • 48
  • 76

5 Answers5

20

I set full access to D:\Program Files\PostgreSQL\8.3\data to Users group and now it works. Detail are at http://forumserver.twoplustwo.com/114/pokertracker/cant-connect-db-422617/ (last post).

DSblizzard
  • 4,007
  • 7
  • 48
  • 76
  • 1
    Pretty nasty that SO uses rel-nofollow in order to steal all google rep coming from that link, I must say – SamGoody Oct 16 '13 at 08:48
12

You need to ensure that the user postgres has write permission to the postgres data_directory configured in postgresql.conf file. In my case /var/lib/postgresql/9.5/main/ if not add permission with:

chmod u+w /var/lib/postgresql/9.5/main/
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
7

You have to make ensure that the user postgres has right to write & execute /var/run/postgresql

sudo chmod 765 /var/run/postgresql  
sudo chown postgres /var/run/postgresql

I had this issue due to installing postgres-xc and the solution was to remove it.

pg_ctl is the most common (and recommended) way used to start/stop/etc postgres.

For some reason it was not part of my postgres install.
After duckduckgo'ing a little, I installed postgre-xc which includes pg_ctl.
postgres-xc changed the owner of /var/run/postgresql from postgres to postgres-xc.
This caused lots of headaches and warnings about being unable to lock the pid file.

So, I removed postgres-xc (and reverted the owner of /var/run/postgresql to postgres).

Instead of using pg_ctl, I control postgres using

service postgresql status
or
/etc/init.d/postgresql status.

Hopefully this will help someone.

Sharpless512
  • 3,062
  • 5
  • 35
  • 60
SamGoody
  • 13,758
  • 9
  • 81
  • 91
  • The equiv on Windows would be net start postgresql-9.5, see https://stackoverflow.com/questions/36629963/how-to-start-postgresql-on-windows – SamGoody Jul 12 '17 at 14:21
5

postgresql serviceis logined in NETWORK SERVICE, so you must needed make data dir(ie: "D:\Program Files\PostgreSQL\8.3\data") is full control over to NETWORK SERVICE group.

Zhengkun Gong
  • 51
  • 1
  • 1
-1

I just added my username to group "postgres"; all went fine

sudo adduser your-user-name postgres

Ciao