- What is pgmer2?
- How to Launch the Project within Docker
- Using psql
- How to Launch Manually
- Connecting to the Database
pgmer2 is a PostgreSQL Foreign Data Wrapper (FDW) for the MeritRank service.
The Foreign Data Wrapper (FDW) is a PostgreSQL extension that enables you to access and manipulate data from external sources as if they were local tables, facilitating seamless integration and real-time querying without the need to move data.
If you prefer not to read through all the steps and copy-paste commands, here’s a single command that prepares everything for you:
sudo apt install docker git && \
git clone https://github.com/Intersubjective/meritrank-service-rust.git && \
cd meritrank-service-rust && \
docker build -t mr-service -f ./Dockerfile .. && \
cd .. && \
git clone https://github.com/Intersubjective/meritrank-psql-connector.git && \
cd meritrank-psql-connector && \
docker build -t mr-psql-connector -f ./Dockerfile .. && \
docker network create my-network && \
docker run --network my-network -p 10234:10234 -e MERITRANK_SERVICE_URL=tcp://0.0.0.0:10234 --detach --name container1 mr-service && \
docker run --network my-network -e POSTGRES_PASSWORD=postgres -e MERITRANK_SERVICE_URL=tcp://container1:10234 --detach --name container2 -p 5432:5432 mr-psql-connector:latest
Before executing any commands, ensure that you have git
and docker
installed. We will build both the service and the psql-connector
.
git clone https://github.com/Intersubjective/meritrank-service-rust.git
cd meritrank-service-rust/
docker build -t mr-service -f ./Dockerfile ..
cd ..
git clone https://github.com/Intersubjective/meritrank-psql-connector.git
cd meritrank-psql-connector/
docker build -t mr-psql-connector -f ./Dockerfile ..
A shared network is essential for enabling seamless communication between the two Docker containers, mr-service
and mr-psql-connector
. By creating a custom network named my-network
, both containers can resolve each other's names directly, facilitating the connection specified in the MERITRANK_SERVICE_URL
. This setup allows mr-psql-connector
to access mr-service
using its container name (container1
) as the hostname, eliminating the need for hardcoded IP addresses.
docker network create my-network
Execute the following command to run mr-service
:
docker run --network my-network -p 10234:10234 -e MERITRANK_SERVICE_URL=tcp://0.0.0.0:10234 --name container1 mr-service
--network my-network
: Connects to the shared network created earlier.-p 10234:10234
: Makes the service accessible outside of the container.- The address
tcp://0.0.0.0
indicates that the service listens on all available network interfaces within the container, allowing connections from any IP address that can reach it on port10234
.
Next, execute this command to run mr-psql-connector
:
docker run --network my-network -e POSTGRES_PASSWORD=postgres -e MERITRANK_SERVICE_URL=tcp://container1:10234 --name container2 -p 5432:5432 mr-psql-connector:latest
--network my-network
: Connects to the shared network created earlier.-e POSTGRES_PASSWORD=postgres
: Sets an environment variable required to establish a password for the default PostgreSQL user; omitting this will result in an error.- The connection string
MERITRANK_SERVICE_URL=tcp://container1:10234
connects to ourmr-service
, which is mapped to port10234
. --name container2
: Assigns a specific name to this container.-p 5432:5432
: Makes this service accessible outside of the container.
You can now open an interactive shell session as the postgres user inside container2
, allowing you to manage and interact with your PostgreSQL database directly from within the container.
docker exec -it container2 su - postgres && psql
Here are some basic commands you can use:
\df
SELECT mr_service_url();
SELECT mr_service();
SELECT mr_create_context('my-context');
If you prefer not to read through all these steps or copy-paste commands, here’s a single command that also checks if Rust is already installed on your system:
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config rustc clang git cmake && \
if command -v rustc &> /dev/null; then echo "Rust is already installed"; else curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh && source "$HOME/.cargo/env"; fi && \
git clone https://github.com/Intersubjective/meritrank-service-rust.git && \
git clone https://github.com/Intersubjective/meritrank-psql-connector.git
Next, navigate to the directory and launch meritrank-service-rust
:
cd meritrank-service-rust && cargo run > log.txt 2>&1
cd ../meritrank-psql-connector
cargo install --locked cargo-pgrx
cargo pgrx init
cargo pgrx run
To launch the project, you need to install several dependencies. The installation command for Debian-based distributions is as follows:
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config
sudo apt-get install rustc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install rustup
source "$HOME/.cargo/env" # Add Rust to PATH
sudo apt-get install clang git
Before working with meritrank-psql-connector
, you also need to install and launch the service in the background:
git clone https://github.com/Intersubjective/meritrank-service-rust.git
Here is how your folder structure should look:
intersubjective/
├── meritrank-psql-connector
└── meritrank-service-rust
Navigate to the directory and launch meritrank-service-rust
:
cd meritrank-service-rust
cargo run
Clone this repository:
git clone https://github.com/Intersubjective/meritrank-psql-connector.git
cd meritrank-psql-connector
Some of these steps are described on pgrx’s GitHub page:
cargo install --locked cargo-pgrx
cargo pgrx init
This command downloads all currently supported PostgreSQL versions, compiles them into ${PGRX_HOME}
, and runs initdb
.
You may want to run automated tests:
export RUST_TEST_THREADS=1
cargo pgrx test
If tests complete without errors, execute:
cargo pgrx run
You can now enter psql and perform actions with MeritRank’s service through the psql connector.
Log in as the postgres user, enter your default password, and execute psql
:
su - postgres
psql
Here are some commands to ensure that the service is functioning correctly:
\df
SELECT mr_service_url();
SELECT mr_service();
SELECT mr_create_context('my-context');