centos8下postgreSQL入门1.1之安装

安装

参考
https://wiki.postgresql.org/wiki/YUM_Installation
https://wiki.postgresql.org/wiki/YUM_Installation#Install_PGDG_Repo_RPM_and_PostgreSQL
https://www.postgresql.org/download/linux/redhat/

  1. 切换到 root 用户
    su

  2. 生成安装脚本
    https://www.postgresql.org/download/linux/redhat/
    上进行版本选择,生成脚本

  3. 创建安装脚本
    touch install-psql.sh

  4. vim install-psql.sh
    将2 中生成的脚本粘贴进来

  5. 修改脚本文件的权限
    chmod 777 install-psql.sh

  6. 执行脚本
    install-psql.sh

安装 和 配置 service

参考
https://wiki.postgresql.org/wiki/YUM_Installation#Install_PGDG_Repo_RPM_and_PostgreSQL

简版:

dnf install postgresql-server

postgresql-setup --initdb
// 允许开机启动
systemctl enable postgresql.service
systemctl start postgresql.service


完全参考版:

Data Directory
The PostgreSQL data directory contains all of the data files for the database. The variable PGDATA is used to reference this directory.

The default data directory is:

/var/lib/pgsql//data
For example:

/var/lib/pgsql/12/data
Initialize
The first command (only needed once) is to initialize the database in PGDATA.

For RHEL/CentOS 7, 8, and Fedora 30 and above:

If the previous command did not work, try directly calling the setup binary, located in a similar naming scheme:

/usr/pgsql-y.x/bin/postgresqlyx-setup initdb
For versions 10 and above:

/usr/pgsql-12/bin/postgresql-12-setup initdb (Notice the extra dash before major version)
E.g. for version 9.6:

/usr/pgsql-9.6/bin/postgresql96-setup initdb
For Red Hat 6:

service initdb
E.g. for version 9.6:

service postgresql-9.6 initdb
Startup
If you want PostgreSQL to start automatically when the OS starts, do the following:

In RHEL 7+, and Fedora 30+ try:

systemctl enable postgresql-12.service
In RHEL 6 and PostgreSQL 12:

chkconfig postgresql-12 on

Control service
To control the database service, use:

With RHEL/CentOS 7, 8 , and Fedora 30:

systemctl enable postgresql-12.service
systemctl start postgresql-12.service
for RHEL/CentOS 6:

service
where can be:

start : start the database
stop : stop the database
restart : stop/start the database; used to read changes to core configuration files
reload : reload pg_hba.conf file while keeping database running
E.g. to start version 12:

service postgresql-12 start

Removing

To remove everything:

yum erase postgresql12*
or
dnf remove postgresql12* for RHEL 8 and Fedora 30+
Or remove individual packages as desired.

你可能感兴趣的:(centos8下postgreSQL入门1.1之安装)