PostgreSQL
Installation & Configuration
Install Postgres
sh
sudo apt install postgresql postgresql-contribStart the Postgres service
sh
sudo systemctl start postgresqlUpdate Authentication method
By default, the postgres role is created with the authentication method set to peer for local connections. Update it to trust.
sh
# Change version 16 in the path if applicable
sudo vi /etc/postgresql/16/main/pg_hba.confMake following changes:
sh
local all postgres trust
host piratedev piratedev 192.168.1.0/24 md5Enable Remote Connections
sh
# Change version 16 in the path if applicable
sudo vi /etc/postgresql/16/main/postgresql.confMake following changes:
sh
listen_addresses = '192.168.1.100'Setup User and Database
Log into Postgres Shell as postgres user:
sh
psql -U postgresCreate a new superuser and database:
sql
-- Replace <Your Password> with a strong password of your choice
CREATE USER piratedev ENCRYPTED PASSWORD '<Your Password>';
CREATE DATABASE piratedev WITH OWNER=piratedev;
exitRestart PostgreSQL Service:
sh
sudo systemctl restart postgresqlBackup and Restore
On the remote server, dump the current database into a file using:
sh
cd ~ && pg_dump -U postgres -d piratedev -f backup.sqlCopy the remote file to local using:
sh
scp piratedev@192.168.1.100:/home/piratedev/backup.sql .Restore the backup:
Make sure the DB user and database are created on new server before doing this.
sh
psql -U postgres -d piratedev -f backup.sql