How do I launch postgresql on terminal without using homebrew? (SQL state: 42501, trying to import CSV to pgAdmin4 with COPY) - postgresql

I am unable to import a CSV with postgres(v12) into pgAdmin4 using the copy command.
COPY revenue
FROM "../Desktop/Home/revenue.csv"
DELIMITER ','
CSV HEADER;
The result I get is:
ERROR: could not open file "../Desktop/Home/revenue.csv" for reading: Permission denied
HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.
SQL state: 42501
I found article
How to import a CSV file into PostgreSQL using Mac
but it was unsolved and I already tried ging the user 'postgres' 'read and write' permissions. Maybe I did it wrong, I right clicked on the CSV file and I also tried giving it permission in pgAdmin4 (properties, default privileges)
I found the solution below suggesting I launch postgres from my command line
Postgres ERROR: could not open file for reading: Permission denied
However everything I read on launching postgres on a mac via command line includes homebrew. I didn't install postgresql with homebrew.
-Can I launch postgres on a mac without using homebrew?
If I install homebrew, will it work to launch postgresql even if I didn't use it to install postgres initially?
-Is there another way to use the copy command via pgadmin ? (I tried using dbeaver but it wouldn't connect to my database)
I am super lost.
Thank you!

Related

I can't open the file in SQL Shell Permission Denied

I have a 10gb postgresql file I am trying to open but it is not allowed.Pgadmin gives the output exit code as 1 and I can't get the data. When I do it in SQL Shell, it says it didn't allow it.When I put it in the general file areas, it still gives an error. I set the sharing options for everyone, it still didn't work.
Postgresql 9.6 and Pgadmin 4v4

Postgresql Permission denied for Copy from on Windows

I am running postgresql with pgAdmin4 on windows x64. I just created a database, then a table and now I want to add data to the table from an excel sheet using
copy table from 'C:\Users\username\Desktop\copy.csv' delimiter ',' csv header;
I get this error message:
ERROR: could not open file "C:\Users\username\Desktop\copy.csv" for
reading: Permission denied HINT: COPY FROM instructs the PostgreSQL
server process to read a file. You may want a client-side facility
such as psql's \copy. SQL state: 42501
I tried running it as admin but it didn't help.
Side note: pgadmin 4 opens on my Firefox browser with high privacy settings in case it has anything to do with it.
For people who are still having this issue, one of the fastest workarounds I found (that sidesteps permission changes) is to use the "Users\Public" folder when reading or writing files.
E.g if you want to read in "copy.csv", moving the file's location to "Users\Public\copy.csv" should allow you to read it without explicitly setting permissions for postgres/pgadmin

Import CSV to Azure PostgreSQL withough Superuser

I'm trying to upload a CSV file into Azure Postgresql. However when I run the command, I get the following error:
ERROR: must be superuser to COPY to or from a file
However, Azure Postgresql doesn't allow users to be super users. How can I import the file?
Have you tried the \copy command available in psql? I'm fairly sure it allows reading/ writing files local to the client and doesn't require you to be a superuser. See https://codeburst.io/two-handy-examples-of-the-psql-copy-meta-command-2feaefd5dd90

Export Postgres table to csv

I am trying to export my Postgres table to a csv on my desktop and I get this error:
ERROR: could not open file "C:\Users\blah\Desktop\countyreport.csv" for writing: Permission denied
SQL state: 42501
This is my query which I believe is the correct syntax
COPY countyreport TO 'C:\\Users\\blah\\Desktop\\countyreport.csv' DELIMITER ',' CSV HEADER;
According to the user manual:
Files named in a COPY command are read or written directly by the
server, not by the client application.
https://www.postgresql.org/docs/current/static/sql-copy.html
The common mistake is to believe that the filesystem access will be that of the (client) user, but it's not. It's normal to run the postgresql server as its own user. Therefore action carried out by the server will be done as a different OS user to the client. The server is usually run as an OS user postgres.
Assuming that you are running the server on your local machine then the simplest way to fix it would be to give postgres access to your home directory or desktop. This can be done by changing the windows security settings on your home directory.
Before you do this.... Stop and think. Is this what you are looking for? If the server is in development then will it always run on the user's machine. If not then you may need to use COPY to write to the stdout. See the manual for information on this.

could not open file error with PostgreSQL

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.