Professional Documents
Culture Documents
A. Installation:
a) lsb_release –a #to check the Ubuntu version
b) sudo apt-get update
c) sudo apt-get install postgresql #default version of postgresql
supported by Ubuntu is 9.3
d) sudo su postgres #to switch to postgres user
e) psql –d postgres –U postgres #to log on to postgres database
B. Creating Users:
a) #CREATE USER app_ro WITH PASSWORD ‘mypassword’;
b) #CREATE USER app_rw WITH PASSWORD ‘mypassword’;
c) #ALTER USER app_ro WITH PASSWORD ‘mynewpassword’;
C. Creating Database
CREATE DATABASE myapp;
D. Granting Permissions :
#GRANT CONNECT ON DATABASE myapp to app_ro;
#GRANT CONNECT ON DATABASE myapp to app_rw;
To see the information of the granted permissions
#\l
#GRANT SELECT ON ALL TABLES IN SCHEMA public to app_ro;
For app_rw user
#GRANT SELECT,UPDATE,INSERT,DELETE ON ALL TABLES IN
SCHEMA public to app_rw;
#\l
vii. To give all the permissions give the following 3 commands for
app_ro user:
#GRANT SELECT ON ALL TABLES IN SCHEMA public to app_ro;
#GRANT SELECT ON ALL SEQUENCES IN SCHEMA public to app_ro;
#GRANT USAGE ON SCHEMA public to app_ro;
#\z
viii. To give all the permissions give the following 3 commands for
app_rw user:
#GRANT SELECT, UPDATE, INSERT, DELETE ON ALL TABLES IN SCHEMA
public to app_rw;
#GRANT SELECT, UPDATE, INSERT, DELETE ON ALL SEQUENCES IN
SCHEMA public to app_rw;
#GRANT USAGE ON SCHEMA public to app_rw;
#\z
#\q
ix. To add privileges by default, so that we do not need to do the
above 3 steps repeatedly
$psql –d postgres –U postgres
#\c myapp
#ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT
ON TABLES to app_ro;
# ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT
ON SEQUENCES to app_ro;
xi. Now create a table and see, the privileged are given by default
#CREATE TABLE test2(id serial,name varchar(40));
#\z
exit
We have already installed R, so open a terminal and type R, to get into the R-
prompt.