To install PostgreSQL on Ubuntu, follow these steps:
✅ Steps to Install PostgreSQL on Ubuntu
- Update Package List
sudo apt update
sudo apt upgrade
- Install PostgreSQL
sudo apt install postgresql postgresql-contrib
- Check PostgreSQL Service Status
sudo systemctl status postgresql
If running, it will show active (running).
- Start/Stop/Restart Service
- Start:
sudo systemctl start postgresql
- Stop:
sudo systemctl stop postgresql
- Restart:
sudo systemctl restart postgresql
✅ Access PostgreSQL
Switch to the default PostgreSQL user:
sudo -i -u postgres
Then access the PostgreSQL prompt:
psql
You will see:
postgres=#
✅ Create a New Database
CREATE DATABASE mydb;
✅ Create a New User
CREATE USER myuser WITH PASSWORD 'mypassword';
✅ Grant Privileges
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
✅ Exit PostgreSQL
\q
Exit user:
exit
đ¯ Enable Remote Access (Optional)
- Edit postgresql.conf:
sudo nano /etc/postgresql/*/main/postgresql.conf
Uncomment:
listen_addresses = '*'
- Edit pg_hba.conf:
sudo nano /etc/postgresql/*/main/pg_hba.conf
Add:
host all all 0.0.0.0/0 md5
- Restart PostgreSQL:
sudo systemctl restart postgresql
✅ Now PostgreSQL is installed and ready to use!
No comments:
Post a Comment