Sign In
Sign In

How to Set Up Physical Streaming Replication with PostgreSQL on Ubuntu

How to Set Up Physical Streaming Replication with PostgreSQL on Ubuntu
Hostman Team
Technical writer
PostgreSQL
20.12.2024
Reading time: 8 min

Streaming replication is a common method for horizontally scaling relational databases. It involves one or more copies of the same database cluster operating on different devices. The primary database cluster handles both read and write operations, while the replicas are read-only. We can also use streaming replication to provide high availability: if the primary database cluster or server fails unexpectedly, the replicas can continue handling read operations, or one of them can be promoted to become the new primary cluster.

PostgreSQL, a popular relational database, supports both logical and physical replication:

  • Logical replication streams high-level changes from the primary cluster to replicas, allowing you to replicate changes to a single database or table.

  • Physical replication, on the other hand, streams changes from the Write-Ahead Log (WAL) files, copying the entire cluster's state rather than specific areas. This method ensures that all changes to the primary cluster are replicated.

This guide will help you set up physical streaming replication with PostgreSQL on Ubuntu 22.04 across two separate devices, each running PostgreSQL 17 clusters. One device will host the primary cluster, and the other will serve as the replica.

Hostman offers a cloud PostgreSQL for your projects. 

Prerequisites

To follow this tutorial, you will need:

  • Two separate devices running Ubuntu 22.04: One will act as the primary server and the other as the replica.
  • Firewall settings that allow HTTP/HTTPS traffic and traffic on port 5432 (the default port for PostgreSQL 17).
  • PostgreSQL 17 installed and running on both servers.

Step 1: Configuring the Primary Database to Accept Connections

The first step is to configure the primary database to allow connections from the replica(s). By default, PostgreSQL only accepts connections from localhost (127.0.0.1). To change this behavior, you need to modify the listen_addresses configuration parameter in the primary database.

On the primary server, open the PostgreSQL configuration file postgresql.conf, located in the /etc/postgresql/17/main/ directory:

sudo nano /etc/postgresql/17/main/postgresql.conf

Once the file is open, find the listen_addresses variable and change its value from localhost to the IP address of the primary server. Remove the # symbol at the beginning of the line as well:

listen_addresses = 'your_primary_IP_address'

Save the changes and exit the file.

The primary database is now ready to accept connections from other devices using the specified IP address. Next, you need to create a user role with the appropriate permissions that the replica will use to connect to the primary database.

Step 2: Creating a Replication Role with Permissions

Next, you need to create a dedicated role in the primary database with permissions for database replication. The replica will use this role to connect to the primary database. Creating a specific role for replication is crucial for security, as the replica will only have permission to copy data, not modify it.

  1. Connect to the database cluster:

Log in as the postgres user by running:

sudo -u postgres psql
  1. Create a replication role:

Use the CREATE ROLE command to set up a role for replication:

CREATE ROLE test WITH REPLICATION PASSWORD 'testpassword' LOGIN;

This will output:

CREATE ROLE

We have now created the test role with the password testpassword, which has replication permissions for the database cluster.

  1. Configure access for replication:

PostgreSQL has a special pseudo-database, replication, which replicas use to connect. To allow access, edit the pg_hba.conf file. Exit the PostgreSQL prompt by typing:

\q

Then open the configuration file using nano or your preferred editor:

sudo nano /etc/postgresql/17/main/pg_hba.conf
  1. Add a rule for the replica:

Append the following line to the end of the pg_hba.conf file:

host  replication   test  your-replica-IP/32  md5
  • host: Enables non-local connections over plain or SSL-encrypted TCP/IP sockets.

  • replication: Specifies the special pseudo-database used for replication.

  • test: Refers to the previously created replication role.

  • your-replica-IP/32: Restricts access to the specific IP address of your replica.

  • md5: Sets the authentication method to password-based.

If you plan to create multiple replicas, repeat this step for each additional replica, specifying its IP address.

  1. Restart the primary database cluster:

To apply these changes, restart the primary cluster:

sudo systemctl restart postgresql@17-main

If the primary cluster restarts successfully, it is properly configured and ready to stream data once the replica connects. Next, proceed with configuring the replica cluster.

Step 3: Backing Up the Primary Cluster to the Replica

