Skip to content
Unofficial documentation for PostgreSQL hooks.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
templates Apply header changes to template. Mar 22, 2018
.gitignore Update gitignore Mar 20, 2018 Update Mar 22, 2018 Add license Mar 22, 2018 Update Mar 22, 2018 Document row_security_policy_hook_permissive(restrictive) Mar 21, 2018
requirements.txt Init template Mar 18, 2018

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 ''.

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.

General Hooks

  • 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.

Security Hooks

Function Manager Hooks

  • needs_fmgr_hook — auxiliary hook which decides whether fmgr_hook should be applied to a function.
  • fmgr_hook — hook for controlling function execution process.

Planner Hooks

Executor Hooks

PL/pgsql Hooks

  • 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.
You can’t perform that action at this time.