{"id":14819,"date":"2025-05-02T18:43:26","date_gmt":"2025-05-02T13:13:26","guid":{"rendered":"https:\/\/www.skynats.com\/?p=14819"},"modified":"2025-05-02T18:43:28","modified_gmt":"2025-05-02T13:13:28","slug":"how-to-install-and-configure-postgresql-with-pgadmin-4-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/how-to-install-and-configure-postgresql-with-pgadmin-4-on-ubuntu\/","title":{"rendered":"How to Install and Configure PostgreSQL with pgAdmin 4 on Ubuntu"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">PostgreSQL is a powerful, open-source object-relational database system known for its reliability, robustness, and performance. Whether you&#8217;re working on a production-grade application or exploring data for a side project, PostgreSQL is an excellent choice. In this blog we will learn how to Install and Configure PostgreSQL with pgAdmin 4 on <a href=\"https:\/\/ubuntu.com\/\" target=\"_blank\" rel=\"noopener\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-secondary-color\">Ubuntu<\/mark><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To make database management easier, pgAdmin 4 provides a user-friendly web interface that allows you to interact with your PostgreSQL databases visually.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-small-font-size\" id=\"h-update-system-packages\"><strong>Update System Packages<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before we begin, it&#8217;s essential to update the package list and upgrade all existing packages. This ensures that you&#8217;re using the latest versions and reduces the risk of compatibility issues.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading has-small-font-size\" id=\"h-install-postgresql\"><strong>Install PostgreSQL<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, install PostgreSQL along with postgresql-contrib, which provides additional utilities and extensions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install postgresql postgresql-contrib -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, PostgreSQL starts automatically and runs as a service. You can verify that it&#8217;s installed correctly by checking its version:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">psql &#8211;version<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-small-font-size\" id=\"h-start-and-enable-the-postgresql-service\"><strong>Start and Enable the PostgreSQL Service<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To ensure PostgreSQL starts on boot and is currently running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl start postgresql\nsudo systemctl enable postgresql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To check the status of the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status postgresql<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading has-small-font-size\" id=\"h-switch-to-the-default-postgresql-user\"><strong>Switch to the Default PostgreSQL User<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL creates a system user called postgres. You must switch to this user to perform administrative tasks like creating roles and databases:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -i -u postgres<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now you\u2019re operating under the PostgreSQL user context.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-small-font-size\" id=\"h-access-the-postgresql-shell\"><strong>Access the PostgreSQL Shell<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To enter the interactive PostgreSQL shell (psql), run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>psql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, you can execute SQL queries and administrative commands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-small-font-size\" id=\"h-create-a-new-user-and-database\"><strong>Create a New User and Database<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We\u2019ll now create a new <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\">PostgreSQL<\/mark> role (user) and a database, then assign appropriate privileges.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the psql shell, run:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212; Create a new user with a secure password<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE ROLE pguser WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD 'password';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212; Check that the user was created<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\\du<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212; Create a new database<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE pgdb;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212; Grant all privileges on the database to the new user<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GRANT ALL PRIVILEGES ON DATABASE pgdb TO pguser;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace pguser and pgdb with your preferred username and database name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Replace &#8216;password&#8217; with a strong password of your choice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once done, exit the PostgreSQL shell:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\\q<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And switch back to your regular system user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exit<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading has-small-font-size\" id=\"h-install-pgadmin-4-web-interface\"><strong>Install pgAdmin 4 (Web Interface)<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">pgAdmin is a powerful, browser-based PostgreSQL database management tool. Let\u2019s install it step-by-step.<\/p>\n\n\n\n<h4 class=\"wp-block-heading has-small-font-size\" id=\"h-install-required-tools\"><strong>Install Required Tools<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You\u2019ll need curl to download external resources:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt install curl -y<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading has-small-font-size\" id=\"h-add-pgadmin-s-gpg-key\"><strong>Add pgAdmin&#8217;s GPG Key<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Import the repository key to verify package authenticity:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -fsS https:\/\/www.pgadmin.org\/static\/packages_pgadmin_org.pub | sudo gpg --dearmor -o \/usr\/share\/keyrings\/packages-pgadmin-org.gpg<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading has-small-font-size\" id=\"h-add-the-pgadmin-repository\"><strong>Add the pgAdmin Repository<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Add pgAdmin\u2019s official APT repository to your sources list:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sh -c 'echo \"deb &#91;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 &amp;&amp; apt update'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Adds the official pgAdmin APT source<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Refreshes the package list<\/p>\n\n\n\n<h4 class=\"wp-block-heading has-small-font-size\" id=\"h-install-pgadmin-4\"><strong>Install pgAdmin 4<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, install pgAdmin 4 using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install pgadmin4 -y<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading has-small-font-size\" id=\"h-configure-pgadmin-4-web-mode\"><strong>Configure pgAdmin 4 Web Mode<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, configure pgAdmin to run in web mode. This will prompt you to create an admin login for the web UI:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/usr\/pgadmin4\/bin\/setup-web.sh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">During this process, you\u2019ll be asked:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To enter an email address \u2014 this will be your login<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To choose a password \u2014 make it strong and secure<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once configured, the pgAdmin web server will start.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-small-font-size\" id=\"h-access-pgadmin-in-your-web-browser\"><strong>Access pgAdmin in Your Web Browser<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can now access pgAdmin via your browser using your server\u2019s IP address:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:\/\/&lt;your-server-ip>\/pgadmin4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You\u2019ll be greeted with a login screen. Use the credentials you provided during the web setup (email and password).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After logging in, you can:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add a new server<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Connect using your pguser and pgdb<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run SQL queries, manage tables, users, and backups \u2014 all through the graphical interface!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Setting up PostgreSQL with pgAdmin 4 on Ubuntu gives you a powerful and user-friendly environment for managing databases. With PostgreSQL as your robust backend and pgAdmin 4 providing a graphical interface, you&#8217;re now ready to Install and Configure PostgreSQL with pgAdmin 4 and build, manage, and scale your applications with ease.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you encounter any issues or need expert assistance while you Install and Configure PostgreSQL with pgAdmin 4 on Ubuntu, our team is here to help. We offer reliable <a href=\"https:\/\/www.skynats.com\/server-management\/\">server management services<\/a> to ensure your database setup is secure, optimized, and scalable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL is a powerful, open-source object-relational database system known for its reliability, robustness, and performance. Whether you&#8217;re working on a production-grade application or exploring data for a side project, PostgreSQL is an excellent choice. In this blog we will learn how to Install and Configure PostgreSQL with pgAdmin 4 on Ubuntu To make database management [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1013,1014,315,236],"class_list":["post-14819","post","type-post","status-publish","format-standard","hentry","category-blog","tag-install-and-configure-postgresql-with-pgadmin-4-on-ubuntu","tag-pgadmin-4","tag-postgresql","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/14819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=14819"}],"version-history":[{"count":1,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/14819\/revisions"}],"predecessor-version":[{"id":14820,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/14819\/revisions\/14820"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=14819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=14819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=14819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}