简体   繁体   English

在pgAgent中设置文件导出

[英]Set Up File Export in pgAgent

I'm new to pgAgent, and trying to set up a job that will export a file every 5 minutes (just for testing; once I have the syntax down it'll be dispersed to numerous jobs). 我是pgAgent的新手,并尝试设置一个每5分钟导出一次文件的作业(仅用于测试;一旦我掌握了语法,它将分散到许多作业中)。 The below test code works fine when I run it in a query editor, however pgAgent doesn't seem to like it. 当我在查询编辑器中运行它时,下面的测试代码工作正常,但是pgAgent似乎不喜欢它。 Any help on what I need to change? 对我需要更改的任何帮助吗?

DO $$
DECLARE ssql varchar := 'COPY (SELECT * FROM public.users LIMIT 10) TO ''C:\Program Files\PostgreSQL\11\pgExport' || TO_CHAR(NOW(),'YYYYMMDDHH24MI') || '.csv'' WITH CSV DELIMITER '','' HEADER;';

BEGIN
    EXECUTE ssql;
END; $$

I can't find any sort of error as far as what's happening; 就发生的事情而言,我找不到任何类型的错误; rather the file just doesn't appear when I run the job manually nor when I let the schedule run. 相反,当我手动运行作业时,或者当我让计划运行时,文件才会出现。

So it turned out to not be a syntax issue, but rather a permissions issue. 因此,事实证明这不是语法问题,而是权限问题。 Found the answer here ( couldn't get a connection to the database - Postgres Job Scheduling issued (Windows based machine) ) if anyone is interested - basically have to set job as a "remote" server (even if running locally) and supply the connection string with localhost. 如果有人感兴趣,请在这里找到答案( 无法连接到数据库-发出Postgres Job Scheduling(基于Windows的计算机) )-基本上必须将作业设置为“远程”服务器(即使在本地运行)并提供连接字符串与localhost。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM