安装
参考
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/
切换到 root 用户
su生成安装脚本
https://www.postgresql.org/download/linux/redhat/
上进行版本选择,生成脚本创建安装脚本
touch install-psql.shvim install-psql.sh
将2 中生成的脚本粘贴进来修改脚本文件的权限
chmod 777 install-psql.sh执行脚本
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/<name>/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 <name> 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 <name> <command>
where <command> 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.