A
A
Alexander Vishnev2019-09-16 16:04:10
PostgreSQL
Alexander Vishnev, 2019-09-16 16:04:10

How to import data into PostgreSQL DB via psql to remote server?

I'm trying to upload data from a text file to a remote server in a PostgreSQL database.

@echo off
"C:\PostgreSQL\11\bin\psql.exe" -h srv.local -U postgres -d postgres -p 5432 -c "COPY datatest FROM 'C:/1.txt' DELIMITER '|' CSV HEADER"
pause

But it throws an error:
ОШИБКА:  не удалось открыть файл "C:/1.txt" для чтения: No such file or directory
ПОДСКАЗКА:  COPY FROM указывает серверному процессу PostgreSQL прочитать данные из файла. Возможно, на самом деле вам нужно клиентское средство, например, \copy в psql.
Для продолжения нажмите любую клавишу . . .

The file definitely exists. He gave me the rights that are possible.
Locally (on the server) the data is normally imported by such command.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2019-09-16
@fromdns

The command COPYreads the file on the server, not where you started psql.

A
Anton, 2019-09-17
@Anton-PG

psql -h "Host" -U "User" < sql.sql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question