作者:@张扶摇
本文为作者原创,转载请注明出处:https://www.cnblogs.com/zhangshengdong/p/12502227.html
目录
1、创建psotgres用户
2.查看操作系统版本
3.配置postgreSQL 12的yum源
4.安装客户端包
5.安装服务器端包
6.初始化数据库和设置自启动服务
7.设置环境变量
附录
Centos7版本的安装方式
场景:感受一下PostgreSQL12。可以通过如下方式安装:
1、创建psotgres用户
groupadd postgres
useradd -g postgres postgres
2.查看操作系统版本
[root@db ~]# cat /etc/issue.bak
CentOS release 6.9 (Final)
Kernel \r on an \m
3.配置postgreSQL 12的yum源
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
4.安装客户端包
yum install postgresql12
5.安装服务器端包
yum install postgresql12-server
6.初始化数据库和设置自启动服务
service postgresql-12 initdb
chkconfig postgresql-12 on
service postgresql-12 start
-------------分割附录--------------
- pg的启动日志查看【/var/lib/pgsql/12/pgstartup.log】
- 数据目录是[/var/lib/pgsql/12/data]
- 二进制目录是[/usr/pgsql-12/bin/]
通过ps -ef 可以看到.pg是通过postmaster进程,来推动pg的运行。
[root@db data]# ps -ef |grep pg
postgres 14917 1 0 10:30 ? 00:00:00 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data
root 15042 14534 0 10:35 pts/0 00:00:00 grep pg
启动服务
[postgres@db bin]$ ./postgres -D /var/lib/pgsql/12/data/ > /home/postgres/zsdstartupPg.log 2>&1 &
也可以通过pg_ctl启动和关闭服务。
[root@db 12]# su postgres -c '/usr/pgsql-12/bin/pg_ctl stop -D /var/lib/pgsql/12/data/ -l zsdpglog'
[root@db 12]# su postgres -c '/usr/pgsql-12/bin/pg_ctl start -D /var/lib/pgsql/12/data/ -l zsdpglog'
生成的zsdpglog位置在/var/lib/pgsql/12/zsdpglog
7.设置环境变量
在/home/postgres/.bash_profile中。添加如下:
PG_BIN=/usr/pgsql-12/bin
export PG_BIN
生效
source /home/postgres/.bash_profile
-------------------------数据库进入和使用-------------
创建数据库
[postgres@db ~]$ createdb zsddb
进入数据库
$ psql zsddb
查看数据库版本和当前时间。
zsddb=# SELECT version();
附录
Centos7版本的安装方式
# Install the repository RPM:
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL:
yum install postgresql12-server
# Optionally initialize the database and enable automatic start:
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12
具体使用可以参考:https://www.cnblogs.com/zhangshengdong/p/11975778.html
感谢您的阅读,如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮。本文欢迎各位转载,但是转载文章之后必须在文章页面中给出作者和原文连接。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?