Back to articles
AI & Cloud

Configure FerretDB with PostgreSQL: Solution to Run MongoDB Applications Without Commercial Licensing

Guide to configure FerretDB with PostgreSQL for running MongoDB applications without commercial licensing, ideal for small businesses and self-hosted setups.

DPTCloud Engineering4 min read
Configure FerretDB with PostgreSQL: Solution to Run MongoDB Applications Without Commercial Licensing

Image credit: StockSnap · Pixabay Content License

Configure FerretDB with PostgreSQL to Run MongoDB Applications Without Commercial Licensing

FerretDB is an open-source solution that allows you to run MongoDB applications without commercial licensing by using PostgreSQL as the backend instead of the native MongoDB. With this architecture, you can self-host, fully control your data, and avoid licensing fees—ideal for small businesses and self-hosted projects.

Introduction to FerretDB and Its Benefits

FerretDB is an open service that is fully compatible with the MongoDB protocol, enabling MongoDB applications to communicate with PostgreSQL as a backend database. This means you can use MongoDB tools and libraries such as mongoose, pymongo, or MongoDB Compass without changing your source code, while also benefiting from PostgreSQL’s powerful features like ACID compliance, replication, and backup capabilities.

Key advantages of FerretDB:

  • No need for commercial MongoDB licenses
  • Full compatibility with MongoDB protocol
  • Runs on PostgreSQL, leveraging features like ACID, replication, and backups
  • Cost-effective for small businesses and startups

Requirements and Prerequisites

To deploy FerretDB with PostgreSQL, you will need:

  • A Linux-based server or VPS (Ubuntu/Debian/CentOS)
  • PostgreSQL 12+ installed and running
  • Node.js 14+ or Go (if building FerretDB from source)
  • Network access and package installation capabilities

Configure FerretDB with PostgreSQL

Below is a step-by-step guide to configure FerretDB on a Linux server using PostgreSQL as the backend.

1. Install PostgreSQL

On Ubuntu, install PostgreSQL using the following commands:

sudo apt update
sudo apt install postgresql postgresql-contrib -y

After installation, start the service:

sudo systemctl start postgresql
sudo systemctl enable postgresql

2. Create Database and User for FerretDB

Log in to PostgreSQL:

sudo -u postgres psql

Create the database and user:

CREATE DATABASE ferretdb;
CREATE USER ferretdb_user WITH PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE ferretdb TO ferretdb_user;

3. Install FerretDB

The simplest method is using Docker:

docker run -d \
  --name ferretdb \
  -p 27017:27017 \
  -e FERRETDB_POSTGRES_HOST=your-postgres-host \
  -e FERRETDB_POSTGRES_PORT=5432 \
  -e FERRETDB_POSTGRES_USER=ferretdb_user \
  -e FERRETDB_POSTGRES_PASSWORD=your_secure_password \
  -e FERRETDB_POSTGRES_DATABASE=ferretdb \
  ferretdb/ferretdb:latest

Replace your-postgres-host with the IP address or hostname of your PostgreSQL server.

4. Verify Connection

Run the following command to verify FerretDB is running:

mongosh --host localhost --port 27017

If the connection succeeds, you will see the MongoDB shell interface.

Self-Hosted Solution for Small Businesses

Using FerretDB with PostgreSQL helps small businesses:

  • Avoid MongoDB Atlas or commercial service licensing fees
  • Retain full control over data, backups, and recovery
  • Optimize costs by using VPS or dedicated servers
  • Easily integrate with existing systems like ClickHouse, Metabase

Troubleshooting and Verification

If FerretDB fails to start:

  • Check PostgreSQL connection: psql -h your-postgres-host -U ferretdb_user -d ferretdb
  • Review Docker logs: docker logs ferretdb
  • Ensure port 27017 is not blocked by the firewall

References

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478