-1

I am trying to install ApacheAGE and for this I am following the instruction in the following article but I have installed postgres 12 instead of 11. The installation was successful but when I tried to initialize DB using the command sudo ./bin/initdb demo I am getting the following 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.

How do I fix the issue? Do I need to create another Linux user for this? I am using Ubuntu 22.04. Postgresql version is 12 and is installed in the following directory /usr/lib/postgresql/12/bin.

I created another Linux user, added that to sudoers list, logged in using su command but I am still getting the same error.

abhishek2046
  • 312
  • 1
  • 11
  • Installing Postgres typically creates a Linux user named `postgres`. You need to run `initdb` as _that_ user. –  Mar 23 '23 at 16:09

15 Answers15

2

The error code is telling you to not use sudo before the initdb command.

Just do ./bin/initdb demo in that step.

I'd advise to use commands with sudo only when it's strictly necessary.

Marco Souza
  • 296
  • 7
1

Basically, if you prefix sudo with any Linux command, it will run that command with elevated privileges. Elevated privileges are required to perform specific administrative tasks. It is clear from your error message that initdb cannot be run as root. Also, it suggests you use an unprivileged user.

So here ./bin/initdb <DbName> will to the work.

0

You don't need to run the initdb command with privileges, try to run this without sudo

Make sure that you have exported the PATH variables before run the make install.

./configure --prefix=/usr/local/pgsql-12
sudo mkdir /usr/local/pgsql-12
sudo chown [user] /usr/local/pgsql-12
make install 
0

simply do this, unprivileged command

"./bin/initdb DBNAME"

using sudo will give admin privileges

0

You're supposed to run the command as a non-root user, the convention is a user called "postgres".

tokamak32
  • 27
  • 7
0

just add sudo before your command it will hopefully resolve your error.

0

This error message indicates that you may have installed the Postgres version as a ROOT user and do not have the privilege to run it therefore.

By right, you should be running the command as user postgres

Try building and installing from source again after a clean uninstall. Please do not run as superuser during install.

RU-D
  • 224
  • 8
0
  1. Set the PATH environment variable to include PostgreSQL's bin directory.

export PATH=/usr/local/pgsql/bin/:$PATH

  1. Set the PGDATA environment variable

export PGDATA=/usr/local/pgsql/bin/data

  1. Create a data directory for PostgreSQL

sudo mkdir -p /usr/local/pgsql/bin/data sudo chown $USER

/usr/local/pgsql/bin/data

  1. Initialize the database cluster by running

initdb

0

I had this issue as well! Installing PostgreSQL as well as AGE with the sudo command causes this error as you're not meant to initialise a new DB with root privileges.

You could try uninstalling everything and installing it without using the sudo commands (except for regression tests) and not use bash commands.

If this doesn't work, I'd recommend switching to PostgreSQL 11 instead of 12 because that helped me!

Shanzay
  • 19
  • 3
0

The error message indicates that you're trying to run the 'initdb' as root user, which is not recommended for security reasons. To resolve this issue

  1. Create a dedicated user:

    sudo adduser apacheageuser

  2. Give access to the new user

    sudo usermod -aG postgres apacheageuser

  3. Now, using su command switch to new user account and log out from the root account

    su - apacheageuser

  4. Initialize the ApacheAGE database, and run the 'initdb' command:

    cd /path/to/apacheage./bin/initdb demo

change the path: "/path/to/apacheage" with the actual path to your ApacheAGE installation directory

Hope it helps!

0

run the same command ./bin/initdb demo without sudo it should work properly

0

I had this error as well when installing, try to run the ./bin/initdb demo without sudo.

0

The problem here is that only non-root users can claim ownership of Postgres databases. In your scenario, you have correctly created a user and added it to the sudoers list. However, the issue still persists because you are logged in as the root user. In order to fix the issue that you are currently facing, you ought to log out of the root user and then you need to log back in using the new user you just created. Once you have completed the steps I just mentioned, you will be able to run the initdb command without facing any sort of error.

0

As it is mentioned in the documentation of postgresql as well about initdb that initdb can only be run by the user that will own the server process not by root user because it will refuse to do so.

So therefore try to simply run it without the sudo command.

If again you face error then it means that in the directory that you are trying to create new DB it is owned by root. In that situation create an empty data directory as root, then use chown to assign ownership of that directory to the database user account, then su to become the database user to run initdb.

ShaHeen
  • 59
  • 5
-1

Do not use sudo while installing and also while installcheck. This solved the problem I was facing.

abhishek2046
  • 312
  • 1
  • 11