Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error initdb: error: cannot be run as root when initializing db on postgresSQL [closed]

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.

like image 718
abhishek2046 Avatar asked Oct 20 '25 23:10

abhishek2046


1 Answers

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.

like image 169
Marco Souza Avatar answered Oct 22 '25 19:10

Marco Souza