Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Importing a CSV into PostgreSQL fails with Permission denied

ErrorPermission denied when importing a CSV file from pgAdmin

Short 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.

  • Applies to PostgreSQL 17, PostgreSQL 18, pgAdmin 4 9.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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();
  2. 2Match what you see, then jump to its fix

    1. 1Permission denied, and the CSV lies in a personal folder such as Downloads or DesktopThe server's operating-system user cannot read the fileFix
    2. 2The 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. 3The 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

What does the error look like?

  • Permission denied when importing a CSV file from pgAdmin
  • Permission 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.csv

3Verify

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

Did this fix it?

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

Did this fix it?

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

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.