Skip to content

Commit d51d546

Browse files
committed
support citus v11.1.3(pg-13/14/15) v10.2.8(pg-12)
1 parent cdb838c commit d51d546

File tree

6 files changed

+91
-3
lines changed

6 files changed

+91
-3
lines changed

image/postgresql/Dockerfile.template

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ RUN apt install -y --no-install-recommends \
3232
libxslt-dev \
3333
uuid-dev \
3434
tcl-dev \
35-
{{ if .major >= 14 then ( -}}
3635
liblz4-dev \
37-
{{ ) else "" end -}}
3836
libperl-dev \
39-
libkrb5-dev
37+
libkrb5-dev \
38+
libcurl4-openssl-dev \
39+
libzstd-dev \
40+
automake \
41+
autoconf
4042
#{{ if env.arch == "aarch64" then ( -}}
4143
# ""
4244
#{{ ) else "" end -}}
@@ -84,6 +86,13 @@ RUN cd /usr/src/pg_dirtyread; \
8486
make PG_CONFIG=/var/lib/postgresql/bin/pg_config -j `expr $(nproc) - 2` >/dev/null; \
8587
make install PG_CONFIG=/var/lib/postgresql/bin/pg_config;
8688

89+
ADD citus /usr/src/citus
90+
RUN cd /usr/src/citus; \
91+
git checkout {{ .citus }}; \
92+
PG_CONFIG=/var/lib/postgresql/bin/pg_config ./configure ; \
93+
make PG_CONFIG=/var/lib/postgresql/bin/pg_config -j `expr $(nproc) - 2` >/dev/null; \
94+
make install PG_CONFIG=/var/lib/postgresql/bin/pg_config;
95+
8796
RUN cd /var/lib/postgresql; \
8897
tar czhvf lib.tar.gz `find . -type f | xargs ldd 2>/dev/null | grep "=>" | cut -d ">" -f 2 | cut -d "(" -f 1 | sort -u`
8998

@@ -95,6 +104,8 @@ ENV DATA /var/lib/postgresql/data
95104
ENV XDG_CONFIG_HOME /var/lib/postgresql/data/auto_failover
96105
ENV XDG_DATA_HOME /var/lib/postgresql/data/auto_failover
97106
ENV ASSIST /var/lib/postgresql/data/assist
107+
ENV PGPASSFILE /var/lib/postgresql/data/assist/pgpassfile
108+
ENV LD_LIBRARY_PATH /var/lib/postgresql/lib/
98109
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/postgresql/bin
99110
ENV PGHOME /var/lib/postgresql
100111
VOLUME /var/lib/postgresql/data

image/postgresql/generate_image.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ build_image()
4242
cp -r ../../source_code/postgresql "$dir/"
4343
cp -r ../../source_code/pg_auto_failover "$dir/"
4444
cp -r ../../source_code/pg_dirtyread "$dir/"
45+
cp -r ../../source_code/citus "$dir/"
4546

4647
cd "$dir"
4748
echo "build docker image $image ..."

