This commit is contained in:
Your Name 2022-11-27 15:55:13 -07:00
parent 6d3d10f237
commit 963916d6bb
4 changed files with 5 additions and 215 deletions

View File

@ -15,7 +15,6 @@ ADD postgres.sh /
#POSTGRES Tweaks
COPY postgresql.conf /etc/
COPY pg_hba.conf /etc/
COPY notes.txt /root/
CMD bash /start.sh

View File

@ -1,108 +0,0 @@
# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file. A short
# synopsis follows.
#
# This file controls: which hosts are allowed to connect, how clients
# are authenticated, which PostgreSQL user names they can use, which
# databases they can access. Records take one of these forms:
#
# local DATABASE USER METHOD [OPTIONS]
# host DATABASE USER ADDRESS METHOD [OPTIONS]
# hostssl DATABASE USER ADDRESS METHOD [OPTIONS]
# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]
# hostgssenc DATABASE USER ADDRESS METHOD [OPTIONS]
# hostnogssenc DATABASE USER ADDRESS METHOD [OPTIONS]
#
# (The uppercase items must be replaced by actual values.)
#
# The first field is the connection type:
# - "local" is a Unix-domain socket
# - "host" is a TCP/IP socket (encrypted or not)
# - "hostssl" is a TCP/IP socket that is SSL-encrypted
# - "hostnossl" is a TCP/IP socket that is not SSL-encrypted
# - "hostgssenc" is a TCP/IP socket that is GSSAPI-encrypted
# - "hostnogssenc" is a TCP/IP socket that is not GSSAPI-encrypted
#
# DATABASE can be "all", "sameuser", "samerole", "replication", a
# database name, or a comma-separated list thereof. The "all"
# keyword does not match "replication". Access to replication
# must be enabled in a separate record (see example below).
#
# USER can be "all", a user name, a group name prefixed with "+", or a
# comma-separated list thereof. In both the DATABASE and USER fields
# you can also write a file name prefixed with "@" to include names
# from a separate file.
#
# ADDRESS specifies the set of hosts the record matches. It can be a
# host name, or it is made up of an IP address and a CIDR mask that is
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
# specifies the number of significant bits in the mask. A host name
# that starts with a dot (.) matches a suffix of the actual host name.
# Alternatively, you can write an IP address and netmask in separate
# columns to specify the set of hosts. Instead of a CIDR-address, you
# can write "samehost" to match any of the server's own IP addresses,
# or "samenet" to match any address in any subnet that the server is
# directly connected to.
#
# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
# Note that "password" sends passwords in clear text; "md5" or
# "scram-sha-256" are preferred since they send encrypted passwords.
#
# OPTIONS are a set of options for the authentication in the format
# NAME=VALUE. The available options depend on the different
# authentication methods -- refer to the "Client Authentication"
# section in the documentation for a list of which options are
# available for which authentication methods.
#
# Database and user names containing spaces, commas, quotes and other
# special characters must be quoted. Quoting one of the keywords
# "all", "sameuser", "samerole" or "replication" makes the name lose
# its special character, and just match a database or username with
# that name.
#
# This file is read on server startup and when the server receives a
# SIGHUP signal. If you edit the file on a running system, you have to
# SIGHUP the server for the changes to take effect, run "pg_ctl reload",
# or execute "SELECT pg_reload_conf()".
#
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
# CAUTION: Configuring the system for local "trust" authentication
# allows any local user to connect as any PostgreSQL user, including
# the database superuser. If you do not trust all your local users,
# use another authentication method.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all 0.0.0.0/0 md5
host all all 10.5.0.5/32 md5
host replication root 10.5.0.5/32 md5
host all all 10.6.0.5/32 md5
host replication all 10.6.0.5/32 md5
host all all 172.19.0.1/32 md5
host replication root 172.19.0.1/32 md5

View File

