Book Image

PostgreSQL Server Programming - Second Edition

Book Image

PostgreSQL Server Programming - Second Edition

Overview of this book

Table of Contents (21 chapters)
PostgreSQL Server Programming Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 6. PostgreSQL Event Triggers

PostgreSQL 9.3 introduced a special type of triggers to complement the trigger mechanism we discussed in the preceding chapter. These triggers, are database-specific and are not attached to a specific table. Unlike regular triggers, event triggers capture DDL events. Event triggers can be the BEFORE and AFTER triggers, and the trigger function can be written in any language except SQL. Other popular database vendors such as Oracle and SQL Server also provide a similar functionality.

One can think of several use cases for DDL triggers. The most popular one among the DBAs normally is to do an audit trail. You, as a DBA, might want to audit the users and the DDL commands. Schema changes, in a production environment, should be done very carefully; hence, the need for an audit trail is apparent. Event triggers are disabled in the single user mode and can only be created by a superuser.

In this chapter, we will cover the following topics:

  • Use cases for event triggers...