PostgreSQL 16数据库的yum、编译、docker三种方式安装——筑梦之路

news/2024/6/17 6:48:06 标签: 数据库, docker, 容器

一、 docker方式

docker pull postgres:16.0

docker rm -f lhrpg16

docker run --name lhrpg16 -h lhrpg16 -d -p 54329:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:16.0

docker exec -it lhrpg16 bash

docker exec -it lhrpg16 psql -U postgres -d postgres

select * from pg_tables;
select version();

二、yum方式

dnf install -y cmake make gcc zlib gcc-c++ perl readline readline-devel zlib zlib-devel \
    perl python36 tcl openssl ncurses-devel openldap pam  perl-IPC-Run libicu-devel

dnf install epel-release -y

dnf --enablerepo=powertools install perl-IPC-Run -y

# 自2023年8月起,PostgreSQL RPM repo停止向PostgreSQL RPM repo添加新包,**包括PostgreSQL 16**.我们将维护旧的主要版本,直到每个主要版本被PostgreSQL项目终止。请访问这里每个主要版本的最新发布日期。https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-8-x86_64/

wget https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-8-x86_64/postgresql16-16.0-1PGDG.rhel8.x86_64.rpm
 
wget https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-8-x86_64/postgresql16-server-16.0-1PGDG.rhel8.x86_64.rpm

wget https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-8-x86_64/postgresql16-contrib-16.0-1PGDG.rhel8.x86_64.rpm

wget https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-8-x86_64/postgis34_16-devel-3.4.0-1PGDG.rhel8.x86_64.rpm
 
wget https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-8-x86_64/postgresql16-libs-16.0-1PGDG.rhel8.x86_64.rpm

# 安装

dnf localinstall postgresql16-*

# (建议安装)安装开发包,若后期需要编译一些插件,例如pg_recovery、pg_dirtyread等都需要该包

dnf localinstall postgresql16-devel-16.0-1PGDG.rhel8.x86_64.rpm

rpm -aq| grep postgres

echo "export PATH=/usr/pgsql-16/bin:$PATH" >> /etc/profile

# 初始化

/usr/pgsql-16/bin/postgresql-16-setup initdb

systemctl enable postgresql-16 --now

# 本地登陆

su - postgres

psql

# 安装插件

create extension pageinspect;

create extension pg_stat_statements;

select * from pg_extension;

select * from pg_available_extensions order by name;

# 修改密码

alter user postgres with  password 'lhr'; 或 \password

select * from pg_tables;

select version();

# 配置允许远程登陆

cat >> /var/lib/pgsql/16/data/postgresql.conf <<"EOF"
listen_addresses = '*'
port=5432
unix_socket_directories='/var/lib/pgsql/16/data'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
EOF

cat  << EOF > /var/lib/pgsql/16/data/pg_hba.conf
 # TYPE  DATABASE    USER    ADDRESS       METHOD
 local     all       all                    trust
 host      all       all    ::1/128         trust
 host      all       all   127.0.0.1/32     trust
 host      all       all    0.0.0.0/0        md5
 host   replication  all    0.0.0.0/0        md5
 EOF

systemctl restart postgresql-16

psql -U postgres -h 192.168.100.100 -d postgres -p54327

# 从Postgresql 9.2开始,还可以使用URI格式进行远程连接:psql postgresql://myuser:mypasswd@myhost:5432/mydb

psql postgresql://postgres:lhr@192.168.100.100:54327/postgres

mkdir -p /home/postgres

chown postgres.postgres /home/

sed -i 's|/var/lib/pgsql|/home/postgres|' /etc/passwd

echo "lhr" |passwd --stdin postgres

cat > /home/postgres/.bash_profile <<"EOF"
export PGPORT=54327
export PGHOME=/usr/pgsql-16
export PGDATA=/var/lib/pgsql/16/data
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.UTF-8
export DATE='date +"%Y%m%d%H%M"'
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGPASSWORD=lhr
export PGDATABASE=postgres
export PS1="[\u@\h \W]\$ "
alias ll='ls -l'
EOF


chown postgres.postgres /home/postgres/.bash_profile

三、编译方式

# 下载源码

wget https://ftp.postgresql.org/pub/source/v16.0/postgresql-16.0.tar.gz

# 创建用户

groupadd -g 60000 pgsql

useradd -u 60000 -g pgsql pgsql

echo "lhr" | passwd --stdin pgsql

# 创建目录

mkdir -p /postgresql/{pgdata,archive,scripts,backup,pg16,soft}

chown -R pgsql:pgsql /postgresql

chmod -R 775 /postgresql

# 安装依赖包

yum install -y cmake make gcc zlib gcc-c++ perl readline readline-devel zlib zlib-devel 
    perl python36 tcl openssl ncurses-devel openldap pam perl-IPC-Run libicu-devel

# 编译源码

su - pgsql

cd /postgresql/soft

tar zxvf postgresql-16.0.tar.gz

cd postgresql-16.0

./configure --prefix=/postgresql/pg16

make -j 8 && make install

make world -j 8 && make install-world

# 配置环境变量

