yay -S postgresql15
run this:
. /opt/postgresql15/bin/pgenv.sh
init database first:
sudo -u postgres /opt/postgresql15/bin/initdb -k -D /var/lib/postgres/data15
fix permission
sudo mkdir -p /run/postgresql
sudo chown postgres:postgres /run/postgresql
sudo chmod 755 /run/postgresql
dont forget log file:
sudo touch /var/lib/postgres/data15/logfile
sudo chown postgres:postgres /var/lib/postgres/data15/logfile
check and login:
sudo -u postgres /opt/postgresql15/bin/psql
or
sudo -u postgres psql
Optional:
if you want it run on background:
[Unit]
Description=PostgreSQL 15 database server
After=network.target
[Service]
Type=forking
User=postgres
RuntimeDirectory=postgresql
RuntimeDirectoryMode=0755
Environment=PGDATA=/var/lib/postgres/data15
ExecStart=/opt/postgresql15/bin/pg_ctl start -D /var/lib/postgres/data15 -s -l /var/lib/postgres/data15/logfile
ExecStop=/opt/postgresql15/bin/pg_ctl stop -D /var/lib/postgres/data15 -s -m fast
ExecReload=/opt/postgresql15/bin/pg_ctl reload -D /var/lib/postgres/data15 -s
TimeoutSec=300
[Install]
WantedBy=multi-user.target
restart and reload daemon and enable service:
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable postgresql15