postgres 前言
PostgreSQL 是一个功能强大的开源对象关系数据库系统,拥有超过 35 年的积极开发经验 这为其赢得了可靠性、功能稳健性和性能的良好声誉。
通过官方文档可以找到大量描述如何安装和使用 PostgreSQL 的信息。 开源社区提供了许多有用的地方来熟悉PostgreSQL, 了解其运作方式,并寻找职业机会。了解更多有关 如何与社区互动。
download postgres
postgres all | pgadmin all | 文档 |
download | download | 参考 |
Linux 各系统下载使用参考
Red Hat | Rocky Linux | Oracle Linux | AlmaLinux | ubuntu | suselinux | esxi | RHEL标准安装 | 系统安装参考 | YUM参考 | MobaXterm 远程连接工具 | Red Hat Enterprise 9.0 文档 | Kickstart 生成器 | |||||
download | download | download | download | download | download | download | 参考 | 参考 | 配置参考 | download | 参考 | Kickstart | |||||
版本兼容性 |
postgres 一键自动化部署
- 最终实现在线下载postgres,编译安装postgres,环境变量,初始化postgres数据库,用户密码配置,用户权限设置,远程连接设置,数据库创建postdb,启动脚本创建,防火墙配置,安装包删除。
- postgres/Report@123 #postgres用户名密码
- postgres / postgres #用户名,组
- /opt/pgsql/data #数据目录
- /opt/pgsql #安装目录
- postgresql 5432 #postgresql端口
- /opt/pgsql/data/pg_hba.conf #远程连接授权
- /opt/pgsql/data/postgresql.conf #远程连接授权
- /usr/lib/systemd/system/postgresql.service #postgresql启动服务脚本
- su - postgres -c 'psql -c "SELECT version();"' #postgres版本获取
- if 判断是否存在postgres用户(if ! compgen -u postgres &> /dev/null)
- increase indent:Tab
- decrease indent:Shift+Tab
vim /postgres_15_install.sh
#!/bin/bash
# -*- coding: utf-8 -*-
# Author: CIASM
# update 2023/06/02
# increase indent:Tab
# decrease indent:Shift+Tab
# install source postgres
install_postgres (){
if ! compgen -u postgres &> /dev/null
then
if [ $? -eq 0 ];then
postgres_user=postgres
postgres_password=postgres@123
pgsql_opt=/opt
pgsql_url=https://ftp.postgresql.org/pub/source/v15.3/
pgsql_gz=postgresql-15.3.tar.gz
pgsql_data=data
pgsql_download=download
pgsql_pgsql=pgsql
pgsql_decompression_directory=postgresql-15.3
pgsql_installation_directory=/opt/pgsql
echo "Create user and groups for postgres Database service"
groupadd $postgres_user
useradd -m -g $postgres_user -d $pgsql_installation_directory $postgres_user
mkdir -p $pgsql_installation_directory/{/$pgsql_data,/$pgsql_download}
chown -R $postgres_user:$postgres_user $pgsql_installation_directory/$pgsql_data
echo "Firewall port development"
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
firewall-cmd --zone=public --add-port=5432/tcp --permanent && firewall-cmd --reload
echo "Add postgres users to users and user groups"
echo "$postgres_password" | passwd --stdin $postgres_user
echo "Dependent installation"
yum install -y http://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
yum install -y ncurses-devel readline-devel zlib zlib-devel perl-ExtUtils-Embed
yum install -y lz4-devel openssl openssl-devel libxml2 libxml2-devel pam pam-devel systemd-devel
yum install -y gcc gcc-c++ net-tools make cmake
echo "download pgsql"
wget -N -P $pgsql_opt/$pgsql_download $pgsql_url$pgsql_gz
echo "install pgsql"
tar -zxf $pgsql_opt/$pgsql_download/$pgsql_gz -C $pgsql_opt
cd $pgsql_opt/$pgsql_decompression_directory
./configure --prefix=$pgsql_installation_directory && make && make install
echo "pgsql environment variable"
su - postgres <<EOF
echo 'umask 022' >> ~/.bash_profile
echo 'export PGHOME=/opt/pgsql' >> ~/.bash_profile
echo 'export PGDATA=/opt/pgsql/data' >> ~/.bash_profile
echo 'export PATH=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/pgsql/bin' >> ~/.bash_profile
echo 'export MANPATH=/opt/pgsql/share/man' >> ~/.bash_profile
echo 'export LD_LIBRARY_PATH=/opt/pgsql/lib' >> ~/.bash_profile
echo 'export LANG=en_US.utf8' >> ~/.bash_profile
source ~/.bash_profile
/opt/pgsql/bin/initdb -D /opt/pgsql/data
/opt/pgsql/bin/pg_ctl -D /opt/pgsql/data -l logfile start
psql -c "ALTER USER postgres WITH PASSWORD 'Report@123'"
sed -i "59a\listen_addresses = '*'" /opt/pgsql/data/postgresql.conf
echo 'host all all 0.0.0.0/0 md5' >> /opt/pgsql/data/pg_hba.conf
psql -c "SELECT version();"
psql -c "create database postdb owner postgres;"
psql -c "grant all privileges on database postdb to postgres;"
/opt/pgsql/bin/pg_ctl -D /opt/pgsql/data -l logfile reload
EOF
echo "postgresql.service add system"
cat >>/usr/lib/systemd/system/postgresql.service<<EOF
[Unit]
Description=PostgreSQL database server
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGHOME=/opt/pgsql
Environment=PGDATA=/opt/pgsql/data
ExecStart=/opt/pgsql/bin/pg_ctl -D /opt/pgsql/data start
ExecStop=/opt/pgsql/bin/pg_ctl -D /opt/pgsql/data -l logfile stop
ExecReload=/opt/pgsql/bin/pg_ctl -D /opt/pgsql/data -l logfile reload
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable postgresql
echo "Deleting an installation package"
rm -rf $pgsql_opt/$pgsql_download $pgsql_opt/$pgsql_decompression_directory
echo -e "\033[32mThe postgresql Install Success...\033[0m"
else
echo -e "\033[31mThe postgresql Install Failed...\033[0m"
exit 1
fi
else
echo -e "\033[33mThe postgresql Install already...\033[0m"
fi
}
main (){
install_postgres
}
main
执行一键安装postgres
sh /postgres_15_install.sh
pgadmin连接postgres
- 端口5432
- 用户名密码postgres/Report@123
- postgres IP地址