Setup PostgreSQL + Vector and Connect to Local PgAdmin

✅ Install PostgreSQL
sudo apt update
sudo apt install postgresql postgresql-contrib -y
Check status:
sudo systemctl status postgresql
✅ STEP 1 — PostgreSQL ko remote connections allow karna
1. postgresql.conf edit karo
sudo nano /etc/postgresql/*/main/postgresql.conf
Find:
#listen_addresses = 'localhost'
Replace with:
listen_addresses = '*'
Save → CTRL+X → Y → Enter
✅ STEP 2 — pg_hba.conf me remote access allow karo
sudo nano /etc/postgresql/*/main/pg_hba.conf
File ke end me add karo:
host all all 0.0.0.0/0 md5
Save → CTRL+X → Y → Enter
✅ STEP 3 — Restart PostgreSQL
sudo systemctl restart postgresql
✅ STEP 4 — Firewall allow (important)
Agar server me UFW enable hai:
sudo ufw allow 5432/tcp
Security Tip:
Only your IP allow karna best hai:
sudo ufw allow from YOUR_LOCAL_PC_IP to any port 5432 proto tcp
✅ STEP 5 — Default Postgres user password set karo (if not done)
sudo -u postgres psql
Inside postgres shell:
ALTER USER postgres WITH PASSWORD 'yourstrongpassword';
\q
✅ STEP 6 — Now connect from your pgAdmin (local machine)
Open pgAdmin → Add New Server:
General
- Name:
My Server
Connection
Host:
YOUR_SERVER_IPPort:
5432Username:
postgresPassword:
yourstrongpasswordSSL: Prefer
Save → Connect 🎉
💯 Done!
Now you can manage server-side PostgreSQL directly from your local pgAdmin.
Create New DB or User
Perfect — main aapko copy-paste commands de deta hoon jo PostgreSQL me naya database + naya user + full permissions create karega.
✅ STEP 1 — PostgreSQL shell open karo
sudo -u postgres psql
✅ STEP 2 — Naya user create karo (with password)
CREATE USER myuser WITH PASSWORD 'mypassword';
Replace:
myuser→ your usernamemypassword→ strong password
✅ STEP 3 — Naya database create karo
CREATE DATABASE mydb OWNER myuser;
Isse:
Database name =
mydbOwner =
myuserPermissions auto-set
(Optional) STEP 4 — User ko full privileges (if needed)
Normally owner ko full rights mil jaate hain, but if you want:
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
✅ STEP 5 — PostgreSQL se exit
\q
🎉 Done!
Ab aap pgAdmin4 me connect karke mydb dekh sakte ho:
pgAdmin Connection:
Host: your server IP
Port: 5432
Database:
mydbUsername:
myuserPassword:
mypassword
Agar chaho toh main aapke Laravel/SaaS project ke liye .env PostgreSQL config bhi de sakta hoon.


