Skip to content

Commit 3f7ebff

Browse files
committed
Add docker image template with installed PostgreSQL, AQO and optimal startup settings.
1 parent 6c2fcef commit 3f7ebff

File tree

3 files changed

+135
-9
lines changed

3 files changed

+135
-9
lines changed

Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2016-2019, Postgres Professional
2+
FROM alpine
3+
LABEL maintainer="Andrey V. Lepikhov <a.lepikhov@postgrespro.ru>"
4+
ENV PG_VERSION 11.5
5+
ENV PG_SHA256 7fdf23060bfc715144cbf2696cf05b0fa284ad3eb21f0c378591c6bca99ad180
6+
7+
# the home directory for the postgres user is not created by default
8+
RUN set -ex; \
9+
postgresHome="$(getent passwd postgres)"; \
10+
postgresHome="$(echo "$postgresHome" | cut -d: -f6)"; \
11+
[ "$postgresHome" = '/var/lib/postgresql' ]; \
12+
mkdir -p "$postgresHome"; \
13+
chown -R postgres:postgres "$postgresHome"
14+
15+
# Install minimal set of packages
16+
RUN apk add --update gcc libc-dev bison flex readline-dev zlib-dev perl make \
17+
diffutils gdb iproute2 musl-dbg iputils patch bash su-exec
18+
19+
RUN mkdir /pg && chown postgres:postgres pg
20+
21+
# Download corresponding version of PostgreSQL sources
22+
RUN set -ex \
23+
\
24+
&& wget -O postgresql.tar.bz2 "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" \
25+
&& echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c - \
26+
&& mkdir -p /pg/src \
27+
&& tar \
28+
--extract \
29+
--file postgresql.tar.bz2 \
30+
--directory /pg/src \
31+
--strip-components 1 \
32+
&& rm postgresql.tar.bz2
33+
34+
# Configure, compile and install
35+
RUN mkdir /pg/src/contrib/aqo
36+
COPY ./ /pg/src/contrib/aqo
37+
RUN cd /pg/src/contrib/aqo && ls
38+
RUN cd /pg/src && \
39+
patch -p1 --no-backup-if-mismatch < contrib/aqo/aqo_pg11.patch
40+
RUN cd /pg/src && \
41+
./configure --enable-cassert --enable-debug --prefix=/pg/install && \
42+
make -j 4 install
43+
RUN cd /pg/src/contrib/aqo && make clean && make install
44+
45+
# Set environment
46+
ENV LANG en_US.utf8
47+
ENV CFLAGS -O0
48+
ENV PATH /pg/install/bin:$PATH
49+
ENV PGDATA /pg/data
50+
51+
USER postgres
52+
ENTRYPOINT ["/pg/src/contrib/aqo/docker-entrypoint.sh"]
53+
54+
EXPOSE 5432
55+
CMD ["postgres"]

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@ for improving cardinality estimation. Experimental evaluation shows that this
66
improvement sometimes provides an enormously large speed-up for rather
77
complicated queries.
88

9+
## Docker container
10+
For quick look into the query-driven adaptive query optimization you can use
11+
docker container defined by `Dockerfile` and `docker-entrypoint.sh` files.
12+
13+
Frequently used commands:
14+
* docker build -t aqo . # Build an image
15+
* docker run -d -p 5432:5432 aqo # Run a container
16+
* docker exec -it `<CONTAINER_ID>` bash # Open command prompt in the container
17+
Now, you can use `psql`.
18+
919
## Installation
1020

11-
The module works with PostgreSQL 9.6 and above.
21+
The module works with PostgreSQL 9.6 and above. You need to use appropriate
22+
branch from git repository. The repository contains branch `master` corresponding
23+
to current PostgreSQL master branch, and a number of branches called `stable9_6`
24+
`stable11` and `stable12`. The branch `stable11` can be used with PostgreSQL 10 too.
1225

