PostgreSQL 16 : Remote Connection2024/05/30 |
It's possible to connect to PostgreSQL Server only from Localhost by default like here, |
|
[1] | There are many authentication methods on PostgreSQL, though. On this example, Configure scram-sha-256 password method. |
root@www:~#
vi /etc/postgresql/16/main/postgresql.conf # line 60 : uncomment and change listen_addresses = ' * '
root@www:~#
vi /etc/postgresql/16/main/pg_hba.conf # add to last line # specify network range you allow to connect on [ADDRESS] section # if allow all, specify [0.0.0.0/0] host all all 10.0.0.0/24 scram-sha-256root@www:~# systemctl restart postgresql |
[2] | To connect to a PostgreSQL Database from remote hosts, set password for each PostgreSQL user. |
# connect to own database ubuntu@www:~$ psql -d testdb psql (16.2 (Ubuntu 16.2-1ubuntu4)) Type "help" for help. # set or change own password testdb=> \password Enter new password: Enter it again: testdb=> \q # also possible to set or change password for any users with PostgreSQL admin user postgres@dlp:~$ psql -c "alter user ubuntu with password 'password';" ALTER ROLE |
[3] | Verify settings to connect to PostgreSQL Database with password from remote hosts. |
root@node1:~# psql -h www.srv.world -d testdb -U ubuntu Password for user ubuntu: # password psql (16.2 (Ubuntu 16.2-1ubuntu4)) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off) Type "help" for help. testdb=> # connected |
Sponsored Link |
|