--新建用户
create role test_user nosuperuser nocreatedb nocreaterole noinherit login connection limit 100 encrypted password 'password';
--新建表空间,注:location中指定的目录必须在建表空间之前建好,并把文件夹权限授权给系统用户postgres
create tablespace tbs_test owner postgres location '/var/lib/pgsql/data/tbs_test';
--建库
create database test_db with owner postgres template template0 encoding 'UTF8' tablespace tbs_test;
--授权
grant all on tablespace tbs_test to test_user;
grant all on database test_db to test_user;
先通过系统超级用户postgres去新建表空间,新建数据库,再把相关权限授权给指定的用户,然后开发人员只需要知道普通用户的账号密码就可以了。避免开发人员误操作,把数据库删了或出现其他不可修复的问题。