Install from source

This document describes how to build and install PGroonga from source.

Build and install instruction is different between on Windows and on non Windows. This document describes it separately.

On non Windows

Install PostgreSQL.

Install Groonga. We recommend that you use package. If you use package to install Groonga, install the following package:

Extract PGroonga source:

$ wget https://packages.groonga.org/source/pgroonga/pgroonga-4.0.8.tar.gz
$ tar xvf pgroonga-4.0.8.tar.gz
$ cd pgroonga-4.0.8

FYI: If you want to use the unreleased latest version, use the followings:

$ git clone --recursive https://github.com/pgroonga/pgroonga.git
$ cd pgroonga

Build and install PGroonga with Meson and Ninja:

$ meson setup build
$ meson compile -C build
$ sudo meson install -C build

If pg_config command doesn't exist in your PATH, specify it explicitly with the pg_config option:

$ meson setup build -Dpg_config=/path/to/pg_config

If you get any error, confirm the followings:

If pg_config command doesn't exist, you may forget to install the development package of PostgreSQL.

If pkg-config --list-all doesn't include groonga, you may forget to install the development package of Groonga. Or groonga.pc is installed into non-standard directory. You can use PKG_CONFIG_PATH environment variable for the case.

Here is an example when you install Groonga with --prefix=/usr/local:

$ PKG_CONFIG_PATH=/usr/local/lib/pkgconfig meson setup build

If you use SELinux, you must create a policy package(.pp) and install it. PGroonga makes PostgreSQL map <data dir>/pgrn* files into memory, which is not allowed by default. First, install policycoreutils and checkpolicy.

$ sudo dnf install policycoreutils checkpolicy

Let's assume that PostgreSQL binaries are of type postgresql_t and PostgreSQL data files are of type postgresql_db_t. Allow postgresql_t type to memory map files of type postgresql_db_t. Then compile it (.mod), package it (.pp) and install the resulting policy package.

$ cat > my-pgroonga.te << EOF
module my-pgroonga 1.0;

require {
    type postgresql_t;
    type postgresql_db_t;
    class file map;
}

allow postgresql_t postgresql_db_t:file map;
EOF

$ checkmodule -M -m -o my-pgroonga.mod my-pgroonga.te
$ semodule_package -o my-pgroonga.pp -m my-pgroonga.mod
$ sudo semodule -i my-pgroonga.pp

Create a database:

$ psql --command 'CREATE DATABASE pgroonga_test'

(Normally, you should create a user for pgroonga_test database and use the user. See GRANT USAGE ON SCHEMA pgroonga for details.)

Connect to the created database and execute CREATE EXTENSION pgroonga:

$ psql -d pgroonga_test --command 'CREATE EXTENSION pgroonga;'

That's all!

Try tutorial. You can understand more about PGroonga.

On Windows

Here is a list of required software to build and install PGroonga from source. Install them:

Download the Groonga source archive and PGroonga source archive from packages.groonga.org and extract them:

Variables used for the build:

Build and install Groonga:

> cmake -B groonga.build -G Ninja -S groonga-latest -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=%GROONGA_INSTALL_DIR% -DGRN_WITH_MECAB=bundled -DGRN_WITH_MESSAGE_PACK=bundled -DGRN_WITH_MRUBY=yes -DGRN_WITH_RAPIDJSON=bundled -DGRN_WITH_XXHASH=bundled -DGRN_WITH_ZSTD=bundled
> cmake --build groonga.build
> cmake --install groonga.build

Build PGroonga:

> meson setup pgroonga.build -S pgroonga-4.0.8 --buildtype=release --cmake-prefix-path=%GROONGA_INSTALL_DIR% -Dpg_config=%POSTGRESQL_INSTALL_FOLDER%\bin\pg_config.exe
> meson compile -C pgroonga.build

Install PGroonga. You may be required administrator privilege. For example, you installed PostgreSQL by installer, you will be required administrator privilege.

> meson install -C pgroonga.build

Create a database:

postgres=# CREATE DATABASE pgroonga_test;

(Normally, you should create a user for pgroonga_test database and use the user. See GRANT USAGE ON SCHEMA pgroonga for details.)

Connect to the created database and execute CREATE EXTENSION pgroonga:

postgres=# \c pgroonga_test
pgroonga_test=# CREATE EXTENSION pgroonga;

That's all!

Try tutorial. You can understand more about PGroonga.