你如何更改 PostgreSQL 中的用户?

How do you change a user in PostgreSQL?

postgres=# \du
                         List of roles
Role name |                   Attributes                   | Member of 

-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 shorturl  | Superuser                                      | {}

postgres=# create database shorturl;
CREATE DATABASE

postgres=# \c shorturl;
You are now connected to database "shorturl" as user "postgres".

shorturl=# 

我的偏好是使用数据库 shorturl 作为用户 shorturl 而不是 postgres。我该如何更改?

提前致谢。

当您输入\?显示psql联机帮助时,您可以看到:

Connection
  \c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
                         connect to new database (currently "postgres")

所以你需要使用:

\c shorturl shorturl