gitea: gitea does not start - can not find public schema

  • Gitea version: 1.5.2 (docker)
  • Git version: 2.19.1
  • Operating system: Debian
  • Database (use [x]):
    • PostgreSQL
  • Can you reproduce the bug at https://try.gitea.io:
    • Not relevant

Hello, I have multiple instances for gitea. Every installation should use one big postgres database with his own schema.

So I create for one instance his own schema and username and changed the search_path to disable querying statements to the public schema, because I don’t want, that any application or instance create his schema into public.

Here my psql statements

CREATE SCHEMA gitea;
CREATE ROLE gitea WITH LOGIN;
ALTER USE gitea SET search_path=gitea;
GRANT ALL ON SCHEMA gitea to gitea;

After installation gitea does not start and I get in my logs every time the same error.

root@vgttp:/srv/docker/gitea_01/data/gitea/log# tailf xorm.log
2018/10/23 20:37:33 [I] PING DATABASE postgres
2018/10/23 20:37:33 [I] [SQL] SELECT tablename FROM pg_tables WHERE schemaname = $1 AND tablename = $2 []interface {}{"public", "version"}
2018/10/23 20:37:33 [I] [SQL] CREATE TABLE IF NOT EXISTS "version" ("id" BIGSERIAL PRIMARY KEY  NOT NULL, "version" BIGINT NULL)
2018/10/23 20:37:33 [I] [SQL] SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = $1 AND table_name = $2 AND column_name = $3 [public version id]
2018/10/23 20:37:33 [I] [SQL] ALTER TABLE "version" ADD "id" BIGSERIAL PRIMARY KEY  NOT NULL ;

Gitea look in the public schema? I have installed the instance into his own schema! How can I change in my docker-compose or app.ini the schema name?

Volker

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@lunny It turns out xorm already handled the case correctly; only Gitea didn’t use engine.SetSchema() to specify a different one. PR’d at #8819 (no need for weird ALTER user statements 😁)

@appleboy’s PR #3348 will try to fix this.

@lunny The solution is much much simpler 😁. I’ve just tested it locally. The problem is that xorm is forcing the public schema in some queries.

What I did:

  • Started from an existing Gitea database.
  • Created a new schema (notpublic).
  • Moved all tables to the new schema (alter table access set schema notpublic;, etc.)
  • Ran ALTER USER gitea SET search_path = notpublic;.
  • Edited vendor/xorm.io/xorm/dialect_postgres.go, changed DefaultPostgresSchema and postgresPublicSchema to notpublic.
  • Compiled gitea.
  • Run (works).

IMHO #3348 is trying to change all queries unnecessarily, and xorm almost handles this. There are only a few problems:

  • DefaultPostgresSchema is initialized to "public" instead of postgresPublicSchema, so no compilation customization (-X) can be used.
  • Engine.tbNameWithSchema() uses postgresPublicSchema instead of db.Schema, so the two values are not synchronized.
  • Gitea has no setting to pass a customized schema name into xorm.

If you agree with my analysis, I could pass a PR to xorm for the first two.

@guillep2k Good catch! And if you can add a new database test with non-public schema of postgres, that’s better. 😃