admin管理员组

文章数量:1124798

I followed the documention to install pgAdmin4 in server mode on a Debian 12 system. I used nginx and gunicorn. nginx was installed from the Debian repos. The rest was setup inside a virtual environment under ~/postgresql-env. I even created a systemd service:

[Unit]
Description=pgAdmin4 service
After=network.target

[Service]
User=root
Group=root
Environment="PATH=/home/gin/postgresql-env/bin"
ExecStart=/home/gin/postgresql-env/bin/gunicorn --bind unix:/tmp/pgadmin4.sock --workers=1 --threads=25 --chdir /home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4 pgAdmin4:app

[Install]
WantedBy=multi-user.target

From the service you can also see how I launch the pgAdmin4 application using gunicorn from within the Python virtual environment. Here I am wondering whether I should change User and Group since everything (var directories related to pgAdmin as well as the actual Python virtual environment in /home/gin/postgresql-env are chown-ed by the user gin that I used to log into the machine (not the PostgreSQL DB!).

The config_local.py (found under /home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/config_local.py) contains the following:

LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'
SERVER_MODE = True

I ran setup.py setup-db and entered a non-existing email just for the sake of having something to login with. In my case the username is [email protected] with very simple password.

I edited the default nginx configuration under /etc/nginx/sites-available/default as follows:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location /pgadmin4/ {
        include proxy_params;
        proxy_pass http://unix:/tmp/pgadmin4.sock;
        proxy_set_header X-Script-Name /pgadmin4;
    }
}

nginx is working since I do get the Welcome! page on the usual HTTP port.

When I try to visit the pgAdmin in my browser under http://<some-host>/pgadmin4 I get the login page. There I enter [email protected] with the respective password.

I do not get any errors. I get redirected to http://<some-host>/pgadmin4/browser/, which Firefox displays as a JSON:

{
    "success":0,
    "errormsg":"'user_management.index'",
    "info":"",
    "result":null,
    "data":null
}

Checking the /var/log/pgadmin4/pgadmin4.log reveals the following:

2025-01-09 13:57:09,359: ERROR  pgadmin:    'user_management.index'
Traceback (most recent call last):
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/flask/app.py", line 1517, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/flask/app.py", line 1503, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/flask_login/utils.py", line 290, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/authenticate/mfa/utils.py", line 304, in inner
    return mfa_enabled(
           ^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/authenticate/mfa/utils.py", line 169, in mfa_enabled
    return execute_if_enabled()
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/authenticate/mfa/utils.py", line 301, in if_else_func_inner
    return _func(first, second)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/authenticate/mfa/utils.py", line 242, in mfa_session_authenticated
    return authenticated() if session.get('mfa_authenticated', False) is True \
           ^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/authenticate/mfa/utils.py", line 297, in execute_func
    return wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/browser/__init__.py", line 712, in index
    response = Response(render_template(
                        ^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/flask/templating.py", line 154, in render_template
    return _render(
           ^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/flask/templating.py", line 128, in _render
    rv = template.render(context)
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/browser/templates/browser/index.html", line 6, in top-level template code
    {% import 'browser/macros/static_user_icon.macro' as IMG with context %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/templates/base.html", line 55, in top-level template code
    'pgadmin.user_management.current_user': "{{ url_for('user_management.index') }}" + "current_user",
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/flask/helpers.py", line 309, in url_for
    appctx.app.inject_url_defaults(endpoint, values)
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/flask/app.py", line 1812, in inject_url_defaults
    func(endpoint, values)
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/pgadmin4/pgadmin/__init__.py", line 842, in add_internal_version
    urls = [url for url in app.url_map.iter_rules(endpoint)]
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/gin/postgresql-env/lib/python3.11/site-packages/werkzeug/routing.py", line 1531, in iter_rules
    return iter(self._rules_by_endpoint[endpoint])
                ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'user_management.index'

I did try another non-existing user just to check if it's not a more general problem but the error produced is a valid one, namely

2025-01-09 13:56:02,819: ERROR  pgadmin:    'NoneType' object is not subscriptable

which happens when trying to retrieve a non-existing user and the returned object is None, leading to an exception in the pgAdmin code after attempting to access something in it.

I am very unfamiliar with nginx and gunicorn. I have also never run pgAdmin in a server mode. I have a special VM on my server, where I would like to have PostgreSQL DB setup.

If you need more info, let me know in the comments and I'll do my best to provide it.

本文标签: linuxReceiving error message usermanagementindex when visiting pgadmin browser after loginStack Overflow