{"id":15945,"date":"2019-03-14T07:51:25","date_gmt":"2019-03-14T07:51:25","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15945"},"modified":"2026-03-09T19:19:41","modified_gmt":"2026-03-09T19:19:41","slug":"how-to-install-postgresql-on-ubuntu","status":"publish","type":"post","link":"\/ng\/tutorials\/how-to-install-postgresql-on-ubuntu\/","title":{"rendered":"How to install PostgreSQL on Ubuntu and usage instructions for effective database management"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>PostgreSQL is a popular open-source relational database management system (RDBMS) known for its scalability and efficiency in handling large amounts of data.<\/p><p>Due to its high performance, PostgreSQL is ideal for large enterprise websites or applications. It also supports various data types and programming languages, including PHP and Python.<\/p><p>In this tutorial, we will explain how to install PostgreSQL on<strong> Ubuntu 22.04 <\/strong>and later. We will also cover the pgAdmin installation process and solutions to common PostgreSQL issues.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure>\n<\/div><p>\n\n\n<div class=\"protip\"><div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                   What Is PostgreSQL?\n                <\/p>\n            <\/div>\n            <p class=\"protip__content\"> PostgreSQL is a relational database management system (RDBMS) popular for its performance. Unlike a standard DBMS, it arranges data in a logical structure for more efficient access.<br>\nHighly efficient and capable of handling many queries, the database solution is excellent for large enterprises. Moreover, it is free, open-source, and compatible with various data types.<\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-install-postgresql-on-ubuntu\">How to Install PostgreSQL on Ubuntu<\/h2><p>Before proceeding, ensure your virtual private server (VPS) runs <strong><a href=\"\/ng\/vps\/ubuntu-hosting\">Ubuntu 22.04<\/a> <\/strong>or later. Otherwise, follow our guide to <a href=\"https:\/\/support.hostinger.com\/en\/articles\/4965922-how-to-change-the-operating-system-for-your-vps\">change the operating system in Hostinger&rsquo;s VPS<\/a>.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-install-postgresql\">1. Install PostgreSQL<\/h3><p>PostgreSQL installation involves executing <a href=\"\/ng\/tutorials\/linux-commands\/\">Linux commands<\/a> on your machine. For a local system, run them directly via Terminal, the Linux command prompt.<\/p><p>For a remote machine like VPS, connect <a href=\"\/ng\/tutorials\/how-to-use-putty-ssh\/\">using an SSH application<\/a> or Terminal. Hostinger users can find their remote machine login credentials by navigating to the <strong>VPS overview<\/strong> menu<strong> <\/strong>in hPanel.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a588296d94f3\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a588296d94f3\" class=\"aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"1041\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/vps-ssh-username-and-ip-address-on-hpanel.png\/public\" alt=\"The SSH access credentials on the VPS overview menu\" class=\"wp-image-125811\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/vps-ssh-username-and-ip-address-on-hpanel.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>You can install PostgreSQL Ubuntu packages from the local repository or using the APT package manager. We recommend the latter to ensure you get the latest version.<\/p><p>Our VPS also supports other databases. For example, you can <a href=\"\/ng\/tutorials\/how-to-install-mongodb-on-ubuntu\/\">install MongoDB<\/a> if you prefer a NoSQL DBMS. <\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/ng\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p><strong>Option 1 &ndash; Installation From APT Repository<\/strong><\/p><p>The popular method to install PostgreSQL on Ubuntu is from the official repository via the <strong>APT package manager<\/strong>. Here are the steps to do so:<\/p><ol class=\"wp-block-list\">\n<li>Run these commands to import the key from PostgreSQL&rsquo;s official repository to the APT package manager:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo sh -c 'echo \"deb http:\/\/apt.postgresql.org\/pub\/repos\/apt $(lsb_release -cs)-pgdg main\" &gt; \/etc\/apt\/sources.list.d\/pgdg.list'\n\nwget --quiet -O - https:\/\/www.postgresql.org\/media\/keys\/ACCC4CF8.asc | sudo gpg -<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Refresh APT to synchronize all repositories using this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt update<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Install the latest version of PostgreSQL with APT and sudo privileges:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt-get -y install postgresql<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>To confirm the installation, run this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo -u postgres psql<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Enter the PostgreSQL version query statement:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">SELECT version();<\/pre><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Pro Tip                <\/p>\n            <\/div>\n            <p class=\"protip__content\">To install a specific version, add the number in your command, for example <strong>sudo apt-get -y install postgresql-12<\/strong>. In this example, the command will install PostgreSQL version 12.<\/p>\n                    <\/div>\n        \n\n\n\n<\/p><p><strong>Option 2 &ndash; Installation Using Local Ubuntu Repository<\/strong><\/p><p>The alternative PostgreSQL installation method uses the local <a href=\"\/ng\/tutorials\/what-is-ubuntu\/\">Ubuntu<\/a> repository. Here are the steps:<\/p><ol class=\"wp-block-list\">\n<li>Run this command to refresh the Ubuntu repository:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt-get update<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Verify the available <strong>PostgreSQL<\/strong> <strong>apt<\/strong> <strong>repository<\/strong> using this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt show postgresql<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Run this command to install the latest available version. <\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt install postgresql postgresql-contrib<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>To verify whether the PostgreSQL installation is successful, run the following:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo -u postgres psql<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Then, run this command to check the current PostgreSQL version:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">SELECT version();<\/pre><p>The command line should show that the <strong>PostgreSQL server version <\/strong>14.11 is successfully installed, similar to this:<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\"><img loading=\"lazy\" decoding=\"async\" width=\"2470\" height=\"306\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\/public\" alt=\"PostgreSQL version 14.11 in code\" class=\"wp-image-108576\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\/w=2470,fit=scale-down 2470w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\/w=1536,fit=scale-down 1536w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/PostgreSQL.png\/w=2048,fit=scale-down 2048w\" sizes=\"auto, (max-width: 2470px) 100vw, 2470px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-2-check-the-postgresql-status\">2. Check the PostgreSQL Status<\/h3><p>After installing PostgreSQL, check whether it is enabled and active. Use the <strong>systemctl <\/strong>or <strong>service <\/strong>command utility to verify the service status:<\/p><pre class=\"wp-block-preformatted\">sudo service postgresql status\n\nsudo systemctl status postgresql<\/pre><p>If PostgreSQL is enabled, your command line will output <strong>active <\/strong>and <strong>loaded<\/strong>.<\/p><p>For Hostinger users, you can also check whether PostgreSQL is running by asking the <a href=\"\/blog\/kodee\/\">Kodee AI assistant<\/a>. Simply enter, &ldquo;Check the postgresql service status in my VPS,&rdquo; and Kodee will output the service status. <\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a588296dcfa9\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a588296dcfa9\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"489\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/kodee-outputs-the-postgresql-service-status.png\/w=1024,h=1024,fit=scale-down\" alt=\"Kodee outputs the postgresql service status\" class=\"wp-image-124640\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/kodee-outputs-the-postgresql-service-status.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/kodee-outputs-the-postgresql-service-status.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/kodee-outputs-the-postgresql-service-status.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/kodee-outputs-the-postgresql-service-status.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/kodee-outputs-the-postgresql-service-status.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Ask Kodee to manage services                <\/p>\n            <\/div>\n            <p class=\"protip__content\">Aside from checking service statuses on your VPS, you can ask <strong>Kodee<\/strong> to reset services to their default settings and states.<\/p>\n                    <\/div>\n        \n\n\n\n<\/p><p>In addition to the service status, check whether PostgreSQL is ready to accept a connection using this command:<\/p><pre class=\"wp-block-preformatted\">sudo pg_isready<\/pre><h3 class=\"wp-block-heading\" id=\"h-3-connect-to-postgresql\">3. Connect to PostgreSQL<\/h3><p>During the installation, PostgreSQL automatically creates the default <strong>postgres <\/strong>role for logging in to the database. To switch to this user, run the following command:<\/p><pre class=\"wp-block-preformatted\">sudo su - postgres<\/pre><p>Your command line should now begin with <strong>postgres<\/strong>. To connect to the PostgreSQL database, use the PostgreSQL shell using the following:<\/p><pre class=\"wp-block-preformatted\">sudo psql<\/pre><p>The <strong>psql<\/strong> command will create a session in the default<strong> <\/strong>database. If the command isn&rsquo;t found, manually install the PostgreSQL client using this command:<\/p><pre class=\"wp-block-preformatted\">sudo apt-get install postgresql-client<\/pre><p>To check the connection status, run this command using the PostgreSQL prompt:<\/p><pre class=\"wp-block-preformatted\">conninfo<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/The-conninfo-command-outputs-a-confirmation-message-on-Terminal.png\"><img loading=\"lazy\" decoding=\"async\" width=\"958\" height=\"72\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-conninfo-command-outputs-a-confirmation-message-on-Terminal.png\/public\" alt=\"The conninfo command outputs a confirmation message on Terminal\" class=\"wp-image-93042\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-conninfo-command-outputs-a-confirmation-message-on-Terminal.png\/w=958,fit=scale-down 958w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-conninfo-command-outputs-a-confirmation-message-on-Terminal.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-conninfo-command-outputs-a-confirmation-message-on-Terminal.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-conninfo-command-outputs-a-confirmation-message-on-Terminal.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 958px) 100vw, 958px\" \/><\/a><\/figure><\/div><p>To quit the PostgreSQL prompt and return to the regular system user, use the <strong>exit <\/strong>command. Meanwhile, use <strong>q <\/strong>to detach from the database&rsquo;s interactive session.<\/p><h3 class=\"wp-block-heading\" id=\"h-4-change-user-password\">4. Change User Password<\/h3><p>Changing the<strong> <\/strong>default <strong>postgres<\/strong> role password is essential to improve database security. Here&rsquo;s how to do it:<\/p><ol class=\"wp-block-list\">\n<li>Activate the PostgreSQL prompt using this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo -u postgres psql<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Run this statement to change the <strong>postgres<\/strong> account password. Don&rsquo;t forget to replace <strong>NewPassword<\/strong> with your actual password:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">ALTER USER postgres PASSWORD 'NewPassword';<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Check whether the change is applied successfully using the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">p<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Restart the PostgreSQL service using this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo service postgresql restart<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/Postgres-returns-a-confirmation-about-the-account-password-change.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"155\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Postgres-returns-a-confirmation-about-the-account-password-change.png\/w=1024,h=1024,fit=scale-down\" alt=\"Postgres returns a confirmation about the account password change\" class=\"wp-image-93043\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Postgres-returns-a-confirmation-about-the-account-password-change.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Postgres-returns-a-confirmation-about-the-account-password-change.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Postgres-returns-a-confirmation-about-the-account-password-change.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Postgres-returns-a-confirmation-about-the-account-password-change.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-5-create-a-user-on-postgresql\">5. Create a User on PostgreSQL<\/h3><p>To manage database access and ensure proper data organization, you will need multiple PostgreSQL users. The easiest way to create one is to use the <strong>interactive mode<\/strong>. Here are the steps:<\/p><ol class=\"wp-block-list\">\n<li>Switch to the <strong>postgres<\/strong> user:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo su - postgres<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Run this command to create a new user:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">createuser --interactive<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Enter the new PostgresQL account name. For this tutorial, it is <strong>TheNewUser<\/strong>.<\/li>\n\n\n\n<li>To validate the new role, log in to PostgreSQL with the <strong>postgres<\/strong> account:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo -u postgres psql<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Check all the users with the following command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">du<\/pre><p><div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> As a part of security best practices for PostgreSQL, avoid granting the new role a superuser privilege unless necessary.\n            <\/p><\/div>\n\n\n\n<\/p><p>As shown in the output, the database successfully creates <strong>TheNewUser<\/strong>.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-shows-the-new-PostgreSQL-user.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"189\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-shows-the-new-PostgreSQL-user.png\/w=1024,h=1024,fit=scale-down\" alt=\"Terminal shows the new PostgreSQL user\" class=\"wp-image-93044\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-shows-the-new-PostgreSQL-user.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-shows-the-new-PostgreSQL-user.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-shows-the-new-PostgreSQL-user.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-shows-the-new-PostgreSQL-user.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-6-create-a-database-on-postgresql\">6. Create a Database on PostgreSQL<\/h3><p>PostgreSQL assumes the <a href=\"https:\/\/www.postgresql.org\/docs\/current\/user-manag.html\">role<\/a> and the database will have the same name. Therefore, if you create a <strong>TheNewUser<\/strong> role, PostgreSQL will access a database with the same<strong> <\/strong>name.<\/p><p><div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> PostgreSQL uses Linux information for authentication. In the previous example, you need a user called <strong>TheNewUser<\/strong>.\n            <\/p><\/div>\n\n\n\n<\/p><p>Here are the PostgreSQL database setup steps:<\/p><ol class=\"wp-block-list\">\n<li>Run the following to switch to the <strong>postgres <\/strong>user and create a new database:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo -u postgres createdb TheNewUser<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>To log in to the new database, create a Linux user account with the same name. Since the username contains capital letters, add the <strong>&ndash;force-badname<\/strong> option.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo adduser TheNewUser --force-badname<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Enter the interactive PostgreSQL prompt using the new user account:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo -u TheNewUser psql<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Confirm the connection using this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">conninfo<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-output-confirms-the-new-PostgreSQL-user-is-connected-to-the-new-database.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"102\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-output-confirms-the-new-PostgreSQL-user-is-connected-to-the-new-database.png\/w=1024,h=1024,fit=scale-down\" alt=\"Terminal output confirms the new PostgreSQL user is connected to the new database\" class=\"wp-image-93045\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-output-confirms-the-new-PostgreSQL-user-is-connected-to-the-new-database.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-output-confirms-the-new-PostgreSQL-user-is-connected-to-the-new-database.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-output-confirms-the-new-PostgreSQL-user-is-connected-to-the-new-database.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Terminal-output-confirms-the-new-PostgreSQL-user-is-connected-to-the-new-database.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>The user should now connect to the new database and be able to create a new table. For example, enter the following to create a buyer data table:<\/p><pre class=\"wp-block-preformatted\">CREATE TABLE buyers(usr_id INT PRIMARY KEY, usr_name VARCHAR(240) NOT NULL, usr_location VARCHAR(240) NOT NULL);<\/pre><p>When creating a database table, consider the six PostgreSQL constraints:<\/p><ul class=\"wp-block-list\">\n<li><strong>PRIMARY KEY <\/strong>&ndash; indicates that a column can be a row&rsquo;s unique identifier.<\/li>\n\n\n\n<li><strong>FOREIGN KEY <\/strong>&ndash; specifies that the values in a column must be the same as the ones in another table&rsquo;s rows.<\/li>\n\n\n\n<li><strong>NOT NULL <\/strong>&ndash; ensures a column&rsquo;s value is not empty.<\/li>\n\n\n\n<li><strong>CHECK<\/strong> &ndash; sets a column&rsquo;s value so that it must satisfy a Boolean expression, which is either &ldquo;true&rdquo; or &ldquo;false&rdquo;.<\/li>\n\n\n\n<li><strong>UNIQUE <\/strong>&ndash; guarantees that the values in a column are unique among all rows.<\/li>\n\n\n\n<li><strong>EXCLUSION <\/strong>&ndash; prevents values in two rows from overlapping when compared.<\/li>\n<\/ul><p>To add values to your table, use the following statement. Don&rsquo;t forget to replace the placeholders with the appropriate value and adjust the number of rows accordingly:<\/p><pre class=\"wp-block-preformatted\">INSERT INTO tablename (column1, column2, column3) VALUES (row1, row2, row3);<\/pre><p>To show the table, enter the following statement:<\/p><pre class=\"wp-block-preformatted\">SELECT * FROM tablename<\/pre><h3 class=\"wp-block-heading\" id=\"h-7-configure-the-postgresql-server\">7. Configure the PostgreSQL Server<\/h3><p>Configure your PostgreSQL server to allow other systems to access the database remotely. To do so, let the server listen to all IP addresses by editing the configuration file.<\/p><p>Before proceeding, use the <strong>exit <\/strong>command to quit the PostgreSQL shell and return as the regular system user. Then, follow these steps:<\/p><ol class=\"wp-block-list\">\n<li>Open the configuration file using a text editor. Replace <strong>vim <\/strong>if you use another editor and change the directory accordingly:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">vim \/etc\/postgresql\/14\/main\/postgresql.conf<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Find the <strong>listen_addresses<\/strong> line.<\/li>\n\n\n\n<li>Remove the <strong># <\/strong>symbol and change the value to an asterisk. Here&rsquo;s how it should look:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">listen_addresses = '*'<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Use the <strong>:wq<\/strong> command to save the changes and quit <strong>vim<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/The-listen-address-line-in-the-PostgreSQL-configuration-file.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1062\" height=\"58\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-listen-address-line-in-the-PostgreSQL-configuration-file.png\/w=1024,h=1024,fit=scale-down\" alt=\"The listen address line in the PostgreSQL configuration file\" class=\"wp-image-93046\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-listen-address-line-in-the-PostgreSQL-configuration-file.png\/w=1062,fit=scale-down 1062w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-listen-address-line-in-the-PostgreSQL-configuration-file.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-listen-address-line-in-the-PostgreSQL-configuration-file.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-listen-address-line-in-the-PostgreSQL-configuration-file.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-listen-address-line-in-the-PostgreSQL-configuration-file.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1062px) 100vw, 1062px\" \/><\/a><\/figure><\/div><ol start=\"5\" class=\"wp-block-list\">\n<li>Set the access policy to authenticate client connection to your PostgreSQL server. To do so, open the <strong>pg_hba.conf<\/strong> file in the same directory using <strong>vim<\/strong>. The command should look like this:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">vim \/etc\/postgresql\/14\/main\/pg_hba.conf<\/pre><ol start=\"6\" class=\"wp-block-list\">\n<li>Add a new policy at the bottom of the file using this syntax:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">connection database user ip_address encryption<\/pre><ol start=\"7\" class=\"wp-block-list\">\n<li>For instance, we will enable all TCP\/IP connections from all users to every PostgreSQL database. These users can use any IP address with an MD5-encrypted password. The rule looks as follows:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">host all all 0.0.0.0\/0 md5<\/pre><ol start=\"8\" class=\"wp-block-list\">\n<li>Restart the PostgreSQL service to apply the changes.<\/li>\n<\/ol><h3 class=\"wp-block-heading\" id=\"h-8-set-up-a-remote-database-connection\">8. Set up a Remote Database Connection<\/h3><p>After configuring the database, set up remote access to PostgreSQL using the <strong>psql<\/strong> command. To do so, use this command syntax in the client machine:<\/p><pre class=\"wp-block-preformatted\">psql -h ip_address -p port -d database -U username<\/pre><p>For example, run this command to connect to the TheNewUser database hosted in a VPS with the <strong>185.185.185.185 <\/strong>IP address using the <strong>TheNewUser<\/strong> account:<\/p><pre class=\"wp-block-preformatted\">psql -h 185.185.185.185 -p 5432 -d TheNewUser -U TheNewUser<\/pre><p>Remember that the default PostgreSQL port is <strong>5423<\/strong>. To verify if the connection is successful, run this command:<\/p><pre class=\"wp-block-preformatted\">conninfo<\/pre><p>Once connected, you can send database queries to retrieve data. To enable PostgreSQL remote access in your application, install a database driver and import the module into your code.<\/p><p>For this tutorial, we will show you how to do so in a Python application hosted in an <strong>Ubuntu 22.04<\/strong> VPS. After connecting via SSH, follow these steps:<\/p><ol class=\"wp-block-list\">\n<li>Install the <strong>pip package manager <\/strong>using this command. If you already have it, skip this step:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt-get install python-pip<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Download and install the <strong>psycopg2<\/strong> database driver using pip:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">pip install psycopg2-binary<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Add the following line to your application code to import the module and establish a connection with the PostgreSQL database. Remember to change the value accordingly:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">import psycopg2\n# Connect your app to the remote database.\nconn = psycopg2.connect(host=\"182.182.182.182\", port=\"5432\", dbname=\"TestNewUser\", user=\"TestNewUser\", password=\"UserPassword\")\n# Open a cursor for database operations\ncur = conn.cursor()\n# Execute a query. Replace table with your own. \ncur.execute(\"SELECT * FROM table\")\n# Retrieve data\nrecords = cur.fetchall()<\/pre><h3 class=\"wp-block-heading\" id=\"h-9-install-pgadmin\">9. Install pgAdmin<\/h3><p>Install the<strong> pgAdmin<\/strong> web-based GUI to simplify your PostgreSQL database management tasks. We will use the APT package manager to install it:<\/p><ol class=\"wp-block-list\">\n<li>Run these commands individually to add the pgAdmin official repository:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">curl -fsSL https:\/\/www.pgadmin.org\/static\/packages_pgadmin_org.pub | sudo gpg --dearmor -o \/etc\/apt\/trusted.gpg.d\/pgadmin.gpg\n\nsudo sh -c 'echo \"deb https:\/\/ftp.postgresql.org\/pub\/pgadmin\/pgadmin4\/apt\/$(lsb_release -cs) pgadmin4 main\" &gt; \/etc\/apt\/sources.list.d\/pgadmin4.list'<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Update the package lists to synchronize the repository.<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt update<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Run the following command to install pgAdmin:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo apt install pgadmin4<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>After the GUI setup finishes, initiate the primary pgAdmin configuration with this command:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">sudo \/usr\/pgadmin4\/bin\/setup-web.sh<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Enter your email address and password. It should look like the following:<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/The-bash-script-to-initiate-pgAdmin-configuration.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1238\" height=\"402\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-bash-script-to-initiate-pgAdmin-configuration.png\/w=1024,h=1024,fit=scale-down\" alt=\"The bash script to initiate pgAdmin configuration\" class=\"wp-image-93047\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-bash-script-to-initiate-pgAdmin-configuration.png\/w=1238,fit=scale-down 1238w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-bash-script-to-initiate-pgAdmin-configuration.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-bash-script-to-initiate-pgAdmin-configuration.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-bash-script-to-initiate-pgAdmin-configuration.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-bash-script-to-initiate-pgAdmin-configuration.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1238px) 100vw, 1238px\" \/><\/a><\/figure><\/div><p>To access the pgAdmin web-based interface, enter the following in your web browser&rsquo;s address bar:<\/p><pre class=\"wp-block-preformatted\">185.185.185.185\/pgadmin4<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/Login-screen-for-pgAdmin-GUI-with-the-login-button-highlighted.png\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"543\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Login-screen-for-pgAdmin-GUI-with-the-login-button-highlighted.png\/public\" alt=\"Login screen for pgAdmin GUI with the login button highlighted\" class=\"wp-image-93048\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Login-screen-for-pgAdmin-GUI-with-the-login-button-highlighted.png\/w=851,fit=scale-down 851w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Login-screen-for-pgAdmin-GUI-with-the-login-button-highlighted.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Login-screen-for-pgAdmin-GUI-with-the-login-button-highlighted.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/Login-screen-for-pgAdmin-GUI-with-the-login-button-highlighted.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/a><\/figure><\/div><p>Replace the IP address with your VPS&rsquo;. Then, enter your email address and password. Click <strong>Login<\/strong> to enter the<strong> <\/strong>main pgAdmin dashboard.<\/p><p>To connect PostgreSQL, select <strong>Add New Server<\/strong> and proceed with the configuration process.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/The-main-management-window-for-pgAdmin-with-the-Add-New-Server-button-highlighted.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"824\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-main-management-window-for-pgAdmin-with-the-Add-New-Server-button-highlighted.png\/w=1024,h=1024,fit=scale-down\" alt=\"The main management window for pgAdmin with the Add New Server button highlighted\" class=\"wp-image-93049\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-main-management-window-for-pgAdmin-with-the-Add-New-Server-button-highlighted.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-main-management-window-for-pgAdmin-with-the-Add-New-Server-button-highlighted.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-main-management-window-for-pgAdmin-with-the-Add-New-Server-button-highlighted.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/03\/The-main-management-window-for-pgAdmin-with-the-Add-New-Server-button-highlighted.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-troubleshooting-postgresql-installation\">Troubleshooting PostgreSQL Installation<\/h2><p>In this section, we will explore common issues regarding PostgreSQL installation and their solutions.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-unable-to-connect-to-postgresql-server\">1. Unable to Connect to PostgreSQL Server<\/h3><p>First, you should check whether the client system is properly connected to the internet. If the internet connection isn&rsquo;t the issue, other common causes for this error include an inactive database or misconfigured file permission.<\/p><p>Check PostgreSQL status and ensure it is <strong>loaded <\/strong>and <strong>active<\/strong>. Otherwise, restart it using the following command:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl restart postgresql<\/pre><p>If that doesn&rsquo;t work, check whether the PostgreSQL directory and files permissions are set to <strong>0700<\/strong> and <strong>0600<\/strong>. To do so, use the following command:<\/p><pre class=\"wp-block-preformatted\">ls \/var\/lib\/postgresql\/main<\/pre><p>Then, use the <a href=\"\/ng\/tutorials\/how-to-change-linux-permissions-and-owners\/\"><strong>chmod <\/strong>command to change their permissions<\/a>.<\/p><h3 class=\"wp-block-heading\" id=\"h-2-postgresql-connection-issues-from-remote-host\">2. PostgreSQL Connection Issues from Remote Host<\/h3><p>A misconfigured connection policy may cause remote host issues that prevent you from accessing the PostgreSQL server. To solve it, open your <strong>pg_hba.conf<\/strong> file and add the access policy from every client&rsquo;s IP address:<\/p><pre class=\"wp-block-preformatted\">host all all 0.0.0.0\/0 md5<\/pre><p>Then, check the <strong>listen_address <\/strong>value in your <strong>postgres.conf <\/strong>configuration file. Ensure it has an <strong>asterisk<\/strong> to ensure PostgreSQL can listen to all IP addresses.<\/p><p>If that doesn&rsquo;t work, check if your firewall closes the PostgreSQL listening port. For Ubuntu server, run the <strong>ufw <\/strong>command:<\/p><pre class=\"wp-block-preformatted\">sudo ufw status verbose<\/pre><p>If the connection from and to port <strong>5432<\/strong> is disabled, open it using the following command:<\/p><pre class=\"wp-block-preformatted\">sudo ufw allow 5432\/tcp <\/pre><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Learn more about Ubuntu Firewall                <\/p>\n            <\/div>\n            <p class=\"protip__content\"> Check out our other article to learn <a href=\"\/ng\/tutorials\/how-to-configure-firewall-on-ubuntu-using-ufw\/\">how to configure Ubuntu firewall using Uncomplicated Firewall (UFW)<\/a>.<\/p>\n                    <\/div>\n        \n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-3-pgadmin-login-issues\">3. pgAdmin Login Issues<\/h3><p>pgAdmin login issues may occur due to a database connection error. If it is network-related, try the previous solutions and reinstall pgAdmin.<\/p><p>If the problem is related to the user account login credentials, enter the <strong>psql <\/strong>session<strong> <\/strong>and reset the password using this statement:<\/p><pre class=\"wp-block-preformatted\">ALTER USER username WITH PASSWORD 'new_password';<\/pre><p>You may also encounter login issues if the user doesn&rsquo;t have the<strong> LOGIN<\/strong> privilege. To grant one, use the following statement:<\/p><pre class=\"wp-block-preformatted\">ALTER USER username WITH LOGIN;<\/pre><h3 class=\"wp-block-heading\" id=\"h-4-postgresql-version-conflict\">4. PostgreSQL Version Conflict<\/h3><p>Version conflicts occur when PostgreSQL is incompatible with the database or other applications. Its common cause includes not updating PostgreSQL, resulting in a version mismatch.<\/p><p>To solve it, reinstall or update PostgreSQL from the APT official repository. Also, update all third-party applications since they may be outdated.<\/p><p>We recommend testing the newest version in a development environment to avoid further issues in the live server.<\/p><h3 class=\"wp-block-heading\" id=\"h-5-unable-to-create-postgresql-user-or-database\">5. Unable to Create PostgreSQL User or Database<\/h3><p>An incorrect command syntax often triggers PostgreSQL user and database creation errors. To fix it, ensure your command ends with a semicolon (<strong>;<\/strong>).<\/p><p>Also, you must run the command using the <strong>postgres<\/strong> user and the <strong>psql <\/strong>command line. To do so, run this command:<\/p><pre class=\"wp-block-preformatted\">sudo -u postgres psql<\/pre><p>If your Terminal shows the following, you should be able to create a user and database.<\/p><pre class=\"wp-block-preformatted\">postgres=#<\/pre><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Learn More About PostgreSQL and VPS                <\/p>\n            <\/div>\n            <p class=\"protip__content\"><a href=\"\/ng\/tutorials\/getting-started-with-vps-hosting\/\">How to Set Up a VPS<\/a><br>\n<a href=\"\/ng\/tutorials\/what-is-vps-hosting\/\">What is a VPS<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-install-postgresql-on-centos-7\/\">how to install PostgreSQL on CentOS7<\/a><\/p>\n                    <\/div>\n        \n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>PostgreSQL is an open-source, community-driven database management system. It uses a logical structure to efficiently store large amounts of data and simplify access.<\/p><p>In this relational database management system tutorial, we have explained the steps to install PostgreSQL on Ubuntu 22.04 via the Linux command prompt. Here is the recap:<\/p><ol class=\"wp-block-list\">\n<li>Install PostgreSQL from the official repository using <strong>APT<\/strong>.<\/li>\n\n\n\n<li>Run <strong>systemctl status <\/strong>to check if Postgresql is active.<\/li>\n\n\n\n<li>Connect to the PostgreSQL account using <strong>sudo su &ndash; postgres<\/strong>.<\/li>\n\n\n\n<li>Change the default admin account&rsquo;s password to improve security.<\/li>\n\n\n\n<li>Create a new PostgreSQL user to manage your databases.<\/li>\n\n\n\n<li>Make a new database using the <strong>createdb <\/strong>command.<\/li>\n\n\n\n<li>Set up the PostgreSQL server by configuring its connection policy.<\/li>\n\n\n\n<li>Configure a connection to your remote PostgreSQL database.<\/li>\n\n\n\n<li>Install pgAdmin to provide a graphical user interface.<\/li>\n<\/ol><p>To avoid issues, ensure the connection policies and pgAdmin login credentials are set correctly. Moreover, install the latest version of the RDBMS via APT to avoid incompatibility issues.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-install-postgresql-on-ubuntu-faq\">How to Install PostgreSQL on Ubuntu FAQ<\/h2><p>In this section, we will answer several commonly asked questions about installing PostgreSQL on an Ubuntu server.<\/p><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1693491145690\"><h3 class=\"schema-faq-question\">Where Is Postgres Installed on Ubuntu?&nbsp;<\/h3> <p class=\"schema-faq-answer\">On Ubuntu, the main PostgreSQL server files are in the <strong>\/usr\/lib\/postgresql\/&lt;version\/bin\/postgres <\/strong>directory. All database clusters are stored in <strong>\/var\/lib\/postgresql\/main<\/strong> directory. Meanwhile, the PostgreSQL settings are in the <strong>\/etc\/postgresql\/main\/postgresql.conf <\/strong>file.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1693491155361\"><h3 class=\"schema-faq-question\">How Do I Know if PostgreSQL Is Installed on Ubuntu?<\/h3> <p class=\"schema-faq-answer\">The easiest way to check if PostgreSQL is installed on an Ubuntu server is to run <strong>sudo -u postgres psql<\/strong> or <strong>which psql<\/strong>. Terminal should output the installation path if it is installed.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1693491165378\"><h3 class=\"schema-faq-question\">Should I Use PostgreSQL 13 or 14?<\/h3> <p class=\"schema-faq-answer\">PostgreSQL 14 has an improved connection scaling. It makes PostgreSQL 14 more suitable for large enterprises with many database connections. We recommend sticking to the newest version for the latest features, improvements, and patches.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL is a popular open-source relational database management system (RDBMS) known for its scalability and efficiency in handling large amounts of data. Due to its high performance, PostgreSQL is ideal for large enterprise websites or applications. It also supports various data types and programming languages, including PHP and Python. In this tutorial, we will explain [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/how-to-install-postgresql-on-ubuntu\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Install PostgreSQL on Ubuntu + pgAdmin Setup","rank_math_description":"Learn how to install postgreSQL on Ubuntu 22.04 using APT and local repository. pgAdmin installation and usage guide included.","rank_math_focus_keyword":"install postgresql ubuntu","footnotes":""},"categories":[22644],"tags":[],"class_list":["post-15945","post","type-post","status-publish","format-standard","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-install-postgresql-on-ubuntu","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/instalar-postgresql-ubuntu","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/install-postgresql-ubuntu","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-install-postgresql-on-ubuntu","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-install-postgresql-on-ubuntu","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-install-postgresql-on-ubuntu","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/que-son-hooks-wordpress-8","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/que-son-hooks-wordpress-8","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/instalar-postgresql-ubuntu","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-install-postgresql-on-ubuntu","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-install-postgresql-on-ubuntu","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-install-postgresql-on-ubuntu","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-install-postgresql-on-ubuntu","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/15945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=15945"}],"version-history":[{"count":30,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/15945\/revisions"}],"predecessor-version":[{"id":145114,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/15945\/revisions\/145114"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=15945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=15945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=15945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}