@ -1,101 +0,0 @@
#!/bin/bash
databases+=( raygungothic nextcloud gitea akkoma prosody synapse minetest )
LOCATION='/saves'
PRIMARY='192.168.0.146'
replication-status(){
echo "select * from pg_stat_replication;" | su postgres -s /bin/bash -lc "psql "
echo "select * from pg_stat_wal_receiver;" | su postgres -s /bin/bash -lc "psql "
echo "select pg_is_wal_replay_paused();" | su postgres -s /bin/bash -lc "psql "
}
configure-secondary-replication () {
echo "pg_ctl stop -D /var/lib/postgresql/data" | su postgres -s /bin/bash
cd /var/lib/postgresql/data
rm -rf *
echo "pg_basebackup -R -P -h 192.168.0.146 -X stream -c fast -U root -W -D /var/lib/postgresql/data/" | su postgres -s /bin/bash
echo "pg_ctl start -D /var/lib/postgresql/data" | su postgres -s /bin/bash
echo "select pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
grep primary_conninfo postgresql.auto.conf
}
configure-primary-replication (){
#echo "SELECT * FROM pg_drop_replication_slot('db02_repl_slot');" | su postgres -s /bin/bash -lc "psql "
#echo "select * from pg_create_physical_replication_slot('db02_repl_slot');" | su postgres -s /bin/bash -lc "psql "
echo "select pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
echo "select slot_name, slot_type, active, wal_status from pg_replication_slots;" | su postgres -s /bin/bash -lc "psql "
echo "pg_ctl restart -D /var/lib/postgresql/data" | su postgres -s /bin/bash
}
replication-failover () {
echo "select pg_promote();" | su postgres -s /bin/bash -lc "psql "
echo "SELECT pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
}
backup (){
vacuum_off
for i in "${databases[@]}"
do
echo;echo "Backing Up: "$i;echo
su postgres -s /bin/bash -lc "pg_dump -d $i --format=custom -f $LOCATION/$i-`cat /etc/hostname`-`date +%Y-%m-%d-%H-%M`.pgdump"
done
vacuum_on
}
vacuum_off (){
sed -i 's/autovacuum = on/autovacuum = off/i' /var/lib/postgres/data/postgresql.conf
echo "SELECT pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
}
vacuum_on (){
sed -i 's/autovacuum = off/autovacuum = on/i' /var/lib/postgres/data/postgresql.conf
echo "SELECT pg_reload_conf();" | su postgres -s /bin/bash -lc "psql "
}
vacuum (){
for i in "${databases[@]}"
do
echo "vacuum(full,analyse,verbose);" | su postgres $i -s /bin/bash -lc "psql "
done
}
help_menu (){
clear
echo "./postgres.sh backup"
echo "./postgres.sh replication-status"
echo "./postgres.sh configure-primary-replication"
echo "./postgres.sh configure-secondary-replication"
echo "./postgres.sh base"
echo "./postgres.sh replication-failover"
echo "./postgres.sh vacuum"
echo "./postgres.sh setup"
echo "./postgres.sh vacuum-on"
echo "./postgres.sh vacuum-off"
}
if [ "$1" = "vacuum-on" ];
then vacuum_on;
elif [ "$1" = "vacuum-off" ];
then vacuum_off;
elif [ "$1" = "configure-primary-replication" ];
then configure-primary-replication;
elif [ "$1" = "replication-failover" ];
then replication-failover;
elif [ "$1" = "backup" ];
then backup "$2";
elif [ "$1" = "configure-secondary-replication" ];
then configure-secondary-replication;
elif [ "$1" = "replication-status" ];
then replication-status;
elif [ "$1" = "restore" ];
then restore;
elif [ "$1" = "vacuum" ];
then vacuum;
elif [ "$1" = "vacfull" ];
then vacuum_full "$2";
else
help_menu
fi

View File

@ -7,15 +7,15 @@ mkdir /run/postgresql
chown -R postgres:postgres /run/postgresql/
chown -R postgres:postgres /var/lib/postgresql
chown -R postgres:postgres /var/log/postgresql
chmod 0700 /var/lib/postgresql/data
#su postgres -s $SHELL -lc "mkdir /var/lib/postgresql/data;chmod 0700 /var/lib/postgresql/13/main"
su postgres -s $SHELL -lc "initdb --auth-host=trust -D /var/lib/postgresql/data"
cp -f /etc/postgresql.conf /var/lib/postgresql/data/
cp -f /etc/pg_hba.conf /var/lib/postgresql/data/
echo "host all all 0.0.0.0/0 md5" >> /var/lib//postgresql/data/pg_hba.conf
chown -R postgres:postgres /var/lib/postgresql
su postgres -s $SHELL -lc "pg_ctl start -D /var/lib/postgresql/data"
sleep 10
sleep 5
echo "create user root with encrypted password 'sql';"| su postgres -s $SHELL -lc psql
echo "ALTER ROLE root SUPERUSER;" | su postgres -s $SHELL -lc psql
echo "CREATE DATABASE pleroma with template = template0 OWNER = root ENCODING = 'UTF8';" | su postgres -s $SHELL -lc psql
touch /configured.txt
echo "CREATE DATABASE pleroma with template = template0 OWNER = root ENCODING = 'UTF8';" | su postgres -s $SHELL -lc psql
touch /configured.txt