How to install PgAgent in Windows

If you are developer, then you might come across the postgresql database.  It was a famous database which was used by most of the developers because of its robust features. In postgresql there is a small application called pgagent which was used for doing jobs in PgAdmin.

The work of the PgAgent is to run the script which you have configured in PgAdmin.  if you want to use postgre SQL in the G remote then you need to go for period means it does the job neatly.  pgagent access one of the plug in which was used in the PG admin.

The work of the pgagent is to schedule a job, which will be running at the specific time which the user has mentioned. PgAgent was mostly used for taking the backup of the database.

How to Install PgAgent:

To install PgAgent Goto Start -> PostgreSQL -> Application Stack Builder -> Select the PostgreSQL Server on 5432 Port -> Goto Addons and Select the PgAgent -> Install the Addon.





After selecting the pgagent add on, proceed to install, the installation will take for about 2 minutes depending on the bandwidth you are having. It will download a file from the Internet, that will be installed in your computer. After completing the installation, you can open PG admin and check for the jobs option in your database.

I will tell you with some scripts, which was used for taking a regular backup of a database using the PgAgent.

@echo off
REM - backup directory can be a file server share that the PgAgent windows service account has access to
set BACKUPDIR="/path/to/backup/"
set PGHOST="localhost"
set PGUSER="postgres"
set PGBIN="C:/Program Files/PostgreSQL/8.2/bin/"
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
 set dow=%%i
 set month=%%j
 set day=%%k
 set year=%%l

for /f "tokens=1-3 delims=: " %%i in ("%time%") do (
 set hh=%%i
 set nn=%%j

REM - It would be nice to use gzip in the pg_dumpall call (or if pg_dumpall supported compression as does the pg_dump)
REM here as we do on the linux/unix script
REM - but gzip is not prepackaged with windows so requires a separate install/download. 
REM Our favorite all purpose compression/uncompression util for Windows is 7Zip which does have a command-line
%PGBIN%pg_dumpall -h %PGHOST% -U %PGUSER% -f %BACKUPDIR%fullpgbackup-%year%%month%.sql 
%PGBIN%pg_dump -i -h %PGHOST% -U %PGUSER% -F c -b -v -f "%BACKUPDIR%db1-%year%%month%%day%%hh%.compressed" db1
%PGBIN%pg_dump -i -h %PGHOST% -U %PGUSER% -F c -b -v -f "%BACKUPDIR%db2-%year%%month%%day%%hh%.compressed" db2

This is the script, which we can use to take backup of the postgresql database on the daily basis, it will take the backup of the database in the regular manner that is each and every day and it also deletes the old backups. You can keep this as an option. You can change the script to do some of the activities on the regular basis.

You can also check out the detailed documentation of How to install pgagent in the windows.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *