skip to Main Content

When running bin/initdb demo I encounter the following error:

The files belonging to this database system will be owned by user "USER_1".
This user must also own the server process.

The database cluster will be initialized with locales
  COLLATE:  en_US.UTF-8
  CTYPE:    en_US.UTF-8
  MESSAGES: en_US.UTF-8
  MONETARY: ur_PK
  NUMERIC:  ur_PK
  TIME:     ur_PK
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory newDB ... initdb: error: could not create directory "newDB": Permission denied

Running it as root gives me this error:

initdb: error: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

What could be the problem here, would appreciate any help.

2

Answers


  1. You dont need to run it with sudo. But you need to get permissions before you use initdb. Use :

    sudo chown <username> /path/to/postgres/bin/
    

    usually the path is something like

    /usr/local/pgsql/bin/
    

    You can find by typing pg_config. The correct path is in the variable BINDIR.

    Login or Signup to reply.
  2. You cannot run initdb with sudo.

    The steps prior to initdb should be like so:

    sudo mkdir /usr/local/pgsql-12
    sudo chown [user] /usr/local/pgsql-12
    make install
    export PATH=/usr/local/pgsql-12/bin/:$PATH
    export PGDATA=/usr/local/pgsql-12/bin/data
    

    then, make sure you create the main cluster first before creating others

    initdb
    

    then, you can create others with a name assigned

    initdb [db name]
    

    This should solve that.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search