conf_server/install_postgresql_service.sh

48 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
install_postresql_packages()
{
pkg_add postgresql-client-14.5 postgresql-server-14.5
}
configure_postgresql_service()
{
cat > my_configuration/postgresql/pg_hba.conf <<EOF
# TYPE DATABASE USER ADDRESS METHOD
local all postgres trust
# "local" is for Unix domain socket connections only
#local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all md5
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
EOF
su -m _postgresql -c "mkdir /var/postgresql/data"
echo $postgresql_root_password > /tmp/passwordpsql.txt
su -m _postgresql -c "initdb -D /var/postgresql/data -U postgres -A md5 -E UTF8 --pwfile=/tmp/passwordpsql.txt"
rm /tmp/passwordpsql.txt
}
install_postgresql_configurations_files(){
cp -v my_configuration/postgresql/pg_hba.conf /var/postgresql/data/pg_hba.conf
}
start_postgresql_service(){
rcctl start postgresql
}
mkdir my_configuration/postgresql/
#install_postresql_packages
configure_postgresql_service
install_postgresql_configurations_files
start_postgresql_service