How to install PostgreSQL on Debian 12

Post Reply
User avatar
myVesta
Site Admin
Posts: 1000
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 10 times
Been thanked: 6 times

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'
Post Reply