Liquibase: Custom SQL statement - oracle

I have my liquibase schema defined initially for PostreSQL. Now, I have to modify the schema file to support Oracle. I have a change-set that has a <sql> tag. It has a query that accesses the pg_catalog table to set a value to the sequence. However, this will not work for Oracle. If I remove it, the Liquibase complains with check-sum validation fail. It complains even if I have an empty <sql> tag or some other query specified within. Within this change-set, I have many other create-table statement, so I cannot just remove oracle from dbms attribute. Is there any way I can suppress this sql from running for Oracle?

The dbms attribute on the changeset is the mechanism designed to handle this problem..... Sounds like you're trying to do too much within one changesest (but I guess you've figured that out)
The checksum validation failure is liquibase's safety mechanism designed to defend the database against someone tampering with the schema files.
How to fix it is to use the clearChecksums option when running liquibase. It tells liquibase to recompute the checksums for the changesets already in the database. This will enable your postgres database instance to accept the alterations to its changesets that you've made for Oracle.

Related

Can liquibase be helpful if the aim is to only automate execution of SQL queries?

My understanding of using Liquibase is as follows:
It is a repository for SQL queries migration on to Production database.
If xml is prefered ,it has a changelog.xml file which contains changesets which carry instructions in xml tags to perform actions like create, drop alter table etc.
What I want to achieve and for which I am evaluating if liquibase can serve my purpose.
My deployment process on UAT/Production have EAR and DB scripts execution as the major aspects.
I already have the .sql files which are to be fired in a particular sequence post which the EAR is to be brought up. These .sql files contain DDL as well as DML queries and stored procedures.
My aim is to automate the execution of these .sql scripts which is presently carried out manually.
Since liquibase works on an xml to generate the .sql, can my situation where .sqls are already available be proceeded with. Any inputs will be much appreciated.
Liquibase supports multiple formats. XML is only one of them. You can use SQL format. You will have to just add some comments in your scripts with meta information for Liquibase.
You did not provide much information, but what you want to do is exactly what Liquibase is for - upgrade database structure and data when you release a new version of your Java (?) application.

Oracle package invalidated automatically

We have a oracle 12.1 Prod database. One of the packages in the database become invalid abruptly and all the sessions have the state of that package has been invalidated. We are sure that there was no manual actions (Deployment, DDL, Compile etc.. ) performed on the database. Is there any other way that package can become invalid automatically?
This package is directly referencing 3 remote database tables using DB link.
If any dependency undergoes a DDL operation, it will invalidate stored PL/SQL programs that depend on it. It could be a table, a synonym, a view, another PL/SQL routine, etc.. I suggest you look at dba_dependencies to see what the dependencies are for your package, then look at dba_objects for every one of those objects to see what has a recent last_ddl_time value. Don't forget the remote objects on the other side of that database link. When you find it, you are well on your way to finding the root cause. If you can't figure out what DDL is hitting that object, enable DDL auditing so you can capture the event the next time it happens.
If you find that the offending object cannot avoid undergoing DDL for some reason, then you may need to consider breaking the dependency on it by embedding your reference to it inside an EXECUTE IMMEDIATE.

How do I integrate Liquibase within an existing CI/CD pipeline in large organization?

