简体   繁体   中英

Postgres : Change current user to root

Complete database newbie here. I installed postgres on my laptop to run some local apps and stuff. However the fact that postgres is setup using myname instead of root is quite a hinderance. Any way I cant replace it with root ?

I open psql with this:

psql -h localhost

myname=# \l
                                         List of databases
     Name     |    Owner     | Encoding |   Collate   |    Ctype    |       Access privileges
--------------+--------------+----------+-------------+-------------+-------------------------------
 myname       | myname | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 pixelmanager | myname | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 postgres     | myname | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0    | myname | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/myname              +
              |        |          |             |             | myname=CTc/myname
 template1    | myname | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/myname              +
              |        |          |             |             | myname=CTc/myname
(5 rows)

Thanks for the help

Simply set the two default databases ( template1 / template0 ) to the user you want, and all future / new databases would be created with this new user.

For eg

ALTER DATABASE template0 OWNER TO newname1;
ALTER DATABASE template1 OWNER TO newname1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM