{"id":2071,"date":"2024-05-26T10:41:55","date_gmt":"2025-06-18T03:43:48","guid":{"rendered":""},"modified":"2025-02-02T00:46:18","modified_gmt":"2025-02-01T23:46:18","slug":"how-to-install-postgresql-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-postgresql-on-ubuntu-22-04\/","title":{"rendered":"Linux VPS &#038; VPS Windows Setup Guide | NetCloud24 PostgreSQL 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 highly reliable and provides advanced features for database management. In this guide, we will walk you through the steps to install PostgreSQL on <strong>Ubuntu 22.04<\/strong>. Hosting PostgreSQL on a  ensures that your database operates efficiently with dedicated resources and scalability through a <strong>VPS server<\/strong>.<\/p>\n<h2>Step 1: Update Your VPS Server<\/h2>\n<p>Before installing PostgreSQL, make sure your <a href=\"https:\/\/ie.netcloud24.com\">VPS server<\/a> is up to date. Run the following commands to update your system:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<p>Using a <strong>Windows VPS<\/strong> ensures that your PostgreSQL database benefits from dedicated CPU, memory, and storage, leading to better performance and reliability.<\/p>\n<h2>Step 2: Install PostgreSQL<\/h2>\n<p>PostgreSQL is available in the default Ubuntu repositories, so installation is straightforward. Use the following command to install PostgreSQL:<\/p>\n<pre><code>sudo apt install postgresql postgresql-contrib -y<\/code><\/pre>\n<p>This command installs both PostgreSQL and additional useful extensions provided by <code>postgresql-contrib<\/code>.<\/p>\n<h2>Step 3: Start and Enable PostgreSQL<\/h2>\n<p>After the installation, the PostgreSQL service will start automatically. You can verify its status with this command:<\/p>\n<pre><code>sudo systemctl status postgresql<\/code><\/pre>\n<p>To ensure that PostgreSQL starts automatically at boot, run:<\/p>\n<pre><code>sudo systemctl enable postgresql<\/code><\/pre>\n<h2>Step 4: Configure PostgreSQL<\/h2>\n<p>By default, PostgreSQL creates a system user named <code>postgres<\/code> for administrative purposes. You can log in to the PostgreSQL prompt using this user:<\/p>\n<pre><code>sudo -i -u postgres<\/code><\/pre>\n<p>Once logged in, start the PostgreSQL shell:<\/p>\n<pre><code>psql<\/code><\/pre>\n<p>From here, you can execute SQL queries and perform administrative tasks. To exit the PostgreSQL shell, type:<\/p>\n<pre><code>\\q<\/code><\/pre>\n<h2>Step 5: Create a New Database and User<\/h2>\n<p>For security and organization, it\u2019s recommended to create a new PostgreSQL user and database instead of using the default <code>postgres<\/code> user. To create a new user and database, log into the PostgreSQL shell and run the following commands:<\/p>\n<pre><code>\r\nCREATE DATABASE mydatabase;\r\nCREATE USER myuser WITH PASSWORD 'mypassword';\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> with the password <code>mypassword<\/code> and assigns all privileges on <code>mydatabase<\/code> to the user.<\/p>\n<h2>Step 6: Enable Remote Access to PostgreSQL (Optional)<\/h2>\n<p>By default, PostgreSQL only listens on <code>localhost<\/code>, which means it&#8217;s not accessible from remote machines. To allow remote access, 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 begins with <code>#listen_addresses = 'localhost'<\/code> and change it to:<\/p>\n<pre><code>listen_addresses = '*'<\/code><\/pre>\n<p>Save and close the file. Then, modify the <code>pg_hba.conf<\/code> file to allow external connections:<\/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 (for production environments, limit the range of allowed IPs):<\/p>\n<pre><code>host    all             all             0.0.0.0\/0               md5<\/code><\/pre>\n<p>Restart PostgreSQL to apply the changes:<\/p>\n<pre><code>sudo systemctl restart postgresql<\/code><\/pre>\n<p>If you are using a firewall, allow PostgreSQL traffic (port 5432) through the firewall:<\/p>\n<pre><code>\r\nsudo ufw allow 5432\/tcp\r\nsudo ufw reload\r\n<\/code><\/pre>\n<h2>Step 7: Test PostgreSQL Connection<\/h2>\n<p>To verify that PostgreSQL is working properly, you can connect to the database using the new user and database you created. Use the following command:<\/p>\n<pre><code>psql -U myuser -d mydatabase -h 127.0.0.1 -W<\/code><\/pre>\n<p>Enter the password when prompted, and you will be logged into the PostgreSQL database.<\/p>\n<h2>Step 8: Optimize Your VPS Server for PostgreSQL<\/h2>\n<p>For high-performance database management, it\u2019s recommended to host PostgreSQL on a . A <strong>VPS server<\/strong> offers dedicated resources like CPU, memory, and storage that are essential for handling large databases and high-concurrency connections. As your database grows, you can easily scale the server to ensure that PostgreSQL continues to perform efficiently.<\/p>\n<h2>Conclusion<\/h2>\n<p>PostgreSQL is a powerful and feature-rich database management system that is easy to set up on Ubuntu 22.04. By hosting your PostgreSQL instance on a , you can ensure that your database operates reliably with dedicated resources, providing excellent performance for your applications.<\/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 highly reliable and provides advanced features for database management. In this guide, we will\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-2071","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\/2071","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=2071"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2071\/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=2071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}