The current trends to work in Agile and DevOps are challenging for database developers. Source control is a standard for non-database code but it’s a challenge for databases. This talk has an ambition to change that situation and help developers and DBA take over control of source code and data.
3. Role: DBA / Release manager
1st Attempt:
- Package / schema management tool
- Developers to provide a create script
- DBA to generate an alter script if needed
History
4. Role: DBA / Release manager
2nd attempt:
- Web-based automation tool
- All changes needs to be deployed using same mechanism ( dev, test, UAT, prod )
- All files needs to be provided by developers
History
5. Role: DBA / Release manager
3rd attempt:
- Developers to provide change / create files
- All changes needs to be deployed using same method
- Each developer has a its own copy of the seed database
History
6. • Source control
• How to upgrade online with data
• How to detect / prevent changes done outside of process
• Rollbacks
Issues
7. • File based source control (ex. GIT)
– ALWAYS OPEN YOUR PL/SQL CODE THROUGH FILES !!!
• What about Apex ?
Source Control
9. • Changelog
Liquibase uses a changelog to explicitly list database changes in order. The changelog acts as a ledger of changes and contains a list of
changesets (units of change) that Liquibase can execute on a database.
• Change set concept
Liquibase uses changesets to represent a single change to your database.
Liquibase
10. • Directory structure and source control
• One or many changes logs
• One main
• One object type
• How to manage PL/SQL code
Liquibase
13. • Usually works fine without data
• Schema change with data could be resource expensive and not always online operation
How to upgrade online with data
14. • Talk with your DBA to find a best way to do so
Ex:
- Add columns with default ( works since 11g)
- Use platform features like edition-based redefinition or dbms_redefinition
- Insert is the fastest delete / update
Seriously, I think this is one of the main tasks for DBA’s those days
How to upgrade online with data
15. --liquibase formatted sql
--changeset marcinp:check_redef endDelimiter:/
DECLARE
l_num_errors PLS_INTEGER;
begin
DBMS_REDEFINITION.can_redef_table('SCOTT', 'EMP');
DBMS_REDEFINITION.START_REDEF_TABLE ('SCOTT', 'EMP', 'EMP3’);
DBMS_REDEFINITION.copy_table_dependents(
uname => 'SCOTT',
orig_table => 'EMP',
int_table => 'EMP3',
copy_indexes => DBMS_REDEFINITION.cons_orig_params,
num_errors => l_num_errors);
DBMS_REDEFINITION.finish_redef_table( 'SCOTT', 'EMP', 'EMP3' );
end;
/
How to upgrade online with data
16. • Protect schema account – close to impossible in non prods environments
• Be real DEVOPS – developers should be responsible for production changes – there is no better way to
prevent errors than being oncall during / after deployment
• Make deployment using your preferred way EASY – like running a pipeline
• Pipeline allows you to test your deployment process and detect errors early on
How to detect / prevent changes done outside of process
17. • Trust but verify
• My recommendation – use DDLFS and git repository
(https://github.com/usrecnik/ddlfs)
How to detect / prevent changes done outside of process
18. How to detect / prevent changes done outside of process
$ git init
Initialized empty Git repository in /home/oracle/databases/.git/
$ ddlfs -o
ro,dbro,username=/,password=/,database=/,userrole=SYSDBA,schemas=SCOTT:DELPHIX,filesize=-
1,keepcache,temppath=/tmp/ddlfs /home/oracle/databases/test19
2020-11-06 12:37:03 INFO DDL Filesystem v2.3 for Oracle Database, FUSE v2.9
2020-11-06 12:37:03 INFO .. connected to database server.
2020-11-06 12:37:03 INFO Cache validation started beacuase temppath_reused=[1] and
dbro=[1]
2020-11-06 12:37:03 INFO Cache validation completed.
20. How to detect / prevent changes done outside of process
$ ddlfs -o ro,dbro,username=/,password=/,database=/,userrole=SYSDBA,schemas=SCOTT:DELPHIX,
filesize=-1,keepcache,temppath=/tmp/ddlfs /home/oracle/databases/test19
2020-11-06 12:39:51 INFO DDL Filesystem v2.3 for Oracle Database, FUSE v2.9
2020-11-06 12:39:51 INFO .. connected to database server.
2020-11-06 12:39:51 INFO Cache validation started beacuase temppath_reused=[1] and
dbro=[1]
2020-11-06 12:39:51 INFO Cache validation completed.
$ git status .
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: test19/SCOTT/TABLE/DEMOTABLE.SQL
deleted: test19/SCOTT/TABLE/EMP3.SQL
$ git commit -m "next commit" test19/
[master 69fadf5] next commit
2 files changed, 2 insertions(+), 17 deletions(-)
delete mode 100644 test19/SCOTT/TABLE/EMP3.SQL
21. How to detect / prevent changes done outside of process
$ git diff df2332928a41dbdd0a1e157e0b2fcbce4523 69fadf5f4d06919f1cbf35abf7abec826e7
diff --git a/test19/SCOTT/TABLE/DEMOTABLE.SQL b/test19/SCOTT/TABLE/DEMOTABLE.SQL
index 83eecfa..ce24d39 100644
--- a/test19/SCOTT/TABLE/DEMOTABLE.SQL
+++ b/test19/SCOTT/TABLE/DEMOTABLE.SQL
@@ -1,6 +1,7 @@
CREATE TABLE "SCOTT"."DEMOTABLE" (
"COLUMNNAME1" VARCHAR2(355 BYTE) NULL,
- "NAME" VARCHAR2(10 BYTE) NULL);
+ "NAME" VARCHAR2(10 BYTE) NULL,
+ "HACK" NUMBER NULL);
diff --git a/test19/SCOTT/TABLE/EMP3.SQL b/test19/SCOTT/TABLE/EMP3.SQL
deleted file mode 100644
index ed99eb3..0000000
--- a/test19/SCOTT/TABLE/EMP3.SQL
+++ /dev/null
…
22. • Always rollback database to pre-upgrade state on lower environments – use Pipelines
• Difficult on the production databases
• Should be limited to code only – if upgrade done online – to avoid data loss
• Try to move forward by incremental change rather then rollback
• Deployments and tests should be done on fresh copy of production to limit a number of rollbacks to
minimum
Rollbacks
23. • Data control for developer on laptop
• Data control on test / integration system
• Masking / GDPR / Privacy
Data control
24. • Potential solutions:
– Multiple databases ( V1, V2, almost prod, UAT, preprod )
– Backups
– Snapshots
( check my presentation “Pipeline my database” )
• ML/AL examples:
• DOLT - https://dbdb.io/db/dolt
• DVC
Data control
25. • Seed data only
– Docker + schema + plus inserts
– Seed PDB + schema + plus inserts
• What if you want to have a production like database locally ?
– Clone whole database but mask all sensitive columns
– Prepare working rules for sub-setting data sets but still mask all sensitive columns
– Is this really necessary
Local development
26. • Virtual machine snapshots or Docker snapshots
• Titan – an open-source to control a version of Docker container databases
( not active for some time - https://titan-data.io/ )
• Use snapshots on your Linux file system:
( ZFS, BTRFS, others )
• Bonus - APEX ”source control”
Local development – data control
29. • Deploy changes using an automated way – ideally same as for production update
• It’s allows you to test all at early stage
• End goal is:
Masked production like data + new schema changes
Shared databases
30. • Data control allows you to run destructive tests using different data sets
• utPLSQL is a great tool – data control allows you to use it with “commit” in your code
Shared databases
32. 32
Database: DEV
Docker container
Docker volume
mapped to file system
with snapshots
Database: DEV
Docker container
Database: DEV
Docker container
Shared databases