skip to Main Content

When I run the following command to start the server with database in a different location:

/bin/pg_ctl -D /path/to/db -l logfile start

I face the following error :

waiting for server to start..../bin/sh: 1: cannot create logfile: Permission denied stopped waiting pg_ctl: could not start server Examine the log output.

Any help will be highly appreciated.

2

Answers


  1. This error is arising due to the process lacking the appropriate permissions to inscribe to the logfile at the spot where you’re attempting to generate it. The PostgreSQL process commonly operates as a specific user (typically ‘postgres’ or similar), and that user needs to have write access to the directory where you’re aiming to write the log file.

    Here are several steps you could take to troubleshoot this issue:

    Verify your current user: Make sure that you’re running the pg_ctl command as a user holding the correct permissions (for instance, the postgres user). You can switch to the postgres user with the command sudo -i -u postgres.

    Assess the logfile’s location permissions: Confirm the directory in which you’re trying to spawn the logfile permits write access for the user under which PostgreSQL is executing. You can transform the permissions of a directory with the command chmod and the ownership with the command chown. For instance:

    sudo chown postgres:postgres /path/to/logfile/directory
    sudo chmod 700 /path/to/logfile/directory
    

    The above commands alter the ownership of the directory to the postgres user and group, and fix the permissions such that only the owner (postgres) can read, write, and execute files in the directory.

    Examine your data directory permissions: Similarly, PostgreSQL must have read/write permissions for the new data directory (/path/to/db). You can set these permissions in the same manner:

    sudo chown postgres:postgres /path/to/db
    sudo chmod 700 /path/to/db
    

    After you’ve scrutinized and modified the permissions and ownership as needed, you should be capable to initiate the PostgreSQL server with your new data directory. If you continue to encounter problems, kindly inspect the PostgreSQL server’s logs for any error messages, as these will aid in diagnosing the issue.

    Login or Signup to reply.
  2. The error message is telling that the command is unable to create logfile in the directory you are trying to create. The command you have mentioned is trying to create logfile in the bin directory and with the user you are trying to do this does not have the privilege of writing in that directory. I suppose you want to create the logfile in the path where your database cluster is and when you run the pg_ctl command with only -l logfile it will try to create it in the current active directory.

    To solve the issue try the following command

    /bin/pg_ctl -D /path/to/db -l /path/to/db/logfile.log start
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search