How to add a system table field to PostgreSQL

Source: Internet
Author: User
Tags postgresql

1. Bki Introduction: http://www.postgresql.org/docs/9.4/static/bki.html

Can not understand, nor affect us to continue, because there are many examples of ready-made reference;

2. Add a field datdummy for Pg_database to open/src/include/catalog/pg_database.h:

CATALOG (pg_database,1262)  bki_shared_relation bki_rowtype_oid (1248)  bki_schema_macro{ namedatadatname;/* database name */oiddatdba;/* owner of database */ int32encoding;/* character encoding */namedatadatcollate;/* lc_collate setting * /namedatadatctype;/* lc_ctype setting */booldatistemplate;/* allowed as create  database template? */booldatallowconn;/* new connections allowed? */ int32datconnlimit;/* max connections allowed  ( -1=no limit)  */Oiddatlastsysoid;/*  highest OID to consider a system OID */TransactionId  Datfrozenxid; /* all xids < this are frozen in this db  */transactionid datminmxid;/* all multixacts in the db are >=  this */oiddattablespace;/* default table space for this db */#ifdef  catalog_varlen/* variable-length  fields start here */aclitemdatacl[1];/* access permissions */#endif}  formdata_pg_database;/* ---------------- *Form_pg_database corresponds to a  Pointer to a tuple with *the format of pg_database relation.  * ---------------- */typedef FormData_pg_database *Form_pg_database;/* -------- -------- *compiler constants for pg_database * ---------------- */#define  natts_pg_database13#define anum_pg_database_datname1#define anum_pg_database_datdba2#define  anum_pg_database_encoding3#define anum_pg_database_datcollate4#define anum_pg_database_ datctype5#define anum_pg_database_datistemplate6#define anum_pg_database_datallowconn7#define  Anum_pg_database_datconnlimit8#defiNe anum_pg_database_datlastsysoid9#define anum_pg_database_datfrozenxid10#define anum_pg_ Database_datminmxid11#define anum_pg_database_dattablespace12#define anum_pg_database_datacl13

They will eventually be used by the script genbki.pl to generate the Postgresql.bki file, used in the INITDB initialization of data cluster, interested in learning, PG compilation system is a full display of the powerful perl language system;

3. Add a new definition under Dattablespace:

int8datdummy;/* Dummy Column */

The definition of the following field ordinal is also important and must be modified in order, as well as the corresponding modification of the attribute number:

#define NATTS_PG_DATABASE14 #define Anum_pg_database_dattablespace12#define Anum_pg_database_datdummy13#define Anum_pg_database_datacl14

The pre-defined database must also be modified, adding 100 fields to the _null_ front datdummy data:

DATA (Insert OID = 1 (template1 pguid ENCODING "lc_collate" "lc_ctype" T t-1 0 0 1 1663 (_null_)));

4, compile run, what will happen, compile normal, then initdb, unexpectedly also magically passed, is this good?

Tip:linux under a directory to change the code, you may encounter inexplicable program problems, try make clean

5, then create a database to try: Creation database Quanzl; Success, is not the feeling seems to have shortcomings what?

Datdummy assignment, can not UPDATE pg_database SET datdummy = xxx bar?

Subscribe to a database like template1, we can define a BKI script in the catalog, such as the above example, giving it an initial value. The program must also be changed in order to become an operational attribute;

6, referring to the syntax modification, creating a CREATE DATABASE xxx DUMMY nnn syntax, modifying the structure createdbstmt add a new attribute, the parsing phase will read this value in the creation of databases when it is written to the property;

NEW_RECORD[ANUM_PG_DATABASE_DATDUMMY-1] = 1234;

This part of the code in the SRC/BACKEND/COMMANDS/DBCOMMANDS.C, self-reading, write the program is so simple. :)


How to add a system table field to PostgreSQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.