{"id":2735,"date":"2023-03-08T13:06:38","date_gmt":"2022-11-01T18:54:40","guid":{"rendered":""},"modified":"2025-02-02T00:46:19","modified_gmt":"2025-02-01T23:46:19","slug":"how-to-install-postgresql-and-pgadmin-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-postgresql-and-pgadmin-on-ubuntu-22-04\/","title":{"rendered":"Linux VPS &#038; VPS Windows Setup Guide | NetCloud24 PostgreSQL and pgAdmin on Ubuntu 22.04"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<\/header>\n<article>\n<p><strong>PostgreSQL<\/strong> is a powerful, open-source relational database management system (RDBMS) that is known for its robustness and flexibility. <strong>pgAdmin<\/strong> is a popular, feature-rich management tool for PostgreSQL databases. In this guide, we will walk you through how to install both PostgreSQL and pgAdmin on <strong>Ubuntu 22.04<\/strong>. Hosting PostgreSQL on a  ensures better performance, scalability, and control over your database using a dedicated <strong>VPS server<\/strong>.<\/p>\n<h2>Step 1: Update Your VPS Server<\/h2>\n<p>Before installing PostgreSQL and pgAdmin, ensure your <a href=\"https:\/\/ie.netcloud24.com\">VPS server<\/a> is up to date. Use the following commands to update your system:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<p>Hosting PostgreSQL on a <strong>Windows VPS<\/strong> allows you to take advantage of dedicated resources, ensuring your database performs optimally even under high traffic or heavy loads.<\/p>\n<h2>Step 2: Install PostgreSQL<\/h2>\n<p>PostgreSQL is available in the official Ubuntu repositories, making installation straightforward. Install PostgreSQL by running the following command:<\/p>\n<pre><code>sudo apt install postgresql postgresql-contrib -y<\/code><\/pre>\n<p>Once installed, PostgreSQL will start automatically. You can verify the status of the PostgreSQL service using this command:<\/p>\n<pre><code>sudo systemctl status postgresql<\/code><\/pre>\n<h2>Step 3: Secure PostgreSQL and Set Up a User<\/h2>\n<p>By default, PostgreSQL creates a user called <code>postgres<\/code> for administrative tasks. Log in as the <code>postgres<\/code> user with the following command:<\/p>\n<pre><code>sudo -i -u postgres<\/code><\/pre>\n<p>Now, access the PostgreSQL prompt by running:<\/p>\n<pre><code>psql<\/code><\/pre>\n<p>Create a new user and database by running the following commands in the PostgreSQL prompt:<\/p>\n<pre><code>\r\nCREATE USER myuser WITH PASSWORD 'mypassword';\r\nCREATE DATABASE mydatabase;\r\nGRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;\r\n\\q\r\n<\/code><\/pre>\n<p>This creates a new user <code>myuser<\/code> and a new database <code>mydatabase<\/code>, and grants all privileges on the database to the user.<\/p>\n<h2>Step 4: Install pgAdmin<\/h2>\n<p><strong>pgAdmin<\/strong> is a popular web-based tool for managing PostgreSQL databases. To install pgAdmin on Ubuntu, first add the pgAdmin repository:<\/p>\n<pre><code>\r\ncurl https:\/\/www.pgadmin.org\/static\/packages_pgadmin_org.pub | sudo apt-key add -\r\nsudo sh -c 'echo \"deb https:\/\/ftp.postgresql.org\/pub\/pgadmin\/pgadmin4\/apt\/jammy pgadmin4 main\" &gt; \/etc\/apt\/sources.list.d\/pgadmin4.list &amp;&amp; apt update'\r\n<\/code><\/pre>\n<p>Next, install pgAdmin with the following command:<\/p>\n<pre><code>sudo apt install pgadmin4-web -y<\/code><\/pre>\n<h2>Step 5: Configure pgAdmin<\/h2>\n<p>Once pgAdmin is installed, configure it by running the setup script:<\/p>\n<pre><code>sudo \/usr\/pgadmin4\/bin\/setup-web.sh<\/code><\/pre>\n<p>You will be prompted to set up an email and password for the pgAdmin web interface. After that, pgAdmin will be accessible through a web browser. Open your browser and go to <code>http:\/\/your-server-ip\/pgadmin4<\/code> and log in using the credentials you just created.<\/p>\n<h2>Step 6: Connect pgAdmin to PostgreSQL<\/h2>\n<p>After logging in to the pgAdmin interface, you can connect it to your PostgreSQL database:<\/p>\n<ul>\n<li>Click on &#8220;Add New Server&#8221; in the pgAdmin interface.<\/li>\n<li>In the &#8220;General&#8221; tab, give the server a name (e.g., &#8220;My PostgreSQL Server&#8221;).<\/li>\n<li>In the &#8220;Connection&#8221; tab, enter the following details:\n<ul>\n<li><strong>Host:<\/strong> <code>localhost<\/code><\/li>\n<li><strong>Port:<\/strong> <code>5432<\/code><\/li>\n<li><strong>Username:<\/strong> <code>myuser<\/code> (the user you created earlier)<\/li>\n<li><strong>Password:<\/strong> The password for <code>myuser<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Click &#8220;Save&#8221; to connect to your PostgreSQL database. You can now manage your PostgreSQL instance through pgAdmin&#8217;s web interface.<\/p>\n<h2>Step 7: Enable Remote Access (Optional)<\/h2>\n<p>If you need to access your PostgreSQL database remotely, you will need to configure PostgreSQL to accept remote connections. Edit the PostgreSQL configuration file:<\/p>\n<pre><code>sudo nano \/etc\/postgresql\/14\/main\/postgresql.conf<\/code><\/pre>\n<p>Find the line that says <code>#listen_addresses = 'localhost'<\/code> and change it to:<\/p>\n<pre><code>listen_addresses = '*'<\/code><\/pre>\n<p>Next, allow connections in the <code>pg_hba.conf<\/code> file:<\/p>\n<pre><code>sudo nano \/etc\/postgresql\/14\/main\/pg_hba.conf<\/code><\/pre>\n<p>Add the following line at the end of the file to allow all IP addresses to connect:<\/p>\n<pre><code>host    all             all             0.0.0.0\/0               md5<\/code><\/pre>\n<p>Save and close the file. Then restart PostgreSQL to apply the changes:<\/p>\n<pre><code>sudo systemctl restart postgresql<\/code><\/pre>\n<p>To allow remote connections through the firewall, run the following command:<\/p>\n<pre><code>sudo ufw allow 5432\/tcp<\/code><\/pre>\n<h2>Step 8: Optimize Your VPS Server for PostgreSQL<\/h2>\n<p>Hosting PostgreSQL on a  provides dedicated CPU, memory, and storage resources, which are crucial for database performance, especially as the database grows or handles heavy loads. A <strong>VPS server<\/strong> ensures that your PostgreSQL and pgAdmin setup runs efficiently, with the ability to scale as your database demands increase.<\/p>\n<h2>Conclusion<\/h2>\n<p>PostgreSQL and pgAdmin offer a powerful combination for managing databases on Ubuntu 22.04. By hosting PostgreSQL on a , you gain the benefits of increased performance, scalability, and control over your database infrastructure, making it ideal for modern web applications and data-driven systems.<\/p>\n<p>For more information about VPS hosting and optimizing your PostgreSQL setup, visit  today.<\/p>\n<\/article>\n<footer>\n<p>\u00a9 2024 Windows VPS &#8211; All Rights Reserved<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 PostgreSQL is a powerful, open-source relational database management system (RDBMS) that is known for its robustness and flexibility. pgAdmin is a popular, feature-rich management tool for\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-2735","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=2735"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2735\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=2735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}