Here we can see that we are able to access DB from the remote client. In this example, 192.168.1.192 is the IP address of the PostgreSQL database server. Now, let’s try to access DB from remote client. In case, Ubuntu firewall is running on your system then allow PostgreSQL 5432 port using following command, $ sudo ufw allow 5432/tcp Verifying Remote Connectionįinally, restart the service and verify it’s up and running: $ sudo systemctl restart postgresql In the above configuration indicates to allow connection from the network 192.168.1.0/24 $ sudo vi /etc/postgresql/15/main/pg_hba.confĪfter modification the file will look like this: Please note that this file is also located in /etc/postgresql/15/main/ directory. Next, edit the IPv4 local connections section of the pg_hba.conf file to allow IPv4 connections from all clients. After modification the file will look like this: This setting is located under the CONNECTIONS AND AUTHENTICATION section. Now, open the nf file in a text editor, uncomment the line that starts with the listen_addresses, and replace ‘localhost’ with ‘*’. Here, the version indicates the major version of PostgreSQL.įor example, in our case the full path of the file is /etc/postgresql/15/main/nf. PostgreSQL reads its configuration from the nf file which is located in the /etc/postgresql//main/ directory. However, we can easily modify the configuration to allow connection from remote clients. Let’s enter the demoPassword string as a password and now we are connected to the database.Ĥ) Configure PostgreSQL to Allow Remote Connectionsīy default, PostgreSQL accepts connections from the localhost only. Now, let’s connect to the database server again: $ psql -h localhost -U postgres So first, terminate the current session with the server using the \q command. Let’s verify that the password has been set successfully. However, the same is not recommended in the production environment. Please note that, we have used a very simple password because this is a demo environment. The above SQL query sets the user password to demoPassword. So, let’s set the password for the postgres user: postgres=# ALTER USER postgres PASSWORD 'demoPassword' This is an admin user of PostgreSQL and it gets created during the installation process.Īllowing administrative access to the database without any password isn’t a good idea. In this example, we have used the postgres user. In the above output, the postgres=# prompt indicated the active connection with the PostgreSQL server. Let’s see this in action using the psql utility: $ sudo -u postgres psql Here, we can see that the version of PostgreSQL is 15.īy default, we can connect to the PostgreSQL server without using any password. Next, let’s verify that the PostgreSQL service is up and running: $ sudo systemctl status postgresqlįinally, check the PostgreSQL version using the psql command line utility: $ psql -version Let’s install the PostgreSQL client and server using the below apt command: $ sudo apt install postgresql postgresql-client -y The postgresql package installs the default version of the PostgreSQL database server whereas the postgresql-client package installs the client utility. 2) Install PostgreSQL 15 Database Server and Client The above command will take a few seconds to complete. We can achieve this using the apt update command as shown below: $ sudo apt update To begin, let’s fetch the latest versions of the packages. $ wget -qO- | sudo tee /etc/apt//pgdg.asc
0 Comments
Leave a Reply. |