{"id":13441613,"url":"https://github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL","last_synced_at":"2025-03-20T12:31:55.717Z","repository":{"id":43734850,"uuid":"372674141","full_name":"DigitalChinaOpenSource/TiDB-for-PostgreSQL","owner":"DigitalChinaOpenSource","description":"PgSQL compatible on distributed database TiDB","archived":false,"fork":false,"pushed_at":"2022-09-08T09:03:40.000Z","size":242928,"stargazers_count":387,"open_issues_count":12,"forks_count":21,"subscribers_count":13,"default_branch":"tidb4pg_v5.3.0","last_synced_at":"2024-10-28T04:18:44.060Z","etag":null,"topics":["database","golang","mysql","postgresql","tidb"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DigitalChinaOpenSource.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null}},"created_at":"2021-06-01T01:59:04.000Z","updated_at":"2024-09-26T08:43:22.000Z","dependencies_parsed_at":"2023-01-18T01:01:17.347Z","dependency_job_id":null,"html_url":"https://github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DigitalChinaOpenSource%2FTiDB-for-PostgreSQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DigitalChinaOpenSource%2FTiDB-for-PostgreSQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DigitalChinaOpenSource%2FTiDB-for-PostgreSQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DigitalChinaOpenSource%2FTiDB-for-PostgreSQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DigitalChinaOpenSource","download_url":"https://codeload.github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL/tar.gz/refs/heads/tidb4pg_v5.3.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244611310,"owners_count":20481171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","golang","mysql","postgresql","tidb"],"created_at":"2024-07-31T03:01:36.058Z","updated_at":"2025-03-20T12:31:51.667Z","avatar_url":"https://github.com/DigitalChinaOpenSource.png","language":"Go","funding_links":[],"categories":["HarmonyOS","Go"],"sub_categories":["Windows Manager"],"readme":"# TiDB for PostgreSQL\n\n[![LICENSE](https://img.shields.io/github/license/pingcap/tidb.svg)](https://github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL/blob/main/LICENSE)\n[![Language](https://img.shields.io/badge/Language-Go-blue.svg)](https://golang.org/)\n[![Build Status](http://tidb4pgci.eastasia.cloudapp.azure.com/buildStatus/icon?job=jenkins-tidb4pg-build)](http://tidb4pgci.eastasia.cloudapp.azure.com/job/jenkins-tidb4pg-build/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL)](https://goreportcard.com/report/github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL)\n[![codecov](https://codecov.io/gh/DigitalChinaOpenSource/TiDB-for-PostgreSQL/branch/main/graph/badge.svg?token=OZ16DNE6JH)](https://codecov.io/gh/DigitalChinaOpenSource/TiDB-for-PostgreSQL)\n![GitHub commit activity](https://img.shields.io/github/commit-activity/w/DigitalChinaOpenSource/TiDB-for-PostgreSQL)\n\n## Introduction\n\nTiDB for PostgreSQL is an open source launched by Digital China Cloud Base to promote and integrate into the open source community of TiDB. In addition to its high availability, horizontal scalability, and cloud-native features, TiDB for PostgreSQL is compatible with the PostgreSQL protocol. On the one hand, you can use the PostgreSQL client to connect to TiDB for PostgreSQL, which we have basically completed. On the other hand, you can also use the unique grammatical features of PostgreSQL in your business system, which is in the development process.\n\nMore details can be found in the [Design Document](https://github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL/blob/main/DESIGN_DOCUMENT.md)\n\n## Background\n\nAs the general trend of the massive explosion of information in the current data era becomes more and more obvious, the database is more and more likely to become the bottleneck of the upper-level business system. For this problem, TiDB solves most of migration problems of business system based on MySQL database through its highly compatibility of MySQL protocol. In view of its distributed transactions with strong consistency, flexible scalability, and excellent disaster recovery backup architecture, users prefer to use mature solutions of TiDB rather than scale MySQL by sharding. However, there is no mature solution for the upper-level business system based on PostgreSQL to migrate to TiDB. If you want to migrate a PostgreSQL-based business system to TiDB, you have to modify lots of code of business system. To solve this，we try to refactor the underlying source code of TiDB to make it compatible with the PostgreSQL protocol, making it possible to migrate PostgreSQL-based business systems to TiDB without modifying much code.\n\n\n\n## Development progress\n\nThe largest amount of work for the development of TiDB for PostgreSQL is compatibility with PostgreSQL, which has two things to do. One is to implement the PostgreSQL connection protocol, which we have basically achieved, So PostgreSQL client can connect to TiDB for PostgreSQL. The other is the unique PostgreSQL syntax. TiDB for PostgreSQL can support general sql syntax, but there are a certain amount of work to do to make it compatible with PostgreSQL’s unique syntax. This is one of the reasons why TiDB for PostgreSQL is open sourced. We hope that through the open source, engineers interested in our TiDB for PostgreSQL can work together to make our project bigger and better.\n\n\n\n## Quick start\n\nFirst, make sure you have a Go environment, because TiDB for PostgreSQL is based on the Go language.\n\nTiDB for PostgreSQL can be started on a single node without pd and tikv.\n\nIf there is no pd and tikv, it will create mock pd and mock tikv to maintain the stable operation of the system.\n\nThe following is an example of locally compiling and running TiDB for PostgreSQL on localhost.\n\n```shell\nmkdir -p  $GOPATH/src/github.com/digitalchina\n\ncd  $GOPATH/src/github.com/digitalchina\n\ngit clone https://github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL.git\n\ncd TiDB-for-PostgreSQL/tidb-server\n\ngo run main.go\n\n# If you get an error: export ordinal to larger\n# Please run the following cmd:\ngo run -buildmode=exe  main.go\n```\n\nAfter starting the main program of TiDB for PostgreSQL , it will run on port 4000 of the host.\n\nHow to use PostgreSQL client to connect to TiDB for PostgreSQL? Here, we take the command line tool psql that comes with PostgreSQL as an example.\n\n```\nServer [localhost]:\nDatabase [postgres]: test\nPort [5433]: 4000\nUsername [postgres]: root\npsql (13.1, server 8.3.11)\nType \"help\" to get help information.\n\ntest=# show tables;\n Tables_in_test\n----------------\n t1\n t2\n(2 行记录)\n```\n\n## Docker \n\n```shell\n# Log in to your dockerhub account\ndocker login\n\n# Pull the image and start the container\ndocker pull dcleeray/tidb-for-pg\ndocker run -it --name tidbforpg -p 4000:4000 -d  dcleeray/tidb-for-pg:latest\n```\n\n## Cluster deployment\nTiDB for PostgreSQL also supports cluster deployment.\n\nOur current modification work does not involve the communication module of each component in the cluster. Therefore, the connection of TiDB for PostgreSQL to pd and tikv will not be affected in any way.\n\nWe recommend using binary file to deploy TiDB for PostgreSQL cluster.\n\nFirst, download the official binary package file and unzip it.\n\n```shell\nwget http://download.pingcap.org/tidb-v5.3.0-linux-amd64.tar.gz\nwget http://download.pingcap.org/tidb-v5.3.0-linux-amd64.sha256\n\nsha256sum -c tidb-v5.3.0-linux-amd64.sha256\n\ntar -xzf tidb-v5.3.0-linux-amd64.tar.gz\ncd tidb-v5.3.0-linux-amd64/bin\n```\n\nSecond, deploy each node in the cluster in order. According to the cluster architecture of TiDB for PostgreSQL, pd nodes are deployed first, then the tikv node, and finally the TiDB for PostgreSQL node. The number of nodes in the cluster is not specified, but there is at least one of each type.\n\nDeploy a pd node\n\n```shell\n./pd-server --name=pd1 --data-dir=pd1 --client-urls=\"http://pdhost:2379\" --peer-urls=\"http://host:2380\" -L \"info\" --log-file=pd.log\n```\n\nDeploy three tikv nodes\n\n```shell\n./tikv-server --pd=\"pdhost:2379\" --addr=\"kvhost1:20160\"  --data-dir=tikv  --log-file=tikv1.log\n./tikv-server --pd=\"pdhost:2379\" --addr=\"kvhost2:20160\"  --data-dir=tikv  --log-file=tikv2.log\n./tikv-server --pd=\"pdhost:2379\" --addr=\"kvhost3:20160\"  --data-dir=tikv  --log-file=tikv3.log\n```\n\nDeploy a TiDB for PostgreSQL node. You need to compile the TiDB for PostgreSQL project into a binary file named tidb-server and upload it to this server for replace the original tidb-server\n\n```shell\n## If compiled on windows, the following parameters need to be set\nSET GOARCH=amd64\nSET GOOS=linux\n\n## Running tidb-server on linux\n./tidb-server --store=tikv  --path=\"pdhost:2379\" --log-file=tidb.log\n```\n\nWith the above done, a TiDB for PostgreSQL cluster is successfully deployed, and you can connect to TiDB for PostgreSQL cluster in the same way as you did with single TiDB for PostgreSQL demonstrated earlier.\n\n## Contribute code to TiDB for postgresql\n\nWe greatly welcome and appreciate developers who are interested in TiDB for PostgreSQL to make contributions. At present, we provide several directions to get started.\n\n[Learning Guide](https://github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL/blob/main/LEARNING_GUIDANCE.zh.md)\n\n[Contribution Guide](https://github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL/blob/main/CONTRIBUTING.md)\n\n### Schema structure\n\nThe database structure of PostgreSQL is very different from that of MySQL, which is also a big problem we encountered in our development. It involves the realization of database system tables, system views, and system functions. It’s a lot of work and very hard. Developers are required to be very familiar with the database table structure of both PostgreSQL and MySQL.\n\n### Postgresql grammatical features\n\nCompared with MySQL, PostgreSQL has many new syntax features. For example, Returning can return specified column or all columns of the modified row. Implementing a syntax involves modifying codes of the Parser module, TiDB for PostgreSQL's internal plan structure, plan optimization, plan execution, and data write-back, and many other parts. It’s really very hard. We recommend that developers start with clauses such as RETURNING and modify them on the basis of the original code. After being familiar with the logic of TiDB for PostgreSQL planning and execution, you can try to implement a brand new statement.\n\n## Version notice\n\nTo keep our code improvement running stable, we currently choose a fixed version for development. The following is our selected version:\n\nTiDB v5.3.0\n\nPostgreSQL 13\n\n## License\n\nApache-2.0 License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDigitalChinaOpenSource%2FTiDB-for-PostgreSQL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDigitalChinaOpenSource%2FTiDB-for-PostgreSQL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDigitalChinaOpenSource%2FTiDB-for-PostgreSQL/lists"}