1

linux安装PostgreSQL12

 3 years ago
source link: https://www.jianshu.com/p/1d438ce4e2f0
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

linux安装PostgreSQL12

2021.08.24 10:03:16字数 195阅读 16

PostgreSQL 是一个强大的开源对象关系数据库系统,经过 30 多年的积极开发,在可靠性、功能稳健性和性能方面赢得了良好的声誉。

image.png

官网: https://www.postgresql.org

设置安装包目录

mkdir -pv /data/software
cd /data/software/

下载页: https://www.postgresql.org/ftp/source/v12.8/

wget https://ftp.postgresql.org/pub/source/v12.8/postgresql-12.8.tar.gz
tar -zxvf postgresql-12.8.tar.gz
# 安装依赖
sudo apt install -y libreadline-dev
#进入目录
cd postgresql-12.8
# 编译安装
./configure --prefix=/usr/local/postgresql-12.8
make 
make install

创建postgres用户

# 创建用户
adduser postgres 
# 新建数据目录
mkdir -pv /usr/local/postgresql-12.8/data
# 更改权限
chown -R postgres:postgres /usr/local/postgresql-12.8 
su postgres 

初始化数据库

/usr/local/postgresql-12.8/bin/initdb -D /usr/local/postgresql-12.8/data/

启动数据库

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

# 停止数据库
/usr/local/postgresql-12.8/bin/pg_ctl -D /usr/local/postgresql-12.8/data/ stop               

# 重启数据库
/usr/local/postgresql-12.8/bin/pg_ctl restart -D /usr/local/postgresql-12.8/data/ -m fast    
image.png

PostgreSQL安装后会自动创建一个数据库用户,名为postgres

cd /usr/local/postgresql-12.8
./bin/psql -U postgres
...
ALTER USER postgres with encrypted password 'a123456';
...


image.png

测试,创建数据库和用户

1.创建用户

# 登录系统
/usr/local/postgresql-12.8/bin/psql -U postgres -W

# 创建dev_admin用户并设置密码为a123456
create user dev_admin with password 'a123456';    
 
# 将用户赋予超级管理员权限
alter role dev_admin with superuser;        

# 创建his2021数据库
create database his2021;     
image.png
# -U: 用户 -W:强制输入密码
/usr/local/postgresql-12.8/bin/psql -U dev_admin -W his2021
image.png

使用pgAdmin连接数据库

配置IP,5432端口,用户,密码:a123456 就可以连接了

image.png
image.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK