postgreSQL

switch over to Posgres user

sudo -i -u postgres



Then get into the sql terminal



psql


Edit password

sudo -i -u postgrespsql \password

Basically


sudo -u postgres 
psqlpostgres=# create database mydb;postgres=# create user myuser with encrypted password 'mypass';postgres=# grant all privileges on database mydb to myuser;


To quit



postgres-# /q



Load data

Be sure to dump old db and recreate it...

sudo -i -u postgrespsqldrop database DBNAME; create database DBNAME;grant all privileges on database DBNAME to DB_USERNAME; 

Then load into the empty db while still logged in as postgres

psql DBNAME < /absolute/location/data.sqlpsql DBNAME < /absolute/location/session.sql exit 


export user="cytel" 
export dbs="new_cytel_2"

for db in $dbs; do     psql -c "alter database $db owner to $user" $db; done

for db in $dbs; do     psql -c "alter schema public owner to $user" $db; done 
for db in $dbs; do     tables=`psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $db`;      for tbl in $tables; do         psql -c "alter table \"$tbl\" owner to $user" $db;     done; done

for db in $dbs; do     seqs=`psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" $db`;      for seq in $seqs; do         psql -c "alter table \"$seq\" owner to $user" $db ;     done; done 
for db in $dbs; do     views=`psql -qAt -c "select table_name from information_schema.views where table_schema = 'public';" $db`;      for view in $views; do         psql -c "alter table \"$view\" owner to $user" $db ;     done; done