我想为我的安装结构脚本创建一个数据库用户,但是createuser输入的交互式密码和不喜欢结构的接口.
使用Fabric示例扩展答案...
# In fabfile.py def create_database(): """Creates role and database""" db_user = get_user() # define these db_pass = get_pass() db_name = get_db_name() sudo('psql -c "CREATE USER %s WITH NOCREATEDB NOCREATEUSER " \ "ENCRYPTED PASSWORD E\'%s\'"' % (db_user, db_pass), user='postgres') sudo('psql -c "CREATE DATABASE %s WITH OWNER %s"' % ( db_name, db_user), user='postgres')
只需使用纯SQL创建新用户:
CREATE ROLE user_name WITH ENCRYPTED PASSWORD 'your password';