1326
The module contains a patch and an extension. Patch has to be applied to the
1427
sources of PostgresSQL. Patch affects header files, that is why PostgreSQL
@@ -18,16 +31,19 @@ Extension has to be unpacked into contrib directory and then to be compiled and
1831
installed with `make install`.
1932

2033
```
21-
cd postgresql-9.6 # enter postgresql source directory
22-
git clone https://github.com/tigvarts/aqo.git contrib/aqo # clone aqo into contrib
23-
patch -p1 --no-backup-if-mismatch < contrib/aqo/aqo_pg9_6.patch # patch postgresql
24-
make clean && make && make install # recompile postgresql
25-
cd contrib/aqo # enter aqo directory
26-
make && make install # install aqo
27-
make check # check whether it works correctly (optional)
34+
cd postgresql-9.6 # enter postgresql source directory
35+
git clone https://github.com/postgrespro/aqo.git # clone aqo into contrib
36+
patch -p1 --no-backup-if-mismatch < contrib/aqo/aqo_pg<ver>.patch # patch postgresql
37+
make clean && make && make install # recompile postgresql
38+
cd contrib/aqo # enter aqo directory
39+
make && make install # install aqo
40+
make check # check whether it works correctly (optional)
2841
```
2942

30-
For PostgreSQL 10 and above use aqo_pg10.patch instead of aqo_pg9_6.patch
43+
Tag `ver` at the patch name corresponds to suitable PostgreSQL release.
44+
For PostgreSQL 10 use aqo_pg10.patch; for PostgreSQL 11 use aqo_pg11.patch and so on.
45+
Also, you can see git tags at the master branch for more accurate definition of
46+
suitable PostgreSQL version.
3147

3248
In your database:
3349

docker-entrypoint.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$1" = 'postgres' ]; then
4+
mkdir -p "$PGDATA"
5+
chown -R postgres "$PGDATA"
6+
chmod 700 "$PGDATA"
7+
8+
# look specifically for PG_VERSION, as it is expected in the DB dir
9+
if [ ! -s "$PGDATA/PG_VERSION" ]; then
10+
initdb --nosync
11+
12+
{ echo; echo "host all all 0.0.0.0/0 trust"; } >> "$PGDATA/pg_hba.conf"
13+
{ echo; echo "host replication all 0.0.0.0/0 trust"; } >> "$PGDATA/pg_hba.conf"
14+
15+
cat <<-EOF >> $PGDATA/postgresql.conf
16+
listen_addresses='*'
17+
fsync = on
18+
shared_preload_libraries = 'aqo'
19+
aqo.mode = 'intelligent'
20+
min_parallel_table_scan_size = 0
21+
min_parallel_index_scan_size = 0
22+
EOF
23+
24+
pg_ctl -D "$PGDATA" \
25+
-o "-c listen_addresses=''" \
26+
-w start
27+
28+
: ${POSTGRES_USER:=postgres}
29+
: ${POSTGRES_DB:=$POSTGRES_USER}
30+
export POSTGRES_USER POSTGRES_DB
31+
32+
if [ "$POSTGRES_DB" != 'postgres' ]; then
33+
psql -U `whoami` postgres <<-EOSQL
34+
CREATE DATABASE "$POSTGRES_DB" ;
35+
EOSQL
36+
echo
37+
fi
38+
39+
if [ "$POSTGRES_USER" = `whoami` ]; then
40+
op='ALTER'
41+
else
42+
op='CREATE'
43+
fi
44+
45+
psql -U `whoami` postgres <<-EOSQL
46+
$op USER "$POSTGRES_USER" WITH SUPERUSER PASSWORD '';
47+
EOSQL
48+
echo
49+
50+
psql -U `whoami` $POSTGRES_DB -c 'CREATE EXTENSION aqo;'
51+
pg_ctl -D "$PGDATA" -m fast -w stop
52+
fi
53+
fi
54+
55+
exec "$@"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy