简体   繁体   中英

Unable to start Postgres Server because of permission denied on lock file

I restarted my Postgres server but now. I checked my "pgstartup.log" log file. This says:

creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

Success. You can now start the database server using:
/usr/bin/postgres -D /var/lib/pgsql/data
/usr/bin/pg_ctl -D /var/lib/pgsql/data -l logfile start

FATAL:  could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
FATAL:  could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied

Do you think deleting /tmp/.s.PGSQL.5432.lock would work?

Postgres cannot write a file to /tmp because of permissions set on /tmp directory. As root user execute in terminal:

chmod 1777 /tmp

PostgreSQL normally deletes the lock file when terminates correctly.

It is probably due to another PostgreSQL instance running with a different user that has been terminated abnormally (a kill -9 to postmaster).

So, if you are sure no Postgres processes are running, you can probably delete that file without any issue. You should also check with the ipcs command if there is any stale shared memory segment, and in that case delete it with ipcrm .

Probably the be best way to address all these things at once is rebooting the server.

PS: never kill -9 any PostgreSQL process.

It looks like you probably have another PostgreSQL instance running on the same port as a different user, or you previously started this PostgreSQL instance as a different user then stopped it uncleanly.

Check the ownership of /tmp/.s.PGSQL.5432.lock :

ls -l /tmp/.s.PGSQL.5432.lock

Does it match the user you're running PostgreSQL as?

It's relatively harmless to delete the lock files in /tmp/ . (Never, ever delete the postmaster.pid lock file though). If the other PostgreSQL instance is still running you'll lose the ability to connect to it over a unix socket, or you might get an error about being unable to bind to port 5432 on tcp.

I agree with @mnencia that a server reboot is the best option if it's easy and practical.

To me it was permission problem for database file, It was group/world readable. And that was wrong! Database file should be 0700. Aft

Thanks for the suggestions. First I tried changing the permission of the lock file but it didn't work Later I deleted the lock file which resolved my issue.

Thanks

If you know that no other Postgres processes are running, please delete these 2 files and try again:

$ sudo rm /tmp/.s.PGSQL.5432.lock
$ sudo rm /tmp/.s.PGSQL.5432

Then, you would be able to run the server as a background process with the command:

$ pg_ctl -D /usr/local/var/postgres start

If you are in OS X, put the alias in the.bash_profile as below:

alias pgb='pg_ctl -D /usr/local/var/postgres start'

Now, source it with the command:

$ source ~/.bash_profile

The Postgres server will run with the command:

$ pgb

Thanks. I was trying to install postgres on my mac.I was receiving FATAL: could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied

After deleting the /tmp/.s.PGSQL.5432.lock file, the server started working.

Yes, I had the same issue, and I fixed it by running this command $ sudo rm /tmp/.s.PGSQL.5432.lock $ sudo rm /tmp/.s.PGSQL.5432 $ pg_ctl -D /usr/local/var/postgres start

I killed the Postgress service running on port 5432 which is something you should never do, this can be done unknowingly. So running the above commands would remove the lock file, and now when you start a new Postgres server, it would create a new process for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM