Commit 2bcc0f7a authored by Alexander Galushko's avatar Alexander Galushko
Browse files

added postges13_repmgr docker,awx export hosts to ansible

parent 2f38a50d
......@@ -66,7 +66,7 @@ defaults
retries 3
option redispatch
maxconn ${HAPROXY_OPT_MAXCONN:-500}
timeout client ${HAPROXY_TIMEOUT_CLIENT:-440s}
timeout client ${HAPROXY_TIMEOUT_CLIENT:-10800s}
timeout server ${HAPROXY_TIMEOUT_SERVER:-440s}
timeout connect ${HAPROXY_TIMEOUT_CONNECT:-440s}
frontend writer-front
......@@ -76,7 +76,7 @@ frontend writer-front
acl white_list src ${HAPROXY_SERVICE_ALLOW_HOSTS:-10.0.0.0/8 172.16.0.0/12 127.0.0.1/32 192.168.0.0/16}
tcp-request content accept if white_list
tcp-request content reject
timeout client ${HAPROXY_TIMEOUT_CLIENT:-440s}
timeout client ${HAPROXY_TIMEOUT_CLIENT:-10800s}
frontend reader-front
bind *:3307
mode tcp
......@@ -84,7 +84,7 @@ frontend reader-front
acl white_list src ${HAPROXY_SERVICE_ALLOW_HOSTS:-10.0.0.0/8 172.16.0.0/12 127.0.0.1/32 192.168.0.0/16}
tcp-request content accept if white_list
tcp-request content reject
timeout client ${HAPROXY_TIMEOUT_CLIENT:-440s}
timeout client ${HAPROXY_TIMEOUT_CLIENT:-10800s}
frontend stats-front
bind *:80
mode http
......
......@@ -3,7 +3,7 @@ version: '3.8'
services:
haproxy:
image: devsadds/haproxy-mysql:2.3.5_consul-1.9.3_consul-template-0.25.1-v1.3.1
image: devsadds/haproxy-mysql:2.3.5_consul-1.9.3_consul-template-0.25.1-v1.3.2
build:
context: build/haproxy-mysql/.
args:
......
......@@ -8,7 +8,7 @@ work_mem = 32MB
max_worker_processes = 4
max_parallel_workers_per_gather = 2
temp_buffers = 512MB # Это размер буфера под временные объекты (временные таблицы). Среднее значение 2-4% всего количества RAM
temp_buffers = 512MB
pg_stat_statements.max = 10000
pg_stat_statements.track = all
#shared_preload_libraries = 'repmgr,pg_stat_statements'
......@@ -19,4 +19,5 @@ cpu_tuple_cost = 0.01
cpu_index_tuple_cost = 0.5
cpu_operator_cost = 0.25
parallel_tuple_cost = 1
parallel_setup_cost = 100
\ No newline at end of file
parallel_setup_cost = 100
#synchronous_commit = OFF
\ No newline at end of file
all: docker_build docker_push
docker_build:$(eval SHELL:=/bin/bash)
docker-compose build
docker_push:$(eval SHELL:=/bin/bash)
docker-compose push
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
LABEL maintainer "Bitnami <containers@bitnami.com>"
ENV HOME="/" \
OS_ARCH="amd64" \
OS_FLAVOUR="debian-10" \
OS_NAME="linux" \
DEBIAN_FRONTEND=noninteractive \
BITNAMI_APP_NAME="postgresql-repmgr" \
BITNAMI_IMAGE_VERSION="13.2.0-debian-10-r21" \
LANG="en_US.UTF-8" \
LANGUAGE="en_US:en" \
NSS_WRAPPER_LIB="/opt/bitnami/common/lib/libnss_wrapper.so" \
PATH="/opt/bitnami/postgresql/bin:/opt/bitnami/repmgr/bin:/opt/bitnami/common/bin:$PATH" \
CONSUL_VERSION="1.9.3"
COPY prebuildfs /
RUN install_packages acl ca-certificates unzip curl gzip libbsd0 libc6 libedit2 libffi6 libgcc1 libgmp10 libgnutls30 libhogweed4 libicu63 libidn2-0 libldap-2.4-2 liblzma5 libnettle6 libp11-kit0 libsasl2-2 libsqlite3-0 libssl1.1 libstdc++6 libtasn1-6 libtinfo6 libunistring2 libuuid1 libxml2 libxslt1.1 locales procps tar zlib1g apt-transport-https iproute2 net-tools iputils-ping \
&& . /opt/bitnami/scripts/libcomponent.sh \
&& component_unpack "postgresql-repmgr" "13.2.0-6" --checksum 9a41470ff762c7abd6dbcb696e456251b909cc3fa155d1d13b299dba585d643b \
&& . /opt/bitnami/scripts/libcomponent.sh \
&& component_unpack "gosu" "1.12.0-2" --checksum 4d858ac600c38af8de454c27b7f65c0074ec3069880cb16d259a6e40a46bbc50 \
&& apt-get update && apt-get upgrade -y \
&& rm -r /var/lib/apt/lists /var/cache/apt/archives \
&& chmod g+rwX /opt/bitnami \
&& localedef -c -f UTF-8 -i en_US en_US.UTF-8 \
&& update-locale LANG=C.UTF-8 LC_MESSAGES=POSIX \
&& DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales \
&& echo 'en_GB.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen \
&& echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen \
&& echo 'ru_RU.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen \
&& mkdir -p /temp/ \
&& cd /temp/ \
&& curl https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip -o /temp/consul_${CONSUL_VERSION}_linux_amd64.zip \
&& unzip -d /bin consul_${CONSUL_VERSION}_linux_amd64.zip \
&& chmod +x -v /bin/consul \
&& rm -rf /temp
COPY rootfs /
RUN /opt/bitnami/scripts/postgresql-repmgr/postunpack.sh \
&& /opt/bitnami/scripts/locales/add-extra-locales.sh
RUN install_packages wget gcc make build-essential libxml2-dev libgeos-dev libproj-dev libgdal-dev libssl-dev cmake \
&& cd /tmp \
&& wget "https://github.com/timescale/timescaledb/archive/2.1.0.tar.gz" \
&& export C_INCLUDE_PATH=/opt/bitnami/postgresql/include/:/opt/bitnami/common/include/ \
&& export LIBRARY_PATH=/opt/bitnami/postgresql/lib/:/opt/bitnami/common/lib/ \
&& export LD_LIBRARY_PATH=/opt/bitnami/postgresql/lib/:/opt/bitnami/common/lib/ \
&& tar zxf 2.1.0.tar.gz \
&& cd timescaledb-2.1.0 \
&& ./bootstrap -DUSE_OPENSSL=0 -DREGRESS_CHECKS=OFF \
&& ls -la \
&& cd build \
&& ls -la \
#&& ./configure --with-pgconfig=/opt/bitnami/postgresql/bin/pg_config \
&& make \
&& make install \
&& rm -rfv /tmp/*
COPY files/pgscripts /pgscripts/
COPY files/configs/bitnami/postgres/conf.d /opt/bitnami/postgresql/conf/conf.d
COPY files/bashrc_alias.sh /usr/sbin/bashrc_alias.sh
COPY files/initbash_profile.sh /usr/sbin/initbash_profile
COPY files/docker-entrypoint.d /docker-entrypoint.d/
RUN chmod +x /usr/sbin/bashrc_alias.sh /usr/sbin/initbash_profile \
&& sed -i '/postgresql_custom_init_scripts/a bash /docker-entrypoint.d/consul_agent.sh' /opt/bitnami/scripts/librepmgr.sh \
&& sed -i '/Starting repmgrd/a info \"** Start consul agent! **\" ' /opt/bitnami/scripts/postgresql-repmgr/run.sh \
&& sed -i '/Start consul agent/a bash /docker-entrypoint.d/consul_agent.sh & disown' /opt/bitnami/scripts/postgresql-repmgr/run.sh \
&& echo "bash /docker-entrypoint.d/consul_agent.sh" >> /opt/bitnami/repmgr/events/execs/includes/unlock_standby.sh \
&& chmod 777 -R -v /pgscripts/ \
/opt/bitnami/scripts/librepmgr.sh \
/opt/bitnami/scripts/postgresql-repmgr/run.sh \
/opt/bitnami/repmgr/events/execs/includes/unlock_standby.sh \
&& chmod 777 -R /docker-entrypoint.d/ \
&& ls -la /opt/bitnami/postgresql/conf/conf.d/ \
&& /bin/bash -C "/usr/sbin/initbash_profile" \
&& mkdir -p /docker-info.d/ \
&& VERSION_POSTGRES=$(psql --version | awk '{print $NF}') \
&& VERSION_CONSUL=${CONSUL_VERSION} \
&& DOCKER_BUILD_DATA=$(date +%Y_%m_%d_%R_%Z) \
&& DOCKER_BASE_IMAGE="docker.io/bitnami/minideb:buster" \
&& echo "DOCKER_BUILD_DATA=${DOCKER_BUILD_DATA}" > /docker-info.d/build.info \
&& echo "VERSION_POSTGRES=${VERSION_POSTGRES}" >> /docker-info.d/build.info \
&& echo "VERSION_CONSUL=${VERSION_CONSUL}" >> /docker-info.d/build.info \
&& echo "--------Build info----------------" \
&& cat /docker-info.d/build.info \
&& echo "--------Build info----------------" \
&& cat /opt/bitnami/scripts/postgresql-repmgr/run.sh
USER 1001
EXPOSE 5432
ENTRYPOINT [ "/opt/bitnami/scripts/postgresql-repmgr/entrypoint.sh" ]
CMD [ "/opt/bitnami/scripts/postgresql-repmgr/run.sh" ]
postgresroot() {
echo "Run psql"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username "$POSTGRESQL_USERNAME"
}
shared_buffers = 2096MB #should be roughly 25% of the total system RAM for
effective_cache_size = 2096MB # Most commonly, the value is set to 75%
maintenance_work_mem = 64MB
wal_buffers = 16MB
random_page_cost = 1.1
effective_io_concurrency = 200
work_mem = 32MB
max_worker_processes = 4
max_parallel_workers_per_gather = 2
temp_buffers = 512MB
pg_stat_statements.max = 10000
pg_stat_statements.track = all
#shared_preload_libraries = 'repmgr,pg_stat_statements'
#max_connections = 200
seq_page_cost = 0.01
random_page_cost = 0.01
cpu_tuple_cost = 0.01
cpu_index_tuple_cost = 0.5
cpu_operator_cost = 0.25
parallel_tuple_cost = 1
parallel_setup_cost = 100
#synchronous_commit = OFF
\ No newline at end of file
#!/bin/bash
START_ARG="${1}"
ipaddr=$(ifconfig "${SERVER_INTERFACE_BIND:-eth0}" | grep 'inet' | awk '{print $2}')
hostname=$(hostname)
version_postgres=$(psql --version | awk '{print $NF}')
trigger_file="standby.signal"
if [[ -f "${POSTGRESQL_DATA_DIR}/${trigger_file}" ]];then
echo "File ${POSTGRESQL_DATA_DIR}/${trigger_file} exist.Become standby"
ls -la ${POSTGRESQL_DATA_DIR}/${trigger_file}
server_role="standby"
else
echo "File ${POSTGRESQL_DATA_DIR}/${trigger_file} not exist. Become master"
ls -la ${POSTGRESQL_DATA_DIR}/${trigger_file} || echo "File ${POSTGRESQL_DATA_DIR}/${trigger_file} not exist"
server_role="master"
fi
tags="[\"${server_role}\"]"
func_consul_agent_start(){
echo "Begin func ${FUNCNAME[0]}"
echo "{ \"services\": [ { \"name\": \"${CONSUL_SERVICE_NAME}\", \"id\": \"${hostname}-${server_role}\", \"address\": \"${ipaddr}\", \"port\": 5432, \"Tags\": $tags, \"checks\": [ { \"name\": \"check if postgres port is open\", \"tcp\": \"${ipaddr}:5432\", \"interval\": \"7s\", \"timeout\": \"3s\" } ] } ] }" > /tmp/${CONSUL_SERVICE_NAME}.json
sleep 1;
echo "show /tmp/${CONSUL_SERVICE_NAME}.json"
echo "------------------------------------"
cat /tmp/${CONSUL_SERVICE_NAME}.json
echo "------------------------------------"
sleep 1;
if [[ $(ps aux | grep "consul.*agent.*join" | grep -ve 'grep') == "" ]];then
if [[ "${START_ARG}" == "wait" ]];then
echo "Start sleep 35"
sleep 35;
fi
echo "/bin/consul agent -retry-join ${DISCOVERY_SERVICE_HOST} -client 0.0.0.0 -bind ${ipaddr} -node ${SERVER_NAME}-${hostname} -data-dir /tmp -config-file /tmp/${CONSUL_SERVICE_NAME}.json 2>&1 & disown"
/bin/consul agent -retry-join ${DISCOVERY_SERVICE_HOST} -client 0.0.0.0 -bind ${ipaddr} -node ${SERVER_NAME}-${hostname} -data-dir /tmp -config-file /tmp/${CONSUL_SERVICE_NAME}.json 2>&1 & disown
echo "sleep 5" && sleep 5
else
echo "consul agent already running. Make sigint and start"
local pid=$(ps aux | grep "consul.*agent.*join" | grep -ve 'grep' | awk '{print $2}')
kill -s SIGINT $pid && sleep 7;
/bin/consul agent -retry-join ${DISCOVERY_SERVICE_HOST} -client 0.0.0.0 -bind ${ipaddr} -node ${SERVER_NAME}-${hostname} -data-dir /tmp -config-file /tmp/${CONSUL_SERVICE_NAME}.json 2>&1 & disown
fi
echo "End func ${FUNCNAME[0]}"
}
func_consul_agent_start
\ No newline at end of file
# add the bash aliases
cat /usr/sbin/bashrc_alias.sh >> ~/.bashrc
\ No newline at end of file
#!/bin/bash
##############
PG_DB_USER="$1"
PG_DB_USER_PASS="$2"
PG_DB_NAME="$3"
##############
function help_usage(){
echo "USAGE: scriptname PG_DB_USER PG_DB_USER_PASS PG_DB_NAME"
echo "EXAMPLE: /bin/bash /pgscripts/02-create-db.sh \"user1\" \"123123\" \"test_db\""
}
function check_variables() {
pattern=$'*( |\t)'
if [[ ${PG_DB_USER} = $pattern ]]; then
echo "First parameter PG_DB_USER has no non-whitespace characters"
exit 1
fi
if [[ ${PG_DB_USER_PASS} = $pattern ]]; then
echo "Second parameter PG_DB_USER_PASS has no non-whitespace characters"
exit 1
fi
if [[ ${PG_DB_NAME} = $pattern ]]; then
echo "Third parameter PG_DB_NAME has no non-whitespace characters"
exit 1
fi
}
create_db() {
echo "Creating user ${PG_DB_USER} with password ${PG_DB_USER_PASS}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" <<-EOSQL
create role "${PG_DB_USER}" with password '${PG_DB_USER_PASS}' login;
CREATE DATABASE "${PG_DB_NAME}" WITH OWNER "${PG_DB_USER}" ENCODING 'UTF8' LC_COLLATE 'ru_RU.UTF-8' LC_CTYPE 'ru_RU.utf8' TEMPLATE template0;
EOSQL
echo "GRANT PRIVILEGES ON ${PG_DB_NAME} to USER ${PG_DB_USER}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" <<-EOSQL
GRANT ALL PRIVILEGES on DATABASE "${PG_DB_NAME}" to "${PG_DB_USER}";
EOSQL
}
create_extensions() {
EXTENSIONS=$(echo ${POSTGRES_EXTENSIONS} | tr "," "\n")
echo "Creating postgres extension with list ${POSTGRES_EXTENSIONS}"
for EXTENSION in ${EXTENSIONS}
do
echo "Create extension ${EXTENSION} in ${PG_DB_NAME}";
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "CREATE EXTENSION IF NOT EXISTS \"${EXTENSION}\";" "${PG_DB_NAME}"
done
}
##############
help_usage
check_variables
create_db
create_extensions
#/bin/bash /docker-entrypoint-initdb.d/02-create-db.sh "user1" "123123" "test_db"
\ No newline at end of file
#!/bin/bash
##############
PG_DB_USER=$1
PG_DB_NAME=$2
##############
help_usage(){
echo "USAGE: scriptname PG_DB_USER PG_DB_NAME"
echo "EXAMPLE: /bin/bash /pgscripts/03-change-db-owner.sh \"user1\" \"test_db\""
}
check_variables() {
pattern=$'*( |\t)'
if [[ ${PG_DB_USER} = $pattern ]]; then
echo "First parameter PG_DB_USER has no non-whitespace characters"
exit 1
fi
if [[ ${PG_DB_NAME} = $pattern ]]; then
echo "Third parameter PG_DB_NAME has no non-whitespace characters"
exit 1
fi
}
rights_db() {
echo "Изменяем владельца базы ${PG_DB_NAME} на ${PG_DB_USER}"
for tbl in `PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "select tablename from pg_tables where schemaname = 'public';" ${PG_DB_NAME}` \
`PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" ${PG_DB_NAME}` \
`PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "select table_name from information_schema.views where table_schema = 'public';" ${PG_DB_NAME}` ;
do
echo "ALTER TABLE $tbl in DATABASE ${PG_DB_NAME} TO USER ${PG_DB_USER}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "alter table \"$tbl\" owner to \"${PG_DB_USER}\"" ${PG_DB_NAME} ;
done
}
rights_db_reports() {
echo "Изменяем владельца базы ${PG_DB_NAME} на ${PG_DB_USER}"
for tbl in `PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "select tablename from pg_tables where schemaname = 'reports';" ${PG_DB_NAME}` \
`PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'reports';" ${PG_DB_NAME}` \
`PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "select table_name from information_schema.views where table_schema = 'reports';" ${PG_DB_NAME}` ;
do
echo "ALTER TABLE $tbl in DATABASE ${PG_DB_NAME} TO USER ${PG_DB_USER}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "alter table \"$tbl\" owner to \"${PG_DB_USER}\"" ${PG_DB_NAME} ;
done
}
rights_func() {
IFS=$'\n'
for fnc in `PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "SELECT '\"' || p.proname||'\"' || '(' || pg_catalog.pg_get_function_identity_arguments(p.oid) || ')' FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_proc p ON p.pronamespace = n.oid WHERE n.nspname = 'public';" ${PG_DB_NAME}`
do
echo "ALTER function $fnc in DATABASE ${PG_DB_NAME} TO USER ${PG_DB_USER}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "alter function $fnc owner to \"${PG_DB_USER}\"" ${PG_DB_NAME} ;
done
}
rights_func_reports() {
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "ALTER SCHEMA public OWNER TO \"${PG_DB_USER}\"" ${PG_DB_NAME} ;
}
main() {
help_usage
check_variables
rights_func_reports
rights_db
rights_db_reports
rights_func
}
main
#!/bin/bash
##############
POSTGRES_USER="postgres"
set -e
##############
exporter_add() {
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -v --username "$POSTGRES_USER" <<-EOSQL
CREATE USER postgres_exporter PASSWORD 'kiokfhubhlundsfjbdsufdsf';
alter user postgres_exporter with password 'kiokfhubhlundsfjbdsufdsf';
ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;
CREATE SCHEMA postgres_exporter AUTHORIZATION postgres_exporter;
CREATE VIEW postgres_exporter.pg_stat_activity AS SELECT * from pg_catalog.pg_stat_activity;
GRANT SELECT ON postgres_exporter.pg_stat_activity TO postgres_exporter;
CREATE VIEW postgres_exporter.pg_stat_replication AS SELECT * from pg_catalog.pg_stat_replication;
GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
EOSQL
}
##############
exporter_add
#!/bin/bash
##############
PG_DB_NAME=$1 #db_name
# .---------- constant part!
# vvvv vvvv-- the code from above
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# .----------
DATETIME=$(date +%F_+%T) #date
precheck () {
if [ "${PG_DB_NAME}" == "" ];
then
echo -e "${RED} Arg 1 - \"PG_DB_NAME\" is empty. Stop script ${DATETIME} ${NC}"
exit 1
fi
}
prewarm_postgres() {
echo -e "${CYAN} Начинаем hразогрев базы ${PG_DB_NAME}. Время начала ${DATETIME} ${NC}"
echo -e "${CYAN} Creating extension prewarm_postgres if not exist in ${PG_DB_NAME} ${NC}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c 'CREATE EXTENSION IF NOT EXISTS pg_prewarm;' ${PG_DB_NAME};
for tbl in `PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "select tablename from pg_tables where schemaname = 'public';" ${PG_DB_NAME}`;
do
echo -e "${CYAN} MAKE WARM UP TABLE $tbl in DATABASE ${PG_DB_NAME} begin at ${DATETIME}${NC}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "SELECT pg_prewarm('$tbl')" ${PG_DB_NAME};
echo -e "${GREEN} MAKE WARM UP TABLE $tbl in DATABASE ${PG_DB_NAME} finished at ${DATETIME}${NC}"
done
echo -e "${BLUE} Разогрев базы ${PG_DB_NAME} закончен в ${DATETIME} ${NC}"
}
precheck
prewarm_postgres
#!/bin/bash
PG_DB_NAME=$1 #db_name
maintenance_work_mem_vacuum="128"
# .---------- constant part!
# vvvv vvvv-- the code from above
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# .----------
DATETIME=$(date +%F_+%T) #date
precheck () {
if [ "${PG_DB_NAME}" == "" ];
then
echo -e "${RED} Arg 1 - \"PG_DB_NAME\" is empty. Stop script ${DATETIME} ${NC}"
exit 1
fi
if [ "${maintenance_work_mem_vacuum}" == "" ];
then
echo -e "${RED} maintenance_work_mem_vacuum is empty. Stop script ${DATETIME} ${NC}"
exit 1
fi
}
vacuum_full_anazize_postgres() {
#vars
maintenance_work_mem_default=$(PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "SHOW maintenance_work_mem;" | grep -ve '(' | grep -o [0-9]*)
#begin
echo -e "${CYAN} Начинаем full vacuum analyze базы ${PG_DB_NAME}. Время начала ${DATETIME} ${NC}"
echo -e "${GREEN} Default maintenance_work_mem if ${maintenance_work_mem_default} ${NC}"
echo -e "${CYAN} SET maintenance_work_mem TO ${maintenance_work_mem_vacuum} ${DATETIME} ${NC}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "SET maintenance_work_mem TO '${maintenance_work_mem_vacuum} MB';";
for tbl in `PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -qAt -c "select tablename from pg_tables where schemaname = 'public';" ${PG_DB_NAME}`;
do
echo -e "${CYAN} MAKE full vacuum analyze E $tbl in DATABASE ${PG_DB_NAME} begin at ${DATETIME}${NC}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "VACUUM (VERBOSE, ANALYZE) \"$tbl\"" ${PG_DB_NAME};
echo -e "${GREEN} MAKE full vacuum analyze $tbl in DATABASE ${PG_DB_NAME} finished at ${DATETIME}${NC}"
done
echo -e "${CYAN} SET maintenance_work_mem TO ${maintenance_work_mem_default} ${DATETIME} ${NC}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "SET maintenance_work_mem TO '${maintenance_work_mem_default} MB';";
echo -e "${BLUE} full vacuum analyze базы ${PG_DB_NAME} закончен в ${DATETIME} ${NC}"
}
vacuum_full_anazize_show_statistic() {
echo -e "${CYAN} !!!!SHOW STATISTICS POSTGRES VACUUM!!! ${NC}"
PGPASSWORD=${POSTGRESQL_PASSWORD} psql --username="$POSTGRESQL_USERNAME" -c "SELECT relname, last_vacuum, last_autovacuum, last_analyze, last_autoanalyze FROM pg_stat_all_tables WHERE schemaname = 'public';"
#SELECT schemaname, relname, last_analyze FROM pg_stat_all_tables WHERE relname = 'db_uk_dzr_release';
}
precheck
vacuum_full_anazize_postgres
vacuum_full_anazize_show_statistic
\ No newline at end of file
{
"gosu": {
"arch": "amd64",
"digest": "4d858ac600c38af8de454c27b7f65c0074ec3069880cb16d259a6e40a46bbc50",
"distro": "debian-10",
"type": "NAMI",
"version": "1.12.0-2"
},
"postgresql-repmgr": {
"arch": "amd64",
"digest": "9a41470ff762c7abd6dbcb696e456251b909cc3fa155d1d13b299dba585d643b",
"distro": "debian-10",
"type": "NAMI",
"version": "13.2.0-6"
}
}
\ No newline at end of file
Bitnami containers ship with software bundles. You can find the licenses under: