Skip to content

[Bug]: schema clone functions created before dependant table exist nreturn aerror #3

@herwigg

Description

@herwigg

pgclone version

4.0.0

PostgreSQL version

18

Operating system

RHEL 8.10

Installation method

Built from source (make install)

Feature area

Schema clone (pgclone_clone_schema)

Sync or async?

Synchronous (foreground call)

What happened?

I called schema clone into another database (target fron now on) excluding table data, excluding constraints , I get a waring message on the create of a function that the underlying table does not exist . (which is in fact the case):
WARNING: pgclone: local exec failed: ERROR: relation "itiniris.inbox_messages" does not exist
(query: CREATE OR REPLACE FUNCTION itiniris.inbox_messages_fct_ck(p_id bigint)
the function is not created in the target db.
but the same for triggers.
WARNING: pgclone: local exec failed: ERROR: relation "city_street" does not exist
(query: CREATE TRIGGER city_street_insert_trigger BEFORE INSERT ON city_street FOR EACH ROW EXECUTE FUNCTION city_street_insert_nextval()
ERROR: pgclone: failed to create table locally: ERROR: relation "documents_to_resend_id_seq" does not exist
LINE 1: ...ts_to_resend (id integer NOT NULL DEFAULT nextval('documents...

I have the impression objects are created alphabetically but this does not guarantee that dependencies are met.

Reproduction steps

CREATE TABLE itiniris.inbox_messages ( message_id int8 NOT NULL, "type" varchar(10) NOT NULL, overall_start_date date NULL, overall_end_date date NULL, person_id int8 NULL, "content" text NOT NULL, handling_date timestamp NULL, validcontent bool NOT NULL, sequence_nr int2 NULL, creation_date timestamp NOT NULL, file_number int8 NULL, childact_handling_date timestamp NULL, CONSTRAINT inbox_messages_pkey PRIMARY KEY (message_id, creation_date)) PARTITION BY RANGE (creation_date);

CREATE OR REPLACE FUNCTION itiniris.inbox_messages_fct_ck(p_id bigint)
 RETURNS boolean
 LANGUAGE sql
 PARALLEL SAFE
AS $function$
select exists (select 1 from itiniris.inbox_messages where message_id = p_id);
$function$
;
On the target db:
SELECT pgclone.schema(
    'dbname=itiniris user=postgres',
    'itiniris',            -- schema to clone
    false                -- include table data
   ,'{"constraints": false}');
WARNING:  pgclone: local exec failed: ERROR:  relation "itiniris.inbox_messages" does not exist
LINE 6: select exists (select 1 from itiniris.inbox_messages where m...
                                     ^
 (query: CREATE OR REPLACE FUNCTION itiniris.inbox_messages_fct_ck(p_id bigint)
 RETURNS boolean
 LANGUAGE sql
 PARALLEL SAFE
AS $functio)

but there are many more tables (alphabetically) before (and after) inbox_messages

PostgreSQL logs

pgclone_jobs_view (async only)

Additional context

No response

Pre-flight checks

  • I've redacted any passwords from connection strings and logs
  • I've checked existing issues for duplicates
  • This is not a security vulnerability (those go through SECURITY.md)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions