Create database:
create database mydb;
####################################################
Create user:
create user myuser with encrypted password 'mypass';
####################################################
Show all users from all Databases:
SELECT usename AS role_name,
CASE
WHEN usesuper AND usecreatedb THEN
CAST('superuser, create database' AS pg_catalog.text)
WHEN usesuper THEN
CAST('superuser' AS pg_catalog.text)
WHEN usecreatedb THEN
CAST('create database' AS pg_catalog.text)
ELSE
CAST('' AS pg_catalog.text)
END role_attributes
FROM pg_catalog.pg_user
ORDER BY role_name desc;####################################################
Grand all privileges for user:
grant all privileges on database mydb to myuser;
####################################################
Check user privilages:
SELECT table_catalog, table_schema, table_name, privilege_type FROM information_schema.table_privileges WHERE grantee = 'MY_USER'
####################################################
Delete table:
DROP TABLE test;
####################################################
Create table:
CREATE TABLE DB_NAME (
user_id serial PRIMARY KEY,
username VARCHAR ( 50 ) UNIQUE NOT NULL,
password VARCHAR ( 50 ) NOT NULL,
email VARCHAR ( 255 ) UNIQUE NOT NULL,
created_on TIMESTAMP NOT NULL,
last_login TIMESTAMP
);####################################################
Check user privelages:
select * from information_schema.role_table_grants where grantee='payments_invoices';
select * from pg_tables where tableowner = 'payments_invoices';
####################################################