

Now, let's connect from the client's machine How to access PostgreSQL from the remote system Save changes and restart the PostgreSQL: sudo systemctl restart postgresql Here, I'm going with the nano: sudo nano /etc/postgresql/15/main/pg_hba.confĪdd the following line at the end of this config file: host all all 0.0.0.0/0 md5 Once you find the location of the pg_hba.conf file, open it using your preferred text editor. To allow the remote connections, you will have to make changes in pg_hba.conf file.Īnd to know its exact path, use the following command: sudo find / -name "pg_hba.conf" 2>/dev/null However, if you will try to use PostgreSQL remotely, it will throw the following error: To benefit from the configuration, restart the PostgreSQL: sudo systemctl restart postgresqlĪnd now, if you will use the ss command to list listening ports, you will find that PostgreSQL is listening on all interfaces: ss -nlt Save changes and exit from the nano text editor. Which needs to be replaced with: listen_addresses = '*' In this config file, under the CONNECTIONS AND AUTHENTICATION section, you will find the following line: #listen_addresses = 'localhost' Here, I'm going with nano: sudo nano /etc/postgresql/15/main/nf Once you find the exact location of the nf, you can open that file using any of your preferred text editors. You can learn more about how you can redirect standard input, output, and errors by the given guide: Here, I have redirected the errors to the /dev/null. And to find the exact location nf file, use: sudo find / -name "nf" 2>/dev/null To use PostgreSQL remotely, you will have to make changes in nf file.īut the location of that file might be different based on the version you are using. So in simple words, you can only use PostgreSQL on the main machine where you have performed the installation.ĭon't trust me? You can check the listing ports by yourself using the ss command: ss -nlt In its default configuration, PostgreSQL can only be accessed via a loopback interface 127.0.0.1 on port 5432 and a UNIX socket.
#POSTGRESQL UBUNTU PASSWORD#
Now, you can follow the given command syntax to change the user password: ALTER USER postgres PASSWORD 'Enter_password_here' įor reference, I changed my password to ALTER USER postgres PASSWORD How to allow PostgreSQL to accept remote connections To change the password, first, connect to the PostgreSQL server that will get you to the PostgreSQL prompt: sudo -u postgres psql How to change user password in PostgreSQL So let me start with changing the password. Allowing PostgreSQL to accept remote connections.In this section, I will walk you through the two most basic configurations that you should do on your fresh PostgreSQL install: So to start the prompt, use the following command: sudo -u postgres psqlĪnd now, execute the following command in PostgreSQL to check the installed version: SELECT version() How to configure PostgreSQL on Ubuntu The installed version of PostgreSQL can be retrieved from its shell prompt.
#POSTGRESQL UBUNTU INSTALL#
To take effect from the steps you made recently, update system repositories: sudo apt updateĪnd finally, you can have the latest version of PostgreSQL: sudo apt install postgresql Next, add the repository signing keys to have the authentic packages: wget -quiet -O - | sudo apt-key add. So first, create a repository configuration file using the following command: sudo sh -c 'echo "deb $(lsb_release -cs)-pgdg main" > /etc/apt//pgdg.list' To have the most recent version, you are required to utilize PostgreSQL's repository. Install the latest version of PostgreSQL on Ubuntu (if you need it) So if the version is not the major concern, it can be installed using a single command: sudo apt install postgresqlīut what if you want to have the most recent version? Well, that's what today's guide is all about.

While writing, I got PostgreSQL version 14.6 from the default repo. Being open-source, and supporting SQL and JSON querying is one of the crucial reasons why it is one of the most popular names when choosing a database management system.Īnd PostgreSQL is available in the default repository of Ubuntu.
