supabase / supavisor

A cloud-native, multi-tenant Postgres connection pooler.

Home Page:https://supabase.github.io/supavisor/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run supavisor on already hosted postgresql server

jahnavisana2812 opened this issue · comments

Improve documentation

https://supabase.github.io/supavisor/development/installation/

Describe the problem

There is no proper documentation on how to host the supavisor on the self hosted postgres servers without using the supabase postgres14.If that's possible

Describe the improvement

Please provide any essential documentation for the above

Additional context

I was trying to run the docker-compose file with our self hosted url but that seems to be throwing some error

`version: '3'

services:
  supavisor:
    image: supabase/supavisor:1.1.2
    container_name: supavisor
    ports:
      - 4000:4000
      - 5452:5452
      - 6543:6543
    environment:
      PORT: 4000
      PROXY_PORT_SESSION: 5452
      PROXY_PORT_TRANSACTION: 6543
      DATABASE_URL: "postgres://supavisor:XXX@db-cluster:5432/postgres"
      CLUSTER_POSTGRES: "true"
      SECRET_KEY_BASE: "dev"
      VAULT_ENC_KEY: "12345678901234567890123456789032"
      API_JWT_SECRET: "dev"
      METRICS_JWT_SECRET: "dev"
      REGION: "local"
      ERL_AFLAGS: -proto_dist inet_tcp
    command:  sh -c "/app/bin/migrate && /app/bin/server"`

Error shown:

`✔ Container supavisor  Created                                                                                                                          0.0s 
Attaching to supavisor
supavisor  | Setting RLIMIT_NOFILE to 100000
supavisor  | 11:06:33.765 [error] Could not create schema migrations table. This error usually happens due to the following:
supavisor  | 
supavisor  |   * The database does not exist
supavisor  |   * The "schema_migrations" table, which Ecto uses for managing
supavisor  |     migrations, was defined by another library
supavisor  |   * There is a deadlock while migrating (such as using concurrent
supavisor  |     indexes with a migration_lock)
supavisor  | 
supavisor  | To fix the first issue, run "mix ecto.create" for the desired MIX_ENV.
supavisor  | 
supavisor  | To address the second, you can run "mix ecto.drop" followed by
supavisor  | "mix ecto.create", both for the desired MIX_ENV. Alternatively you may
supavisor  | configure Ecto to use another table and/or repository for managing
supavisor  | migrations:
supavisor  | 
supavisor  |     config :supavisor, Supavisor.Repo,
supavisor  |       migration_source: "some_other_table_for_schema_migrations",
supavisor  |       migration_repo: AnotherRepoForSchemaMigrations
supavisor  | 
supavisor  | The full error report is shown below.
supavisor  | 
supavisor  | ** (Postgrex.Error) ERROR 3F000 (invalid_schema_name) schema "_supavisor" does not exist
supavisor  |     (ecto_sql 3.10.2) lib/ecto/adapters/sql.ex:1047: Ecto.Adapters.SQL.raise_sql_call_error/1
supavisor  |     (elixir 1.14.3) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
supavisor  |     (ecto_sql 3.10.2) lib/ecto/adapters/sql.ex:1154: Ecto.Adapters.SQL.execute_ddl/4
supavisor  |     (ecto_sql 3.10.2) lib/ecto/migrator.ex:756: Ecto.Migrator.verbose_schema_migration/3
supavisor  |     (ecto_sql 3.10.2) lib/ecto/migrator.ex:564: Ecto.Migrator.lock_for_migrations/4
supavisor  |     (ecto_sql 3.10.2) lib/ecto/migrator.ex:433: Ecto.Migrator.run/4
supavisor  |     (ecto_sql 3.10.2) lib/ecto/migrator.ex:170: Ecto.Migrator.with_repo/3
supavisor  |     nofile:1: (file)
supavisor exited with code 1`

There was some database permission issue due to which it happened the supavisor has started now.when i run this curl command I'm getting this error

`curl -i -X PUT \
  'http://localhost:4000/api/tenants/dev_tenant' \
  --header 'Accept: */*' \
  --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNjQ1MTkyODI0LCJleHAiOjE5NjA3Njg4MjR9.M9jrxyvPLkUxWgOYSf5dNdJ8v_eRrq810ShFRT8N-6M' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "tenant": {
    "db_host": "postgres://supavisor:xxxx@xxxx:5432/supavisor",
    "db_port": 6432,
    "db_database": "supavisor",
    "ip_version": "auto",
    "enforce_ssl": false,
    "require_user": true,
    "users": [
      {
        "db_user": "supavisor",
        "db_password": "supavisor",
        "pool_size": 9,
        "mode_type": "transaction",
        "is_manager": true
      }
    ]
  }
}'
`
Error encountered
`HTTP/1.1 400 Bad Request
cache-control: max-age=0, private, must-revalidate
content-length: 702
content-type: application/json; charset=utf-8
date: Wed, 10 Jan 2024 08:16:33 GMT
server: Cowboy
x-request-id: F6juaIng35N5YJgAAAKh

{"error":"Can't connect the user supavisor: %DBConnection.ConnectionError{message: \"connection not available and request was dropped from queue after 2000ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:\\n\\n  1. Ensuring your database is available and that you can connect to it\\n  2. Tracking down slow queries and making sure they are running fast enough\\n  3. Increasing the pool_size (although this increases resource consumption)\\n  4. Allowing requests to wait longer by increasing :queue_target and :queue_interval\\n\\nSee DBConnection.start_link/2 for more information\\n\", severity: :error, reason: :queue_timeout}"}`

Any update on this?

Not yet, sorry but it's on the stack

I was able to run Supavisor as a standalone service in the docker-compose file for Supabase Storage:

https://github.com/supabase/storage/blob/master/docker-compose-infra.yml#L50-L112

This might help

Thansk @fenos! Apologies @jahnavisana2812 I'll try to make time for this tmrw after work

Thanks for your input, @fenos! @J0, I have a question regarding tenant creation. Can tables,data generated by one tenant (tenant1) be isolated from that of another (tenant2)?

@jahnavisana2812 not too sure but I can check with team. Things are a little busy atm as there's an ongoing migration but they should get back once things are more stable.

Lmk if the linked docker-compose works for you

The docker-compose is working for me.I was able to create tenants!!Would be happy if you can confirm with the team regarding the data isolation from one tenant to other.Thanks!!

Great to hear! Let's follow up with that query in #290

Going to close this issue, see you on #290