I have installed centos 6.3 On vmware, and the postgresql is self-contained, the Version is PostgreSQL 8.4.13 on i386-redhat-linux-gnu.
I want to create a tablespace with command like This:
create tablespace foo LOCATION '/usr/foo1';
But I am getting Error like this:
ERROR: could not set permissions on directory "/tmp/foo1": Permission denied
Then I checked the /tmp/foo1's owner and the owner is indeed postgres,
So I confused about this.
Can anyone help me?
things I would check:
Usually /tmp should have open permissions. However if they are closed off...
What filesystem is /tmp on? Does it support file permissions?
What are the appropriate filesystem mounting options or such for /tmp? Could these interfere?
Related
I am trying to create a tablespace in a Windows folder, but nothing seems to be working.
I am doing so with pgadmin.
CREATE TABLESPACE test
LOCATION 'C:\test'
This gives me error:
ERROR: tablespace location must be an absolute path
SQL state: 42P17
I have tried writing the location differently:
'C:/test'
'C:\\test'
'C://test'
But nothing fixes it.
Where is the issue?
Two things to verify, which you have not made clear:
Is your database running on a Windows Server?
Have you actually already created the folder?
Both of theses are necessary in your case. A tablespace is not created so much as it is assigned. The create only creates the Postgres internal definition not the physical implementation. From the Documentation
The location must be an existing, empty directory that is owned by the
PostgreSQL operating system user. All objects subsequently created
within the tablespace will be stored in files underneath this
directory. The location must not be on removable or transient storage,
as the cluster might fail to function if the tablespace is missing or
lost.
I know there has been a dozen times a similar question, but I could not find an answer that worked for me.
I have a Debian 9 machine, fresh from install on which I have installed a Postgresql 9.6 server.
I am trying to create a new tablespace but it fails. The command :
CREATE TABLESPACE newTableSPace LOCATION '/DATA/PostgreSQL/';
Returns the following error :
ERROR: could not set permissions on directory "/DATA/PostgreSQL": Permission denied
SQL state: 42501
So, after a few basis searches, I have already checked the following points :
The directory /DATA/PostgreSQL exists
Its owner/group is postgres:postgres
The rights on the directory are 770
SELinux is apparently not installed (in Synaptic, libselinux1 is installed, but all selinux commands that I have tried returned me "command not found". Examples : selinuxenabled, setenforce 0).
I am running out of ideas.
Anybody has a suggestion ?
And I just found the solution !
The problem was the permissions of the user postgres not on directory /DATA/PostgreSQL/ but on the directory /DATA, on which it had no permission at all (it belonged to the current user with rights 770).
I have changed the permissions on this folder to 775. I guess another way would be to make the user postgres belong to the group that owns the DATA folder.
Hey I just found a possible solution, the thing is that you´ll have to give everyone access to the directory you to write in.
Right click in the directory ".../targetDirectory".
Properties> Security> In Group /usernames click on "edit"
Add another group or username, type "Everyone" and click "OK"
If you need to add more permisson to this group you check the permissions and press Ok.
You could see it in this video: https://www.youtube.com/watch?v=FQzBgEFkdes
This worked for me creating tablespaces and copy files from one directory to another one.
Hope this helps.
My goal is to import csv file to postgresql database.
my file is located in network shared folder and I do not have no option to make it in a local folder.
My Folder located in :
"smb://file-srv/doc/myfile.csv"
When I run my this PostgreSQL script:
COPY tbl_data
FROM 'smb://file-srv/doc/myfile.csv' DELIMITER ',' CSV;
I would get this error :
ERROR: could not open file "smb://file-srv/doc/myfile.csv" for reading: No such file or directory
SQL state: 58P01
I have no problem to access the file and open it.
I am using PostgreSQL 9.6 under Ubuntu 16.04.
Please Advice how to fix this problem.
Update
When I try to access the file with postgres user I would have same error:
postgres#file-srv:~$$ cat smb://file-srv/doc/myfile.csv
cat: 'smb://file-srv/doc/myfile.csv' : No such file or directory
As I mention when I user mounted folder I created I can access the file.
it is about permission. you have to check read access on file and folders.
also, logging with superuser access may solve your problem.
In short, this is a permissions issue: Your network share is likely locally mounted to your user's UID, while the PostgreSQL server is running as the postgres user.
Second, when you log into your database, there is not an overlap between the database's users and the system's users, even if you have the same username. This means that when you request a file from your network share, the DB user, in this case postgres, does not have the necessary permissions.
To see this, and assuming you have root access on the box in question, you might try to become the postgres user and see that you cannot access the file:
$ sudo su - postgres
$ cat /run/user/.../smb.../yourfile.csv
Permission denied
The fix to your issue will involve -- somehow -- making the file or share accessible to the postgres user. Copying is certainly the quickest way. But that's off the table. You could mount the share (perhaps as read only) as the postgres user. You might do this in fstab.
However, unless this is going to be an automated detail that happens regularly, this seems like heroics. Without more information as to why you can't copy locally, I suggest copying the file locally.
I am using PostgreSQL and Centos
While in the the task database I am trying to do this
COPY CUSTOMERS TO '/home/cjones/cfolder/customers.txt' (DELIMITER '|');
I am getting the
Error: could not open file "/home/cjones/customers.txt" for writing: Permission denied
I have done ls -al and chmod the customers.txt to 777 and still getting this error. Any ideas?
Are you aware of all requirements? Per documentation:
1.
You must have select privilege on the table whose values are read by
COPY TO
2.
COPY naming a file or command is only allowed to database superusers,
since it allows reading or writing any file that the server has
privileges to access.
Plus, for the file to be accessible by the server it must lie on the same machine of course. And the directory must be accessible to the user the postgres server runs as, typically postgres (not only the file).
An alternative would be to use the \copy meta-command of psql.
I'm trying to create a tablespace in postgres, but I'm getting ownership problems. The command I'm using is:
CREATE TABLESPACE magdat OWNER maggie LOCATION '/home/john/BSTablespace'
I get the error:
ERROR: could not set permissions on directory "/home/john/BSTablespace": Operation not permitted
The folder belongs to postgres:postgres, I've tried changing it to maggie, but if I go :
chown maggie:postgres /home/john/BSTablespace
I get:
chown: invalid user: `maggie:postgres'
How come the user does not exist? If I list the users inside of postgres it does come up. Any ideas what I could be doing wrong?
I would hazard a guess that the problem lies in the permissions of the parent directory "/home/john". Your home directory is probably setup so that only your user has access (i.e chmod 700) to it (it's a good thing for your home directory to be chmod 700, don't change it).
Doing something like:
mkdir /BSTablespace
chown postgres:postgres /BSTablespace
and then
CREATE TABLESPACE magdat OWNER maggie LOCATION '/BSTablespace';
should work fine.
Regarding the user maggie: database users are not the same as OS users. That isn't to say that you couldn't have a user in both places named maggie-- but you would need to create the user in both the database and the OS for that to happen.
When you install Postgres on a Mac, and are trying to use PgAdmin to create your databases, tablespaces, etc. You need to know that the PgAdmin Utility is running under the postgres account that it created when you installed the postgres database and the utilities.
The postgres account is part of the _postgres group
( dscacheutil -q group|grep -i postgres command will list the group associated with the postgres account)
The best practice would be to create a new directory under root(/) for housing the tablespaces,(let us call it /postgresdata then make postgres:_postgres the owners of that directory, using the command below)
sudo chown postgres:_postgres /postgresdata
This should do it for you.
You could then create a subdirectory under /postgresdata for each unique table space
There is a problem with this solution. Think about it. Why do you want to create a new tablespace? Most people do it for either space limitations or performance. In both cases, that means placing each tablespace on a different drive. So, archive data goes on the slower hard-drive, while actively used data does on the SSD.
Assume your OS is on the SSD and you have mounted your slower spin up hard drive as /media/slowdrive. The same dilemma would occur if the reverse, where the spinup is the OS and SSD is the mounted.
Your solution would place the new tablespace at /newtablespace.
Do you see the problem? ... /newtablespace is on the SSD, which does not have the capacity to hold both the archival and active data. If it did, we would not be creating a new tablespace in the first place.
So, how do we solve this issue when our newtablespace is mounted at /media/slowdrive/newtablespace? In my case, the slowdrive (spinup HD) is mounted as root:root for security purposes, although I am not entirely sure about why. What you are suggesting is that I have to chage the mount of my secondary drive to postgres:postgres in addition to having the newtablespace directory as postgres:postgres. That makes no sense, especially since I use this drive for many other reasons than just a postgres tablesapce.
Joe