Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

pgAdmin 4 installed with pip exits before it opens on port 5050

Your error

Failed to create the directory /var/lib/pgadmin:3 more lines it can show

Fix it fast

Most common cause, 1 of 2

The server-mode folders were never created

Create both folders once with sudo and give them to your own user, then start pgAdmin from the venv without sudo.

Fix
sudo mkdir /var/lib/pgadmin
sudo mkdir /var/log/pgadmin
sudo chown $USER /var/lib/pgadmin
sudo chown $USER /var/log/pgadmin
source pgadmin4/bin/activate
pgadmin4
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

pgAdmin 4 installed with pip runs in server mode, with its data in /var/lib/pgadmin and its log in /var/log/pgadmin. pip never creates those folders and a normal user cannot, so pgadmin4 prints Failed to create the directory or Permission denied and quits. Create both with sudo, chown them to the user running pgadmin4, and retry. Applies to pgAdmin 4 9.x.

  • Applies to pgAdmin 4 9.19, pip wheel in a Python venv, Linux
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List both server-mode folders with their owners. A missing folder points to the first cause; a folder owned by root or by another account points to the second.

Run this first
ls -ld /var/lib/pgadmin /var/log/pgadmin

Then find the line you see in this list and open its fix:

  1. 1The server-mode folders were never createdls: cannot access '/var/lib/pgadmin': No such file or directory
  2. 2The folders exist but belong to root or another accountls -ld shows root (or a different user) as owner, and the error names a path inside the folder, such as '/var/lib/pgadmin/sessions'

What does the error look like?

  • Failed to create the directory /var/lib/pgadmin:
  • [Errno 13] Permission denied: '/var/lib/pgadmin'
  • Create the directory /var/lib/pgadmin, ensure it is writeable by
  • [Errno 13] Permission denied: '/var/lib/pgadmin/sessions'

Cause 1 of 2

The server-mode folders were never created

You seels: cannot access '/var/lib/pgadmin': No such file or directory

Check

Failed to create the directory /var/lib/pgadmin means the pip-installed pgadmin4 tried to make its own data folder and was refused. Run from a wheel, pgAdmin uses server mode and system-wide paths, and pgAdmin's install page says these may have to be created first; under /var/lib and /var/log only root can do that.

Check
pip show pgadmin4 | grep -i '^version'
ls -ld /var/lib/pgadmin

Fix

Create both folders once with sudo and give them to your own user, then start pgAdmin from the venv without sudo.

Fix
sudo mkdir /var/lib/pgadmin
sudo mkdir /var/log/pgadmin
sudo chown $USER /var/lib/pgadmin
sudo chown $USER /var/log/pgadmin
source pgadmin4/bin/activate
pgadmin4

Verify

On first start pgadmin4 asks for the email address and password of the initial pgAdmin user, and then serves the UI on port 5050.

Verify
curl -sI http://127.0.0.1:5050 | head -n 1

Confirmed by pgadmin.org

Did this fix it?

Cause 2 of 2

The folders exist but belong to root or another account

You seels -ld shows root (or a different user) as owner, and the error names a path inside the folder, such as '/var/lib/pgadmin/sessions'

Check

A Permission denied error under /var/lib/pgadmin while the folder itself exists means it was made with sudo mkdir and never handed over. pgAdmin only checks whether each path exists and skips the ones that do; it does not test write access, so the failure appears one level down, when it tries to create its sessions and storage sub-folders or its database file.

Check
whoami
ls -ld /var/lib/pgadmin /var/log/pgadmin

Fix

Give both folders, and anything already created inside them, to the account that runs pgadmin4. If a service account runs it, use that name instead of $USER.

Fix
sudo chown -R $USER /var/lib/pgadmin /var/log/pgadmin

Verify

Your user can now write in both folders, and pgadmin4 starts without a traceback.

Verify
touch /var/lib/pgadmin/.write-test && rm /var/lib/pgadmin/.write-test
touch /var/log/pgadmin/.write-test && rm /var/log/pgadmin/.write-test

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Keep the two mkdir and two chown lines in the same setup script that creates the venv and runs pip install pgadmin4, so a new machine never starts pgAdmin before the folders exist.
  • Start pgadmin4 as the account that owns the folders, and never with sudo from inside the venv.
  • Pin pgadmin4 in a requirements file for that venv and read the release notes before you raise the version.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.