question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

drop-all fails when schema contains tables defined using postgresql 11 table partitioning

See original GitHub issue

Environment

Liquibase Version: 3.8.9

Liquibase Integration & Version: Dropwizard 2.0.10

Liquibase Extension(s) & Version: NA

Database Vendor & Version: Postgresql 12.2

Operating System Type & Version: Postgresql:12 docker image

Description

When executing the liquibase:drop-alll , the following error occurs:

Caused by: liquibase.exception.DatabaseException: ERROR: cannot drop inherited constraint "XXXX_fkey" of relation "XXXX_y2020m10" [Failed SQL: (0) ALTER TABLE "public"."XXXX_y2020m10" DROP CONSTRAINT "XXXX_fkey"]
	at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:402)
	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:59)
	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:131)
	at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:111)
	at liquibase.database.AbstractJdbcDatabase.dropDatabaseObjects(AbstractJdbcDatabase.java:801)
	at liquibase.command.core.DropAllCommand.run(DropAllCommand.java:88)

Steps To Reproduce

List the steps to reproduce the behavior.

  • This is a partitioned table with a foreign key constraint like to following:
--liquibase formatted sql

-- changeset jh:some-change
create othertable (
id bigserial primary key,
somedata text );

create table thistable (
                                 id bigserial,
                                 otherid int references othertable(otherid) NOT NULL,
                                 thisdate timestamp with time zone NOT NULL,
                                
)  PARTITION BY RANGE (thisdate);

CREATE UNIQUE INDEX thistable_unique_idx ON thistable(id, thisdate);

CREATE TABLE thistable_y2020m6 PARTITION OF thistable FOR VALUES FROM ('2020-06-01 00:00:00')  TO ('2020-06-30 23:59:59+00');
CREATE TABLE thistable_y2020m7 PARTITION OF thistable FOR VALUES FROM ('2020-07-01 00:00:00')  TO ('2020-07-31 23:59:59+00');

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
stevesalimancommented, Jan 16, 2021

Looking into it further, I don’t think this is an issue with the Postgres JDBC driver. It supports partitioned tables, but it uses a different type for them, Liquibase isn’t using that type when it calls DatabaseMetadata.getTables.

The fix to this needs to be in JdbcSnapshot.getTables(). It has a ResultSetCache.SingleResultSetExtractor that declares a ResultSetCache.SingleResultSetExtractor() method, which needs to to add “PARTITIONED TABLE” to the list of types it passed to the JDBC driver when we’re in Postgres. Doing this will fix the problem, but I’m not certain what other side effects this change would have - I suspect they would be good ones. Also, as I suspected, we need to remove Foreign Keys from the types to include for this to all work.

I’ll submit a patch, and the good folks at Liquibase, who know the code base better than I do, can make sure there isn’t anything bad about the change.

0reactions
nvoxlandcommented, Aug 2, 2021

I’ll close this issue as resolved, since #1650 solved this in 4.3, and there is the separate issue for including them in the diff.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: 5.11. Table Partitioning - PostgreSQL
Dropping an individual partition using DROP TABLE , or doing ALTER TABLE DETACH ... Partitions may themselves be defined as partitioned tables, resulting...
Read more >
How to list all tables in postgres without partitions
For example, if the schema contains a table named 'example' which is partitioned on the column 'bla' with the two values 'a' and...
Read more >
PostgreSQL Partition Manager Extension (`pg_partman`)
For PG11, only unique indexes that don't include the parition column require the template table; all other properties are managed by the parent...
Read more >
24.3.1 Management of RANGE and LIST Partitions
Suppose that you have created a table that is partitioned by range and then populated with 10 records using the following CREATE TABLE...
Read more >
Database Engine events and errors - SQL Server
The table contains error message numbers and the description, ... ls' is ambiguous: both a user-defined function and a method call with this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found