How to Install PostgreSQL on Debian 13 (Trixie)
PostgreSQL is a powerful and reliable open-source object-relational database system, widely used for its performance and advanced features. This guide will walk you through installing and configuring it on Debian 13.
Update the System
apt update && apt upgrade -y
Output:
root@server:~# apt update && apt upgrade -y
Get:1 http://security.debian.org/debian-security trixie-security InRelease [43.4 kB]
Get:2 http://deb.debian.org/debian trixie InRelease [168 kB]
Get:3 http://deb.debian.org/debian trixie-updates InRelease [45.1 kB]
Get:4 http://deb.debian.org/debian trixie/main Sources.diff/Index [27.9 kB]
Get:5 http://deb.debian.org/debian trixie/non-free-firmware Sources.diff/Index [27.8 kB]
Get:6 http://deb.debian.org/debian trixie/main amd64 Packages.diff/Index [27.9 kB]
Get:7 http://deb.debian.org/debian trixie/main Translation-en.diff/Index [27.9 kB]
Install PostgreSQL
apt install -y postgresql postgresql-contrib
This will install:
- PostgreSQL server
- Useful tools like
psql - Additional modules via
postgresql-contrib
Enable and Start PostgreSQL
systemctl enable postgresql
systemctl start postgresql
Check the status:
systemctl status postgresql
Switch to the PostgreSQL User
PostgreSQL creates a default system user called postgres. Use it to interact with PostgreSQL:
su - postgres
Access PostgreSQL shell:
psql
To exit psql:
\q
To exit the postgres user shell:
exit
Install Sudo and Set Password for the postgres User
apt install sudo
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'your_secure_password';"
Create a New Database and User (Optional)
sudo -u postgres createuser yourusername
sudo -u postgres createdb yourdatabase
Grant privileges:
sudo -u postgres psql
Inside psql:
ALTER USER yourusername WITH ENCRYPTED PASSWORD 'userpassword';
GRANT ALL PRIVILEGES ON DATABASE yourdatabase TO yourusername;
\q
Conclusion
Done. You now have PostgreSQL installed and configured on Debian 13.
You can manage your database using the psql CLI or tools like pgAdmin or DBeaver if using a GUI environment.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS