PostgreSQL使用yum快速安装

前言

快速安装

参考地址

安装

yum安装

改变版本只需要把 10改为 11、12、13

1
2
3
4
5
6
7
8
9
# Install the repository RPM:
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
yum install -y postgresql10-server

# Optionally initialize the database and enable automatic start:
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10;systemctl start postgresql-10

查看安装的配置路径

1
2
3
4
5
6
su postgres
# 查看配置文件
psql -U postgres -c 'SHOW config_file'
psql -U postgres
alter user postgres with password 'maxzhao'
\password

退出

1
2
3
4
# 退出
\q
# 切换到 root
su

添加访问

1
2
3
4
5
6
7
8
9
10
11
# 这个地址会变动的,需要根据当前查看的配置文件
# vim /var/lib/pgsql/10/data/postgresql.conf
# 修改配置监听所有的IP
sed -i "s|#listen_addresses = 'localhost'|listen_addresses = '*'|g" /var/lib/pgsql/10/data/postgresql.conf
# 设置IP登录模式
#vim /var/lib/pgsql/10/data/pg_hba.conf
echo "host all all 0.0.0.0/0 md5">>/var/lib/pgsql/10/data/pg_hba.conf
# 重启
systemctl restart postgresql-10
# 查看状态
systemctl status postgresql-10

配置

关闭防火墙

1
2
systemctl stop firewalld
systemctl disable firewalld

备份和恢复

1
2
pg_dump --format=t -d db_name -U user_name -h 127.0.0.1 -O -W  > dump.sql
psql -h 127.0.0.1 -U user_name -d db_name < dump.sql

分布式事物

XA是open group提出的分布式事务处理规范,JTA支持XA规范,JTA只规定了接口,有些应用容器提供实现,也有一些三方的开源实现可用,比如Atomikos。

如果PostgreSQL参与分布式事务(XA)处理,则需要在配置文件postgres.conf中设置参数,此参数用于指定分布式事务中两步提交准备事务的最大数量。默认值为0,此时不支持分布式事务。

max_prepared_transactions参数值不应该小于max_connections参数值,这样每一个session都可以至少有一个可用的准备事务。

1
2
max_connections=100
max_prepared_transactions=100

本文地址: https://github.com/maxzhao-it/blog/post/439bd436/