<\/span><\/h2>\n\n\n\nLog in to your Ubuntu 20.04 VPS<\/p>\n\n\n\n
ssh root@IP_Address -p Port_number<\/pre>\n\n\n\nMake sure to replace \u201cIP_Address\u201d and \u201cPort_number\u201d with your server\u2019s actual IP address and SSH port number.<\/p>\n\n\n\n
Once logged in, you can check whether you have the proper Ubuntu version installed on your server with the following command:<\/p>\n\n\n\n
# lsb_release -a<\/pre>\n\n\n\nYou should get this output:<\/p>\n\n\n\n
Distributor ID: Ubuntu\nDescription: Ubuntu 20.04 LTS\nRelease: 20.04\nCodename: focal<\/pre>\n\n\n\nThen, run the following command to make sure that all installed packages on the server are updated to the latest available version.<\/p>\n\n\n\n
# apt update && apt upgrade -y<\/pre>\n\n\n\n<\/span>Step 2. Install PostgreSQL server<\/span><\/h2>\n\n\n\nWhen writing this tutorial, the default PostgreSQL version in the repository is PostgreSQL 12. Let’s run the following command to install PostgreSQL server.<\/p>\n\n\n\n
# apt install postgresql postgresql-client postgresql-client-common postgresql-common postgresql-contrib -y<\/pre>\n\n\n\nOnce installed, the service will automatically be started, you can check the status with this command:<\/p>\n\n\n\n
# systemctl status postgresql<\/pre>\n\n\n\nIt will show you the status<\/p>\n\n\n\n
root@ubuntu-20:~# systemctl status postgresql\n\n\u25cf postgresql.service - PostgreSQL RDBMS\n Loaded: loaded (\/lib\/systemd\/system\/postgresql.service; enabled; vendor preset: enabled)\n Active: active (exited) since Tue 2020-05-19 04:39:03 CEST; 25 minutes ago\n\nMain PID: 137654 (code=exited, status=0\/SUCCESS)\nTasks: 0 (limit: 2286)\nMemory: 0B\nCGroup: \/system.slice\/postgresql.service\nMay 19 04:39:03 ubuntu-20 systemd[1]: Starting PostgreSQL RDBMS...\nMay 19 04:39:03 ubuntu-20 systemd[1]: Finished PostgreSQL RDBMS.<\/pre>\n\n\n\n<\/span>Step 3. Configure PostgreSQL<\/span><\/h2>\n\n\n\nBy default, the PostgreSQL server will listen on localhost. If you want to access from another network, we need to modify the configuration file to listen on all addresses or a specific address, this time we will make it listen on all addresses.<\/p>\n\n\n\n
# nano \/etc\/postgresql\/12\/main\/postgresql.conf<\/code><\/pre>\n\n\n\nlisten_addresses = '*'\n<\/code><\/pre>\n\n\n\nEdit the PostgreSQL configuration file (pg_hba.conf<\/code>) and enable md5 passwords for local connections to enable password authentication.<\/p>\n\n\n\n# nano \/etc\/postgresql\/12\/main\/pg_hba.conf<\/code><\/pre>\n\n\n\nReplace the following:<\/p>\n\n\n\n
local all postgres peer\nlocal all all peer\n<\/code><\/pre>\n\n\n\nWith this one:<\/p>\n\n\n\n
local all postgres md5\nlocal all all md5\n<\/code><\/pre>\n\n\n\nRestart the PostgreSQL service to apply the changes with the following command<\/p>\n\n\n\n
# systemctl restart postgresql \n<\/code><\/pre>\n\n\n\nNow, if you want to access the PostgreSQL shell using user ‘postgres’, you will be asked for the password you created earlier.<\/p>\n\n\n\n
root@ubuntu-20:~# su - postgres\npostgres@ubuntu-20:~$ psql\nPassword for user postgres:\npsql (12.2 (Ubuntu 12.2-4))\nType \"help\" for help.\npostgres=#<\/code><\/pre>\n\n\n\n