We are working in a very big organization, many Databases (of many types), many schemas, many users.
Does LB has to work with some Source Control (for locking the files
when many users exist in the organization and using the same DB,
same Schema, etc)?
What is the best practice of working with LB in a very big
organization, many concurrent users?
Can SQLCL general sql format type or just xml format type?
Is there some integration with SQL Developer? I mean, suppose a user
changes an objects via sql developer, what happens then?
We get this type of question all the time, after folks get a handle of how to automate DB changes, next step is typically to add it into an existing CI/CD workflow.
Yes, Liquibase works with any source control. Most users are using
Git. But you can use Git, TFS, SVN, CVS... Once you are up and
running with Liquibase, you just need to make sure that your scripts
are in source control and you are good to go.
Besides 3rd party source control tools, Liquibase has tracking tables called "DATABASECHANGELOG" tables that keep track of the changes applied to your database when using Liquibase deployments.
Here is some more information about getting started and How Liquibase Works. https://www.liquibase.org/get_started/how-lb-works.html
Liquibase has one more table that it uses internally called "DATABASECHANGELOGLOCK" table.
This table was designed to prevent multiple Liquibase users running deployments concurrently - potentially leaving the Database in a bad state. Once the Liquibase deployment (the liquibase update command) is done, the "DATABASECHANGELOGLOCK" will allow the next Liquibase user to deploy.
You can use both SQL and XML formats (or even JSON and YAML formats).
When using SQL, you have a few options:
Best option is to use Formatted SQL changeLogs https://www.liquibase.org/documentation/sql_format.html
https://www.liquibase.org/get_started/quickstart_sql.html
You can use plain raw SQL files referenced from an XML changeLog
https://www.liquibase.org/documentation/changes/sql_file.html
When using XML, can find all the available change types (also called changeSets) available in the following page (on the left of the page)
https://www.liquibase.org/documentation/changes/
XML changeLog are more agnostic and sometimes can be used for different Database platforms when doing migrations. Also, many of the change types in XML have the ability to be rolled back automatically. The reason that this is possible with XML is because Liquibase uses it own built in functions to figure out inverse statements like "create table" to be "drop table".
For each of those changeSets you can find out if they are auto rollback eligible (at the bottom of the page). For example, create table changeSet will be Auto Rollback = yes.
https://www.liquibase.org/documentation/changes/create_table.html

Liquibase - Generate changelog from oracle schema to migrate to postgres

Currently I am on an oracle schema which is maintained with liquibase. The liquibase xmls have some oracle specific usage of queries for dataload and using sequences etc (also some usage specific to oracle).
I would like to move to postgres. Would it be possible to generateChangeLog from oracle schema to execute it against a postgres db (or a changelog that is completely liquibase specific so that it will automatically convert it to target database at runtime)? I do not see an option to specify target database type on generatechangelog. Is there any way to achieve that?
Yes this is possible, although it's easier when you start the changelog with multiple DBMS in mind.
<createSequence> changes should be fine, however if you have any explicit calls to .nextval those would need to be changed.
You can run changeSets conditionally depending on the current DBMS:
<changeSet dbms="postgresql">
...
</changeSet>
or use dbms="oracle". I think (not sure though) the DBMS attribute does not change the MD5 checksum, so you can change your existing change log without it breaking against your existing installations.
How much you need to adjust your current changelog depends on how specific you were when e.g. specifying data types, e.g. you can't use varchar2 for obvious reasons, and changing that will change the MD5 checksum which will break running the changelog against your existing installations.
I would try to change the changelog you have to be as much DBMS independent as possible and then bite the bullet and run it once with clearCheckSums against existing installations.

Conversion tools database structure (oracle, mysql,postgreSQl..) to HSQLDB or H2

I want to use HsqlDB or H2 to make tests with an in-memory database. I have databases in production with Oracle and postgreSQL. So I want to know if there are tools that allow converting an oracle, postgreSQL... database structure to a hSQLDB or H2 schema.
Thanks in advance
Have a look at DdlUtils.
Quoted from that site
DdlUtils can generate a DDL file for an existing database.
These are XML files that contain the definition of a database schema, e.g. tables and columns.
These files can be fed into DdlUtils via its Ant task or programmatically
in order to create the corresponding database or alter it so that it corresponds to the DDL
You might encounter difficulties in the first run, if the reverse engineering fails. Anyway, somehow you can manage to get a logical data model, and you can use this both for production and testing.
Just found out RazorSQL can convert between PostgreSQL, Oracle and HSQL, but I couldn't get it to produce valid HSQLDB files from PostgreSQL..
Disclaimer: it's a commercial product with a 30day trial period, and I'm not affiliated in any way..

Resources