Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rename the default postgres superuser to "root"?

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.

like image 367
hobbes3 Avatar asked Mar 07 '12 18:03

hobbes3


People also ask

How do I change the superuser name in PostgreSQL?

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.

What is the default postgres superuser name?

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.

How do I change user privileges in PostgreSQL?

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.


1 Answers

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.

like image 162
Joachim Isaksson Avatar answered Sep 20 '22 01:09

Joachim Isaksson