Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1os6ns-0004Kj-12 for pgsql-general@arkaria.postgresql.org; Mon, 07 Nov 2022 18:25:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1os6nq-0007XL-7p for pgsql-general@arkaria.postgresql.org; Mon, 07 Nov 2022 18:24:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1os6no-0007Wv-Jd for pgsql-general@lists.postgresql.org; Mon, 07 Nov 2022 18:24:57 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1os6nk-0007Hd-He for pgsql-general@lists.postgresql.org; Mon, 07 Nov 2022 18:24:56 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id C31BD320098A; Mon, 7 Nov 2022 13:24:48 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 07 Nov 2022 13:24:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1667845488; x= 1667931888; bh=ulztUGNW/GTQuNxRZ2jbEwIkhjL6oWyHDh4coPP7Nnc=; b=6 QQKks907L/uZx6BXJlsJiPO+FeYBN1J0FVFLyO/ahXkj7oXPXfE3PbK3XcpfRjl0 6tjKCQ55lXmpYc2Lr5xlkrguSBDL3mJnrndMjv2CYj3G9n7AzXlGTM2ls4V0u9aM f2g1K7t7FU+PAakyWDFYe0MbSTxaNW7Yi7jY0IeadnIfRGZdd3I/13sfuqYwX+Kp iKqWf1Iszd9ls3aPRLm3fC1Plnt+0etArnJJNRllS4kb6EiKKLnM3a2GgY/SeJYu vctyyDLRgY5pkicyeiXpPAEOnvBgFtasLb4BK+1LqZLjGWoOjd3yybFkC8RjFAMm 84UVXt+jVCNiZtC1JliPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1667845488; x=1667931888; bh=u lztUGNW/GTQuNxRZ2jbEwIkhjL6oWyHDh4coPP7Nnc=; b=AHBsrOtS9HVdMd5+U gc9UI0O8KIfThu8DCw47DWdcFvYRTEEdtlVVu6bgzK5P03F3AqawCQI0ro2pIKpO U+0JQTD4QQcm3y52OqBzky2vjfFwkxBTnD8qsQN/EQN9G3r5MfkggMdbhPHSrRd4 WKaJsOAvQk9WotInR+UbacHXVckuikPrL6gN7pytKiy2HpYyxeWfK4cN4lVV3kE9 99kwB5Gl7730QoZ1REM/G4AmG5e58aRcb8Fk7xyXBak0TZ64zu8gh+wu7Rab/obH SjHuTBaeX4JhXeiAWLSTrDQwJcyIgU9FOUN1jUun+Mfxr2rKwMqlb2xIJQNS6KXA mvQDQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrvdekgdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnheptedvgfeule ejgefhvdektdevgeefkeekjeekhfejheejffdvheeikeelkefhhffhnecuffhomhgrihhn pehsthgrtghkohhvvghrfhhlohifrdgtohhmpdhpohhsthhgrhgvshhqlhdrohhrghenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgr nhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 7 Nov 2022 13:24:47 -0500 (EST) Subject: Re: copy file from a client app to remote postgres isntance To: =?UTF-8?B?0JLQsNC00LjQvCDQodCw0LzQvtGF0LjQvQ==?= , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Mon, 7 Nov 2022 10:24:46 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/7/22 8:57 AM, Вадим Самохин wrote: > Hi all, > I have an application that must copy a local file in csv format to a > postgres table on a remote host. The closest solution is this one > (https://stackoverflow.com/a/9327519/618020 > ). It boils down to > specifying a \copy meta-command in a psql command: > > |psql -U %s -p %s -d %s -f - < || > and executing it. B|ut it's quite an unnatural way to write database > code. Has anything changed in the last ten years? Or, is there a better > wayto copy file contents in a remote database? > 1) Set up postgres_fdw: https://www.postgresql.org/docs/current/postgres-fdw.html on local machine to point at table on remote machine and then \copy or COPY to local machine. 2) Copy the CSV file to remote machine and then do \copy or COPY there. -- Adrian Klaver adrian.klaver@aklaver.com