ObjectiveThe objective is to Install PostgreSQL server or client on Ubuntu 18.04 Bionic Beaver
Operating System and Software Versions
- Operating System: - Ubuntu 18.04 Bionic Beaver
- Software: - PostgreSQL Server 10
RequirementsPrivileged access to your Ubuntu System as root or via
sudocommand is required.
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
Install PostreSQL Client on UbuntuIn case that you only need to connect to a remote PostreSQL server you only need to install PostgreSQL client on your local Ubuntu host. To do so execute:
$ sudo apt install postgresql-clientOnce the installation of PostreSQl client is completed you can use
psqlcommand to connect to your remote PostreSQL server. For example the following linux command will connect to PostgreSQL server via hostname
$ psql -h postresql-ubuntu -U postgres psql (10.2 (Ubuntu 10.2-1)) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help.See below on how to configure PostreSQL server to accept remote client connections.
BLUE SKY STUDIOS are looking for Linux Administrator to maintain and support the Studio's 450+ production Linux workstations, including daily interactions with the Studio’s digital animation artists.
LOCATION: Greenwich, Connecticut, USA
Install PostreSQL Server on UbuntuIn this section we will be installing PostgreSQL server on Ubuntu 18.04 Linux. The installation is as simple as:
$ sudo apt install postgresqlOnce the PostreSQL installation is finished confirm that it is up and running as expected by checking for its listening socket on port number
The PostgreSQL server will start after reboot. To manipulate this default behavior you can either disable or enable the PostreSQL start after reboot by:
$ ss -nlt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 5 127.0.0.1:631 0.0.0.0:* LISTEN 0 128 127.0.0.1:5432 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 5 [::1]:631 [::]:*
$ sudo systemctl disable postgresql OR $ sudo systemctl enable postgresqlBy default the PostgreSQL server will listen only on a local loop-back interface
127.0.0.1. If you need to configure your PostreSQL server to listen on all networks you will need to configure its main configuration file
$ sudo nano /etc/postgresql/10/main/postgresql.confand add the following line somewhere to the
CONNECTIONS AND AUTHENTICATIONsection:
listen_addresses = '*'Once the configuration is completed restart PostreSQL server:
$ sudo service postgresql restartThe PostreSQL server should be now listening on socket
0.0.0.0:5432. You can confirm this by executing the
Next, to accept connections from a remote PostreSQL client to all databases and all users add the following line to
$ ss -nlt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 5 127.0.0.1:631 0.0.0.0:* LISTEN 0 128 0.0.0.0:5432 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 5 [::1]:631 [::]:*
host all all 0.0.0.0/0 trustFailing to do so may result in the following error message:
psql: FATAL: no pg_hba.conf entry for host "postresql-client", user "postgres", database "postgres", SSL on FATAL: no pg_hba.conf entry for host "postresql-client", user "postgres", database "postgres", SSL offLastly, if you have UFW firewall enabled you can open the PostreSQL's port
5432to any TCP incoming traffic by executing the below command:
$ sudo ufw allow from any to any port 5432 proto tcp Rule added Rule added (v6)If you wish to make your firewall rules more strict visit our How to Open/Allow incoming firewall port guide for more information.