wiki.js on YugabyteDB
Tags: yugabytedb, postgres, wiki, opensource
Published: 2023-06-23 13:58:43

I've [asked on LinkedIn](https://www.linkedin.com/posts/franckpachot_ive-a-query-for-postgres-users-which-activity-7077927200531849216-KpI7?utm_source=share&utm_medium=member_desktop) which PostgreSQL application you use so that I can check that it works on Yugabyte. Please, continue to answer. To start let's try with [Wiki.js](https://js.wiki/), open source wiki software storing into a PostgreSQL database.

From the docker compose file in the documentation ([Using Docker Compose](https://docs.requarks.io/install/docker#using-docker-compose)) I changed the PostgreSQL database to YugabyteDB:
- changed `image: postgres:11-alpine` to `yugabytedb/yugabyte:latest`
- forward port 15433, the YugabyteDB UI, and 7000, the cluster console
- changed `POSTGRES_DB`, `POSTGRES_PASSWORD` and `POSTGRES_USER` environnement variables to `YSQL_DB`, `YSQL_PASSWORD` and `YSQL_USER`
- added `command: yugabyted start --listen 0.0.0.0 --background=false`
- changed the volume to `/root/var/data` the default data dir
- in the application, changed `DB_PORT: 5432` to `DB_PORT: 5433`

Here is my `docker-compose-yaml`:

```yaml
version: "3"
services:

  db:
    image: yugabytedb/yugabyte:latest
    ports:
      - "15433:15433"
      - "7000:7000"
    environment:
      YSQL_DB: wiki
      YSQL_PASSWORD: wikijsrocks
      YSQL_USER: wikijs
    restart: unless-stopped
    volumes:
      - db-data:/root/var/data
    command: yugabyted start --listen 0.0.0.0 --background=false --tserver_flags="yb_enable_read_committed_isolation=true,ysql_colocate_database_by_default=false"

  wiki:
    image: ghcr.io/requarks/wiki:2
    depends_on:
      - db
    environment:
      DB_TYPE: postgres
      DB_HOST: db
      DB_PORT: 5433
      DB_USER: wikijs
      DB_PASS: wikijsrocks
      DB_NAME: wiki
    restart: unless-stopped
    ports:
      - "80:3000"

volumes:
  db-data:
```
In this version of YugabyteDB (2.19) the read-commited behavior is not enabled by default (compatibility with previous versions which implemented only repetable read and serializable) and that's why I pass an additional flag. Colocated can be set to true when testing a new application to decide later which tables needs to be distributed.

I start YugabyteDB first:
```sh
docker compose up -d db
```

Starting with `yugabyted start` is the easiest but takes a few seconds to check everything. That's why I start it first and try to connect until I've no `could not connect to server`. The goal is to test it. It can be optimized for automated tests and for production where, anyway, you start multiple nodes as the database is distributed.

Here is how I check that the database is ready for connections:
```sh
until
docker compose exec -i db bash -c 'PGPASSWORD=wikijsrocks ysqlsh -d wiki -U wikijs -c "show server_version"'
do sleep 1 ; done

```

![11.2-YB-2.19.0.0-b0](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/521hawt2wn9z468vhou9.png)

I can start the remaining service:
```sh`
docker compose up -d
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5kil78oyg9a3g0lldtja.png)


If it takes longer than with PostgreSQL to create the schema, this can be optimized. The default waits after index creation to do it online, without locks, and I used all default settings here to make it simple.

I can use the application:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l973aoyg1dflme504eft.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hct1gcrr5uly98l59v85.png)

Of course, this is not sufficient to run into production. You should test the application. Maybe the default sharding method is not optimal and some indexes may be changed to get the best performance.

If you have any issue, please contact the YugabyteDB community on [Slack](https://communityinviter.com/apps/yugabyte-db/register), [Forum](https://forum.yugabyte.com/?_ga=2.241390146.1933825092.1687382600-647018260.1668067404), [GitHub](https://github.com/yugabyte) or our [Community Open Hours](https://www.youtube.com/@YugabyteDB/streams).