--- title: "Internals" id: internals pg_version: "20devel" --- Part VII. InternalsThis part contains assorted information that might be of use to PostgreSQL developers. ## Table of Contents - [51. Overview of PostgreSQL Internals](overview.md) - [51.1. The Path of a Query](query-path.md) - [51.2. How Connections Are Established](connect-estab.md) - [51.3. The Parser Stage](parser-stage.md) - [51.3.1. Parser](parser-stage.md#parser-stage-parser) - [51.3.2. Transformation Process](parser-stage.md#parser-stage-transformation-process) - [51.4. The PostgreSQL Rule System](rule-system.md) - [51.5. Planner/Optimizer](planner-optimizer.md) - [51.5.1. Generating Possible Plans](planner-optimizer.md#planner-optimizer-generating-possible-plans) - [51.6. Executor](executor.md) - [52. System Catalogs](catalogs.md) - [52.1. Overview](catalogs-overview.md) - [52.2. pg_aggregate](catalog-pg-aggregate.md) - [52.3. pg_am](catalog-pg-am.md) - [52.4. pg_amop](catalog-pg-amop.md) - [52.5. pg_amproc](catalog-pg-amproc.md) - [52.6. pg_attrdef](catalog-pg-attrdef.md) - [52.7. pg_attribute](catalog-pg-attribute.md) - [52.8. pg_authid](catalog-pg-authid.md) - [52.9. pg_auth_members](catalog-pg-auth-members.md) - [52.10. pg_cast](catalog-pg-cast.md) - [52.11. pg_class](catalog-pg-class.md) - [52.12. pg_collation](catalog-pg-collation.md) - [52.13. pg_constraint](catalog-pg-constraint.md) - [52.14. pg_conversion](catalog-pg-conversion.md) - [52.15. pg_database](catalog-pg-database.md) - [52.16. pg_db_role_setting](catalog-pg-db-role-setting.md) - [52.17. pg_default_acl](catalog-pg-default-acl.md) - [52.18. pg_depend](catalog-pg-depend.md) - [52.19. pg_description](catalog-pg-description.md) - [52.20. pg_enum](catalog-pg-enum.md) - [52.21. pg_event_trigger](catalog-pg-event-trigger.md) - [52.22. pg_extension](catalog-pg-extension.md) - [52.23. pg_foreign_data_wrapper](catalog-pg-foreign-data-wrapper.md) - [52.24. pg_foreign_server](catalog-pg-foreign-server.md) - [52.25. pg_foreign_table](catalog-pg-foreign-table.md) - [52.26. pg_index](catalog-pg-index.md) - [52.27. pg_inherits](catalog-pg-inherits.md) - [52.28. pg_init_privs](catalog-pg-init-privs.md) - [52.29. pg_language](catalog-pg-language.md) - [52.30. pg_largeobject](catalog-pg-largeobject.md) - [52.31. pg_largeobject_metadata](catalog-pg-largeobject-metadata.md) - [52.32. pg_namespace](catalog-pg-namespace.md) - [52.33. pg_opclass](catalog-pg-opclass.md) - [52.34. pg_operator](catalog-pg-operator.md) - [52.35. pg_opfamily](catalog-pg-opfamily.md) - [52.36. pg_parameter_acl](catalog-pg-parameter-acl.md) - [52.37. pg_partitioned_table](catalog-pg-partitioned-table.md) - [52.38. pg_policy](catalog-pg-policy.md) - [52.39. pg_proc](catalog-pg-proc.md) - [52.40. pg_propgraph_element](catalog-pg-propgraph-element.md) - [52.41. pg_propgraph_element_label](catalog-pg-propgraph-element-label.md) - [52.42. pg_propgraph_label](catalog-pg-propgraph-label.md) - [52.43. pg_propgraph_label_property](catalog-pg-propgraph-label-property.md) - [52.44. pg_propgraph_property](catalog-pg-propgraph-property.md) - [52.45. pg_publication](catalog-pg-publication.md) - [52.46. pg_publication_namespace](catalog-pg-publication-namespace.md) - [52.47. pg_publication_rel](catalog-pg-publication-rel.md) - [52.48. pg_range](catalog-pg-range.md) - [52.49. pg_replication_origin](catalog-pg-replication-origin.md) - [52.50. pg_rewrite](catalog-pg-rewrite.md) - [52.51. pg_seclabel](catalog-pg-seclabel.md) - [52.52. pg_sequence](catalog-pg-sequence.md) - [52.53. pg_shdepend](catalog-pg-shdepend.md) - [52.54. pg_shdescription](catalog-pg-shdescription.md) - [52.55. pg_shseclabel](catalog-pg-shseclabel.md) - [52.56. pg_statistic](catalog-pg-statistic.md) - [52.57. pg_statistic_ext](catalog-pg-statistic-ext.md) - [52.58. pg_statistic_ext_data](catalog-pg-statistic-ext-data.md) - [52.59. pg_subscription](catalog-pg-subscription.md) - [52.60. pg_subscription_rel](catalog-pg-subscription-rel.md) - [52.61. pg_tablespace](catalog-pg-tablespace.md) - [52.62. pg_transform](catalog-pg-transform.md) - [52.63. pg_trigger](catalog-pg-trigger.md) - [52.64. pg_ts_config](catalog-pg-ts-config.md) - [52.65. pg_ts_config_map](catalog-pg-ts-config-map.md) - [52.66. pg_ts_dict](catalog-pg-ts-dict.md) - [52.67. pg_ts_parser](catalog-pg-ts-parser.md) - [52.68. pg_ts_template](catalog-pg-ts-template.md) - [52.69. pg_type](catalog-pg-type.md) - [52.70. pg_user_mapping](catalog-pg-user-mapping.md) - [53. System Views](views.md) - [53.1. Overview](views-overview.md) - [53.2. pg_aios](view-pg-aios.md) - [53.3. pg_available_extensions](view-pg-available-extensions.md) - [53.4. pg_available_extension_versions](view-pg-available-extension-versions.md) - [53.5. pg_backend_memory_contexts](view-pg-backend-memory-contexts.md) - [53.6. pg_config](view-pg-config.md) - [53.7. pg_cursors](view-pg-cursors.md) - [53.8. pg_dsm_registry_allocations](view-pg-dsm-registry-allocations.md) - [53.9. pg_file_settings](view-pg-file-settings.md) - [53.10. pg_group](view-pg-group.md) - [53.11. pg_hba_file_rules](view-pg-hba-file-rules.md) - [53.12. pg_ident_file_mappings](view-pg-ident-file-mappings.md) - [53.13. pg_indexes](view-pg-indexes.md) - [53.14. pg_locks](view-pg-locks.md) - [53.15. pg_matviews](view-pg-matviews.md) - [53.16. pg_policies](view-pg-policies.md) - [53.17. pg_prepared_statements](view-pg-prepared-statements.md) - [53.18. pg_prepared_xacts](view-pg-prepared-xacts.md) - [53.19. pg_publication_sequences](view-pg-publication-sequences.md) - [53.20. pg_publication_tables](view-pg-publication-tables.md) - [53.21. pg_replication_origin_status](view-pg-replication-origin-status.md) - [53.22. pg_replication_slots](view-pg-replication-slots.md) - [53.23. pg_roles](view-pg-roles.md) - [53.24. pg_rules](view-pg-rules.md) - [53.25. pg_seclabels](view-pg-seclabels.md) - [53.26. pg_sequences](view-pg-sequences.md) - [53.27. pg_settings](view-pg-settings.md) - [53.28. pg_shadow](view-pg-shadow.md) - [53.29. pg_shmem_allocations](view-pg-shmem-allocations.md) - [53.30. pg_shmem_allocations_numa](view-pg-shmem-allocations-numa.md) - [53.31. pg_stats](view-pg-stats.md) - [53.32. pg_stats_ext](view-pg-stats-ext.md) - [53.33. pg_stats_ext_exprs](view-pg-stats-ext-exprs.md) - [53.34. pg_tables](view-pg-tables.md) - [53.35. pg_timezone_abbrevs](view-pg-timezone-abbrevs.md) - [53.36. pg_timezone_names](view-pg-timezone-names.md) - [53.37. pg_user](view-pg-user.md) - [53.38. pg_user_mappings](view-pg-user-mappings.md) - [53.39. pg_views](view-pg-views.md) - [53.40. pg_wait_events](view-pg-wait-events.md) - [54. Frontend/Backend Protocol](protocol.md) - [54.1. Overview](protocol-overview.md) - [54.1.1. Messaging Overview](protocol-overview.md#protocol-message-concepts) - [54.1.2. Extended Query Overview](protocol-overview.md#protocol-query-concepts) - [54.1.3. Formats and Format Codes](protocol-overview.md#protocol-format-codes) - [54.1.4. Protocol Versions](protocol-overview.md#protocol-versions) - [54.1.5. Protocol Extensions](protocol-overview.md#protocol-extensions) - [54.2. Message Flow](protocol-flow.md) - [54.2.1. Start-up](protocol-flow.md#protocol-flow-start-up) - [54.2.2. Simple Query](protocol-flow.md#protocol-flow-simple-query) - [54.2.3. Extended Query](protocol-flow.md#protocol-flow-ext-query) - [54.2.4. Pipelining](protocol-flow.md#protocol-flow-pipelining) - [54.2.5. Function Call](protocol-flow.md#protocol-flow-function-call) - [54.2.6. COPY Operations](protocol-flow.md#protocol-copy) - [54.2.7. Asynchronous Operations](protocol-flow.md#protocol-async) - [54.2.8. Canceling Requests in Progress](protocol-flow.md#protocol-flow-canceling-requests) - [54.2.9. Termination](protocol-flow.md#protocol-flow-termination) - [54.2.10. SSL Session Encryption](protocol-flow.md#protocol-flow-ssl) - [54.2.11. GSSAPI Session Encryption](protocol-flow.md#protocol-flow-gssapi) - [54.3. SASL Authentication](sasl-authentication.md) - [54.3.1. SCRAM-SHA-256 Authentication](sasl-authentication.md#sasl-scram-sha-256) - [54.3.2. OAUTHBEARER Authentication](sasl-authentication.md#sasl-oauthbearer) - [54.4. Streaming Replication Protocol](protocol-replication.md) - [54.5. Logical Streaming Replication Protocol](protocol-logical-replication.md) - [54.5.1. Logical Streaming Replication Parameters](protocol-logical-replication.md#protocol-logical-replication-params) - [54.5.2. Logical Replication Protocol Messages](protocol-logical-replication.md#protocol-logical-messages) - [54.5.3. Logical Replication Protocol Message Flow](protocol-logical-replication.md#protocol-logical-messages-flow) - [54.6. Message Data Types](protocol-message-types.md) - [54.7. Message Formats](protocol-message-formats.md) - [54.8. Error and Notice Message Fields](protocol-error-fields.md) - [54.9. Logical Replication Message Formats](protocol-logicalrep-message-formats.md) - [54.10. Summary of Changes since Protocol 2.0](protocol-changes.md) - [55. PostgreSQL Coding Conventions](source.md) - [55.1. Formatting](source-format.md) - [55.2. Reporting Errors Within the Server](error-message-reporting.md) - [55.3. Error Message Style Guide](error-style-guide.md) - [55.4. Miscellaneous Coding Conventions](source-conventions.md) - [56. Native Language Support](nls.md) - [56.1. For the Translator](nls-translator.md) - [56.1.1. Requirements](nls-translator.md#nls-translator-requirements) - [56.1.2. Concepts](nls-translator.md#nls-translator-concepts) - [56.1.3. Creating and Maintaining Message Catalogs](nls-translator.md#nls-translator-message-catalogs) - [56.1.4. Editing the PO Files](nls-translator.md#nls-translator-editing-po) - [56.2. For the Programmer](nls-programmer.md) - [56.2.1. Mechanics](nls-programmer.md#nls-mechanics) - [56.2.2. Message-Writing Guidelines](nls-programmer.md#nls-guidelines) - [57. Writing a Procedural Language Handler](plhandler.md) - [58. Writing a Foreign Data Wrapper](fdwhandler.md) - [58.1. Foreign Data Wrapper Functions](fdw-functions.md) - [58.2. Foreign Data Wrapper Callback Routines](fdw-callbacks.md) - [58.2.1. FDW Routines for Scanning Foreign Tables](fdw-callbacks.md#fdw-callbacks-scan) - [58.2.2. FDW Routines for Scanning Foreign Joins](fdw-callbacks.md#fdw-callbacks-join-scan) - [58.2.3. FDW Routines for Planning Post-Scan/Join Processing](fdw-callbacks.md#fdw-callbacks-upper-planning) - [58.2.4. FDW Routines for Updating Foreign Tables](fdw-callbacks.md#fdw-callbacks-update) - [58.2.5. FDW Routines for `TRUNCATE`](fdw-callbacks.md#fdw-callbacks-truncate) - [58.2.6. FDW Routines for Row Locking](fdw-callbacks.md#fdw-callbacks-row-locking) - [58.2.7. FDW Routines for `EXPLAIN`](fdw-callbacks.md#fdw-callbacks-explain) - [58.2.8. FDW Routines for `ANALYZE`](fdw-callbacks.md#fdw-callbacks-analyze) - [58.2.9. FDW Routines for `IMPORT FOREIGN SCHEMA`](fdw-callbacks.md#fdw-callbacks-import) - [58.2.10. FDW Routines for Parallel Execution](fdw-callbacks.md#fdw-callbacks-parallel) - [58.2.11. FDW Routines for Asynchronous Execution](fdw-callbacks.md#fdw-callbacks-async) - [58.2.12. FDW Routines for Reparameterization of Paths](fdw-callbacks.md#fdw-callbacks-reparameterize-paths) - [58.3. Foreign Data Wrapper Helper Functions](fdw-helpers.md) - [58.4. Foreign Data Wrapper Query Planning](fdw-planning.md) - [58.5. Row Locking in Foreign Data Wrappers](fdw-row-locking.md) - [59. Writing a Table Sampling Method](tablesample-method.md) - [59.1. Sampling Method Support Functions](tablesample-support-functions.md) - [60. Writing a Custom Scan Provider](custom-scan.md) - [60.1. Creating Custom Scan Paths](custom-scan-path.md) - [60.1.1. Custom Scan Path Callbacks](custom-scan-path.md#custom-scan-path-callbacks) - [60.2. Creating Custom Scan Plans](custom-scan-plan.md) - [60.2.1. Custom Scan Plan Callbacks](custom-scan-plan.md#custom-scan-plan-callbacks) - [60.3. Executing Custom Scans](custom-scan-execution.md) - [60.3.1. Custom Scan Execution Callbacks](custom-scan-execution.md#custom-scan-execution-callbacks) - [61. Genetic Query Optimizer](geqo.md) - [61.1. Query Handling as a Complex Optimization Problem](geqo-intro.md) - [61.2. Genetic Algorithms](geqo-intro2.md) - [61.3. Genetic Query Optimization (GEQO) in PostgreSQL](geqo-pg-intro.md) - [61.3.1. Generating Possible Plans with GEQO](geqo-pg-intro.md#geqo-pg-intro-gen-possible-plans) - [61.3.2. Future Implementation Tasks for PostgreSQL GEQO](geqo-pg-intro.md#geqo-future) - [61.4. Further Reading](geqo-biblio.md) - [62. Table Access Method Interface Definition](tableam.md) - [63. Index Access Method Interface Definition](indexam.md) - [63.1. Basic API Structure for Indexes](index-api.md) - [63.2. Index Access Method Functions](index-functions.md) - [63.3. Index Scanning](index-scanning.md) - [63.4. Index Locking Considerations](index-locking.md) - [63.5. Index Uniqueness Checks](index-unique-checks.md) - [63.6. Index Cost Estimation Functions](index-cost-estimation.md) - [64. Write Ahead Logging for Extensions](wal-for-extensions.md) - [64.1. Generic WAL Records](generic-wal.md) - [64.2. Custom WAL Resource Managers](custom-rmgr.md) - [65. Built-in Index Access Methods](indextypes.md) - [65.1. B-Tree Indexes](btree.md) - [65.1.1. Introduction](btree.md#btree-intro) - [65.1.2. Behavior of B-Tree Operator Classes](btree.md#btree-behavior) - [65.1.3. B-Tree Support Functions](btree.md#btree-support-funcs) - [65.1.4. Implementation](btree.md#btree-implementation) - [65.2. GiST Indexes](gist.md) - [65.2.1. Introduction](gist.md#gist-intro) - [65.2.2. Built-in Operator Classes](gist.md#gist-builtin-opclasses) - [65.2.3. Extensibility](gist.md#gist-extensibility) - [65.2.4. Implementation](gist.md#gist-implementation) - [65.2.5. Examples](gist.md#gist-examples) - [65.3. SP-GiST Indexes](spgist.md) - [65.3.1. Introduction](spgist.md#spgist-intro) - [65.3.2. Built-in Operator Classes](spgist.md#spgist-builtin-opclasses) - [65.3.3. Extensibility](spgist.md#spgist-extensibility) - [65.3.4. Implementation](spgist.md#spgist-implementation) - [65.3.5. Examples](spgist.md#spgist-examples) - [65.4. GIN Indexes](gin.md) - [65.4.1. Introduction](gin.md#gin-intro) - [65.4.2. Built-in Operator Classes](gin.md#gin-builtin-opclasses) - [65.4.3. Extensibility](gin.md#gin-extensibility) - [65.4.4. Implementation](gin.md#gin-implementation) - [65.4.5. GIN Tips and Tricks](gin.md#gin-tips) - [65.4.6. Limitations](gin.md#gin-limit) - [65.4.7. Examples](gin.md#gin-examples) - [65.5. BRIN Indexes](brin.md) - [65.5.1. Introduction](brin.md#brin-intro) - [65.5.2. Built-in Operator Classes](brin.md#brin-builtin-opclasses) - [65.5.3. Extensibility](brin.md#brin-extensibility) - [65.6. Hash Indexes](hash-index.md) - [65.6.1. Overview](hash-index.md#hash-intro) - [65.6.2. Implementation](hash-index.md#hash-implementation) - [66. Database Physical Storage](storage.md) - [66.1. Database File Layout](storage-file-layout.md) - [66.2. TOAST](storage-toast.md) - [66.2.1. Out-of-Line, On-Disk TOAST Storage](storage-toast.md#storage-toast-ondisk) - [66.2.2. Out-of-Line, In-Memory TOAST Storage](storage-toast.md#storage-toast-inmemory) - [66.3. Free Space Map](storage-fsm.md) - [66.4. Visibility Map](storage-vm.md) - [66.5. The Initialization Fork](storage-init.md) - [66.6. Database Page Layout](storage-page-layout.md) - [66.6.1. Table Row Layout](storage-page-layout.md#storage-tuple-layout) - [66.7. Heap-Only Tuples (HOT)](storage-hot.md) - [67. Transaction Processing](transactions.md) - [67.1. Transactions and Identifiers](transaction-id.md) - [67.2. Transactions and Locking](xact-locking.md) - [67.3. Subtransactions](subxacts.md) - [67.4. Two-Phase Transactions](two-phase.md) - [68. System Catalog Declarations and Initial Contents](bki.md) - [68.1. System Catalog Declaration Rules](system-catalog-declarations.md) - [68.2. System Catalog Initial Data](system-catalog-initial-data.md) - [68.2.1. Data File Format](system-catalog-initial-data.md#system-catalog-initial-data-format) - [68.2.2. OID Assignment](system-catalog-initial-data.md#system-catalog-oid-assignment) - [68.2.3. OID Reference Lookup](system-catalog-initial-data.md#system-catalog-oid-references) - [68.2.4. Automatic Creation of Array Types](system-catalog-initial-data.md#system-catalog-auto-array-types) - [68.2.5. Recipes for Editing Data Files](system-catalog-initial-data.md#system-catalog-recipes) - [68.3. BKI File Format](bki-format.md) - [68.4. BKI Commands](bki-commands.md) - [68.5. Structure of the Bootstrap BKI File](bki-structure.md) - [68.6. BKI Example](bki-example.md) - [69. How the Planner Uses Statistics](planner-stats-details.md) - [69.1. Row Estimation Examples](row-estimation-examples.md) - [69.2. Multivariate Statistics Examples](multivariate-statistics-examples.md) - [69.2.1. Functional Dependencies](multivariate-statistics-examples.md#functional-dependencies) - [69.2.2. Multivariate N-Distinct Counts](multivariate-statistics-examples.md#multivariate-ndistinct-counts) - [69.2.3. MCV Lists](multivariate-statistics-examples.md#mcv-lists) - [69.3. Planner Statistics and Security](planner-stats-security.md) - [70. Backup Manifest Format](backup-manifest-format.md) - [70.1. Backup Manifest Top-level Object](backup-manifest-toplevel.md) - [70.2. Backup Manifest File Object](backup-manifest-files.md) - [70.3. Backup Manifest WAL Range Object](backup-manifest-wal-ranges.md)