13

Ubuntu 16.04.3

I'd like to install pgAdmin:

I hvae created a virtualenv with python 2.

Then install pgAdmin 4 v2.0:

pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v2.0/pip/pgadmin4-2.0-py2.py3-none-any.whl

It's time to run pgAdmin:

(pgadmin4) michael@michael-desktop:~/PycharmProjects/venv$ python pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
Traceback (most recent call last):
  File "pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py", line 55, in <module>
    exec(open(file_quote(setupfile), 'r').read())
  File "<string>", line 46, in <module>
  File "/home/michael/PycharmProjects/venv/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgadmin/setup/data_directory.py", line 23, in create_app_data_directory
    _create_directory_if_not_exists(os.path.dirname(config.SQLITE_PATH))
  File "/home/michael/PycharmProjects/venv/pgadmin4/lib/python2.7/site-packages/pgadmin4/pgadmin/setup/data_directory.py", line 15, in _create_directory_if_not_exists
    os.mkdir(_path)
OSError: [Errno 13] Permission denied: '/var/lib/pgadmin'

Could you give me a kick here?

Michael
  • 4,273
  • 3
  • 40
  • 69
  • This can easily solved by overriding default paths, You can refer my answer below. – Murtuza Z Oct 16 '17 at 14:38
  • A completely different approach would be to run pgAdmin from Docker. Found this in another post. mkdir ~/.pgadmin4 # to store config and stuff docker run -d --rm --network host -v ~/.pgadmin4:/pgadmin thajeztah/pgadmin4 Then go to http://localhost:5050 and you are done with it. See https://github.com/thaJeztah/pgadmin4-docker for more info. – John Dauphine Feb 07 '20 at 21:49

6 Answers6

33

If you do not want to change the permission of anything, you can always override default paths in pgAdmin4.

Create a file named config_local.py (if not already present) at your installation location ../pgadmin4/web/

File location in my case: /usr/local/lib/python2.7/dist-packages/pgadmin4/config_local.py

and add following code in your config_local.py,

import os
DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/'))
LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
SQLITE_PATH = os.path.join(DATA_DIR, 'pgadmin4.db')
SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions') 
STORAGE_DIR = os.path.join(DATA_DIR, 'storage')

Restart pgAdmin4 and check.

