修改密码:
ALTER USER postgres WITH PASSWORD 'postgres';
创建账户
CREATE USER new_username WITH PASSWORD 'user_password';
要授予新用户对所有数据库和表的权限,可以使用以下 GRANT 语句:
GRANT ALL PRIVILEGES ON DATABASE dbname TO new_username;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO new_username;
这将授予 new_username
用户对所有数据库和表的所有权限。请确保仅向需要这些权限的用户授予此类权限。
配置远程访问
pg_hba.conf
host all all 0.0.0.0/0 md5
完成pg_hba.conf配置
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 0.0.0.0/32 trust
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
host all all 0.0.0.0/0 md5
远程访问配置:
postgresql.conf
listen_addresses = '0.0.0.0'
psql 授权使用户可以创建数据库:
ALTER ROLE your_user CREATEDB;
pgsql权限grant 所有权限给 venuspostgres
//授予 venuspostgres 用户对指定数据库(your_database_name)的所有权限,包括 SELECT、INSERT、UPDATE、DELETE、CREATE、DROP 等权限
GRANT ALL PRIVILEGES ON DATABASE your_database_name TO venuspostgres;
//允许 venuspostgres 用户创建新的数据库
ALTER ROLE venuspostgres CREATEDB;
//允许 venuspostgres 用户创建新的数据库角色(用户和组)。
ALTER ROLE venuspostgres CREATEROLE;