def db_create(name, user=None, host=None, port=None, maintenance_db=None, password=None, tablespace=None, encoding=None, lc_collate=None, lc_ctype=None, owner=None, template=None, runas=None):
 query = 'CREATE DATABASE "{0}"'.format(name)
 with_args = salt.utils.odict.OrderedDict([('TABLESPACE', _quote_ddl_value(tablespace, '"')), ('OWNER', _quote_ddl_value(owner, '"')), ('TEMPLATE', template), ('ENCODING', _quote_ddl_value(encoding)), ('LC_COLLATE', _quote_ddl_value(lc_collate)), ('LC_CTYPE', _quote_ddl_value(lc_ctype))])
 with_chunks = []
 for (key, value) in with_args.items():
  if (value is not None):
   with_chunks += [key, '=', value]
 if with_chunks:
  with_chunks.insert(0, ' WITH')
  query += ' '.join(with_chunks)
 ret = _psql_prepare_and_run(['-c', query], user=user, host=host, port=port, maintenance_db=maintenance_db, password=password, runas=runas)
 return (ret['retcode'] == 0)

def db_create ( name , user = None , host = None , port = None , maintenance_db = None , password = None , tablespace = None , encoding = None , lc_collate = None , lc_ctype = None , owner = None , template = None , runas = None ) : query = 'CREATE DATABASE "{0}"' . format ( name ) with_args = salt . utils . odict . OrderedDict ( [ ( 'TABLESPACE' , _quote_ddl_value ( tablespace , '"' ) ) , ( 'OWNER' , _quote_ddl_value ( owner , '"' ) ) , ( 'TEMPLATE' , template ) , ( 'ENCODING' , _quote_ddl_value ( encoding ) ) , ( 'LC_COLLATE' , _quote_ddl_value ( lc_collate ) ) , ( 'LC_CTYPE' , _quote_ddl_value ( lc_ctype ) ) ] ) with_chunks = [ ] for ( key , value ) in with_args . items ( ) : if ( value is not None ) : with_chunks += [ key , '=' , value ] if with_chunks : with_chunks . insert ( 0 , ' WITH' ) query += ' ' . join ( with_chunks ) ret = _psql_prepare_and_run ( [ '-c' , query ] , user = user , host = host , port = port , maintenance_db = maintenance_db , password = password , runas = runas ) return ( ret [ 'retcode' ] == 0 )
create a database name database name to create user the user to connect as password the password of the user host the host to connect to port the port to connect to cli example: .