Welcome to the ultimate guide for installing PostgreSQL and pgAdmin on Ubuntu (WSL2), all while running on Windows! 🎉 This guide walks you through every step, making sure your database environment is up and running smoothly, with a little fun along the way! 🌟
🚀 Ready to supercharge your Windows 11 development environment? Fork this repository to keep track of your progress and customize your setup!
📝 Track Your Progress: Use the Issues tab to create a checklist of tasks as you work through this guide.
🔧 Customize Your Setup: Share your own tips and tricks by contributing to this guide!
💡 Get Help: Join our Discussions to ask questions and share your experiences with other developers.
- Introduction
- Prerequisites
- Installing PostgreSQL
- Creating and Managing PostgreSQL Clusters
- Installing and Configuring pgAdmin (Web Version)
- Final Verification
- Tips for Productivity
- Conclusion
- Additional Resources
When it comes to managing databases, you need powerful tools! 💪 PostgreSQL is one of the most powerful open-source relational databases available, and pgAdmin is the perfect web-based GUI to interact with it. Let’s make sure you have everything set up inside your Ubuntu (WSL2) environment. No need for clunky Windows apps—we’ll install pgAdmin directly in WSL as a web version! 🌐
Before diving in, make sure you have the following:
- Windows 10/11: With WSL2 enabled.
- Ubuntu (WSL2): Installed from the Microsoft Store.
- Admin Access: To run
sudo
commands. - Internet Connection: To download all necessary packages.
If you haven’t installed WSL2 yet, here’s a quick way to do it:
-
Open PowerShell as Administrator and run:
wsl --install
-
Download Ubuntu from the Microsoft Store and launch it to complete the setup (create a username and password).
Let's get PostgreSQL up and running first! PostgreSQL will serve as the core database engine for your web development projects. 🚀
Before installing anything, it’s always a good idea to update your system:
sudo apt-get update
Now, install PostgreSQL along with some additional utilities:
sudo apt-get install postgresql postgresql-contrib
👨💻 What’s Happening?
postgresql
: The core PostgreSQL database.postgresql-contrib
: Extra useful tools and extensions (likepgcrypto
,adminpack
, etc.).
To make sure everything is installed correctly, check the version:
psql --version
✅ You should see output like this:
psql (PostgreSQL) 14.13 (Ubuntu 14.13-0ubuntu0.22.04.1)
Boom! PostgreSQL is installed and ready to go! 🎉
PostgreSQL uses clusters to manage databases. We’re going to create a new cluster that runs on a different port, so you can keep things organized.
Run the following command to create a cluster on port 5436
:
sudo pg_createcluster 14 main5436 --port=5436
This will create a new cluster for PostgreSQL version 14. Clusters are isolated instances of PostgreSQL.
Next, start your new cluster:
sudo service postgresql@14-main5436 start
Let’s check if everything is running smoothly:
sudo service postgresql@14-main5436 status
🎉 Success! If you see the output saying Active: active (running)
, your cluster is live and ready to handle databases.
Switch to the PostgreSQL user and set a password for your main database user:
sudo -i -u postgres
psql
Then set the password for the postgres
user:
ALTER USER postgres PASSWORD 'yourpassword';
Exit the PostgreSQL prompt by typing \q
.
Now, let's move on to pgAdmin, the GUI for managing PostgreSQL databases. Instead of using the desktop version, we’ll install pgAdmin as a web-based application inside WSL2. This means you'll access pgAdmin through your browser, making it lightweight and flexible! 💻
First, add the pgAdmin repository to your package list:
curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg
Then, add the repository to your list of sources:
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
Run the following command to install the web version of pgAdmin:
sudo apt install pgadmin4-web
📢 Note: This is a web version of pgAdmin, which you will access via your web browser! No need to install the Windows app. 🙌
After installation, set it up for web mode:
sudo /usr/pgadmin4/bin/setup-web.sh
During setup, you’ll be prompted to:
- Enter your email address (this will be your login).
- Create a strong password for the admin account.
The setup script will configure Apache to serve pgAdmin. When prompted to restart Apache, press y
.
You can now access pgAdmin by navigating to:
http://127.0.0.1/pgadmin4
or
http://localhost/pgadmin4
🎉 You’re now able to manage your PostgreSQL databases using pgAdmin, right from your browser! 🚀
Let’s make sure everything is working perfectly.
- Access pgAdmin: Open your browser and navigate to
http://127.0.0.1/pgadmin4
orhttp://localhost/pgadmin4
. - Login: Use the admin credentials you just created.
- Connect to PostgreSQL: Inside pgAdmin, create a new server connection:
- Hostname:
localhost
or127.0.0.1
- Port:
5436
(for the new cluster you created) - Username:
postgres
- Password: The password you set earlier.
- Hostname:
🎉 Congratulations! You now have PostgreSQL and pgAdmin fully configured and ready to use on WSL2!
Here are some quick tips to boost your PostgreSQL and pgAdmin workflow:
- pgAdmin Bookmarks: Bookmark the pgAdmin URL (
http://127.0.0.1/pgadmin4
orhttp://localhost/pgadmin4
) for quick access. - PostgreSQL Tuning: Fine-tune your PostgreSQL configuration by editing
postgresql.conf
to optimize for development or production. - Backup & Restore: Use pgAdmin’s easy-to-use backup and restore features to safeguard your databases.
- Docker: If you prefer containerization, you can also run PostgreSQL in Docker alongside this setup for even more flexibility!
You’ve just set up a fully functional PostgreSQL and pgAdmin (web version) environment inside WSL2! 🎉 This setup is optimized for web developers, making database management both simple and efficient. By using the web version of pgAdmin, you avoid the need for Windows-based applications, keeping your development flow seamless.
If you found this guide helpful, feel free to share it with fellow developers, or contribute to enhancing this guide on GitHub! 🙌