cat >>  ~/.bash_profile <<"EOF"
export LANG=en_US.UTF-8
export PS1="[\u@\h \W]\$ "
export PGPORT=5432
export PGDATA=/postgresql/pgdata
export PGHOME=/postgresql/pg16
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:.
export DATE=`date +"%Y%m%d%H%M"`
export MANPATH=$PGHOME/share/man:$MANPATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres
EOF

source  ~/.bash_profile

# 初始化数据库

su - pgsql

/postgresql/pg16/bin/initdb -D /postgresql/pgdata -E UTF8 --locale=en_US.utf8 -U postgres --data-checksums

# 调整参数

cat >> /postgresql/pgdata/postgresql.conf <<"EOF"
listen_addresses = '*'
port=5432
unix_socket_directories='/postgresql/pgdata'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
EOF

cat   >> /postgresql/pgdata/pg_hba.conf << EOF
# TYPE  DATABASE    USER    ADDRESS       METHOD
local     all       all                    trust
host      all       all   127.0.0.1/32     trust
host      all       all    0.0.0.0/0        md5
host   replication  all    0.0.0.0/0        md5
EOF

# 启动服务

su - pgsql

pg_ctl start

pg_ctl status

pg_ctl stop


# 修改数据库超管密码

pg_ctl start 

psql

alter user postgres with  password 'lhr';

exit

# 注册服务到systemd

cat > /etc/systemd/system/PG16.service <<"EOF"
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network.target

[Service]
Type=forking
User=pgsql
Group=pgsql
Environment=PGPORT=5432
Environment=PGDATA=/postgresql/pgdata
OOMScoreAdjust=-1000
ExecStart=/postgresql/pg16/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/postgresql/pg16/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/postgresql/pg16/bin/pg_ctl reload -D ${PGDATA} -s
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable PG16 --now
systemctl start PG16
systemctl status PG16

随手一记:生成密码的密文sha256加密

echo -n "Enter Password: " && head -1 </dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1


http://www.niftyadmin.cn/n/5036321.html

相关文章

基于java SpringBoot和HTML实验室预约管理系统设计

摘要 实验室信息管理系统是利用计算机网络技术、数据存储技术、快速数据处理技术对实验室进行全方位管理的计算机软件系统。实验室信息管理系统从最初仅完成数据存储和有限的网络功能&#xff0c;发展到现在可以处理海量数据&#xff0c;具备完善的管理职能&#xff0c;并且能够…

QMutableListIterator详解

目录 是什么&#xff1a; 1. 从列表中删除特定元素 2. 替换特定元素 是什么&#xff1a; Qt中&#xff0c;QMutableListIterator 是一个用于迭代和修改 QList&#xff08;动态数组&#xff09; 的类。QMutableListIterator 继承自 QListIterator&#xff0c;并添加了修改和删…

为实验室运维提供安全、智能、节能整体解决方案的易云维®实验室智能化管理平台

实验室安全问题频繁发生&#xff0c;在对生命损失表示遗憾的同时&#xff0c;再次提醒科研人员&#xff0c;实验室安全不容忽视。为了保证实验室工作环境的安全&#xff0c;易云维自主研发了实验室智能化管理平台&#xff0c;其中安防管理功能对确保实验室安全具有重大意义。 实…

用PHP异步协程控制python爬虫脚本,实现多协程分布式爬取

背景 公司需要爬取指定网站的产品数据。但是个人对python的多进程和协程不是特别熟悉。所以&#xff0c;想通过php异步协程&#xff0c;发起爬取url请求控制python爬虫脚本&#xff0c;达到分布式爬取的效果。 准备 1.准备一个mongodb数据库用于存放爬取数据2.引入flask包&a…

【深度学习-第3篇】使用MATLAB快速实现CNN分类(模式识别)任务,含一维、二维、三维数据演示案例

在本文中&#xff0c;我们将介绍如何使用 MATLAB 中的 Convolutional Neural Network&#xff08;CNN&#xff09;进行分类任务。我们将使用 MATLAB 的 Deep Learning Toolbox 来创建、训练和评估 CNN。 一、一个简单的案例 1 安装和准备 首先&#xff0c;确保已安装 MATLAB…

理解MTU VLAN与端口VLAN两个概念

什么是MTU VLAN MTU VLAN 是指将最大传输单元&#xff08;Maximum Transmission Unit&#xff0c;MTU&#xff09;设置为特定值以适应 VLAN 环境的配置。 MTU 是指在网络通信中可以传输的最大数据包大小。以太网的常见 MTU 值为1500字节&#xff0c;这是指在以太网帧中的数据…

openfeign返回消息报错.UnknownContentTypeException

1. springcloud项目使用openfeign报错 org.springframework.web.client.UnknownContentTypeException: Could not extract response: no suitable HttpMessageConverter found for response type [com.yl.base.Result<java.util.List<com.yl.entity.LabelConfig>>…

Learn Prompt-Prompt 高级技巧:思维链 Chain of Thought Prompting

Jason Wei等作者对思维链的定义是一系列的中间推理步骤&#xff08; a series of intermediate reasoning steps &#xff09;。目的是为了提高大型语言模型&#xff08;LLM&#xff09;进行复杂推理的能力。 思维链通常是伴随着算术&#xff0c;常识和符号推理等复杂推理任务出…