๐Ÿ“ฆ yjhjstz / postgres-xl-docker

postgres-xl & age

โ˜… 0 stars โ‘‚ 0 forks ๐Ÿ‘ 0 watching โš–๏ธ MIT License
graph-database
๐Ÿ“ฅ Clone https://github.com/yjhjstz/postgres-xl-docker.git
HTTPS git clone https://github.com/yjhjstz/postgres-xl-docker.git
SSH git clone git@github.com:yjhjstz/postgres-xl-docker.git
CLI gh repo clone yjhjstz/postgres-xl-docker
Jianghua.yjh Jianghua.yjh update 0d9d717 4 years ago ๐Ÿ“ History
๐Ÿ“‚ 0d9d717de191eafb302f282b9590c9adac25f855 View all commits โ†’
๐Ÿ“ bin
๐Ÿ“ ci
๐Ÿ“ lib
๐Ÿ“„ .dockerignore
๐Ÿ“„ .gitignore
๐Ÿ“„ .gitmodules
๐Ÿ“„ .version
๐Ÿ“„ docker-compose.yml
๐Ÿ“„ Dockerfile
๐Ÿ“„ Dockerfile.bak
๐Ÿ“„ g.sql
๐Ÿ“„ gdbpg.py
๐Ÿ“„ LICENSE
๐Ÿ“„ load.py
๐Ÿ“„ node.txt
๐Ÿ“„ q.sql
๐Ÿ“„ README.md
๐Ÿ“„ test.sql
๐Ÿ“„ README.md

Postgres-XL Docker

Postgres-XL Docker is a container image for Postgres-XL, the scalable open-source PostgreSQL-based database cluster.

The images allow for arbitrary database cluster topologies, allowing GTM, GTM Proxy, Coordinator, and Datanode nodes to be created and added as desired. Each service runs in its own container, communicating over a backend network. Coordinator nodes also connect to a frontend network.

Previously, Postgres-XL Docker used pgxc_ctl for initialisation and control, running SSH servers as well as database services. This has now been completely redesigned to run database services directly without SSH, initialising using included helper scripts, and allowing full flexibility with regard to cluster topologies. The pgxc_ctl binary is no longer included in the image, since the recommended Postgres-XL Docker workflow is to not use it.

Usage

Instructions are for running on Docker using Docker Compose. It should be possible to boot an entire Postgres-XL cluster using these instructions. For running on Docker Swarm, you'll likely have to make minor tweaks. Please wave if something isn't clear or you have questions when doing this.

It seems some people think that the way to use Postgres-XL Docker is to build it themselves from the Compose file. This is not the case; the images are published to Docker Hub, and those should normally be used instead. There's no need to compile this locally, unless you actually want to develop Postgres-XL Docker (or possibly Postgres-XL) itself. The supplied docker-compose.image.yml provides an example of how to do this; however, note that the latest tag is for testing and caching only; if you install a production database using latest or no tag at all, then you are doing it wrong, and your production will break at some point in the future. You have been warned. :)

Note that the pg_hba.conf written is wide-open for any user on the backend network; if you use this method, be sure that you trust all users on that network, and isolate client connections using a frontend network. Alternatively, you might like to configure ident or md5, edit pg_hba.conf yourself, or not use the provided init.sh helper scripts.

These instructions, along with the provided docker-compose.yml file, create:

  • 1 GTM (master) (gtm_1)
  • 2 Coordinators (master) (coord_1, coord_2)
  • 2 Datanodes (master) (data_1, data_2)
--------------
                                 |   gtm_1    |
                                 --------------
                                / |          | \
                              /   |          |   \
                            /     |          |     \
                          /       |          |       \
                        /         |          |         \
                      /           |          |           \
                    /             |          |             \
                  /               |          |               \
                /       ------------        ------------      \
               |        | coord_1  |        | coord_2  |       |
               |        ------------        ------------       |
               |       /             \    /             \      |
               |     /                 \/                 \    |
         ------------      ------------/\------------      ------------
         |  data_1  |     /                          \     |  data_2  |
         ------------ ----                            ---- ------------

Other topologies are possible; you likely only need to edit docker-compose.yml, potentially setting additional environment variables.

Build

Clone repository. Pull source with git submodule update --init --recursive. Edit docker-compose.yml to reflect the desired topology.

Build services by bringing them up.

docker-compose up

This will create backend (db_a) and frontend (db_b) networks.

Clustering (Automatically)

Prepare an example cluster locally, using the provided example init script. This is not designed for production. Instead, configure by hand using whichever orchestrator you use, or write your own scripts.

bin/init-eg

Clustering (Swarm; Automatically)

If you're running on Docker Swarm, you can use the provided example docker-compose.stack.yml as a starting point, deploying with docker stack deploy, along with the init script. Note that the example makes various assumptions, such as that the Swarm node is a manager, that it is tagged with grp=dbxl, and that db_a has a lower subnet than db_b (which might or might not happen automatically; create the networks manually, if you're having trouble).

bin/init-eg-swarm STACK_NAME