During the setup of physical replication with PostgreSQL, you need to perform a physical backup of the primary cluster’s data directory to the replica’s data directory. Before doing this, you must clear the replica’s data directory of all existing files. On Ubuntu, the default data directory for PostgreSQL is /var/lib/postgresql/17/main/.

To find the data directory, you can run the following command on the replica database:

SHOW data_directory;

Once you locate the data directory, run the following command to clear all files:

sudo -u postgres rm -r /var/lib/postgresql/17/main/*

Since the files in the default data directory are owned by the postgres user, you need to run the command as postgres using sudo -u postgres.

Note: If a file in the directory is corrupted and the command does not work (this is very rare), you can remove the main directory entirely and recreate it with the correct permissions:

sudo -u postgres rm -r /var/lib/postgresql/17/main
sudo -u postgres mkdir /var/lib/postgresql/17/main
sudo -u postgres chmod 700 /var/lib/postgresql/17/main

Now that the replica’s data directory is cleared, you can physically back up the primary server’s data files. PostgreSQL provides a useful utility called pg_basebackup to simplify this process. It even allows you to promote the server to standby mode using the -R option.

Run the following pg_basebackup command on the replica:

sudo -u postgres pg_basebackup -h primary-ip-addr -p 5432 -U test -D /var/lib/postgresql/17/main/ -Fp -Xs -R
  • -h: Specifies the remote host. Enter the IP address of your primary server.

  • -p: Specifies the port number for connecting to the primary server. By default, PostgreSQL uses port 5432.

  • -U: Specifies the user role to connect to the primary cluster (the role created in the previous step).

  • -D: Specifies the backup's destination directory, which is your replica's cleared data directory.

  • -Fp: Ensures the backup is output in plain format (instead of a tar file).

  • -Xs: Streams the contents of the WAL file during the backup from the primary database.

  • -R: Creates a file named standby.signal in the replica’s data directory, signaling that the replica should operate in standby mode. It also adds the connection information for the primary server to the postgresql.auto.conf file. This configuration file is read each time the standard postgresql.conf is read, but the values in the .auto.conf file override those in the regular configuration file.

When you run this command, you will be prompted to enter the password for the replication role created earlier. The time required to copy all the files depends on the size of your primary database cluster.

At this point, your replica now has all the necessary data files from the primary server to begin replication. Next, you need to configure the replica to start in standby mode and proceed with replication.

Step 4: Restarting and Testing Clusters

After successfully creating a backup of the primary cluster’s data files on the replica, you need to restart the replica database cluster and switch it to standby mode. To restart the replica, run the following command:

sudo systemctl restart postgresql@17-main

Once the replica has restarted in standby mode, it should automatically connect to the primary database cluster on the other machine. To check whether the replica is connected and receiving the stream from the primary server, connect to the primary database cluster with the following command:

sudo -u postgres psql

Next, query the pg_stat_replication table on the primary cluster as follows:

SELECT client_addr, state FROM pg_stat_replication;

The output should look something like this:

client_addr     | state
----------------+-----------
your_replica_IP | streaming

If you see this result, the streaming replication from the primary server to the replica is correctly set up.

Conclusion

You now have two Ubuntu 22.04 servers with PostgreSQL 17 clusters, and streaming replication is configured between the servers. Any changes made in the primary database cluster will be reflected in the replica cluster. You can add more replicas if your databases need to handle higher traffic.

To learn more about physical streaming replication, including how to configure synchronous replication to prevent the loss of critical data, refer to the official PostgreSQL documentation.

PostgreSQL
20.12.2024
Reading time: 8 min

Similar

PostgreSQL

Upgrading PostgreSQL Version

In PostgreSQL, version upgrading is performed in different ways: Installing packages with a new version of PostgreSQL. It is suitable only for minor updates. Before performing the update, study the release notes; Using the standard pg_dumpall program. It is a reliable method, but there may be a long downtime. Using the standard pg_upgrade program. Another quick way to upgrade, but errors may occur. Updating via logical replication. This option has minimal downtime but is only suitable for PostgreSQL versions greater than 10.0. Earlier versions require extensions. The choice depends on which release is used on the server and which version you want to upgrade to. In this article, we will look at all the above upgrade methods. If you have some troubles while using PostgreSQL, check our instruction on how to set up your database. Important notes before upgrading The main thing is to understand the peculiarities of updates between different versions. The numbers consist of two digits, for example, 10.1. The first digit is the major version number (10). The second digit is the minor release number (1). Before PostgreSQL 10, the version numbers consisted of three digits. For example, in 9.6.3, 9.6 is the major release number and 3 is the minor version number. You must understand this difference to choose the right upgrade method. In minor versions, the data storage format does not change, so there are no compatibility problems. Therefore, the transition from PostgreSQL 10.1 to 10.6 can be carried very easily. To upgrade, turn off the server, replace the executable files, and start the server again. However, the documentation notes that some releases may require manual changes. Therefore, always read the release notes before upgrading. In major versions, the data format may change. This makes updating more difficult. You need to either unload the data and upload it again, use the pg_upgrade program, or use logical replication. We'll talk about all these methods below. Upgrading within one major version Let's look at how to update Postgresql Version 14.1 to PostgreSQL 14.3 on an Ubuntu server. PostgreSQL is available on Ubuntu by default. Start with the command: sudo apt-get upgrade Debian and Ubuntu only release one version of PostgreSQL per OS release. For example, Debian Squeeze/6.0 only has PostgreSQL 8.4. If you need a different version of PostgreSQL, use packages from PGDG. If you want the latest version of PostgreSQL, you must first install the Postgres repository. Add a repository: sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' Import the signing key: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - Update the list of packages in the system: sudo apt-get update Install the required Postgres version: sudo apt-get -y install postgresql-14.3 To view the list of installed DBMSs, run: dpkg --get-selections | grep postgres Also see the list of clusters: pg_lsclusters Stop PostgreSQL before making changes: sudo service postgresql stop When Postgres packages are installed, they create a default cluster for you. You should rename the new Postgres cluster so there are no conflicts with the old cluster name when upgrading. sudo pg_renamecluster 14.3 main main_pristine Upgrade the old cluster: sudo pg_upgradecluster 14.1 main Start the service: sudo service postgresql start Check the list of clusters again and make sure the new one is working: pg_lsclusters Get rid of the old cluster: sudo pg_dropcluster 14.1 main Upgrading via pg_dumpall If you need to change the major version, use the pg_dumpall program. The essence of this method is to unload data from one main version and then load it into another. Before unloading data, make sure that no changes are being made to the database right now. Otherwise, some of the changes may not be included in the final dump. Get the dump and write it to a file: pg_dumpall > output_file Stop the server: pg_ctl stop Change the name of the old directory to eliminate name conflicts: mv /usr/local/pgsql /usr/local/pgsql.old The old directory can simply be deleted. But it would be wiser to rename it to leave room for restoring data. Instead of /usr/local/pgsql, specify the path to your directory. Install the new version from source. There is a detailed guide in the documentation.  Form a new cluster: /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data Transfer all changes to the pg_hba.conf and postgresql.conf files. Start the database server: /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data Restore data from backup: /usr/local/pgsql/bin/psql -d postgres -f output_file The disadvantage of this method is that the server will be turned off for a long time. To reduce downtime, you can install the new server in a different directory and then run the old and new servers on different ports. To transfer data, use the command: pg_dumpall -p 5432 | psql -d postgres -p 5433 Instead of 5432 and 5433, specify the port numbers on which you ran the servers. Upgrading via pg_upgrade To avoid unloading and uploading data, use the pg_upgrade program. It helps you update faster. The pg_upgrade program creates system tables anew, taking into account changes in the PostgreSQL latest versions. In this case, the old data files are retained. In addition, pg_upgrade verifies that the clusters are compatible. The pg_upgrade program helps you upgrade from PostgreSQL 8.4.X to the current DBMS release. Let's look at a general upgrade plan using pg_upgrade. Move the old cluster. This must be done if the directory was not linked to the old release. For example, it is located at /usr/local/pgsql. If you do not rename it, a conflict will occur during the update. Renaming is performed when the server is turned off with the command: mv /usr/local/pgsql /usr/local/pgsql.old Build a new version from source. Adjust configure so that the flags are compatible with the old cluster configuration. Before starting the upgrade, pg_upgrade will check the compatibility of the flags. Install new executable files. To place the server in a non-standard directory, use prefix: make prefix=/usr/local/pgsql.new install Use initdb to initialize a new cluster. Check that the flags are compatible with the flags of the old cluster. Install extension shared object files. If updates are available, pg_upgrade will automatically create a script for their subsequent installation. Transfer full text search files. Configure peer authentication in pg_hba.conf. This needs to be done because pg_upgrade will connect to the old and new hosts multiple times. Check that the old and new servers are stopped: pg_ctl -D /opt/PostgreSQL/9.6 stoppg_ctl -D /opt/PostgreSQL/14 stop Run pg_upgrade from the new server. First, call the program in check mode by adding the flag: pg_upgrade --check In response, you will receive a list of adjustments that need to be made manually after the upgrade. If you made changes to the pg_hba.conf file, restore it to its previou state. Sometimes, other configurations on the new cluster need to be changed to match the settings of the old cluster. Start the server. If you are satisfied with the result, delete the old cluster. For details and features of using pg_upgrade, see the documentation. Using Logical Replication Starting from the 10th version of PostgreSQL, we have a method for logical replication of data objects and changes in them. It is based on the use of replication identifiers; usually, they are primary keys. Logical replication uses the publish-subscribe model. The user creates a snapshot of the published database and copies it to the subscriber. In the PostgreSQL documentation, one of the typical scenarios for using logical replication is precisely the replication between different major versions of PostgreSQL. The backup server can be located on the same or different host. After synchronization is complete, various options are available. For example, you can make the new server the main one and turn off the old one. The main advantage of logical replication is minimal downtime. Server interruption, in some cases, is limited to a few seconds. Conclusion We looked at universal methods for upgrading PostgreSQL to a new major version and updating within one major version. Using this guide, you can select the method that works best for your particular case and update your current version of PostgreSQL. Hostman provides pre-configured and ready-to-use cloud databases, including cloud PostgreSQL. Frequently Asked Questions How to check PostgreSQL version on my server? You can run psql --version in the terminal or connect to your DB and run SELECT version();. How do I upgrade PostgreSQL to a new version? Use pg_dumpall to back up, install the new version, and restore your data. What is the difference between pg_upgrade and pg_dump? pg_upgrade is quicker and keeps configs. pg_dump is better if you want full control. Do I need to uninstall the old PostgreSQL version? Nope, you can keep both temporarily to ease migration.
16 June 2025 · 8 min to read
PostgreSQL

How to Migrate a PostgreSQL Database to Another Server

When working with PostgreSQL, you might eventually need to transfer a database from one server to another. Despite seeming complex, PostgreSQL migration can be accomplished using PostgreSQL's built-in tools. This article outlines various methods to transfer a PostgreSQL database from one server to another on Ubuntu 22.04. Prerequisites To migrate a Postgres database, you will need: A current server running Ubuntu 22.04 with PostgreSQL installed. The database to be transferred should already exist in PostgreSQL. A new cloud server or virtual machine with Ubuntu 22.04 and affordable cloud PostgreSQL pre-installed. This article uses PostgreSQL version 15. On Hostman, you can easily deploy such a server by choosing the PostgreSQL image when creating a server. Optionally, the pgAdmin client application for connecting and managing PostgreSQL databases. PgAdmin can be installed on any OS, including Windows, Linux, and macOS. Preparation Before Database Transfer Before starting the Postgres migration, ensure that both servers have: A network connection between them. Use tools like ping and telnet to verify this (with telnet, check ports 22 and 5432). Ports 22 (SSH) and 5432 (PostgreSQL) open. Enough free disk space. Configuring PostgreSQL for Remote Connections Ensure PostgreSQL can accept remote connections on both servers: Edit the postgresql.conf file. If using a different version, replace 15 with your version number: nano /etc/postgresql/15/main/postgresql.conf Find the listen_addresses parameter. By default, it is commented out and accepts only local connections (localhost). Allow remote connections from specific addresses or all addresses (for testing purposes, use *): listen_addresses = '*' In production environments, specify only the required addresses.  Save and exit the file. Edit the pg_hba.conf file: nano /etc/postgresql/15/main/pg_hba.conf Find the line for IPv4 local connections (# IPv4 local connections) and update it to allow connections from specific addresses or all addresses for testing: host all all 0.0.0.0/0 md5 Save and exit the file. Restart the PostgreSQL server: systemctl restart postgresql Set a strong password for the PostgreSQL user on both servers: sudo -i -u postgres psql In the psql console run: ALTER USER postgres WITH PASSWORD 'nsH7z*0kl>&7?7'; Where postgres is the username and nsH7z*0kl>&7?7 is the password. Transferring the Database Using pg_dump and psql Typically, transferring a database involves three steps: Creating a backup of the database. Transferring the backup to the target server. Restoring the database on the new server. These steps can be performed using PostgreSQL's pg_dump and psql tools. Transferring a Database For instance, let's look at transferring a database named e_commerce from a server with IP 166.1.227.252 to a server with IP 91.206.179.207. Create the target database beforehand: CREATE DATABASE e_commerce; Then run: pg_dump -h localhost -U postgres e_commerce | psql -h 91.206.179.207 -U postgres e_commerce Explanation: pg_dump creates a backup of the database. -h localhost specifies the database server address. -U postgres specifies the username. e_commerce is the database name on the current and new server.  psql connects to the remote PostgreSQL server and loads the database. -h 91.206.179.207 specifies the target server address. Transferring Without Remote Access If remote access is unavailable, save the database to a file, transfer it using scp, and restore it on the target server: pg_dump -h localhost -U postgres e_commerce > e_commerce.sql && scp e_commerce.sql db-admin@91.206.179.207:/var/lib/postgresql When executing the command, the password for the postgres system user will be requested, not the password for the postgres user defined within the database. Where: pg_dump creates a database backup; -h localhost is the address of the server (IP address or domain name) where the database is located. In this example, the database server address matches the server address itself. If the database is on another server and network access is available, you can specify the address of the remote database; -U postgres is the username used to connect to the database; e_commerce is the name of the database to be transferred; e_commerce.sql is the name of the file in .sql format where the database will be saved; scp is a utility for secure file copying between hosts. It uses the SSH protocol for data transfer and protection; db-admin@91.206.179.207:/var/lib/postgresql means username_on_remote_server@address_of_remote_server:full_path where the backup file will be saved. After entering the command, you first need to enter the password for the database user account (in this example, it is the postgres user), and then enter the password for the remote server user (in this example, it is the db-admin user). Now you need to upload the file to the database. Run these commands on the target server. Create a database in psql: CREATE DATABASE e_commerce; Then, exit psql and run in the terminal: psql e_commerce < e_commerce.sql Creating a Compressed Archive For larger databases, create a compressed archive: pg_dump -h localhost -U postgres e_commerce > e_commerce.tar.gzip && scp e_commerce.tar.gzip db-admin@91.206.179.207:/var/lib/postgresql Restore from the archive: psql e_commerce < e_commerce.tar.gzip Adding a Timestamp to the Archive Name If you need to know the exact date and time that the database was backed up, you can include it in the name of the file being created.  To do this, use the date command and the date format. The example below will use the day-month-year date format: pg_dump -h localhost -U postgres e_commerce > e_commerce_$(date +%d-%m-%y).sql Transferring the Database Using pgAdmin Alternatively, you can use pgAdmin's graphical interface for the Postgres database migration. Backup Database Launch pgAdmin: Open pgAdmin and connect to your PostgreSQL server. Register Server: Right-click on Object Explorer, select Register, then Server. Configure Connection: Name: In the General tab, enter a name for the connection (e.g., my_db). Next, go to the Connection tab and specify: Host name/address: Specify the IP address or domain name of the PostgreSQL server. Port: Default is 5432; change if needed. Maintenance database: Name of the database for backup. Username and Password: Enter credentials for database access. Connect: Click Save to connect. If successful, the database appears on the left sidebar. Backup Database: Right-click on the database name and select Backup.   Set a Filename for the backup file. Choose a Format and Encoding (UTF8 recommended). Select specific Objects to include. Click Backup to start. Restore Database Prepare New Database: Open psql shell. Execute: CREATE DATABASE e_commerce; Connect to PostgreSQL Server: In pgAdmin, connect to the new PostgreSQL server, selecting e_commerce as the database. Restore Database: Right-click on the database name and choose Restore. Set the Format (ensure it matches the backup file). Specify the Filename of the backup file. Click Restore to begin. Wait for the Process completed confirmation. Conclusion PostgreSQL offers several methods to migrate databases between servers, including using built-in tools for flexible and robust database backups and transfers. If you've ran into some troubles, check our instruction on how to create server on Ubuntu.
15 May 2025 · 6 min to read
PostgreSQL

Installing PostgreSQL on Debian

PostgreSQL is an advanced open-source relational database management system (DBMS). There are two ways to install it on Debian 11: from the operating system repository or the official PostgreSQL repository. In this article, you will learn both methods, as well as how to perform common operations like creating roles and databases. Don't forget to check how to configure static IP address on Debian. Installation from the Debian 11 repository On Debian, you can install PostgreSQL directly from the system repository. First, update your package list. Launch the terminal and run: sudo apt update && sudo apt upgrade The PostgreSQL package is available in the Debian repository, so you can install it using the apt utility. To do this, run: sudo apt install postgresql postgresql-contrib Once the installation is complete, check the status of the service using the command: sudo systemctl status postgresql If the service does not start automatically, you can start it manually. To do this, run: sudo systemctl start postgresql To stop a running service, run: sudo systemctl stop postgresql Before configuring PostgreSQL on Debian, make sure the service is running. Installation from the official PostgreSQL repository If you want to use only the latest versions of Postgres, we recommend using the official PostgreSQL repository for installation and subsequent updates. First of all, you need to add the GPG signing key. This is a security requirement to verify the authenticity of the PostgreSQL repository. To do this, launch a terminal and run: curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg Now you are ready to add the Postgres repository. Use the following command: echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt/bulseye-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql.list After successfully integrating the PostgreSQL library, you can install the DBMS. But before you do that, update the system repository using the command: sudo apt update After updating, run the following command to install PostgreSQL on Debian: sudo apt install postgresql Installation is completed. Now you can proceed to the basic configuration of PostgreSQL. Basic setup When installing Postgres, the postgres user is automatically created. You can use this account for your first connection. Switch to the postgres user: sudo su - postgres Run the psql utility which is a shell for managing PostgreSQL: psql You can now interact with the PostgreSQL server. To exit the shell, enter: \q You can use the following command to access the Postgres command line without switching users: sudo -u postgres psql However, the postgres user is usually only used from localhost. If, for example, you use cloud databases, it is better to create a new role for the connection. Creating a role and a database The createuser command allows you to create new roles from the command line. Only superusers and roles with CREATEROLE privileges can create new roles. In the following example, we will create a new role named hostman and a database named hostman_db, and then grant the new role privileges to manage the database. First create a new role: sudo su - postgres -c "createuser hostman" Then create a new database: sudo su - postgres -c "createdb hostman_db" To grant the user permissions to the database, connect to the shell: sudo -u postgres psql Run the following query to grant the hostman user privileges to manage the hostman_db database: GRANT ALL PRIVILEGES ON DATABASE hostman_db TO hostman; You can create new roles and databases in the PostgreSQL shell. In this case, the syntax will be slightly different. To create a new role with a password, run: create user cloud with password 'hostmancloud'; To create a new database, run: create database cloud_db; Then you must also grant all privileges with the GRANT ALL PRIVILEGES ON DATABASE … TO … command. Setting up remote access By default, the Postgres server only listens on the local interface 127.0.0.1. This may be inconvenient. Let's say you have a server on Hostman with PostgreSQL installed. It will be much more convenient to connect to it remotely. To do this, you need to configure the server to listen to other network interfaces. To change the configuration, open the postgresql.conf file using any editor. This example uses the nano editor: sudo nano /etc/postgresql/12/main/postgresql.conf Find the CONNECTIONS AND AUTHENTICATION section and the line #listen_addresses = 'localhost' in the configuration file. Change the line value to listen_addresses = '*'. If you want the server to listen not to all network interfaces, but only to the selected one, specify it instead of an asterisk. Save the file and restart the Postgres service for the changes to take effect: sudo service postgresql restart The last step is to allow connections from the network. To install it, you need to edit the pg_hba.conf file. Open it in the editor: sudo nano /etc/postgresql/12/main/pg_hba.conf Find the IPv4 local connections line. Specify the desired network. For example, like this: TYPE DATABASE     USER ADDRESS                  METHOD host all hostman 38.62.228.244  md5 You can use other authentication methods. For a complete list, see the PostgreSQL documentation. Conclusion There are two ways to install managed PostgreSQL on Debian. The first option is to use the system repository. Its main advantage is speed. There is no need to install anything additional, just run one command. The downside is that the system repository does not always contain the latest version of the software. The second installation option is to use the official PostgreSQL repository. This method ensures that you are using the latest version of the DBMS. But you will have to perform a few more steps: first, add the official repository itself and only then install Postgres from it.
09 May 2025 · 5 min to read

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start.
Email us
Hostman's Support