Postgres

Contents
Install PostgreSql
sudo apt install postgresqlCreate new Role
create role user;Show all roles
\duChange attributes on existing roles
ALETR ROLE "user" WITH LOGIN CREATEDB;Change role password
Show all database
ALTER ROLE "user" WITH PASSWORD 'password';Set password for postgres user
sudo -u postgres psqland
\passwordEnable remote access to Postgres
- Modify the PostgreSQL configuration file
sudo nano /etc/postgresql/12/main/postgresql.confThen, find the line #listen_addresses = 'localhost' and uncomment it
next, change the value of listen_addresses to *.
- Modify the pg_hba.conf file
sudo nano /etc/postgresql/12/main/pg_hba.confappend next line
host all all 0.0.0.0/0 md5- Restart PostgreSQL
sudo service postgresql restartConnect to remove postgres server
psql postgres://user:password@ip_add_or_domain:port/db_nameor
psql -h <REMOTE HOST> -p <REMOTE PORT> -U <DB_USER> <DB_NAME> -W-W option will prompt for password
check port
# sudo netstat -peanut | grep "postgres"
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 123 614086 92337/postgres
tcp6 0 0 :::5432 :::* LISTEN 123 614087 92337/postgres
udp 0 0 127.0.0.1:41721 127.0.0.1:41721 ESTABLISHED 123 614090 92337/postgres Change PostgreSQL user password
ALTER USER user_name WITH PASSWORD 'new_password';