PostgreSQL#
Config Files#
general config (Ubuntu):
/etc/postgresql/10/main/postgresql.confgeneral config (Archlinux):
/var/lib/postgres/data/postgresql.confto allow access from everywhere:
listen_addresses = '*'
who can access what from where and how (Ubuntu):
/etc/postgresql/10/main/pg_hba.confwho can access what from where and how: (archlinux)
/var/lib/postgres/data/pg_hba.confexample:
host <database> <user> 0.0.0.0/0 md5example:
hostssl <database> <user> 0.0.0.0/0 md5
Commands (prompt)#
change the user from root to postgres:
su -l postgresinit the db:
initdb --locale=en_US.UTF-8 -E UTF8 -D /var/lib/postgres/dataenter db tool psql:
psqlcreate user:
createuser --interactivecreate database
createdb <db_name>create and set owner:
createdb <db_name> -O <role_name>
restart the db:
systemctl restart postgresql.service
Commands (psql)#
connect:
psql -h <host_or_ip> -p <port> -d <database> -U <username>set password:
\password <role_name>list user (roles):
\dulist user (roles) with passwords to check if they are set:
select * from pg_shadow;list databases:
\ldetele db:
DROP DATABASE <db_name>;delete role:
DROP ROLE <role_name>;
Create User / Database#
CREATE USER <username> WITH PASSWORD '<password>';- https://www.postgresql.org/docs/8.0/sql-createuser.htmlCREATE DATABASE <db_name> OWNER <username>;- https://www.postgresql.org/docs/9.0/sql-createdatabase.html