2010-04-19 16 views

回答

8

只需使用普通的SQL創建一個新用戶:

CREATE ROLE user_name WITH ENCRYPTED PASSWORD 'your password'; 
+0

我怎麼送這個SQL語句的Postgres在一個班輪? – user320080 2010-04-19 12:10:41

+0

連接psql客戶端併發送查詢。 http://www.postgresql.org/docs/8.4/interactive/app-psql.html – 2010-04-19 12:41:02

33

要與面料延伸。例如答案...

# 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') 
+0

真棒,非常感謝 – 2011-03-26 01:54:58

+1

Upwote。但是你真的認爲table是在'db_table = get_table()'中嗎?看起來你的意思是數據庫名稱。 – 2018-02-22 11:34:03

相關問題