Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a postgresql user with fabric

I want to create a database user for my setup fabric script but createuser has interactive password entering and seams not to like fabric.

like image 216
user320080 Avatar asked Apr 19 '10 07:04

user320080


People also ask

How do I create an Admin user in PostgreSQL?

You can now run commands as the PostgreSQL superuser.To create a user, type the following command: createuser --interactive --pwprompt At the Enter name of role to add: prompt, type the user's name. At the Enter password for new role: prompt, type a password for the user.

Can we create user table in postgres?

It seems PostgreSQL does not allow to create a database table named 'user'. But MySQL will allow to create such a table.


1 Answers

To extend the answer with a Fabric example...

# 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')
like image 173
robhudson Avatar answered Sep 19 '22 12:09

robhudson