Install Postgresql on Ubuntu
bash
1sudo apt install postgresqlSet the Password for the postgres User
bash
1sudo -u postgres psqlsql
1ALTER USER postgres PASSWORD 'your_secure_password';Test Your Connection
bash
1psql -U postgres -h localhost -WRemote Connection
bash
1sudo -u postgres psql -c "SHOW config_file;"bash
1sudo nano /etc/postgresql/16/main/postgresql.confreplace #listen_addresses = 'localhost' with listen_addresses = '*'
Allow your remote client
bash
1sudo nano /etc/postgresql/16/main/pg_hba.confAdd the following line to the end of the file:
host all all your_remote_ip/32 md5
where all is the database name, all is the username, your_remote_ip is the IP address of the remote client, and md5 is the authentication method.
Connect Remotely
bash
1psql -h 192.168.1.100 -U myapp -d myapp