Skip to content

taminomara/psql-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postgresql hooks documentation

Unofficial documentation for PostgreSQL hooks.

Denial of responsibility:

This work is not a part of the official PostgreSQL documentation.

Contents of this repository were compiled by Begishev Nikita and Goncharov Vladimir, neither of whom appear to be a developer or a maintainer of the PostgreSQL Database Management System.

Use this documentation at your own risk.

Copyright notice:

This work combines some research made by contributors with information acquired from the postgres source code, comments and documentation. Some contents of this work were copied from source code comments as is, others were written from scratch.

In no way we (Begishev Nikita and Goncharov Vladimir) claim copyright on texts that were copied or adapted from the sources described above.

This work is distributed under the terms of the PostgreSQL License, a copy of which may be found in the file called 'License.md'.

PostgreSQL hooks are a simple way to extend functionality of the database. They allow extensions to introspect database state, react to events and interfere with database operations.

In terms of the programming language, each hook is a pointer to a function of a specific type, initially set to be NULL.

Upon init, database extensions are free to overwrite those function pointers with their own values. A previous value of the overwritten pointer is usually stored withing the extension local memory.

During its work, postgres checks whether certain function pointers are not null and if that's the case, calls them.

See the detailed description for an explanation on how to implement a hook and an example.

  • emit_log_hook — hook for intercepting messages before they are sent to the server log.
  • shmem_startup_hook — hook for extensions to initialize their shared memory.
  • needs_fmgr_hook — auxiliary hook which decides whether fmgr_hook should be applied to a function.
  • fmgr_hook — hook for controlling function execution process.
  • func_setup — hook for intercepting PLpgSQL function pre-init phase.
  • func_beg — hook for intercepting post-init phase.
  • func_end — hook for intercepting end of a function.
  • stmt_beg — called before each statement of a function.
  • stmt_end — called after each statement of a function.

About

Unofficial documentation for PostgreSQL hooks

Topics

Resources

License

Stars

Watchers

Forks

Languages