I am using the EnterpriseDB pgAdmin III (v. 1.12.1) on a Windows 7, 32-bit machine to work with PostgreSQL databases on a remote Linux server. I am logged in as the user postgres, which allows me to access the $PGDATA directory (in this instance, it is found here: /var/lib/pgsql/data/)
If I log into the server via a terminal, run psql, and use the \copy command to import data from csv files into newly created tables, I have no problems.
If I'm in pgAdmin, however, I use the COPY command to import data from csv files into newly created tables.
COPY table_name FROM '/var/lib/pgsql/data/file.csv'
WITH DELIMITER AS ',' csv header
Sometimes this works fine, other times I get a permissions error:
ERROR: could not open file '/var/lib/pgsql/data/file.csv" for reading: Permission denied
SQL state: 42501
It is the inconsistency of the error that is confusing to me. When the error arises, I change the file permission to anywhere from 644 - 777, with no effect. I also try moving the file to other folders, e.g., var/tmp/, also with no effect.
Any ideas?
The problem is the access permissions trough the directories to the file. Postgres user does not have access to your home folder, for example. The answer is to use a folder all users have access like /tmp, or create one with the correct permissions so any user can access/read/write there, a sort of users shared folder.
I think your postgres user still don't have access to your file.
Did you tried the folowing commands ?
chown postgres /var/lib/pgsql/data/file.csv
chmod u+r /var/lib/pgsql/data/file.csv
Try \COPY table_name FROM '/var/lib/pgsql/data/file.csv'
WITH DELIMITER AS ',' csv header
Notice the backslash before copy, when you run it with back slash it runs with user permissions other wise it just runs as postmaster which in the documentation is deprecated for recent versions of pg :|, anyways this might probably do the trick for ya .
Related
I tried to copy csv data to a table with
#+begin_src sql :engine postgresql :dbuser postgres :dbpassword 1618 :database analysis
COPY us_counties_2010
FROM 'data/us_counties_2010.csv'
WITH (FORMAT CSV, HEADER);
#+end_src
It report error
psql:/tmp/babel-x3dXSm/sql-in-zo3MDm:3: ERROR: could not open file "data/us_counties_2010.csv" for reading: No such file or directory
HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.
The error "data/us_counties_2010.csv" for reading: No such file or directory does not exits, make no sense.
Because, it does exsit
#+BEGIN_SRC shell
ls -l 'data/us_counties_2010.csv' | sed "s/$USER/me/g"
#+END_SRC
#+RESULTS:
: -rw-rw-r-- 1 me me 1170359 Dec 7 10:22 data/us_counties_2010.csv
What's the problem? Does postgres developers invented yet another arcane path rules to prohibit users?
Where does the file exist? You are using an relative path.
When you use "COPY", what you get is:
The path will be interpreted relative to the working directory of the server process (normally the cluster's data directory), not the client's working directory.
Using \copy rather than COPY will get you not only the client's permissions, but also the clients working directory when searching for the file.
File permissions? I see that "me" has permissions. What user is postgresql?
I am trying to import a sample database "employees.sql" from official phpMyAdmin webpage. I am using uwamp server and getting the following error when using phpMyAdmin "import" option:
Unrecognized statement type. (near "source" at position 0)
.SQL FILE AT LINE WHERE ERROR IS REPORTED:
SELECT 'LOADING departments' as 'INFO';
source load_departments.dump ;
I am not sure what to change to successfully import the database. I also tried different things like putting load_departments.dump in quotes, but it still didn't work.
How do you use MySQL's source command to import large files in windows
must read and you will definitely get many ideas!
I think you should fire source command from cmd (command prompt)
I suggest you to create an empty database and import that sql file inside of it. Check it out..
Assumption: MySQL Server was installed and you have downloaded the employees database from github. Unzip the package and go to the directory from command prompt.
Enter the following command and on prompt, provide the sql password.
mysql -u root -p -t < employees.sql
Verify your installation by entering the following command.
mysql -u root -p -t < test_employees_md5.sql
I am trying to import contents of mysql table from a txt file.
I have already created dump of individual tables in .txt file. I then tried to import this txt file in my local server by LOAD DATA LOCAL INFILE. It worked fine locally. But when I tried to import using the same method in live. I am getting #1148 - The used command is not allowed with this MySQL version. I searched and followed steps from these two threads:
PHPMyAdmin saying: The used command is not allowed with this MySQL version
access denied for load data infile in MySQL
But it didn't work out. Now I am finding way to import these contents into the table from those txt files by ssh. Any help on how to do that from SSH will be great.
BTW, I am using mediatemple DV
TIA
I know that Mac OSx has pre-installed sqlite3.But when I am entering this command, when in
/usr/bin directory, sqlite3 test.db i get this displayed on terminal..
Adityas-MacBook-Air:bin adityabahuguna$ sqlite3 test.db
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
Its fine till now. But when i try to create a table by
sqlite> create table t(name text);
I always get this error:
Error: unable to open database "test.db": unable to open database file
This however does not occur when i directly use create table command without creating a new database. I want to figure out the way to create a new database (say test.db as above).
You're trying to create the database in /usr/bin where normal users don't have write access.
You can write to /usr/bin with root/sudo as suggested by Atul but that's not really something you should do.
Instead, specify a database path that is writable by your normal user, for example
sqlite3 ~/test.db
so the test.db gets created in your home directory.
you need to be logged in as root user to have create database privilege. you can become root user by following these steps: How to Become root user.
I am experiencing some permission problems with my SELECT ... INTO OUTFILE statement.
When I log into my database and do a simple export command, eg:
mysql> select * from XYZ into outfile '/home/mropa/Photos/Desktop/TEST.txt';
I get the respond:
ERROR 1 (HY000):
Can't create/write to file '/home/mropa/Photos/Desktop/TEST.txt'
(Errcode: 13)
However, when I simply write:
mysql> select * from XYZ into outfile 'TEST.txt';
Query OK, 8287 rows affected (0.73 sec)
The file is written into the directory /var/lib/mysql/XYZ.
I looked into the file /etc/apparmor.d/usr.sbin.mysqld where mysql seems to define the reading and writting permissions but I don't really know how to modify it.
How can I give myself permission to export a mysql table into any directory I like?
The issue is directory permissions. mysqld does not run as current_user. Add the mysqld user to the group that has write permissions on your target directories (convenient, but not as secure) or remember to change your target directory permissions before and after you write the outfile.
you can create a directory that is writable by the user that is running mysqld (usually "mysql") and write the file there. For intance:
chmod a+w /home/mropa/mysql
This sounds like you don't have access to that particular folder.
You should add mysql to the group owner of that particular location.
I don't know under what user you are running mysql under, however,
chown mysql:mysql on /home/mropa/Photos/Desktop/logs would mean that mysql user and mysql group is the owner so has permission. You then need to make sure that the permissions include writing but that should be sufficient.
Chown Command
See https://wiki.ubuntu.com/DebuggingApparmor for information on debugging/disabling apparmor profiles.
It may not be an apparmor issue in particular. The user that mysqld is running as may not have permissions to write to the folder you specified. Check the permission on the destination directory/file.
mysql usually runs under user mysqld. permissions may be solved directly with apparmor. see this answer