PgSQL安装 rpm安装&源码安装

rpm安装

# for centos7
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql15-server
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15

# 切换到postgres用户
su - postgres

# 修改系统用户密码,一定要修改不然等你改完配置文件就不能这么轻松愉快的进入这个页面了
ALTER USER postgres WITH PASSWORD '123456';

# 修改配置文件
1.修改postgresql.conf
vim /var/lib/pgsql/15/data/postgresql.conf
# 1).开启远程访问,将listen_address 修改为 *
listen_addresses = '*'

2.修改pg_hba.conf
vim /var/lib/pgsql/15/data/pg_hba.conf
在文件末尾增加如下配置:
host    all             all             0.0.0.0/0            scram-sha-256

3.重启服务
sudo systemctl restart postgresql-15

进入psql命令模式
psql -U postgres -h 127.0.0.1

源码安装

# 上传tar包至服务器并解压
tar zxvf /opt/software/stgresql-15.4.tar.gz
mv /opt/software/postgresql-15.4 /opt/software/postgresql
cd /opt/software/postgresql

# 编译安装
./configure --prefix=/usr/local/postgresql --without-readline
make && make install

# 进入安装后的目录,查看目录结构
cd /usr/local/postgresql/

# 创建目录 data、log
mkdir /usr/local/postgresql/data
mkdir /usr/local/postgresql/log
chmod -R 775 /usr/local/postgresql/data

# 创建用户
useradd postgres
chown -R postgres:postgres /usr/local/postgresql/


# 配置环境变量
vim /etc/profile

PGHOME=/usr/local/postgresql
export PGHOME
PGDATA=/usr/local/postgresql/data
export PGDATA
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATHPGHOME=/usr/local/postgresql
export PGHOME
PGDATA=/usr/local/postgresql/data
export PGDATA
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATH

source /etc/profile
psql -V
psql (PostgreSQL) 15.4

# 初始化数据库
su - postgres
/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/

# 启动数据库
/usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ -l logfile start

# 修改配置文件
1.修改postgresql.conf
vim /var/lib/pgsql/15/data/postgresql.conf
# 1).开启远程访问,将listen_address 修改为 *
listen_addresses = '*'

2.修改pg_hba.conf
vim /var/lib/pgsql/15/data/pg_hba.conf
在文件末尾增加如下配置:
host    all             all             0.0.0.0/0            scram-sha-256


# 重启数据库
/usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data/ -l logfile start

# 登录数据库
/usr/local/postgresql/bin/psql -U postgres -h 127.0.0.1 -p xxx

你可能感兴趣的:(数据库,数据库,linux,sql)