How can you make postgres user a superuser in Linux? Assuming you have a situation where you need to make PostgreSQL “Superuser” in Linux, you can do so by running the following commands: I recently came across this issue and this is the solution that worked for me.
Use single mode
a) As root user – stop postgres service by running
service postgresql stop
b) Change the system user to a non root user such as postgres by running
su postgres
c) Access single user mode by running the following(Change the postgres folder installation location based on your postgresql version)
/usr/lib/postgresql/10/bin/postgres --single -D /etc/postgresql/10/main/
d) Run the alter command
ALTER user postgres with SUPERUSER;
e) Start your postgres server
service postgresql restart
e) Confirm changes by getting onto postgres terminal and typing the following.
\du;
As you can see, postgres is now a superuser – you can do this for any other user you wish
Conclusion
These steps should work for most postgresql installations in 2.6, 2.8 and 9
For earlier versions I would suggest running the commands to start single mode, stop postgres and re-start as a non root user.
Read an interesting article on creating a simple AI as a programmer.