一、参考链接
阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区
postgresql镜像-postgresql下载地址-postgresql装置教程-阿里巴巴开源镜像站
二、PostgreSQL介绍
PostgreSQL是一种个性十分齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为根底的对象关系型数据库管理系统。POSTGRES的许多当先概念只是在比拟迟的时候才呈现在商业网站数据库中。PostgreSQL反对大部分的SQL规范并且提供了很多其余古代个性,如简单查问、外键、触发器、视图、事务完整性、多版本并发管制等。同样,PostgreSQL也能够用许多办法扩大,例如通过减少新的数据类型、函数、操作符、汇集函数、索引办法、过程语言等。另外,因为许可证的灵便,任何人都能够以任何目标收费应用、批改和散发PostgreSQL。(——PostgreSQL_百度百科)
三、PostgreSQL装置
<font color=red>本试验基于CentOS 7.9零碎进行演示操作</font>
[root@postgresql ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
装置筹备
批改主机名
# hostnamectl set-hostname prostgresql
敞开防火墙
# systemctl stop firewalld
# systemctl disable firewalld
敞开SELinux平安模式
# setenforce 0
# getenforce
配置网络信息并测试连通性
vim /etc/sysconfig/network-scripts/ifcfg-ens32
次要批改如下参数信息即可。
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.200.25
PREFIX=24
GATEWAY=192.168.200.1
DNS1=192.168.200.1
按:wq保留退出。
重启网卡
# systemctl restart network
# ping bing.com
配置阿里云CentOS YUM源,放慢镜像拜访下载
参考链接:https://blog.csdn.net/qq_45392321/article/details/121450443
# yum clean all
# yum makecache
# yum repolist
降级零碎🆙
# yum update
查看postgresql是否装置
# rpm -qa | grep postgre
查看PostgreSQL 装置地位
# rpm -qal | grep postgres
新增postgres用户组
# groupadd postgres
新增postgres用户并且设置这个postgres用户属于创立的postgres用户组
# useradd -g postgres postgres
批改postgres用户明码
[root@postgresql ~]# passwd postgres
Changing password for user postgres.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
[root@postgresql ~]#
重启零碎
reboot
1、查问并装置postgresql-server
yum list | grep postgresql-server
yum install -y postgresql-server.x86_64
2、初始化postgresql-server数据库
<font color=red>service postgresql initdb</font>
# service postgresql initdb
Hint: the preferred way to do this is now "postgresql-setup initdb"
Initializing database ... OK
3、启动postgresql服务并设置开机自启动
systemctl start postgresql
systemctl enable postgresql
4、查看postgresql服务状态
systemctl status postgresql
5、查看服务过程信息
[root@postgresql ~]# ps -ef | grep postgres
postgres 1405 1 0 16:05 ? 00:00:00 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
postgres 1406 1405 0 16:05 ? 00:00:00 postgres: logger process
postgres 1408 1405 0 16:05 ? 00:00:00 postgres: checkpointer process
postgres 1409 1405 0 16:05 ? 00:00:00 postgres: writer process
postgres 1410 1405 0 16:05 ? 00:00:00 postgres: wal writer process
postgres 1411 1405 0 16:05 ? 00:00:00 postgres: autovacuum launcher process
postgres 1412 1405 0 16:05 ? 00:00:00 postgres: stats collector process
root 1440 1131 0 16:07 pts/0 00:00:00 grep --color=auto postgres
[root@postgresql ~]#
6、查看postgresql服务端口是否开启
# ss -tunpl | grep postgres
tcp LISTEN 0 128 127.0.0.1:5432 *:* users:(("postgres",pid=1349,fd=4))
tcp LISTEN 0 128 [::1]:5432 [::]:* users:(("postgres",pid=1349,fd=3))
[root@postgresql ~]#
# netstat -tunpl | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1349/postgres
tcp6 0 0 ::1:5432 :::* LISTEN 1349/postgres
四、测试连贯
1、切换postgres用户
[root@postgresql ~]# su postgres
[postgres@postgresql root]$
2、连贯数据库
[root@postgresql ~]# su postgres
[postgres@postgresql root]$ psql -U postgres
could not change directory to "/root"
psql (9.2.24)
Type "help" for help.
postgres=#
# 应用 \l 用于查看曾经存在的数据库:
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=#
# 进入命令行工具,能够应用 \help 来查看各个命令的语法
postgres-# \help
3、创立数据库
# 创立一个 runoobdb 的数据库
postgres=# CREATE DATABASE xybdiy;
CREATE DATABASE
postgres=#
# 应用 \c + 数据库名 来进入数据库
postgres=# \c xybdiy
You are now connected to database "xybdiy" as user "postgres".
xybdiy=#
4、创建表格
# 创立了一个表,表名为 COMPANY 表格,主键为 ID,NOT NULL 示意字段不容许蕴含 NULL 值
xybdiy=# CREATE TABLE COMPANY(
xybdiy(# ID INT PRIMARY KEY NOT NULL,
xybdiy(# NAME TEXT NOT NULL,
xybdiy(# AGE INT NOT NULL,
xybdiy(# ADDRESS CHAR(50),
xybdiy(# SALARY REAL
xybdiy(# );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "company_pkey" for table "company"
CREATE TABLE
# 应用 \d 命令来查看表格是否创立胜利
xybdiy=# \d
List of relations
Schema | Name | Type | Owner
--------+---------+-------+----------
public | company | table | postgres
(1 row)
xybdiy=# CREATE TABLE DEPARTMENT(
xybdiy(# ID INT PRIMARY KEY NOT NULL,
xybdiy(# DEPT CHAR(50) NOT NULL,
xybdiy(# EMP_ID INT NOT NULL
xybdiy(# );
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "department_pkey" for table "department"
CREATE TABLE
xybdiy=# \d
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | company | table | postgres
public | department | table | postgres
(2 rows)
xybdiy=#
五、批改配置文件
1、批改postgresql的配置文件
# vim /var/lib/pgsql/data/postgresql.conf
# 批改监听IP
listen_addresses = '*'
# 关上日志采集器
logging_collector = on
# 设置日志目录
log_directory = 'pg_log'
2、批改 pg_hba.conf 服务连贯配置文件
# vim /var/lib/pgsql/data/pg_hba.conf
77 # TYPE DATABASE USER ADDRESS METHOD
78
79 # "local" is for Unix domain socket connections only
80 local all all trust
81 # IPv4 local connections:
82 host all all 127.0.0.1/32 trust
83 host all all 0.0.0.0/0 trust
84 # IPv6 local connections:
85 host all all ::1/128 md5
3、重启postgresql服务
# systemctl restart postgresql
五、测试近程连贯
测试连贯
测试胜利后,连贯
连贯胜利
至此,装置PostgreSQ数据库实现。
发表回复