0

我对 postgresql 很陌生,无法理解以下查询的作用,因此需要一些社区成员的帮助,他们可以向我解释这一点。

DO $$
DECLARE
    jid integer;
    scid integer;
BEGIN
-- Creating a new job
INSERT INTO pgagent.pga_job(
    jobjclid, jobname, jobdesc, jobhostagent, jobenabled
) VALUES (
    1::integer, 'backup'::text, ''::text, ''::text, true
) RETURNING jobid INTO jid;

-- Steps
-- Inserting a step (jobid: NULL)
INSERT INTO pgagent.pga_jobstep (
    jstjobid, jstname, jstenabled, jstkind,
    jstconnstr, jstdbname, jstonerror,
    jstcode, jstdesc
) VALUES (
    jid, 'backup'::text, true, 'b'::character(1),
    ''::text, ''::name, 'f'::character(1),
    'set PGPASSWORD=password
pg_dump -h "localhost" -U "postgres" -f "D:\backup\backuppg_%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%" "postgres"'::text, ''::text
) ;
4

1 回答 1

0

对于 PostgreSQL 中的备份,您使用pg_dump

pg_dump -h "localhost" -U "postgres" -f "D:\backup\backuppg_%date:~-4% %date:~3,2% %date:~0,2%__%time:~0, 2% %time:~3,2% %time:~6,2%" "postgres"'::text, ''::text ) ;

在上面的备份命令中,您正在使用 psql 和下面解释的选项

-h --host     --> Specifies the hostname of the machine
-U --username --> The user which is used for login 
-f --file     --> This option is used to send output to the specified file
post that "postgres" is the database which is being backed up

现在这将在目录 D:\backup 中D:\backup\backuppg_%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%创建一个名为的文件backuppg_<date>_<time>

其余都是 INSERT 命令在名为pgagent.pga_job和的表中附加有关备份的信息pgagent.pga_jobstep

于 2021-07-17T16:06:07.620 回答