1.创建用户user001
CREATE USER user001 WITH PASSWORD '123456';
ALTER ROLE user001 CREATEROLE CREATEDB;
GRANT ALL PRIVILEGES ON DATABASE testdb TO username;
2.postgres 管理员删除用户user001 报错
DROP user user001
ERROR: role "user001" cannot be dropped because some objects depend on it
DETAIL: owner of database dbname
3.解决办法
revoke all on database databasename from user001;
DROP user user001
4.如果数据库是user001用户创建的
alter database testdb owner to postgres
DROP user user001