Published: 24.03.2021 | Edited: 24.03.2021 | Tags: 100daystooffload,gitea,docker

Accessing Gitea Postgres inside Docker

The gitea issue #5917 discusses how to make multiple users unwatch a repository. It has inspired to write the steps down, as it was not entirely obvious to me.

There was a a change introduced via PR #5852 released that added an option AUTO_WATCH_NEW_REPOS into the Gitea config file, but it's default is true.

The consequence of this behavior is, that unless you are runnig a Gitea at least version 1.8.0, where this config option was introduced and subsequently you have set the AUTO_WATCH_NEW_REPOS to false beforehand, creating a repository (presumably in an Organization) and assigning a team to it makes all the users in that team wath the repository, which creates a lot of noise for the users.

This guide shows how to reduce this noise, it can be adapted for other purposes that require raw SQL commands to be run on PostgreSQL inside Docker.

  • The guide assumes the docker-compose.yml file is identical to the the Gitea docs
version: "3"

    external: false

    image: gitea/gitea:1.13.3
    container_name: gitea
      - USER_UID=1000
      - USER_GID=1000
+     - DB_TYPE=postgres
+     - DB_HOST=db:5432
+     - DB_NAME=gitea
+     - DB_USER=gitea
+     - DB_PASSWD=gitea
    restart: always
      - gitea
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - "3000:3000"
      - "222:22"
+    depends_on:
+      - db
+  db:
+    image: postgres:9.6
+    restart: always
+    environment:
+      - POSTGRES_USER=gitea
+      - POSTGRES_PASSWORD=gitea
+      - POSTGRES_DB=gitea
+    networks:
+      - gitea
+    volumes:
+      - ./postgres:/var/lib/postgresql/data

The following steps have to be modified if changes were made the the lines with different color, specifically converning host, user, password and DB.

  • If the instance is not running already, start it (assuming all the other configuration is done according to docs)
docker-compose up -d
  • Connect to psql inside a container and prompt Postgres password from above
docker-compose run --rm db psql -h db -U gitea gitea

The command could be a little confusing, so here are placeholders

docker-compose run --rm SERVICE psql -h HOST -U USER DB
  • Now you can use standard psql commands, use database gitea
\c gitea

Then for instance list all tables

  • Look up repository id
SELECT id,name FROM repository ORDER BY name;

Disclaimer: following commands can lead to a LOSS OF DATA! Before proceeding further, please make proper backup(s).

  • Remove all the watchers of the given repository, insert change ID to a required value
DELETE FROM watch WHERE repo_id=ID;


This is a 14th post of #100daystooffload.