Linux Yum安装postgresql 13

rpm源安装
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
安装数据库
yum install -y postgresql13-server

数据库安装完成后,会自动创建一个linux用户 postgres

新建数据库数据存放目录
mkdir -p /home/pgsql/data
chown -R postgres.postgres /home/pgsql
初始化postgresql数据库
su postgres
# 初始化数据 -D指定初始化创建的数据库的文件路径
/usr/pgsql-13/bin/initdb -D /home/pgsql/data

lQLPDhr734ALvrHNArfNA9CwYJUi_pfCgOgByelejMBzAA_976_695.png

切换回root用户,配置启动项
su
vim /usr/lib/systemd/system/postgresql-13.service

修改一下启动数据存放目录

[Unit]
Description=PostgreSQL 13 database server
Documentation=https://www.postgresql.org/docs/13/static/
After=syslog.target
After=network.target

[Service]
Type=notify

User=postgres
Group=postgres

# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory
# Environment=PGDATA=/var/lib/pgsql/13/data/
Environment=PGDATA=/home/pgsql/data/

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-13/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
 
# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0

# 0 is the same as infinity, but "infinity" needs systemd 229
TimeoutStartSec=0

TimeoutStopSec=1h

[Install]
WantedBy=multi-user.target
启动
systemctl start postgresql-13.service
# 开机启动
systemctl enable postgresql-13.service
登录

postgresql默认要切换到postgres用户才能登陆数据库

# 切换用户
su postgres
# 登录数据库
psql -U postgres
# 添加密码
Alter USER postgres WITH PASSWORD 'postgres';
ALTER ROLE        //出现这个才算成功
修改远程链接配置文件参数
vim /home/pgsql/data/postgresql.conf

# 修改为 *
listen_addresses = '*'
vim /home/pgsql/data/pg_hba.conf

# # IPv4 local connections 的下面加一行
host    all             all             0.0.0.0/0               trust

重启数据库生效

systemctl restart postgresql-13.service
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值