Code: Select all
apt update
apt -y install postgresql postgresql-contrib
apt -y install php8.2-pgsqlCreate testuser and testdb with testpass:
Code: Select all
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;
EOFTest connection to testdb:
Code: Select all
psql -U testuser -d testdb -h localhostAccess database without password:
Code: Select all
sudo -u postgres psql -d testdbCreate a user:
Code: Select all
sudo -u postgres psql -c "CREATE USER testuser WITH PASSWORD 'testpass';"Create a database:
Code: Select all
sudo -u postgres createdb testdbCreate a database that has an owner:
Code: Select all
sudo -u postgres createdb testdb -O testuserGrant access:
Code: Select all
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;"Dump a database:
Code: Select all
sudo -u postgres pg_dump testdb > testdb.sqlRestore a database:
Code: Select all
sudo -u postgres psql -d testdb < testdb.sqlDrop a user:
Code: Select all
sudo -u postgres psql -c "DROP OWNED BY testuser;"
sudo -u postgres psql -c "REASSIGN OWNED BY testuser TO postgres;"
sudo -u postgres psql -c "DROP USER testuser;"Drop a database:
Code: Select all
sudo -u postgres psql -c "DROP DATABASE testdb;"List all databases:
Code: Select all
sudo -u postgres psql -l