CentOS 8.0 quickly install PostgreSQL 12 database

Reference: PostgreSQL official website-Linux downloads (Red Hat family)

In order to ensure PostgreSQLcorrect pronunciation, please visit the official pronunciation software: http://www.postgresql.org/files/postgresql.mp3 , or you can read short Postgres, or directly said 大象数据库.

1. Install RPM source

dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2. Close the built-in PostgreSQL module

dnf -qy module disable postgresql

3. Install PostgreSQL

dnf install postgresql12-server

[Note] where it is needed to confirm the direct input yand press Enter.

[Note] Due to the distribution strategy of the Red Hat series, the PostgreSQLinstallation will not enable automatic startup or automatic database initialization.

4. Initialize the database and start the service to complete the installation.

[Note] The database must be initialized before startup, otherwise an error will be reported.

# 初始化数据库(必须先初始化数据库在启动,否则会报错)
/usr/pgsql-12/bin/postgresql-12-setup initdb

#启动服务
systemctl start postgresql-12.service

5. Log in to PostgreSQL

[Note] After the installation is complete, the system will automatically create a user postgres (both system user and database super administrator) dedicated to managing the PostgreSQL database, and the password is blank.

# 切换成 postgres 用户
sudo -i -u postgres

# 输入 psql 测试是否启动成功:
psql
# 会显示如下信息
psql (12.3)
Type "help" for help.

# 退出 PostgreSQL:
postgres=# \q

6. Other commonly used commands

#查看 PostgreSQL 状态
systemctl status postgresql-12.service
# 或
ps -ef|grep post

# 启动 postgresql 服务
systemctl start postgresql-12.service

# 停止 postgresql 服务
systemctl stop postgresql-12.service

# 重启 postgresql 服务
systemctl restart postgresql-12.service

Personal blog: Roc's Blog

Guess you like

Origin blog.csdn.net/peng2hui1314/article/details/107545878