postgresql介绍
PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。POSTGRES的许多领先概念只是在比较迟的时候才出现在商业网站数据库中。PostgreSQL支持大部分的SQL标准并且提供了很多其他现代特性,如复杂查询、外键、触发器、视图、事务完整性、多版本并发控制等。同样,PostgreSQL也可以用许多方法扩展,例如通过增加新的数据类型、函数、操作符、聚集函数、索引方法、过程语言等。另外,因为许可证的灵活,任何人都可以以任何目的免费使用、修改和分发PostgreSQL。
查看仓库信息
运行dnf info postgresql-server查看,系统软件仓库中已经存在
[root@iZ2zee2m456rb6bde98jpkZ ~]# dnf info postgresql-server
Last metadata expiration check: 0:10:25 ago on Wed 29 Jun 2022 10:35:22 AM CST.
Available Packages
Name : postgresql-server
Version : 13.3
Release : 1.1.al8
Architecture : x86_64
Size : 5.7 M
Source : postgresql-13.3-1.1.al8.src.rpm
Repository : alinux3-updates
Summary : The programs needed to create and run a PostgreSQL server
URL : http://www.postgresql.org/
License : PostgreSQL
Description : PostgreSQL is an advanced Object-Relational database management system (DBMS).
: The postgresql-server package contains the programs needed to create
: and run a PostgreSQL server, which will in turn allow you to create
: and maintain PostgreSQL databases.
安装
运行dnf install postgresql-server postgresql -y安装服务端
===================================================================================================================================================================
Package Architecture Version Repository Size
===================================================================================================================================================================
Installing:
postgresql x86_64 13.3-1.1.al8 alinux3-updates 1.5 M
postgresql-server x86_64 13.3-1.1.al8 alinux3-updates 5.7 M
Installing dependencies:
libpq x86_64 13.3-1.al8 alinux3-updates 197 k
Transaction Summary
===================================================================================================================================================================
Install 3 Packages
Total download size: 7.4 M
Installed size: 29 M
Downloading Packages:
(1/3): postgresql-server-13.3-1.1.al8.x86_64.rpm 22 MB/s | 5.7 MB 00:00
(2/3): libpq-13.3-1.al8.x86_64.rpm 156 kB/s | 197 kB 00:01
(3/3): postgresql-13.3-1.1.al8.x86_64.rpm 1.0 MB/s | 1.5 MB 00:01
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 5.0 MB/s | 7.4 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : libpq-13.3-1.al8.x86_64 1/3
Installing : postgresql-13.3-1.1.al8.x86_64 2/3
Running scriptlet: postgresql-server-13.3-1.1.al8.x86_64 3/3
Installing : postgresql-server-13.3-1.1.al8.x86_64 3/3
Running scriptlet: postgresql-server-13.3-1.1.al8.x86_64 3/3
[/usr/lib/tmpfiles.d/postgresql.conf:1] Line references path below legacy directory /var/run/, updating /var/run/postgresql → /run/postgresql; please update the tmpfiles.d/ drop-in file accordingly.
Verifying : libpq-13.3-1.al8.x86_64 1/3
Verifying : postgresql-13.3-1.1.al8.x86_64 2/3
Verifying : postgresql-server-13.3-1.1.al8.x86_64 3/3
Installed:
libpq-13.3-1.al8.x86_64 postgresql-13.3-1.1.al8.x86_64 postgresql-server-13.3-1.1.al8.x86_64
Complete!
启动
初始化数据
[root@iZ2zee2m456rb6bde98jpkZ ~]# postgresql-setup --initdb
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
[root@iZ2zee2m456rb6bde98jpkZ ~]#
systemctl start postgresql启动服务
[root@iZ2ze4v0qmpn8c4laatw8qZ ~]# systemctl start postgresql
[root@iZ2zee2m456rb6bde98jpkZ ~]# systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-06-29 10:55:31 CST; 7s ago
Process: 14024 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)
Main PID: 14027 (postmaster)
Tasks: 8 (limit: 47654)
Memory: 14.1M
CGroup: /system.slice/postgresql.service
├─14027 /usr/bin/postmaster -D /var/lib/pgsql/data
├─14028 postgres: logger
├─14030 postgres: checkpointer
├─14031 postgres: background writer
├─14032 postgres: walwriter
├─14033 postgres: autovacuum launcher
├─14034 postgres: stats collector
└─14035 postgres: logical replication launcher
Jun 29 10:55:31 iZ2zee2m456rb6bde98jpkZ systemd[1]: Starting PostgreSQL database server...
Jun 29 10:55:31 iZ2zee2m456rb6bde98jpkZ postmaster[14027]: 2022-06-29 10:55:31.161 CST [14027] LOG: redirecting log output to logging collector process
Jun 29 10:55:31 iZ2zee2m456rb6bde98jpkZ postmaster[14027]: 2022-06-29 10:55:31.161 CST [14027] HINT: Future log output will appear in directory "log".
Jun 29 10:55:31 iZ2zee2m456rb6bde98jpkZ systemd[1]: Started PostgreSQL database server.
切换用户,客户端连接
[root@iZ2zee2m456rb6bde98jpkZ ~]# su - postgres
Last login: Wed Jun 29 10:55:51 CST 2022 on pts/0
[postgres@iZ2zee2m456rb6bde98jpkZ ~]$ psql
psql (13.3)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)