Murtuza Z
  • 5,639
  • 1
  • 28
  • 52
  • 1
    Works for me. Thanks! – JustWonder Oct 13 '17 at 19:44
  • Installed mine today, and there's NO config_local.py anywhere on my system – KhoPhi Nov 04 '17 at 12:38
  • you have to create it, it is user defined config file. – Murtuza Z Nov 04 '17 at 13:45
  • Reference to [pgadmin docs](https://www.pgadmin.org/docs/pgadmin4/2.x/server_deployment.html#python). You're likely to get this error from time to time after upgrading, as the list of paths can be updated from one release to another (which happened to me today). To see which paths need to be updated, you can look at `pgadmin4/pgadmin/setup/data_directory.py` file. – n__o Jan 15 '18 at 16:13
  • Tried this for an upgrade from pgadmin4-1.6, which was operational on my Ubuntu 16.04 to pgadmin4-2.0 and it didn't work. OSError: [Errno 13] Permission denied: '/var/lib/pgadmin' That folder doesn't exist anywhere. – Preston Feb 12 '18 at 01:35
  • @Preston pgAdmin4 is trying to create new folder here and it will fail soon after because of permission issue, better to provide proper permission OR change the paths to home directory where user have all the required permissions – Murtuza Z Feb 12 '18 at 06:49
  • @n33ma Thank you for pointing that out. I posted my solution. Simple, add sudo to the boot script. I didn't need config_local.py. – Preston Feb 12 '18 at 22:04
5

Permission error means the user 'michael' (/var/lib has drwxr-xr-x) has the permission to execute but doesn't have the permission to write on the folder (according to your comment of the folder info below). One of the solutions you can use to be able to access freely the folder would be something like:

chown -R michael:root /path/to/the/directory

The second part of the answer, you've figured it out @Michael. downloading pgadmin by using the command:

wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v1.5/pip/pgadmin4-1.5-py2.py3-none-any.whl 

and then execute command:

pip install pgadmin4*.whl.
abr
  • 2,071
  • 22
  • 38
  • /var/lib has drwxr-xr-x root root. Why should I change it? If is not done for me to change, isn't it? – Michael Oct 12 '17 at 11:08
  • what's the user you're executing the command with? also,write 'groups ' and see if you have the permissions to the folder you're taking action upon – abr Oct 12 '17 at 11:12
  • It is an ordinary user. No permissions. The user belongs to sudo group. But I seem to follow pgAdmin's installation manual. Nothing is about permissions there. Just run python command. Am I alone who faces this problem? – Michael Oct 12 '17 at 11:15
  • Have you tried writing sudo before the sentence? The folder has permissions for the root user, root group. Is 'michael' in the root group? You can just chown -R michael:root /path/to/the/directory and run the command again. – abr Oct 12 '17 at 11:18
  • sudo python pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py ? But does it have any sense? I tried. ImportError: No module named flask appeared at once. – Michael Oct 12 '17 at 11:20
  • But I do have flask module installed. I tried. I run python and wrote import flask. But what is it all about? Am I violating the installation instruction for pgAdmin? I tried on another computer. The same result. Why googling this problem shows no result? And by the way, sudo pip is not working. – Michael Oct 12 '17 at 11:38
  • Is the module flask installed on the same directory? Does it have permissions? – abr Oct 12 '17 at 11:44
  • Well, it something starts clarifying. I downloaded the wheel. And installed in not from a remote repository. wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v1.5/pip/pgadmin4-1.5-py2.py3-none-any.whl Then pip install pgadmin4*.whl. Now it runs. – Michael Oct 12 '17 at 11:45
  • Dear abr, you helped me. And if you organize in your answer what I wrote above, I'd gladly accept it. – Michael Oct 12 '17 at 11:46
  • Glad it helped, altho the flask part you've figured it yourself! Updated it – abr Oct 12 '17 at 11:57
  • Well, it helped. But the problem is still here. Have you noticed that the pgAdmin version is old? Current pgAdmin (2.0) will not install like this. – Michael Oct 12 '17 at 12:00
  • Yeah, the older version, 1.6, installs and works fine. The problem is v2+. I get the same error trying to upgrade and I followed all the advice here. There is no /var/lib/pgadmin folder and of course it can't find it. This isn't a real permissions problem. I also tried a new install and no luck. Same problem. Fully updated Ubuntu 16.04 box. – Preston Feb 12 '18 at 02:14
  • This chown suggestion allowed pgadmin to work, then broke my VM. – Bret Hess Mar 18 '20 at 16:38
4

create the folders manually (or add to your pgAdmin installation script, if there is one), and assign the permissions:

sudo mkdir "/var/log/pgadmin"
sudo chmod a+wrx "/var/log/pgadmin"

sudo mkdir "/var/lib/pgadmin"
sudo chmod a+wrx "/var/lib/pgadmin"

this would not assign permissions to the entire /var/log but just for the /var/log/pgadmin only.

mehmet
  • 7,720
  • 5
  • 42
  • 48
1

solved issue with several steps 1. create empty folders on host vm

mkdir /private/var/lib/pgadmin
chmod 777 /private/var/lib/pgadmin
  1. start pgadmin docker image
docker pull dpage/pgadmin4
docker run -p 80:80\
    -v /private/var/lib/pgadmin:/var/lib/pgadmin \
     ...
  1. you will see newly created file structure like this
/private/var/lib/pgadmin

-rw-------.  1 5050 5050 757760 Jan 13 23:11 pgadmin4.db
drwx------.  2 5050 5050     50 Jan 13 23:00 sessions
drwxr-xr-x.  3 5050 5050     31 Jan 13 23:17 storage

thus UID 5050 is our target one 4. copy your pgadmin4.db into target dir and apply proper UID [5050 in my case]

As a result application will work, user settings will be saved.

Alex F
  • 11
  • 3
0

I installed pgadmin4 v2.1 on Ubuntu 16.04 and had this problem. See the last line of code. (I run this in a script file, lazy.) I also installed 2.0 this way as a test to see if it really is a fix. I did not have to use config_local.py.

cd ..
cd home/vagrant

sudo apt-get install build-essential libssl-dev libffi-dev libgmp3-dev virtualenv python-pip libpq-dev python-dev

virtualenv .pgadmin4
cd .pgadmin4
source bin/activate

wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v2.1/pip/pgadmin4-2.1-py2.py3-none-any.whl

pip install pgadmin4-2.1-py2.py3-none-any.whl

# For this either use your remote host panel to edit the file or:
nano lib/python2.7/site-packages/pgadmin4/config.py
# Change:
# DEFAULT_SERVER = '0.0.0.0'

# Here is the trick.  Run this boot up file with sudo.  This fixed it for me.
sudo python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
Preston
  • 3,260
  • 4
  • 37
  • 51
-4

I had the same problem with pgAdmin4 v3.1, I just write sudo python pgAdmin4.py and it worked!.

Mile
  • 17
  • 6