I currently log in to PostgreSQL using psql -U postgres
. How do I rename postgres
user to root
?
If I am already logged in as postgres
then trying ALTER USER postgres RENAME TO root
will say ERROR: session user cannot be renamed
.
Is it possible to rename the user without logging as postgres
user? I don't think I have any other superuser since this is a fresh install of PostgreSQL.
By the way, I am running Gentoo on Amazon EC2.
Log into PostgreSQL and run the following ALTER USER command to change user test_user to superuser. Replace test_user with username as per your requirement. postgres-# ALTER USER test_user WITH SUPERUSER; In the above command, we use WITH SUPERUSER clause to change user to superuser.
3.2 Login to the PostgreSQL Server The PostgreSQL installation creates a "UNIX USER" called postgres , who is ALSO the "Default PostgreSQL's SUPERUSER". The UNIX USER postgres cannot login interactively to the system, as its password is not enabled.
First, connect to your database cluster as the admin user, doadmin , by passing the cluster's connection string to psql . This brings you into the interactive shell for PostgreSQL, which changes your command prompt to defaultdb=> . From here, connect to the database that you want to modify the user's privileges on.
You should be able to just create a new postgres superuser called root by logging in as the postgres user and (at the shell) typing;
createuser --superuser root
psql> create database root owner root
After that, when logged in as root, you should be able to do what you want with the postgres user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With