🕌

LANからアクセスできるPostgres on Ubuntu

に公開

インストール

sudo apt update
sudo apt install postgresql

configuration

/etc/postgresql/16/main/pg_hba.confの末尾に次を追加。

/etc/postgresql/16/main/pg_hba.conf
host all all 192.168.10.5/24 scram-sha-256

/etc/postgresql/16/main/postgresql.confのlisten_addressesをコメントアウトして、次のように変更。

/etc/postgresql/16/main/postgresql.conf
listen_addresses = '192.168.10.5'

postgresユーザーにパスワードを設定

sudo -u postgres psql
ALTER USER postgres WITH PASSWORD 'p@S5w0rd';

再起動

sudo systemctl restart postgresql

LANからアクセス

psql --host 192.168.10.5 --user postgres
Password for user postgres:
psql (16.11 (Ubuntu 16.11-0ubuntu0.24.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

postgres=#

Discussion