【PG】PostgreSQL12安装


场景:感受一下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

-------------分割附录--------------

  1. pg的启动日志查看【/var/lib/pgsql/12/pgstartup.log】
  2. 数据目录是[/var/lib/pgsql/12/data]
  3. 二进制目录是[/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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM