问题
I installed postgresql-common and postgresql-9.4 with the package manager apt-get.
I changed my database system from OSX to Debian 8.1 after which I have had difficulties with Permission denied errors.
The user postgres exists (CREATE USER postgres;
) and database detector exists CREATE DATABASE detector WITH OWNER=postgres;
).
I run successfully
masi@pc212:~$ sudo -u postgres psql detector -c "DROP TABLE measurements;"DROP TABLE
masi@pc212:~$ sudo -u postgres psql detector -c "CREATE TABLE measurements ( m_id SERIAL PRIMARY KEY NOT NULL, m_size INTEGER NOT NULL );"
CREATE TABLE
but the same unsuccessfully in Dropbox -directory
masi@pc212:~$ cd Dropbox/
masi@pc212:~/Dropbox$ sudo -u postgres psql detector -c "DROP TABLE measurements;"
could not change directory to "/home/masi/Dropbox": Permission denied
DROP TABLE
masi@pc212:~/Dropbox$ sudo -u postgres psql detector -c "CREATE TABLE measurements ( m_id SERIAL PRIMARY KEY NOT NULL, m_size INTEGER NOT NULL );"
could not change directory to "/home/masi/Dropbox": Permission denied
CREATE TABLE
Settings
The command psql
is in the SECURE_PATH in /etc/sudoers:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
The command which psql
gives /usr/bin/psql
.
The real directory where I keep the code is /home/masi/Dropbox/det/ where possibly the Dropbox installation is affecting thing:
- drwxr-xr-x 32 masi masi 4096 Jul 14 10:27 masi/
- drwx------ 26 masi masi 4096 Jul 13 16:05 Dropbox/
- drwxr-xr-x 8 masi developers 4096 Jul 14 09:22 det/
where I can change the Dropbox to
- drwx------ 26 masi developers 4096 Jul 13 16:05 Dropbox/
but not able to increase permissions because I start to get ls: cannot access ../../Dropbox/: Permission denied although having fully open permissions. This is a very strange behaviour that here fully open permissions lead to such a behaviour.
Similar errors
- this thread about nautilus-dropbox but no nautilus-dropbox in my system
Why Dropbox is causing such a problem to PostgreSQL?
回答1:
content of dropbox is encrypted and must be mapped, not every users have access to $HOME/Dropbox on your system. When you use unix file manager line Nautilus or Nemo, Dropbox have to install a plugin so they can browse the files as if it was only a simple directory.
This directory can only be read / write from your user that installed dropbox and usually PostgreSQL runs under it's own user in a different group. you may add the postgreSQL user to your group that have access to $HOME/Dropbox (your user that installed and configured Dropbox)
Alternatly, you might do a script that cp from Dropbox to a normal folder if you intention was to create a live backup even I would discourage using sync cloud service for that for many reasons the first one being this http://support.code42.com/CrashPlan/Latest/Backup/Comparing_Cloud_Backup_And_Cloud_Storage.
EDIT To add postgresql to act as your user you have your own group or to a shared group
Easiest way would be to do ls -la $HOME/Dropbox
and see what is the user and group assosiated with ./
then add this specific group to the user postgres
you can type groups postgres
to look at groups that this user already have access and to confirm once you added the group.
that way postgres's user would have same access as you. But for security, that might not be what a sysadmin would recommend (which I am not). I would more look like : create a new group (lets say my_dropbox_group
) change rights to execute / read / write for that group. then add your user and postgres to the my_dropbox_group
's group that way you would restrict postgres to dropbox only and your user would have same access with the my_dropbox_group
group. If you have multiple users with each one having a personnal Dropbox, you have to create different groups so peoples can't access other dropboxes, like dropbox_mike
and dropbox_paul
being two differents dropbox account and you could manage access manually from that
Hope I didn't mixed up thing with the second part
回答2:
Some piece of answer in Petesh's comment but also read -flag is required. Run
sudo chmod -R go=rx /home/masi/Dropbox
but avoid recursive if you can.
The command allows the subsequent sudo -u postgres
commands. You generally have to open up access to the directory and all parent directories enough to allow commands to work with files in the directory. Execute s not enough in all cases; read -flag is also required.
来源:https://stackoverflow.com/questions/31399266/why-dropbox-causes-postgresql-permission-denied-errors