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.
9
Answers
The error code is telling you to not use
sudo
before theinitdb
command.Just do
./bin/initdb demo
in that step.I’d advise to use commands with
sudo
only when it’s strictly necessary.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.If you’re still encountering the same error even after creating a new user and adding them to the sudoers list, it’s possible that you might be using sudo inadvertently while running the initdb command. Make sure you are not using sudo when executing the command.
Follow these steps to ensure you are running the command as the correct user:
myuser): sudo su – myuser
whoami command: whoami
This should return the username "myuser"
Replace /path/to/your/data/directory with the actual path where you want to store the PostgreSQL data files.
If you still encounter the error, there may be an issue with your PostgreSQL installation or the user permissions. In this case, try reinstalling PostgreSQL or consult the PostgreSQL documentation for further guidance.
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.
simply do this, unprivileged command
"./bin/initdb DBNAME"
using sudo will give admin privileges
You’re supposed to run the command as a non-root user, the convention is a user called "postgres".
just add
sudo
before your command it will hopefully resolve your error.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.