Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time
March 20, 2018 21:01
June 21, 2022 15:47
March 22, 2018 06:59
March 22, 2018 07:05
June 21, 2022 15:47
March 18, 2018 17:00

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.


Unofficial documentation for PostgreSQL hooks