All Projects → DigitalChinaOpenSource → TiDB-for-PostgreSQL

DigitalChinaOpenSource / TiDB-for-PostgreSQL

Licence: Apache-2.0 license
PgSQL compatible on distributed database TiDB

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to TiDB-for-PostgreSQL

Tidb
TiDB is an open source distributed HTAP database compatible with the MySQL protocol
Stars: ✭ 29,871 (+8434.57%)
Mutual labels:  tidb
Apijson
🚀 零代码、热更新、全自动 ORM 库,后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构。 🚀 A JSON Transmission Protocol and an ORM Library for automatically providing APIs and Docs.
Stars: ✭ 12,559 (+3488.29%)
Mutual labels:  tidb
Asky
Asky开源架构:极简、轻量、极致性能《Asky零基础1小时学编程 dnc+vue+tidb+redis+rabbitMQ+ES》QQ群 779699538
Stars: ✭ 213 (-39.14%)
Mutual labels:  tidb
Tidb Operator
TiDB operator creates and manages TiDB clusters running in Kubernetes.
Stars: ✭ 778 (+122.29%)
Mutual labels:  tidb
Killy
🎮 🆓 Play TiDB in Minecraft! Created by @gaocegege @codeworm96 @hawkingrei in Go Hack 2017
Stars: ✭ 59 (-83.14%)
Mutual labels:  tidb
Blog
Stay hungry. Stay foolish.
Stars: ✭ 129 (-63.14%)
Mutual labels:  tidb
Dnc
dnc 去中心化 开源社区 轻联盟 dncto.com QQ群 779699538
Stars: ✭ 551 (+57.43%)
Mutual labels:  tidb
tide
The TiDB IDE
Stars: ✭ 90 (-74.29%)
Mutual labels:  tidb
Tikv
Distributed transactional key-value database, originally created to complement TiDB
Stars: ✭ 10,403 (+2872.29%)
Mutual labels:  tidb
Tiup
A component manager for TiDB
Stars: ✭ 207 (-40.86%)
Mutual labels:  tidb
Goinception
一个集审核、执行、备份及生成回滚语句于一身的MySQL运维工具
Stars: ✭ 905 (+158.57%)
Mutual labels:  tidb
Titan
A Distributed Redis Protocol Compatible NoSQL Database
Stars: ✭ 1,050 (+200%)
Mutual labels:  tidb
Dumpling
Dumpling is a fast, easy-to-use tool written by Go for dumping data from the database(MySQL, TiDB...) to local/cloud(S3, GCP...) in multifarious formats(SQL, CSV...).
Stars: ✭ 134 (-61.71%)
Mutual labels:  tidb
Xorm
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
Stars: ✭ 6,464 (+1746.86%)
Mutual labels:  tidb
perseus
Perseus is a set of scripts (docker+javascript) to investigate a distributed database's responsiveness when one of its three nodes is isolated from the peers
Stars: ✭ 49 (-86%)
Mutual labels:  tidb
Sqlancer
Detecting Logic Bugs in DBMS
Stars: ✭ 672 (+92%)
Mutual labels:  tidb
Docs Cn
TiDB/TiKV/PD documentation in Chinese.
Stars: ✭ 1,646 (+370.29%)
Mutual labels:  tidb
TiBigData
TiDB connectors for Flink/Hive/Presto
Stars: ✭ 192 (-45.14%)
Mutual labels:  tidb
horoscope
horoscope is an optimizer inspector for DBMS.
Stars: ✭ 34 (-90.29%)
Mutual labels:  tidb
Tidb Lightning
A high-speed data import tool for TiDB
Stars: ✭ 139 (-60.29%)
Mutual labels:  tidb

TiDB for PostgreSQL

LICENSE Language Build Status Go Report Card codecov GitHub commit activity

Introduction

TiDB 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.

More details can be found in the Design Document

Background

As 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.

Development progress

The 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.

Quick start

First, make sure you have a Go environment, because TiDB for PostgreSQL is based on the Go language.

TiDB for PostgreSQL can be started on a single node without pd and tikv.

If there is no pd and tikv, it will create mock pd and mock tikv to maintain the stable operation of the system.

The following is an example of locally compiling and running TiDB for PostgreSQL on localhost.

mkdir -p  $GOPATH/src/github.com/digitalchina

cd  $GOPATH/src/github.com/digitalchina

git clone https://github.com/DigitalChinaOpenSource/TiDB-for-PostgreSQL.git

cd TiDB-for-PostgreSQL/tidb-server

go run main.go

# If you get an error: export ordinal to larger
# Please run the following cmd:
go run -buildmode=exe  main.go

After starting the main program of TiDB for PostgreSQL , it will run on port 4000 of the host.

How 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.

Server [localhost]:
Database [postgres]: test
Port [5433]: 4000
Username [postgres]: root
psql (13.1, server 8.3.11)
Type "help" to get help information.

test=# show tables;
 Tables_in_test
----------------
 t1
 t2
(2 行记录)

Docker

# Log in to your dockerhub account
docker login

# Pull the image and start the container
docker pull dcleeray/tidb-for-pg
docker run -it --name tidbforpg -p 4000:4000 -d  dcleeray/tidb-for-pg:latest

Cluster deployment

TiDB for PostgreSQL also supports cluster deployment.

Our 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.

We recommend using binary file to deploy TiDB for PostgreSQL cluster.

First, download the official binary package file and unzip it.

wget http://download.pingcap.org/tidb-v5.3.0-linux-amd64.tar.gz
wget http://download.pingcap.org/tidb-v5.3.0-linux-amd64.sha256

sha256sum -c tidb-v5.3.0-linux-amd64.sha256

tar -xzf tidb-v5.3.0-linux-amd64.tar.gz
cd tidb-v5.3.0-linux-amd64/bin

Second, 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.

Deploy a pd node

./pd-server --name=pd1 --data-dir=pd1 --client-urls="http://pdhost:2379" --peer-urls="http://host:2380" -L "info" --log-file=pd.log

Deploy three tikv nodes

./tikv-server --pd="pdhost:2379" --addr="kvhost1:20160"  --data-dir=tikv  --log-file=tikv1.log
./tikv-server --pd="pdhost:2379" --addr="kvhost2:20160"  --data-dir=tikv  --log-file=tikv2.log
./tikv-server --pd="pdhost:2379" --addr="kvhost3:20160"  --data-dir=tikv  --log-file=tikv3.log

Deploy 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

## If compiled on windows, the following parameters need to be set
SET GOARCH=amd64
SET GOOS=linux

## Running tidb-server on linux
./tidb-server --store=tikv  --path="pdhost:2379" --log-file=tidb.log

With 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.

Contribute code to TiDB for postgresql

We greatly welcome and appreciate developers who are interested in TiDB for PostgreSQL to make contributions. At present, we provide several directions to get started.

Learning Guide

Contribution Guide

Schema structure

The 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.

Postgresql grammatical features

Compared 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.

Version notice

To keep our code improvement running stable, we currently choose a fixed version for development. The following is our selected version:

TiDB v5.3.0

PostgreSQL 13

License

Apache-2.0 License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].