Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

postgre create user

#!/usr/bin/env bash
# to execute, open a terminal in directory and run chmod +x <filename>.sh

user="{user name}"
database="{database name}"
args="--host=localhost --dbname=$database --username=$user"

echo -e "Creating user $user.....
"
sudo -u postgres createuser --createdb --pwprompt $user
echo -e "User Created!
"

echo -e "Creating database $database.....
"
sudo -u postgres createdb --owner=$user $database
echo -e "Database Created!
"
echo -e "Restarting server and starting psql....
"
sudo service postgresql restart

psql $args
Source by www.a2hosting.com #
 
PREVIOUS NEXT
Tagged: #postgre #create #user
ADD COMMENT
Topic
Name
1+9 =