Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PostgreSQL & patchman-manage migrate] ERROR: permission denied for schema public #619

Open
Aleksey-Maksimov opened this issue Nov 8, 2024 · 0 comments

Comments

@Aleksey-Maksimov
Copy link

Aleksey-Maksimov commented Nov 8, 2024

Hello

We are trying to install Patchman on a clean Debian 12 system using PostgreSQL as a backend.

# cat /etc/debian_version
12.7

# dpkg -l | grep postgre
ii  postgresql                           15+248          all
ii  postgresql-15                        15.8-0+deb12u1    amd64
ii  postgresql-client-15                 15.8-0+deb12u1       amd64
ii  postgresql-client-common             248         all          
ii  postgresql-common                    248         all         

# dpkg -l | grep patchman
ii  patchman-client                      3.0.10-1      all          
ii  python3-patchman                     3.0.10-1    all          

In accordance with the document https://github.com/furlongm/patchman/blob/master/INSTALL.md, we installed all packages
We ran psql commands to create a new database:

CREATE DATABASE patchman;
CREATE USER patchman WITH PASSWORD 'MyPwd!O1';
ALTER ROLE patchman SET client_encoding TO 'utf8';
ALTER ROLE patchman SET default_transaction_isolation TO 'read committed';
ALTER ROLE patchman SET timezone TO 'UTC';
GRANT ALL ON SCHEMA public TO patchman;
GRANT ALL PRIVILEGES ON DATABASE patchman to patchman;

Next we set up the configuration /etc/patchman/local_settings.py:

DATABASES = {
    'default': {
       'ENGINE': 'django.db.backends.postgresql_psycopg2',
       'NAME': 'patchman',
       'USER': 'patchman',
       'PASSWORD': 'MyPwd!O1',
       'HOST': '127.0.0.1',
       'PORT': '',
       'CHARSET' : 'utf8'
    }
}

Next we try to execute the database initialization commands and get an error:

# patchman-manage makemigrations
No changes detected


# patchman-manage migrate --run-syncdb --fake-initial
Operations to perform:
  Synchronize unmigrated apps: admindocs, bootstrap3, django_extensions, django_filters, humanize, messages, rest_framework, staticfiles, util
  Apply all migrations: admin, arch, auth, contenttypes, domains, hosts, modules, operatingsystems, packages, reports, repos, sessions, sites, tagging
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
Running migrations:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.InsufficientPrivilege: permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" serial NOT NULL PRIMA...
                     ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/db/migrations/recorder.py", line 68, in ensure_schema
    editor.create_model(self.Migration)
  File "/usr/lib/python3/dist-packages/django/db/backends/base/schema.py", line 345, in create_model
    self.execute(sql, params or None)
  File "/usr/lib/python3/dist-packages/django/db/backends/base/schema.py", line 145, in execute
    cursor.execute(sql, params)
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 79, in _execute
    with self.db.wrap_database_errors:
  File "/usr/lib/python3/dist-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.ProgrammingError: permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" serial NOT NULL PRIMA...
                     ^


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/patchman-manage", line 39, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/core/management/commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/django/db/migrations/executor.py", line 91, in migrate
    self.recorder.ensure_schema()
  File "/usr/lib/python3/dist-packages/django/db/migrations/recorder.py", line 70, in ensure_schema
    raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" serial NOT NULL PRIMA...
                     ^
)

At this point, the following errors appear in the PostgreSQL log:

# tail /var/log/postgresql/postgresql-15-main.log
...
2024-11-08 15:18:49.295 MSK [18094] patchman@patchman ERROR:  permission denied for schema public at character 14
2024-11-08 15:18:49.295 MSK [18094] patchman@patchman STATEMENT:  CREATE TABLE "django_migrations" ("id" serial NOT NULL PRIMARY KEY, "app" varchar(255) NOT NULL, "name" varchar(255) NOT NULL, "applied" timestamp with time zone NOT NULL)

Please tell us what the problem might be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant