Skip to content

Postgresql

Dima edited this page Sep 5, 2017 · 19 revisions

Postgresql

create user and database (Ubuntu)

$ sudo -u postgres psql
postgres=# CREATE USER "username" WITH PASSWORD "password";
postgres=# CREATE database dbname;
postgres=# GRANT ALL PRIVILEGES ON DATABASE "dbname" to username; postgres=# ALTER ROLE somerole CREATEROLE CREATEDB REPLICATION SUPERUSER; postgres=# ALTER database dbname OWNER TO username;
postgres=# ALTER USER username CREATEDB(SUPERUSER);
postgres=# \q


sudo su - postgres  
createuser --pwprompt deploy  
createdb -O deploy my_app_name_production # change "my_app_name" to your app's name which we'll also use later  on  
exit

create user and database (MacOS)

psql -U postges
createuser -P username
createdb dbname
psql dbname
grant all privileges on database "dbname" to "username";

usefull commands

\l – list databases
\connect dbname - connect to database
\du - list users
\di - indexes
\dt - tables
\d tablename describe table - describe table(view, index, sequence)
? - help
ALTER USER "user_name" WITH PASSWORD 'new_password';

Clone this wiki locally