Thread: Backup Functions
Hello experts,
I was just wondering should a schema of a database contain functions and triggering functions does the pg_dump include functions as it takes back up of the schema? I’m on postgres 11 version.
Here’s my command looks like
/pg_dump -Fd --lock-wait-timeout 300 -d tenant1 -n public -f /pgbackup/tenant1_public_20210816_233807
I know in the public schema of the Tenant database there are over 60 functions and are not backed up. Any pointers are greatly helpful.
Regards,
Sridhar Parepalli
I know in the public schema of the Tenant database there are over 60 functions and are not backed up. Any pointers are greatly helpful.
Hey Vijaykumar,
Thank you for the quick response.
Q) do you see the functions expected to be dumped under \df public.* of the db ?
Response) Yes, I do see all the functions listed.
However, when tried to dump it does not include all functions.
--
-- PostgreSQL database dump
--
-- Dumped from database version 11.10
-- Dumped by pg_dump version 11.10
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: public; Type: SCHEMA; Schema: -; Owner: xxx
--
CREATE SCHEMA public;
ALTER SCHEMA public OWNER TO xxx;
--
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: xxx
--
COMMENT ON SCHEMA public IS 'standard public schema';
--
-- Name: dmc_update_row_modified_function(); Type: FUNCTION; Schema: public; Owner: dbmsowner
--
CREATE FUNCTION public.dmc_update_row_modified_function() RETURNS trigger
LANGUAGE plpgsql
AS $$ BEGIN IF TG_OP = 'UPDATE' THEN NEW.modified_dttm = NOW(); RETURN NEW; ELSIF TG_OP = 'INSERT' THEN NEW.created_dttm = NOW(); RETURN NEW; END IF; END; $$;
ALTER FUNCTION public.dmc_update_row_modified_function() OWNER TO dbmsowner;
--
-- PostgreSQL database dump complete
From: Vijaykumar Jain <vijaykumarjain.github@gmail.com>
Sent: Wednesday, August 18, 2021 11:30 AM
To: Sridhar Parepalli <Sridhar.Parepalli@sas.com>
Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
Subject: Re: Backup Functions
EXTERNAL
On Wed, 18 Aug 2021 at 20:35, Sridhar Parepalli <Sridhar.Parepalli@sas.com> wrote:
I know in the public schema of the Tenant database there are over 60 functions and are not backed up. Any pointers are greatly helpful.
dumping only objects in a specific schema, also dumped functions in that schema, at least in my demo run.
postgres@db:~/playground$ psql test
psql (14beta1)
Type "help" for help.
test=# \df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+-------------------------+--------------------------+-----------------------------------------+------
public | get_rounded_up_interval | timestamp with time zone | ts timestamp with time zone, i interval | func
(1 row)
test=# \q
postgres@db:~/playground$ pg_dump -n public test > /tmp/test.sql
postgres@db:~/playground$ grep -A5 get_rounded_up_interval /tmp/test.sql
-- Name: get_rounded_up_interval(timestamp with time zone, interval); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public.get_rounded_up_interval(ts timestamp with time zone, i interval) RETURNS timestamp with time zone
LANGUAGE plpgsql
AS $$
begin
return date_bin(i, ts, date_trunc('day', ts)) + i;
end; $$;
--
ALTER FUNCTION public.get_rounded_up_interval(ts timestamp with time zone, i interval) OWNER TO postgres;
***********
I also tried using -Fd and then checked via. i do see functions dumped.
pg_dump -Fd -d test -n public -f /tmp/test.dump
pg_restore -l /tmp/test.dump | grep -i function
219; 1255 72283 FUNCTION public get_rounded_up_interval(timestamp with time zone, interval) postgres
do you see the functions expected to be dumped under \df public.* of the db ?
--
Thanks,
Vijay
Mumbai, India
Sridhar Parepalli <Sridhar.Parepalli@sas.com> writes: > I was just wondering should a schema of a database contain functions and triggering functions does the pg_dump includefunctions as it takes back up of the schema? I'm on postgres 11 version. Functions belonging to extensions are not included in pg_dump output, maybe that explains your results? It's hard to be sure without a lot more specifics than you've provided. regards, tom lane
Hey Tom, Here's what I got from the \df ... tenant1=# \df List of functions Schema | Name | Result data type | Argument data types | Type --------+----------------------------------+------------------+---------------------------------------------------------------------------------------------------------+------ public | armor | text | bytea | func public | armor | text | bytea, text[], text[] | func public | crypt | text | text, text | func public | dearmor | bytea | text | func public | decrypt | bytea | bytea, bytea, text | func public | decrypt_iv | bytea | bytea, bytea, bytea, text | func public | digest | bytea | bytea, text | func public | digest | bytea | text, text | func public | dmc_update_row_modified_function | trigger | | func public | encrypt | bytea | bytea, bytea, text | func public | encrypt_iv | bytea | bytea, bytea, bytea, text | func public | gen_random_bytes | bytea | integer | func public | gen_random_uuid | uuid | | func public | gen_salt | text | text | func public | gen_salt | text | text, integer | func public | hmac | bytea | bytea, bytea, text | func public | hmac | bytea | text, text, text | func public | pgp_armor_headers | SETOF record | text, OUT key text, OUT value text | func public | pgp_key_id | text | bytea | func public | pgp_pub_decrypt | text | bytea, bytea | func public | pgp_pub_decrypt | text | bytea, bytea, text | func public | pgp_pub_decrypt | text | bytea, bytea, text, text | func public | pgp_pub_decrypt_bytea | bytea | bytea, bytea | func public | pgp_pub_decrypt_bytea | bytea | bytea, bytea, text | func public | pgp_pub_decrypt_bytea | bytea | bytea, bytea, text, text | func public | pgp_pub_encrypt | bytea | text, bytea | func public | pgp_pub_encrypt | bytea | text, bytea, text | func public | pgp_pub_encrypt_bytea | bytea | bytea, bytea | func public | pgp_pub_encrypt_bytea | bytea | bytea, bytea, text | func public | pgp_sym_decrypt | text | bytea, text | func public | pgp_sym_decrypt | text | bytea, text, text | func public | pgp_sym_decrypt_bytea | bytea | bytea, text | func public | pgp_sym_decrypt_bytea | bytea | bytea, text, text | func public | pgp_sym_encrypt | bytea | text, text | func public | pgp_sym_encrypt | bytea | text, text, text | func public | pgp_sym_encrypt_bytea | bytea | bytea, text | func public | pgp_sym_encrypt_bytea | bytea | bytea, text, text | func public | pgpool_pgctl | boolean | action text, stop_mode text | func public | pgpool_recovery | boolean | script_name text, remote_host text, remote_data_directorytext | func public | pgpool_recovery | boolean | script_name text, remote_host text, remote_data_directorytext, remote_port text | func public | pgpool_recovery | boolean | script_name text, remote_host text, remote_data_directorytext, remote_port text, recovery_node integer | func public | pgpool_remote_start | boolean | remote_host text, remote_data_directory text | func public | pgpool_switch_xlog | text | arcive_dir text | func (43 rows) Sridhar Parepalli -----Original Message----- From: Tom Lane <tgl@sss.pgh.pa.us> Sent: Wednesday, August 18, 2021 12:17 PM To: Sridhar Parepalli <Sridhar.Parepalli@sas.com> Cc: pgsql-sql <pgsql-sql@lists.postgresql.org> Subject: Re: Backup Functions EXTERNAL Sridhar Parepalli <Sridhar.Parepalli@sas.com> writes: > I was just wondering should a schema of a database contain functions and triggering functions does the pg_dump includefunctions as it takes back up of the schema? I'm on postgres 11 version. Functions belonging to extensions are not included in pg_dump output, maybe that explains your results? It's hard to besure without a lot more specifics than you've provided. regards, tom lane
Hey Tom,
Here's what I got from the \df ...
Here's what I got from the \df ...
[...]
public | pgpool_remote_start | boolean | remote_host text, remote_data_directory text | func
public | pgpool_switch_xlog | text | arcive_dir text | func
(43 rows)
-- Dumped from database version 11.10
-- Dumped by pg_dump version 11.10
CREATE SCHEMA public;
CREATE FUNCTION public.dmc_update_row_modified_function() RETURNS trigger
-- PostgreSQL database dump complete