pgversions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"tag": ["REL_12_12"],
77
"failover": "v1.6.4",
88
"dirtyread": "2.4",
9+
"citus": "v10.2.8",
910
"name": "radondb-postgresql",
1011
"version": "v1.0.0",
1112
"arches": [
@@ -20,6 +21,7 @@
2021
"tag": ["REL_13_8"],
2122
"failover": "v1.6.4",
2223
"dirtyread": "2.4",
24+
"citus": "v11.1.3",
2325
"name": "radondb-postgresql",
2426
"version": "v1.0.0",
2527
"arches": [
@@ -34,6 +36,7 @@
3436
"tag": ["REL_14_5"],
3537
"failover": "v1.6.4",
3638
"dirtyread": "2.4",
39+
"citus": "v11.1.3",
3740
"name": "radondb-postgresql",
3841
"version": "v1.0.0",
3942
"arches": [
@@ -48,6 +51,7 @@
4851
"tag": ["REL_15_0"],
4952
"failover": "v2.0",
5053
"dirtyread": "2.4",
54+
"citus": "v11.1.3",
5155
"name": "radondb-postgresql",
5256
"version": "v1.0.0",
5357
"arches": [

platforms/kubernetes/postgres-operator/postgres/handle.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
DIFF_ADD = "add"
151151
DIFF_CHANGE = "change"
152152
DIFF_REMOVE = "remove"
153+
PGPASSFILE_PATH = ASSIST_DIR + "/pgpassfile"
153154
DIFF_FIELD_ACTION = (SPEC, ACTION)
154155
DIFF_FIELD_SERVICE = (SPEC, SERVICES)
155156
DIFF_FIELD_AUTOFAILOVER_HBAS = (SPEC, AUTOFAILOVER, HBAS)
@@ -927,6 +928,7 @@ def create_postgresql(
927928
CONTAINER_ENV_VALUE: value
928929
})
929930
if mode == MACHINE_MODE:
931+
machine_env += PG_CONFIG_PREFIX + "shared_preload_libraries='citus,pgautofailover,pg_stat_statements'" + "\n"
930932
machine_env += PG_CONFIG_PREFIX + 'log_truncate_on_rotation=true' + "\n"
931933
machine_env += PG_CONFIG_PREFIX + 'logging_collector=on' + "\n"
932934
machine_env += PG_CONFIG_PREFIX + "log_directory='log'" + "\n"
@@ -941,6 +943,10 @@ def create_postgresql(
941943
machine_env += PG_CONFIG_PREFIX + "tcp_keepalives_interval=30" + "\n"
942944
machine_env += PG_CONFIG_PREFIX + "tcp_keepalives_count=4" + "\n"
943945
else:
946+
k8s_env.append({
947+
CONTAINER_ENV_NAME: PG_CONFIG_PREFIX + "shared_preload_libraries",
948+
CONTAINER_ENV_VALUE: "'citus,pgautofailover,pg_stat_statements'"
949+
})
944950
k8s_env.append({
945951
CONTAINER_ENV_NAME: PG_CONFIG_PREFIX + "log_truncate_on_rotation",
946952
CONTAINER_ENV_VALUE: "true"
@@ -2512,6 +2518,8 @@ async def create_cluster(
25122518
logger.info("waiting for create_cluster success")
25132519
waiting_cluster_final_status(meta, spec, patch, status, logger)
25142520

2521+
update_pgpassfile(meta, spec, patch, status, logger)
2522+
25152523
# wait a few seconds to prevent the pod not running
25162524
time.sleep(5)
25172525
# cluster running
@@ -3464,6 +3472,52 @@ def update_hbas(
34643472
readwrite_conns.free_conns()
34653473
readonly_conns.free_conns()
34663474

3475+
def get_pgpassfile(
3476+
meta: kopf.Meta,
3477+
spec: kopf.Spec,
3478+
patch: kopf.Patch,
3479+
status: kopf.Status,
3480+
logger: logging.Logger,
3481+
users_kind: str,
3482+
) -> str:
3483+
pgpassfile = ""
3484+
if spec[POSTGRESQL][SPEC_POSTGRESQL_USERS].get(users_kind) != None:
3485+
users = spec[POSTGRESQL][SPEC_POSTGRESQL_USERS][users_kind]
3486+
for user in users:
3487+
pgpassfile += "*:*:*:%s:%s\n" % (user[SPEC_POSTGRESQL_USERS_USER_NAME], user[SPEC_POSTGRESQL_USERS_USER_PASSWORD])
3488+
3489+
return pgpassfile
3490+
3491+
def update_pgpassfile(
3492+
meta: kopf.Meta,
3493+
spec: kopf.Spec,
3494+
patch: kopf.Patch,
3495+
status: kopf.Status,
3496+
logger: logging.Logger,
3497+
) -> None:
3498+
pgpassfile = ""
3499+
pgpassfile += get_pgpassfile(meta, spec, patch, status, logger, SPEC_POSTGRESQL_USERS_ADMIN)
3500+
pgpassfile += get_pgpassfile(meta, spec, patch, status, logger, SPEC_POSTGRESQL_USERS_MAINTENANCE)
3501+
pgpassfile += get_pgpassfile(meta, spec, patch, status, logger, SPEC_POSTGRESQL_USERS_NORMAL)
3502+
3503+
if len(pgpassfile) == 0:
3504+
return
3505+
3506+
logger.info(f"update pgpassfile, {pgpassfile}")
3507+
conns = connections(spec, meta, patch,
3508+
get_field(POSTGRESQL, READWRITEINSTANCE), False,
3509+
None, logger, None, status, False)
3510+
readonly_conns = connections(spec, meta, patch,
3511+
get_field(POSTGRESQL, READONLYINSTANCE),
3512+
False, None, logger, None, status, False)
3513+
for conn in (conns.get_conns() + readonly_conns.get_conns()):
3514+
cmd = ["echo", "-e", '"' + pgpassfile + '"', ">", PGPASSFILE_PATH]
3515+
output = exec_command(conn, cmd, logger, interrupt=False)
3516+
cmd = ["chmod", "0600", PGPASSFILE_PATH]
3517+
output = exec_command(conn, cmd, logger, interrupt=False)
3518+
conns.free_conns()
3519+
readonly_conns.free_conns()
3520+
34673521

34683522
def update_users(
34693523
meta: kopf.Meta,
@@ -3480,6 +3534,8 @@ def update_users(
34803534
or FIELD == DIFF_FIELD_POSTGRESQL_USERS_ADMIN \
34813535
or FIELD == DIFF_FIELD_POSTGRESQL_USERS_MAINTENANCE \
34823536
or FIELD == DIFF_FIELD_POSTGRESQL_USERS_NORMAL:
3537+
update_pgpassfile(meta, spec, patch, status, logger)
3538+
34833539
conns = connections(spec, meta, patch,
34843540
get_field(POSTGRESQL, READWRITEINSTANCE), False,
34853541
None, logger, None, status, False)

source_code/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pg_auto_failover
22
postgresql
33
pg_dirtyread
4+
citus
5+
postgis

source_code/download.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,18 @@ else
5656
echo "download pg_dirtyread success"
5757
fi
5858

59+
# citus
60+
if [ -d citus ]
61+
then
62+
echo "citus exists, skip download."
63+
else
64+
git clone https://github.com/citusdata/citus.git
65+
if [ $? -ne 0 ]
66+
then
67+
echo "download citus failed"
68+
exit 1
69+
fi
70+
echo "download citus success"
71+
fi
72+
5973
exit 0

0 commit comments

Comments
 (0)