Postgres

Installing postgres

sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql

check if server is running

systemctl status postgresql

First Steps

Log into the database with sudo -u postgres psql Log into a remote database with passwordenv variables

export PGUSER="myuser"
export PGHOST="myhost"
export PGPASSWORD="mypassword"
export PGDATABASE="mydb"
psql

or password prompt

psql -h $POSTGRES_HOST -U $POSTGRES_USER -d $POSTGRES_DATABASE

Postgres shorts

List all tables \dt List all users \duS+ See info for table \d tablename

Network access

in /etc/postgresql/14/main/postgresql.conf add the * so postgres listens on all IPs.

and in /etc/postgresql/14/main/pg_hba.conf add this line add the permissions that users can access the database from any IP

Find all Users and there rights/roles

This has to go into a Postgres Section

Last updated