Importing a CSV into PostgreSQL fails with Permission denied
Permission denied when importing a CSV file from pgAdminShort answer
COPY with a file name is read by the database server, not by pgAdmin or your computer. So the file must be readable by the server's own operating-system user, and your role must be a superuser or hold pg_read_server_files. If the file sits on your machine, load it through psql's \copy instead.
Fix it fast
1Find out which cause you have
Find out who you are in the database and whether the server is on the same machine as the file.
SELECT current_user, pg_has_role(current_user, 'pg_read_server_files', 'member') AS can_read_server_files; SELECT inet_server_addr();2Match what you see, then jump to its fix
- 1
Permission denied, and the CSV lies in a personal folder such as Downloads or DesktopThe server's operating-system user cannot read the fileFix - 2
The file is readable by the server account and the error still appears, or the first-step query shows falseYour database role may not read server filesFix - 3
The server is remote, in Docker or in a VM, so the path you typed does not exist or is closed for itThe file is on your computer but the server is somewhere elseFix
- 1
What does the error look like?
Permission denied when importing a CSV file from pgAdminPermission denied (CSV import through pgAdmin Import/Export)
Cause 1 of 3
The server's operating-system user cannot read the file
1Check
The server opens the file itself, as the user ID the server runs as. A file in your own home folder is usually closed to that account. Compare the file's permissions with the service account.
# Linux / macOS
ls -l /path/to/data.csv
ps -o user= -p $(pgrep -o postgres)2Fix
Copy the file to a folder the server account can read (for example a shared data folder), or give that account read access to the file and to every folder above it.
sudo cp data.csv /var/lib/postgresql/import/data.csv
sudo chown postgres:postgres /var/lib/postgresql/import/data.csv3Verify
Run the import again with the new absolute path.
COPY my_table FROM '/var/lib/postgresql/import/data.csv' WITH (FORMAT csv, HEADER true);Confirmed by postgresql.org
Cause 2 of 3
Your database role may not read server files
1Check
COPY that names a file is allowed only to superusers and to roles granted pg_read_server_files. The first query above shows whether your role is a member.
SELECT rolname, rolsuper FROM pg_roles WHERE rolname = current_user;2Fix
Either have an administrator grant the role, or skip server-side reading and use the client-side route in the next cause.
GRANT pg_read_server_files TO my_user;3Verify
Reconnect and run the first-step query again.
SELECT pg_has_role(current_user, 'pg_read_server_files', 'member');Confirmed by postgresql.org
Cause 3 of 3
The file is on your computer but the server is somewhere else
1Check
A server-side COPY can only see files on the machine where the server runs. psql's \copy reads the file on your side and sends the rows over the connection, so it needs no server access and no special role.
psql -h db.example.com -U my_user -d my_db -c "SELECT inet_server_addr();"2Fix
Use \copy from psql, with the path on your own machine.
psql -h db.example.com -U my_user -d my_db
\copy my_table FROM '/home/me/data.csv' WITH (FORMAT csv, HEADER true)3Verify
psql prints the row count as COPY n.
SELECT count(*) FROM my_table;Confirmed by postgresql.org
How do I stop it coming back?
- Keep import files in one agreed folder that the server account can read, not in personal folders.
- Use \copy for one-off loads from your own machine, so no server role needs widening.
- Grant pg_read_server_files only to roles that really load files on the server.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Databases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
DBeaver cannot download the PostgreSQL driver from Maven
The PostgreSQL driver files are missing and the download does not complete
DBeaver downloads the PostgreSQL JDBC driver from a Maven repository the first time you connect.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
Django save fails on PostgreSQL: null value in a column violates a not-null constraint
django.db.utils.IntegrityError: null value in column "price" of relation "shop_product" violates not-null constraint
A model field is NOT NULL in the database unless it has null=True.
3 causes, each with a fixDatabases
Django migration on PostgreSQL stops with 'pending trigger events'
django.db.utils.OperationalError: cannot ALTER TABLE "mytable" because it has pending trigger events
PostgreSQL runs a Django migration in one transaction.
2 causes, each with a fixDatabases
Django cannot connect to PostgreSQL: connection refused on port 5432, locally or in Docker
Is the server running on that host and accepting TCP/IP connections?
Connection refused means nothing accepted the connection at the host and port Django used.
4 causes, each with a fix