FerretDB Installation Steps
FerretDB is an open-source project that aims to provide a MongoDB-compatible API (converting the MongoDB 5.0+ wire protocol queries to SQL) using a different database engine (PostgreSQL or SQLite ) on the backend. One common use case is running FerretDB with PostgreSQL as its database engine. This setup can be beneficial for organizations that prefer PostgreSQL for its reliability, advanced features, and open-source nature, but still need a MongoDB-compatible API for their applications.
FerretDB functions as a drop-in replacement for MongoDB 5.0+ in many cases. Features are constantly being added to further increase compatibility and performance.
Benefits of Using FerretDB with PostgreSQL:
Compatibility: Offers a MongoDB-like API while using PostgreSQL’s mature feature set.
Cost-Effective: Suitable for those who prefer open-source solutions without vendor lock-in.
Performance: PostgreSQL’s robust indexing and query optimization can enhance database operations.
I will install FerretDB version 1.21 on Oracle Linux Server release 8.7 using RPM packages and configure it to listen on port 27002.
[root@ferret01 Downloads]# curl -L -o ferretdb.rpm https://github.com/FerretDB/FerretDB/releases/download/v1.21.0/ferretdb-linux-amd64.rpm
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 20.3M 100 20.3M 0 0 7083k 0 0:00:02 0:00:02 --:--:-- 10.3M
[root@ferret01 Downloads]# ls -ls
total 20812
20812 -rw-r--r-- 1 root root 21309814 May 4 21:55 ferretdb.rpm
[root@ferret01 Downloads]# rpm -i ferretdb.rpm
Install PostgreSQL Database for FerretDB backend. You may also use your PostgreSQL Database Server running on different host.
[root@ferret01 ~]# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[root@ferret01 ~]# dnf -qy module disable postgresql
[root@ferret01 ~]# dnf install -y postgresql16-server postgresql16
[root@ferret01 ~]# /usr/pgsql-16/bin/postgresql-16-setup initdb
Initializing database ... OK
[root@ferret01 ~]# systemctl enable postgresql-16
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-16.service → /usr/lib/systemd/system/postgresql-16.service.
Modify the PostgreSQL database to listen on all IP addresses and configure the network access rules in pg_hba.conf.
[root@ferret01 ~]# vi /var/lib/pgsql/16/data/postgresql.conf
...
-- modified listen port
listen_addresses = '*'
...
[postgres@ferret01 ~]$ vi /var/lib/pgsql/16/data/pg_hba.conf
...
host all all 192.168.60.0/24 scram-sha-256
...
[root@ferret01 ~]# systemctl start postgresql-16
Create a database for FerretDB to store MongoDB Collections as tables/relations.
postgres=# create database ferretdb WITH ENCODING='UTF8' LC_CTYPE='C' TEMPLATE=template0;
CREATE DATABASE
Now you may use it store MongoDB collections. Let’s start it.
[postgres@ferret01 ~]$ ferretdb --postgresql-url="postgres://192.168.60.202:5432/ferretdb" --listen-addr="192.168.60.202:27002"
It will utilize the PostgreSQL database located at 192.168.60.202:5432/ferretdb as the backend, and serve from 192.168.60.202:27002.

Using FerretDB with PostgreSQL gives developers a practical solution. It offers the familiar MongoDB-style interface while benefiting from the reliability and robust features of PostgreSQL.
Hope it helps.


Leave your comment