Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

0 votes
1 answers
5576 views
Using pgagent with docker?
I wanted to dive into the world of postgresql so I installed both postgresql and pgadmin using docker (with the portainer web ui) and I found out that for automatic jobs you gotta install pgagent too but I haven't been able to find any information on running it with docker. I found this image https:...
I wanted to dive into the world of postgresql so I installed both postgresql and pgadmin using docker (with the portainer web ui) and I found out that for automatic jobs you gotta install pgagent too but I haven't been able to find any information on running it with docker. I found this image https://hub.docker.com/r/chiavegatto/postgres-pgagent but portainer throws a 400 error code when trying to deploy the container which I haven't been able to figure out and I'm not quite sure of how this setup would work either. I saw it executes the following command pgagent -f hostaddr=postgres dbname=test user=postgres port=5432 at the entrypoint but what if I want to schedule jobs on multiple databases? - Has anyone been able to run pgagent with docker? - Is there any image of postgresql that comes with the agent preinstalled?
Jose134 (11 rep)
Mar 2, 2023, 08:17 PM • Last activity: Jul 30, 2025, 11:02 PM
0 votes
1 answers
404 views
How to fix PgAgent stuck on "r" on batch step errors?
On windows (10,11 and windows server 2022). With PostgreSQL 14 and 15. Pgagent is running as a service. [![enter image description here][1]][1] It runs SQL jobs and access pgpass correctly to run jobs as Local on multiple DBs. It also execute batch files correctly. **BUT if the batch files called in...
On windows (10,11 and windows server 2022). With PostgreSQL 14 and 15. Pgagent is running as a service. enter image description here It runs SQL jobs and access pgpass correctly to run jobs as Local on multiple DBs. It also execute batch files correctly. **BUT if the batch files called in the step does not exists, the job fail (as expected) but the step hangs in an "r" state.** Job log: The job Step log: The step The expected behavior is that it return as status "f", result "1" and output "path to file does not exist" On another vm, with pg10, It works as intended like below: Expected result The "r" state is not an effect of PgAgent crashing. The service keeps running.(To be noted that the service crash if I run another agent that crashes whether it is SQL or Batch) **Anyone had that issue and managed to fix it ?** EDIT : The postgresql log points to the encoding. It is in french and the accents aren't handled. *2023-05-31 17:08:05.928 CEST ERREUR: séquence d'octets invalide pour l'encodage « UTF8 » : 0x82*
Boodoo (65 rep)
May 30, 2023, 06:58 PM • Last activity: Feb 27, 2025, 04:00 PM
2 votes
1 answers
5026 views
pgAgent not working on linux (Ubuntu 14.04)
I am running Postgres 9.3 on Ubuntu 14.04 and I am unable to get pgAgent daemon/service to run. I have confirmed that the daemon is not running using `service --status-all`. When trying to run pgagent (whilst logged in as the only user in ubuntu) using `pgagent hostaddr=127.0.0.1 dbname=postgres use...
I am running Postgres 9.3 on Ubuntu 14.04 and I am unable to get pgAgent daemon/service to run. I have confirmed that the daemon is not running using service --status-all. When trying to run pgagent (whilst logged in as the only user in ubuntu) using pgagent hostaddr=127.0.0.1 dbname=postgres user=user1 the following messages are displayed: WARNING: Couldn't create the primary connection (attempt 10): fe_sendauth: no password supplied ERROR: Stopping pgAgent: Couldn't establish the primary connection with the database server. The lack of running pgAgent was also confirmed when trying to run a job on demand. The user 'user1' is able to log into pgAgmin and connect to the database from other computers on the local network. The user looks like this in the pg_hba.conf file: # Database administrative login by Unix domain socket local all user1 md5 A .pgpass password file also exists for this user in the home directory. What is causing the above messages and what needs to be done to get pgAgent to run scheduled tasks?
Greg (381 rep)
Nov 28, 2015, 11:30 AM • Last activity: Jan 6, 2025, 12:23 PM
0 votes
0 answers
44 views
Postgresql PgAgent can't execute Batch Job "Error: Can not open logfile"
We have a Job setup on PGadmin that is being run via PgAgent in linux. However, when the Job is set as Batch. Even a simple script is getting same error [![Job Kind (SQL or Batch)][1]][1] error message says [![Eror: Can not oepn the logfile! ][2]][2] Any solution would be a great help, thanks [1]: h...
We have a Job setup on PGadmin that is being run via PgAgent in linux. However, when the Job is set as Batch. Even a simple script is getting same error Job Kind (SQL or Batch) error message says Eror: Can not oepn the logfile! Any solution would be a great help, thanks
julius angeles (1 rep)
Sep 5, 2024, 04:25 PM • Last activity: Sep 5, 2024, 04:40 PM
1 votes
0 answers
207 views
PgAdmin4 cant find pgagent as an extension MacOS
I installed **pgagent** using **EnterpriseDB**'s installer on MacOS. However, pgagent doesn't show up in pgadmin after the installation. Even when I try to manually add pgagent as an extension, I get the error: >extension "pgagent" is not available and that pgadmin "Could not open extension control...
I installed **pgagent** using **EnterpriseDB**'s installer on MacOS. However, pgagent doesn't show up in pgadmin after the installation. Even when I try to manually add pgagent as an extension, I get the error: >extension "pgagent" is not available and that pgadmin "Could not open extension control file "/Applications/Postgres.app/Contents/Versions/15/share/postgresql/extension/pgagent.control": No such file or directory" Here are the installed pgagent files inside the mentioned directory, so I don't understand why it's not recognizing it. enter image description here
champa (11 rep)
Aug 6, 2023, 03:38 AM • Last activity: Aug 6, 2023, 04:30 AM
1 votes
1 answers
525 views
How to determine the version of pg_agent installed?
How do I determine the version of pg_agent installed? Is it queriable with SQL just like checking PostgreSQL version / PostGIS version ?
How do I determine the version of pg_agent installed? Is it queriable with SQL just like checking PostgreSQL version / PostGIS version ?
Rino (229 rep)
Sep 2, 2022, 06:51 AM • Last activity: Jan 2, 2023, 02:49 PM
1 votes
1 answers
254 views
pgAgent unwanted delay between jobs start time
I've been trying to make jobs running continuosly, so after previous run is done, the next one starts immediately. I made some initial success with following trigger: CREATE or replace FUNCTION continous_jobs() RETURNS trigger AS $$ BEGIN NEW.jobnextrun = clock_timestamp(); RETURN NEW; END; $$ LANGU...
I've been trying to make jobs running continuosly, so after previous run is done, the next one starts immediately. I made some initial success with following trigger: CREATE or replace FUNCTION continous_jobs() RETURNS trigger AS $$ BEGIN NEW.jobnextrun = clock_timestamp(); RETURN NEW; END; $$ LANGUAGE plpgsql; CREATE TRIGGER continous_jobs_trg BEFORE UPDATE OF jobnextrun ON pgagent.pga_job FOR EACH ROW when (NEW.jobdesc = 'CONTINOUS_JOB' ) EXECUTE PROCEDURE continous_jobs(); I set some test job, with pg_sleep(5) inside, and it worked great enter image description here But after that I put there some real procedure inside, and it started to have delays (3-5 seconds). Why is that happening? I tried setting different jobnextrun values, also clock_timestamp() - '5 second'::interval, but it's still the same, delay is about couple of seconds
sh4rkyy (149 rep)
Dec 16, 2022, 10:25 AM • Last activity: Dec 25, 2022, 08:40 PM
2 votes
1 answers
2793 views
PostgreSQL: how to query statistics of a step in pg_agent?
PgAdmin shows statistics of each run of a step of pg_agent (job). The list details the run ID, status, result, start & end & duration. The following is how it looks: [![enter image description here][1]][1] How to get it by query command ? [1]: https://i.sstatic.net/z2gn3.png
PgAdmin shows statistics of each run of a step of pg_agent (job). The list details the run ID, status, result, start & end & duration. The following is how it looks: enter image description here How to get it by query command ?
Rino (229 rep)
Jul 7, 2022, 02:06 AM • Last activity: Dec 15, 2022, 09:36 AM
-1 votes
1 answers
517 views
How put repeat jobs in pgAgent
I have several data sources and create a C# app to connect to each one, download the data and insert into postgres. That create a Data Pool and I create a Timer Event to execute a store procedure to process that pool in batch of 800. The problem is sometimes the 800 batch give me a time out. So I wa...
I have several data sources and create a C# app to connect to each one, download the data and insert into postgres. That create a Data Pool and I create a Timer Event to execute a store procedure to process that pool in batch of 800. The problem is sometimes the 800 batch give me a time out. So I want change that from C# timer to pgAgent. I have configure pgAgent before, but not sure how will work on this case. Lets say I set the pgAgent to execute process every min - check for the unprocess rows, select 100 and start the process. - but if after one min the process hasnt end it, pgAgent will start again and see the same 100 rows unprocessed. - Also the process need to be sequential, I cant start rows 100 to 200 until first 100 are done. - Finally if process end In more than one minute and still data in the pool, the process should start again and not wait for the pgAgent timer. In C# I just create a thread and if after the timer run off the process is still busy I just wait for another minute. So can I configure pgAgent to handle this scenerio?
Juan Carlos Oropeza (427 rep)
Feb 23, 2016, 04:30 AM • Last activity: Oct 30, 2019, 05:00 AM
2 votes
1 answers
14320 views
pgAgent service for PostgreSQL does not run
OS: Windows 10 PostgreSQL 11.4 I Installed PgAgent with Stackbuilder setup. In Windows services; PostgreServer service is running. However, the pgAgent service is stopped. When I try to start pgAdmin service from there I get this error message: ``` The PostgreSQL Scheduling Agent - pgAgent service o...
OS: Windows 10 PostgreSQL 11.4 I Installed PgAgent with Stackbuilder setup. In Windows services; PostgreServer service is running. However, the pgAgent service is stopped. When I try to start pgAdmin service from there I get this error message:
The PostgreSQL Scheduling Agent - pgAgent service on Local Computer started and then stopped. 
Some services stop automatically if they are not in use by other services or programs.
I have the pgAgent service to log On As -->LocalSystem (Note, I have also tried to change it to an windows administrator account) When opening pgAdmin 4 I can see the pgAgent Jobs tab as well as create jobs. Acording to the description on this page ,one should create an extension as well. However, when pgAgent was installed , there wasen't copied any extension files to %\PostgreSQL\11\share\extension so I can not create the extension in pgAdmin Any advice on how I get the pgAgent service to run my jobs I have createn in pg Admin? ---------- **EDIT:** On This thread They state that editing pgpass.conf in c:/user/user/AppData/postgresql helped. I have no such folder nore file. The only postgres related folders I've found under C:\Users is C:\Users\user\AppData\Roaming\pgAdmin ---------- **EDIT2:** * I opened CMD as an admin and run cd %APPDATA% to find correct folder. * I created the pgpass.conf inside newly created folder postgresql in appdata --> C:\Users\user\AppData\Roaming\postgresql\pgpass.conf. * I added that file as a system variable PGPASSFILE (Source1 and Source2 ). That did not change anything either. Cholud I do some editting in REDEDIT? Source3 ----------
tomatoeshift (143 rep)
Sep 11, 2019, 01:52 PM • Last activity: Sep 13, 2019, 08:36 AM
0 votes
0 answers
1523 views
Unable to start PostgreSQL service after pgAgent installation
I had Postgre running just fine on my Windows 10 (64-bit). Then I tried to install pgAgent via the stackbuilder for postgres. I got some error that it was not able to create a .conf file under `%\user\appdata\postgres`. (Note That folder has never existed. I had my data under `C:\Program Files\Postg...
I had Postgre running just fine on my Windows 10 (64-bit). Then I tried to install pgAgent via the stackbuilder for postgres. I got some error that it was not able to create a .conf file under %\user\appdata\postgres. (Note That folder has never existed. I had my data under C:\Program Files\PostgreSQL\11\data) After that is asked me to restart my PC, so I did. Now I am not able to start pgAdmin, not able to start postgre from microsoft services. I am not either able to run the stack builder for postgres, it simply suggest that it might help to reinstall postgres. Can one stackbuilder install really corrupt my entire database? I got these messages in the logger:
2019-09-10 15:33:03.300 EEST  ERROR:  could not open extension control file "C:/Program Files/PostgreSQL/11/share/extension/pgagent.control": No such file or directory
2019-09-10 15:33:03.300 EEST  STATEMENT:  CREATE EXTENSION pgagent;
2019-09-10 15:35:23.957 EEST  ERROR:  could not open extension control file "C:/Program Files/PostgreSQL/11/share/extension/pgagent.control": No such file or directory
2019-09-10 15:35:23.957 EEST  STATEMENT:  CREATE EXTENSION pgagent;
2019-09-10 15:43:44.944 EEST  ERROR:  schema "pgagent" does not exist
2019-09-10 15:43:44.944 EEST  STATEMENT:  SELECT has_schema_privilege('pgagent', 'USAGE')
2019-09-10 15:48:53.247 EEST  ERROR:  schema "pgagent" does not exist
2019-09-10 15:48:53.247 EEST  STATEMENT:  SELECT has_schema_privilege('pgagent', 'USAGE')
2019-09-10 15:51:53.369 EEST  ERROR:  schema "pgagent" does not exist
2019-09-10 15:51:53.369 EEST  STATEMENT:  SELECT has_schema_privilege('pgagent', 'USAGE')
2019-09-10 15:59:04.716 EEST  ERROR:  schema "pgagent" does not exist
2019-09-10 15:59:04.716 EEST  STATEMENT:  SELECT has_schema_privilege('pgagent', 'USAGE')
2019-09-10 16:17:15.856 EEST  LOG:  could not receive data from client: An existing connection was forcibly closed by the remote host.
2019-09-10 16:17:15.857 EEST  LOG:  could not receive data from client: An existing connection was forcibly closed by the remote host.
2019-09-10 16:17:26.569 EEST  LOG:  received fast shutdown request
2019-09-10 16:17:26.575 EEST  ERROR:  canceling statement due to user request
2019-09-10 16:17:26.576 EEST  ERROR:  canceling statement due to user request
2019-09-10 16:17:26.580 EEST  LOG:  aborting any active transactions
2019-09-10 16:17:26.580 EEST  ERROR:  canceling statement due to user request
2019-09-10 16:17:26.609 EEST  LOG:  background worker "logical replication launcher" (PID 18252) exited with exit code 1
2019-09-10 16:17:26.609 EEST  LOG:  background worker "TimescaleDB Background Worker Launcher" (PID 18188) exited with exit code 1
2019-09-10 16:17:26.610 EEST  LOG:  background worker "TimescaleDB Background Worker Scheduler" (PID 20960) exited with exit code 1
2019-09-10 16:17:26.732 EEST  LOG:  shutting down
2019-09-10 16:17:26.898 EEST  LOG:  database system is shut down
**EDIT:** When I try to execute pg_ctl start -D C:\Program Files\PostgreSQL\11\data, I get this error:
The code execution cannot proceed because LIBPQ.dll was not found.
Reinstalling the program may fix this problem.
The code execution cannot proceed because libiconv-2.dll was not
found. Reinstalling the program may fix this problem.
I do have postgres in windows path **EDIT2:** I ended up reinstalling the PostgreSQL server. Now I got it working again. The source of the original problem was probably that pgAgent was installed in a folder where already existing postgre files were
tomatoeshift (143 rep)
Sep 10, 2019, 02:19 PM • Last activity: Sep 11, 2019, 10:03 AM
0 votes
1 answers
2466 views
How can I run a pgAgent job every 10 second?
I have a PostgreSQL 11.3 Database. I installed pgAgent for creating jobs. Now I want to run my job every 10 second, but in GUI there is possibility to write with precision of minutes, not with precision of second. [![re][1]][1] **Is it possible to run job created by pgAgent faster than every minute?...
I have a PostgreSQL 11.3 Database. I installed pgAgent for creating jobs. Now I want to run my job every 10 second, but in GUI there is possibility to write with precision of minutes, not with precision of second. re **Is it possible to run job created by pgAgent faster than every minute?**
JiboOne (103 rep)
Aug 14, 2019, 08:54 AM • Last activity: Aug 14, 2019, 09:24 AM
1 votes
0 answers
159 views
What security concerns are with allowing pgAgent to database users?
I have a customer who would like to use pgagent, however, as a DBA I have security concerns with pgagent having the ability to execute shell scripts from within the Postgres instance. Can anybody tell me how I might prevent pgagent from running ad-hoc shell scripts, or more generally how I can secur...
I have a customer who would like to use pgagent, however, as a DBA I have security concerns with pgagent having the ability to execute shell scripts from within the Postgres instance. Can anybody tell me how I might prevent pgagent from running ad-hoc shell scripts, or more generally how I can secure pgagent so that the customer can schedule any SQL against any database they have access to but not do much else? Thanks. Bill
vibrantsparrow (11 rep)
Sep 19, 2018, 09:17 PM
1 votes
1 answers
4905 views
What is the pgAgent service account?
Im installing pgAgent using Stack Builder. In one step ask me for service account. Should I use PC, Domain or DB user? Or create a new one? I try using my `DOMAIN\my.user.name` also using the postgres user and return same error. I dont have the `PC_Name\Administrator` password > User creation failed...
Im installing pgAgent using Stack Builder. In one step ask me for service account. Should I use PC, Domain or DB user? Or create a new one? I try using my DOMAIN\my.user.name also using the postgres user and return same error. I dont have the PC_Name\Administrator password > User creation failed. The password specified is incorrect or length of the user name is longer than supported enter image description here
Juan Carlos Oropeza (427 rep)
Dec 12, 2016, 09:16 PM • Last activity: Aug 30, 2018, 12:26 PM
2 votes
1 answers
2404 views
pgAgent doesn't run on another database than "postgres"
I run a postgreSQL 9.3.3 database and I want to do some automatic Tasks with pgAgent, but it doesn't run on another database than "postgres" db. What can I do to run pgAgent on another db ? thanks !
I run a postgreSQL 9.3.3 database and I want to do some automatic Tasks with pgAgent, but it doesn't run on another database than "postgres" db. What can I do to run pgAgent on another db ? thanks !
Corentin Villa (41 rep)
Dec 3, 2015, 02:21 PM • Last activity: Feb 20, 2018, 02:21 PM
1 votes
1 answers
6602 views
PostgreSQLpgagent "Running at: is not runing"
I have a problem to run pgAgent job for PostgreSQL 9.6 under ubuntu 16.04. The job is never executed. I already configured .pgpass and added: localhost:5432:*:postgres:mypass Also modified the permission for .pgpass: $ touch ~/.pgpass $ chmod 0600 ~/.pgpass After that I run pgAgent with no problem:...
I have a problem to run pgAgent job for PostgreSQL 9.6 under ubuntu 16.04. The job is never executed. I already configured .pgpass and added: localhost:5432:*:postgres:mypass Also modified the permission for .pgpass: $ touch ~/.pgpass $ chmod 0600 ~/.pgpass After that I run pgAgent with no problem: $pgagent hostaddr=127.0.0.1 dbname=mydb user=postgres When I check the process for pgAgent I would get this result: user@gis-srv:~$ ps aux | grep pgagent user 153179 0.0 0.0 113844 9392 pts/26 S 17:15 0:00 pgagent hostaddr=127.0.0.1 dbname=postgres user=postgres user 153220 0.0 0.0 113844 9360 pts/26 S 17:16 0:00 pgagent hostaddr=127.0.0.1 dbname=mydb user=postgres user 153227 0.0 0.0 12944 936 pts/26 S+ 17:16 0:00 grep --color=auto pgagent Here is my job setting:
Job Setting:
Job Setting
Schedule setting:
Schedule setting
Step Setting:
Step Setting My propblen that the job is never executed and there is no error in the errors log for PostgreSQL. Please help me to find out why jobs never run. I am receving the following errors: from postgres.log: 2017-11-03 16:01:32.269 EDT postgres@postgres LOG: could not receive data from client: Connection reset by peer from pgagent.log: (attempt 9): fe_sendauth: no password supplied Fri Nov 3 16:01:32 2017 : WARNING: Couldn't create the primary connection (attempt 10): fe_sendauth: no password supplied Fri Nov 3 16:01:32 2017 : ERROR: Stopping pgAgent: Couldn't establish the primary connection with the database server. Also I modified the permission .pgpass to allow everyone to access it. (Just for testing)
Eyla (219 rep)
Nov 2, 2017, 09:45 PM • Last activity: Nov 6, 2017, 11:11 PM
4 votes
1 answers
2680 views
Why doesn't pgAgent run my job every minute?
I have a job and I set the schedule to run every minute. [![enter image description here][1]][1] However, it always skips the next minute after finishing the process, even when the process ends in less than one minute. [![enter image description here][2]][2] The problem is that data is still arrivin...
I have a job and I set the schedule to run every minute. enter image description here However, it always skips the next minute after finishing the process, even when the process ends in less than one minute. enter image description here The problem is that data is still arriving during that minute so when the job starts, it has to process two minutes of data. I'd rather have two 15 seconds runs, than one long 30 seconds run. **How can I make pgAgent run every minute?** In other cases when I set the schedule to every 3 minutes, pgAgent skips the 4th minute and starts on the 5th.
Juan Carlos Oropeza (427 rep)
Dec 20, 2016, 04:35 PM • Last activity: Jul 26, 2017, 05:47 PM
2 votes
1 answers
2422 views
Auto start pgAgent
When my `windows server 2008` start, both services `postgres` and `pgAgent` start because they are automatic. [![enter image description here][1]][1] But if my db is frozen and I need to restart the `postgres` service, the `pgAgent` is also stoped, but when `postgres` restart, `pgAgent` doesn't. So...
When my windows server 2008 start, both services postgres and pgAgent start because they are automatic. enter image description here But if my db is frozen and I need to restart the postgres service, the pgAgent is also stoped, but when postgres restart, pgAgent doesn't. So I have to restart pgAgent manually. Is there a way to link pgAgent, so that it starts whenever postgresql starts? PD: If someone knows a proper tag for windows services please add it, I couldn't find it.
Juan Carlos Oropeza (427 rep)
May 11, 2016, 01:59 PM • Last activity: Dec 26, 2016, 07:44 AM
2 votes
0 answers
117 views
pgAgent Job Slows Over Time
I'm running a scheduled job using pgAgent on PostgresSQL 9.5. The duration of this job seems to grow over subsequent runs, and this slow down doesn't appear to be a direct relationship to the amount of data processed each time. The job itself is a function, which opens a cursor and records results i...
I'm running a scheduled job using pgAgent on PostgresSQL 9.5. The duration of this job seems to grow over subsequent runs, and this slow down doesn't appear to be a direct relationship to the amount of data processed each time. The job itself is a function, which opens a cursor and records results in another table. The function always processes one hour of data, but that hour may contain more or less records depending on the time of day. My question is, is there any resource management I need to do when creating a pgAgent job? In other words, does anything persist between runs that should be cleaned up by the developer or is each instance of the job completely sandboxed?
Matt (121 rep)
Sep 14, 2016, 04:59 AM
1 votes
2 answers
4296 views
Routinely deleting aged postgresql rows via cron
I have a Django website with a postgresql 9.3.10 backend. The website contains dynamic user-generated content (think of it as a form of 9gag). There are some tables from which I routinely delete aged rows. The database is called `dbname` and I log into it via the user `postgres`. The following are t...
I have a Django website with a postgresql 9.3.10 backend. The website contains dynamic user-generated content (think of it as a form of 9gag). There are some tables from which I routinely delete aged rows. The database is called dbname and I log into it via the user postgres. The following are two examples of such routine deletion: begin; DELETE FROM links_groupseen WHERE which_reply_id IN (SELECT id FROM links_reply where "submitted_on" < now() - interval '7 days'); DELETE FROM links_reply WHERE "submitted_on" < now() - interval '7 days'; commit; begin; DELETE FROM links_vote WHERE link_id IN (SELECT id FROM links_link WHERE id NOT IN (select answer_to_id from links_publicreply) AND "submitted_on" < now() - interval '1 hour'); DELETE FROM links_photoobjectsubscription WHERE which_link_id IN (SELECT id FROM links_link WHERE id NOT IN (select answer_to_id from links_publicreply) AND "submitted_on" < now() - interval '1 hour'); DELETE FROM links_link WHERE id NOT IN (select answer_to_id from links_publicreply) AND "submitted_on" < now() - interval '1 hour'; commit; There are ~10 other such operations I run. At the moment, I do everything manually - I want to automate these to run at a certain low-utlization time of day. How do I do that? Can someone give me an illustrative example? ------------------- As per my own rudimentary knowledge, I'm thinking I should first save the following shell script to /etc/cron.daily: #!/bin/sh dbname="dbname" username="postgres" psql $dbname $username << EOF begin; DELETE FROM links_groupseen WHERE which_reply_id IN (SELECT id FROM links_reply where "submitted_on" < now() - interval '7 days'); DELETE FROM links_reply WHERE "submitted_on" < now() - interval '7 days'; commit; begin; DELETE FROM links_vote WHERE link_id IN (SELECT id FROM links_link WHERE id NOT IN (select answer_to_id from links_publicreply) AND "submitted_on" < now() - interval '1 hour'); DELETE FROM links_photoobjectsubscription WHERE which_link_id IN (SELECT id FROM links_link WHERE id NOT IN (select answer_to_id from links_publicreply) AND "submitted_on" < now() - interval '1 hour'); DELETE FROM links_link WHERE id NOT IN (select answer_to_id from links_publicreply) AND "submitted_on" < now() - interval '1 hour'; commit; EOF And then add the said script to crontab like so: 30 4 * * * /etc/cron.daily/mypgscript And then service crond restart
Hassan Baig (2079 rep)
Jun 24, 2016, 09:39 AM • Last activity: Jun 28, 2016, 05:15 PM
Showing page 1 of 20 total questions