Showing posts with label How to Create Server And Database Using pgAdmin 4. Show all posts
Showing posts with label How to Create Server And Database Using pgAdmin 4. Show all posts

Sunday, 23 July 2023

Why pgAgent Job Is Not Working || How To Check pgAgent Job Working Or No...



Are your pgAgent jobs in PostgreSQL not working as expected? This video is designed to help you diagnose and resolve issues related to pgAgent job failures. We walk you through the most common reasons why pgAgent jobs might not be running and provide detailed steps on how to check their status using pgAdmin.

First, we explore the various factors that can cause pgAgent jobs to fail, such as configuration errors, permission issues, and server-side problems. Then, we demonstrate how to verify whether your jobs are running correctly by inspecting job logs, job schedules, and job definitions.

Additionally, this tutorial offers troubleshooting tips to fix common issues and ensure that your jobs execute reliably. We also share best practices for monitoring and maintaining your pgAgent jobs, so you can automate your PostgreSQL tasks with confidence.

Whether you're a database administrator, developer, or PostgreSQL enthusiast, this video will equip you with the knowledge you need to keep your pgAgent jobs running smoothly.


pgAgent job not working, check pgAgent job, PostgreSQL pgAgent, troubleshoot pgAgent job, pgAdmin job scheduling, pgAgent job failure, pgAgent troubleshooting, PostgreSQL automation, pgAgent best practices, PostgreSQL job monitoring
Please Like, Comment, and Subscribe to my channel. ❤


create table test_job (id numeric, time_stamp timestamp default current_timestamp);

SELECT * FROM test_job;

delete FROM test_job;

call public.testing_job_proc();

CREATE OR REPLACE PROCEDURE public.testing_job_proc()
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
lv_id numeric;
BEGIN
begin
select coalesce(max(id),0)+1 into lv_id from test_job;
exception when others then 
lv_id := 0;
end;
Insert into test_job(id) values(lv_id);
END;
$BODY$;


DO $$
DECLARE
    jid integer;
    scid integer;
BEGIN
-- Creating a new job
INSERT INTO pgagent.pga_job(
    jobjclid, jobname, jobdesc, jobhostagent, jobenabled
) VALUES (
    1::integer, 'Test_Job'::text, 'Test Job'::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, 'Step1'::text, true, 's'::character(1),
    ''::text, 'postgres'::name, 'f'::character(1),
    'call public.testing_job_proc();'::text, 'Step1 Test Job Proc'::text
) ;

-- Schedules
-- Inserting a schedule
INSERT INTO pgagent.pga_schedule(
    jscjobid, jscname, jscdesc, jscenabled,
    jscstart, jscend,    jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths
) VALUES (
    jid, 'Scheduler1'::text, ''::text, true,
    '2023-07-23 20:00:00+05:30'::timestamp with time zone, '2023-07-31 20:00:00+05:30'::timestamp with time zone,
    -- Minutes
    '{t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t}'::bool[]::boolean[],
    -- Hours
    '{t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t}'::bool[]::boolean[],
    -- Week days
    '{t,t,t,t,t,t,t}'::bool[]::boolean[],
    -- Month days
    '{t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t}'::bool[]::boolean[],
    -- Months
    '{t,t,t,t,t,t,t,t,t,t,t,t}'::bool[]::boolean[]
) RETURNING jscid INTO scid;
END
$$;

Tuesday, 11 August 2020

How To Create A Stored Procedure And Insert Data Into A Table By Calling...




How To Create A Stored Procedure And Insert Data Into A Table By Calling/Using The Stored Procedure

In this tutorial, you’ll master the process of creating a stored procedure in PostgreSQL and learn how to insert data into a table by calling this procedure. Stored procedures are essential for encapsulating complex SQL operations, and this video will guide you through each step of the process.

We begin by introducing the concept of stored procedures and their benefits, particularly in terms of code reuse and simplifying database management. You'll see a detailed explanation of how to define a stored procedure in PL/pgSQL, the procedural language of PostgreSQL.

Next, we focus on a practical example: creating a stored procedure that inserts data into a specific table. This part of the video will show you:

  • How to declare the procedure.
  • How to define the input parameters that will pass the data to be inserted.
  • How to write the SQL commands within the procedure to perform the data insertion.

Finally, you’ll learn how to call this stored procedure from both pgAdmin and SQL Shell (psql), ensuring that you can apply this knowledge in your daily database management tasks.

This tutorial is perfect for database administrators, developers, and anyone looking to improve their PostgreSQL skills. By the end of the video, you’ll have the knowledge to efficiently create and utilize stored procedures for data manipulation in PostgreSQL.

PostgreSQL, stored procedure, insert data, SQL, table insertion, PLpgSQL, PostgreSQL tutorial, database management, pgAdmin, SQL Shell, data manipulation

-- the purpose is to create a simple stored procedure in PostgreSQL

-- and Insert Data in the table by calling it using pgAdmin
CREATE TABLE public.testing_table (dummy_column text);
CREATE OR REPLACE PROCEDURE public.testing_procedure(p_msg text)
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
BEGIN
INSERT INTO public.testing_table(dummy_column) VALUES('Before Inserting Parameter Value');
INSERT INTO public.testing_table(dummy_column) VALUES (p_msg);
INSERT INTO public.testing_table(dummy_column) VALUES('After Inserting Parameter Value');
END;
$BODY$;
SELECT * FROM public.testing_table;
DELETE from public.testing_table;

CALL public.testing_procedure('Hello Akram, How are you?');
Before Inserting
the message I pass as a parameter
After Inserting...