kibe
kibe

Reputation: 181

"Permission denied" when trying to initialize PostgreSQL database server on Linux

I am trying to set up PostgreSQL in Linux, but the following error comes up:

[postgres@kibearch ~]$ initdb --pgdata=/var/lib/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
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 /var/lib/pgsql/data ... initdb: error: could not create directory "/var/lib/pgsql": Permission denied

If I try to use sudo initdb --pgdata=/var/lib/psql/data/, it says that initdb can not be used with sudo.

Here are the steps I did:

  1. sudo pacman -S postgresql
  2. Switched to user postgres user using this command: su - postgres
  3. Tried to initialize the server but the aforementioned error showed up

What can I do?

Upvotes: 2

Views: 6940

Answers (1)

clamp
clamp

Reputation: 3262

As root:

mkdir /var/lib/pgsql
chown postgres  /var/lib/pgsql

As postgres:

initdb --pgdata=/var/lib/pgsql/data

Upvotes: 4

Related Questions