1、停止服务
2、找到数据库data目录下的 pg_hba.conf 文件
3、打开编辑内容,host后边的 md5 修改为 trust。(下列所有步骤操作完成后记得恢复。)

# TYPE  DATABASE        USER            ADDRESS                 METHOD
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host    replication     all             127.0.0.1/32            md5
#host    replication     all             ::1/128                 md5

4、启动服务,然后输入下边命令可直接进入到命令行模式

psql -U postgres

5、修改默认用户 Postgres 的密码

ALTER USER Postgres WITH PASSWORD '<newpassword>';

6、添加新用户

CREATE USER my_user WITH PASSWORD '123456';

7、新用户赋权

GRANT USAGE ON SCHEMA PUBLIC TO my_user;

8、使用新用户登录

psql -U my_user -W postgres