Code: Select all
apt update
apt -y install postgresql postgresql-contrib
apt -y install php8.2-pgsql
# Create testuser and testdb with testass
cd /
sudo -u postgres psql <<'EOF'
CREATE USER testuser WITH PASSWORD 'testpass';
CREATE DATABASE testdb OWNER testuser;
GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;
EOF
# Test connection
psql -U testuser -d testdb -h localhost
# you will be prompted for a password
# Access database without password
sudo -u postgres psql -d testdb
# Dump:
sudo -u postgres pg_dump testdb > testdb.sql
# Create DB
createdb -U postgres testdb
# Restore
psql -U postgres -d testdb < testdb.sql
# List all databases
sudo -u postgres psql -c '\l'
