How to Install PostgreSQL 12 and pgAdmin 4 on Ubuntu 20.04
PostgreSQL is a powerful, open source object-relational database system with over 15 years of active development and a proven architecture. It has a strong reputation for reliability, data integrity, and correctness. pgAdmin, on the other hand, is the most popular and feature-rich open-source administration and development platform for PostgreSQL.
Prerequisites
- Ubuntu 20.04 server or desktop.
- A non-root user with sudo privileges.
- Basic knowledge of the Linux command line.
Main Steps
Step 1: Update Your System
Before installing PostgreSQL and pgAdmin, it is essential to update your package list to ensure you install the latest available versions of the software.
sudo apt update
sudo apt upgrade
Step 2: Install PostgreSQL 12
To install PostgreSQL 12, you will use the default Ubuntu repository. Execute the following command:
sudo apt install postgresql postgresql-contrib
This command installs PostgreSQL along with additional packages that can be useful during development.
Step 3: Start and Enable PostgreSQL Service
After the installation is complete, you need to start the PostgreSQL service and enable it to start on boot:
sudo systemctl start postgresql
sudo systemctl enable postgresql
Step 4: Verify the Installation
To verify that PostgreSQL is installed and running, execute the following command:
sudo systemctl status postgresql
You should see an output indicating that the PostgreSQL service is active and running.
Step 5: Access PostgreSQL Command Line
PostgreSQL creates a default user called postgres. Switch to this user to access the PostgreSQL command line interface:
sudo -i -u postgres
psql
To exit the PostgreSQL command line, type \q and press Enter.
Step 6: Install pgAdmin 4
To install pgAdmin 4, you need to install its dependencies first. You can do this by running:
sudo apt install wget curl
Next, import the public key used by the package management system:
wget --quiet -O - https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add -
Add the pgAdmin 4 repository to your system:
echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/ubuntu/focal pgadmin4 main" | sudo tee /etc/apt/sources.list.d/pgadmin4.list
Now, update your package list again and install pgAdmin 4:
sudo apt update
sudo apt install pgadmin4
Step 7: Configure pgAdmin 4
After installation, you need to configure pgAdmin. You can do this using the following command:
sudo /usr/pgadmin4/bin/setup-web.sh
This command will prompt you to enter details such as the email and password to create an admin user for pgAdmin.
Step 8: Access pgAdmin 4
pgAdmin 4 can be accessed via your web browser. Open your web browser and navigate to:
http://localhost/pgadmin4
Log in with the credentials you created during the setup process.
Advanced Configuration
Once PostgreSQL and pgAdmin are installed, consider the following advanced configurations:
- Configure PostgreSQL for remote access by editing the
postgresql.confandpg_hba.conffiles located under/etc/postgresql/12/main/. - Enable SSL connections for added security.
- Regularly back up your databases using
pg_dump.
Best Practices
- Always keep your PostgreSQL and pgAdmin versions up to date to ensure you have the latest features and security patches.
- Use strong passwords for database users.
- Regularly monitor your database performance and logs.
Troubleshooting
If you encounter issues during installation or configuration, consider the following:
- Check PostgreSQL service status with
sudo systemctl status postgresql. - Review logs in
/var/log/postgresql/for any error messages. - Ensure that your firewall is not blocking access to PostgreSQL or pgAdmin.
Conclusion
In this tutorial, you have learned how to install and configure PostgreSQL 12 and pgAdmin 4 on Ubuntu 20.04. PostgreSQL offers a robust database system suitable for various applications, while pgAdmin serves as a powerful administration tool. By following the steps outlined above, you can set up a reliable database environment for your projects.
If you face any challenges or require assistance, consider seeking professional services for setup and configuration.
Verifikasi Teknis
Panduan ini disusun berdasarkan referensi teknis terbaru. Namun, konfigurasi server dapat bervariasi. Lihat sumber referensi asli →
📚 Artikel Terkait
Cara Install PostgreSQL 12 dan pgAdmin 4 di Ubuntu 20.04
781 kata • Baca selengkapnya →
Cara Install PostgreSQL di Ubuntu 16.04
583 kata • Baca selengkapnya →
Cara Membuat Managed Database PostgreSQL di DigitalOcean
597 kata • Baca selengkapnya →
How to Create PostgreSQL Managed Database at DigitalOcean
704 kata • Baca selengkapnya →