Codebase

$ git clone git://git.postgresql.org/git/postgresql.git
$ cd postgresql
$ ./src -L 1
./src
├── backend    (Server)
├── bin        (Client Programs)
├── common     (Utilities)
├── fe_utils   (Frontend Utilities)
├── include    (Headers)
├── interfaces (libpg and ecpg)
├── pl         (pl/pgsql)
├── port       (libpgport)
├── test       (tests)
├── timezone   (Timezone data)

The "main" of Postgres backend: src/backend/tcop/postgres.c. tcop — Traffic cop, dispatches request to proper module.

ereport, errcode, errmsg, errdetail, elog.

Postgres Errors (~ 500 of them) all have a code, defined in src/backend/utils/errcodes.txt.