Ich suche nach einer Möglichkeit, Tabellensatz automatisch in PostgreSQL einmal wöchentlich zu kürzen und den letzten 7 Tageseintrag in der Tabelle zu lassen. Ich habe eine Tabelle logged_actions in Audit shcema genannt schaffen, hier sind die Exporttabellenabfragen:Job einplanen, um Tabellensatz in PostgreSQL abzuschneiden
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = audit, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: logged_actions; Type: TABLE; Schema: audit; Owner: postgres; Tablespace:
--
CREATE TABLE logged_actions (
schema_name text NOT NULL,
table_name text NOT NULL,
user_name text,
action_tstamp timestamp with time zone DEFAULT now() NOT NULL,
action text NOT NULL,
original_data text,
new_data text,
query text,
CONSTRAINT logged_actions_action_check CHECK ((action = ANY (ARRAY['I'::text, 'D'::text, 'U'::text])))
)
WITH (fillfactor='100');
ALTER TABLE audit.logged_actions OWNER TO postgres;
--
-- Name: logged_actions_action_idx; Type: INDEX; Schema: audit; Owner: postgres; Tablespace:
--
CREATE INDEX logged_actions_action_idx ON logged_actions USING btree (action);
--
-- Name: logged_actions_action_tstamp_idx; Type: INDEX; Schema: audit; Owner: postgres; Tablespace:
--
CREATE INDEX logged_actions_action_tstamp_idx ON logged_actions USING btree (action_tstamp);
--
-- Name: logged_actions_schema_table_idx; Type: INDEX; Schema: audit; Owner: postgres; Tablespace:
--
CREATE INDEX logged_actions_schema_table_idx ON logged_actions USING btree ((((schema_name || '.'::text) || table_name)));
--
-- Name: logged_actions; Type: ACL; Schema: audit; Owner: postgres
--
REVOKE ALL ON TABLE logged_actions FROM PUBLIC;
REVOKE ALL ON TABLE logged_actions FROM postgres;
GRANT ALL ON TABLE logged_actions TO postgres;
GRANT SELECT ON TABLE logged_actions TO PUBLIC;
--
-- PostgreSQL database dump complete
--
Sollte ich cron oder etwas anderes?
Ich habe den pgAgent Scheduler ausprobiert, aber nicht funktioniert, also entschied ich mich, Trigger-Funktion zu verwenden, und es funktioniert. Danke . – metaphor