Note there are various caveats to using this, which you can read about in detail here:

  • https://github.com/tiredpixel/postgres-xl-docker/issues/27
  • https://github.com/tiredpixel/postgres-xl-docker/pull/28

Clustering (Kubernetes; Automatically)

Please keep in mind:

  • So as docker stack doesn't support depends_on option, it may cause errors until GTM node will be loaded.
  • Scripts below are using kubectl to execute commands on the K8s cluster.
# TO UP
docker stack deploy --orchestrator=kubernetes --namespace=default -c docker-compose.stack.yml pxl_stack
# After you deployed pxl_stack, you need to initialize it (if it didn't do early or you purged PVC)
./bin/init-eg-stack

# TO DOWN
docker stack rm --orchestrator=kubernetes pxl_stack
# Keep in mind that Persistent volumes (PVC) are NOT Docker volumes
# If you want to purge that, you can to remove !!! ALL !!! PVC ๐Ÿ‘‡
kubectl delete pvc --all
# To show all volumes use ๐Ÿ‘‡
kubectl get pv

# TO PORT FORWARD
kubectl port-forward <NAME-OF-POD> 5432:5432
# Also Kubernetes will make port-forwarding. You can find localhost port below ๐Ÿ‘‡
kubectl get service

# TO GET INFO
kubectl get all
# or
docker stack ps --orchestrator=kubernetes pxl_stack

# TO GET LOGS
kubectl describe pod db-data-2-0
kubectl logs db-data-2-0

# TO DEBUG
kubectl exec db-gtm-1-0 -i -t -- bash -il
# Where instead โ˜๏ธ db-gtm-1-0 may be used db-coord-1-0, db-coord-2-0, db-data-1-0, db-data-2-0
# If you wanna run psql inside container, I suggest to add /usr/local/lib/postgresql/bin to $PATH var
PATH=/usr/local/lib/postgresql/bin/:${PATH}

Pgpool

Also you can add pgpool load balacer to the solution. It needs to make base enter point to database cluster and load balansing between coordinators. It sees cordinators nodes. For that:

  • Download pgpool.conf from gist.
  • Add these strings below to a docker-compose file
``docker-compose pgpool: image: smirart/pgpool:latest ports: - "5432:5432" volumes: - ./pgpool.conf:/etc/pgpool/pgpool.conf restart: always networks: - db-b %%CODEBLOCK5%%sql ALTER NODE data_1 WITH (TYPE = 'datanode'); ALTER NODE data_2 WITH (TYPE = 'datanode'); CREATE NODE coord_1 WITH (TYPE = 'coordinator', HOST = 'db_coord_1', PORT = 5432); CREATE NODE coord_2 WITH (TYPE = 'coordinator', HOST = 'db_coord_2', PORT = 5432); CREATE NODE data_1 WITH (TYPE = 'datanode', HOST = 'db_data_1', PORT = 5432); CREATE NODE data_2 WITH (TYPE = 'datanode', HOST = 'db_data_2', PORT = 5432); SELECT pgxc_pool_reload(); %%CODEBLOCK6%%sql ALTER NODE data_1 WITH (PRIMARY, PREFERRED); SELECT pgxc_pool_reload(); %%CODEBLOCK7%%sql ALTER NODE data_2 WITH (PRIMARY, PREFERRED); SELECT pgxc_pool_reload(); %%CODEBLOCK8%%sql SELECT * FROM pgxc_node; %%CODEBLOCK9%%sql CREATE TABLE disttab (col1 int, col2 int, col3 text) DISTRIBUTE BY HASH(col1); \d+ disttab CREATE TABLE repltab (col1 int, col2 int) DISTRIBUTE BY REPLICATION; \d+ repltab INSERT INTO disttab values(1, 2, 'foo'); INSERT INTO disttab values(2, 3, 'foo'); INSERT INTO disttab values(8, 9, 'foo'); INSERT INTO disttab SELECT generate_series(1, 100), generate_series(101, 200), 'foo'; INSERT INTO repltab SELECT generate_series(1, 100), generate_series(101, 200); SELECT count(*) FROM disttab; SELECT xc_node_id, count(*) FROM disttab GROUP BY xc_node_id; SELECT count(*) FROM repltab; SELECT xc_node_id, count(*) FROM repltab GROUP BY xc_node_id; ` ## Blessing May you find peace, and help others to do likewise. ## Contact [tiredpixel.com](https://www.tiredpixel.com/) ยท [tp@tiredpixel.com](mailto:tp@tiredpixel.com) LinkedIn: [in/nic-williams](https://www.linkedin.com/in/nic-williams/) ยท Twitter: [tiredpixel](https://twitter.com/tiredpixel) ยท GitHub: [tiredpixel](https://github.com/tiredpixel) ## Licence Copyright ยฉ 2016-2020 [Nic Williams](https://www.tiredpixel.com/), and other [contributors](https://github.com/tiredpixel/postgres-xl-docker/graphs/contributors). It is free software, released under the MIT licence, and may be redistributed under the terms specified in LICENSE`.