postgresql镜像-postgresql下载地址-postgresql安装教程-阿里巴巴开源镜像站
PostGresql数据库Linux服务器安装-阿里云开发者社区 (aliyun.com)
PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。POSTGRES的许多领先概念只是在比较迟的时候才出现在商业网站数据库中。PostgreSQL支持大部分的SQL标准并且提供了很多其他现代特性,如复杂查询、外键、触发器、视图、事务完整性、多版本并发控制等。同样,PostgreSQL也可以用许多方法扩展,例如通过增加新的数据类型、函数、操作符、聚集函数、索引方法、过程语言等。另外,因为许可证的灵活,任何人都可以以任何目的免费使用、修改和分发PostgreSQL。(——PostgreSQL_百度百科)
<font color=red>本实验基于CentOS 7.9系统进行演示操作</font>
[root@postgresql ~]# cat /etc/redhat-releaseCentOS 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=staticONBOOT=yesIPADDR=192.168.200.25PREFIX=24GATEWAY=192.168.200.1DNS1=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 postgresChanging password for user postgres.New password:BAD PASSWORD: The password is a palindromeRetype new password:passwd: all authentication tokens updated successfully.[root@postgresql ~]#重启系统reboot
yum list | grep postgresql-serveryum install -y postgresql-server.x86_64

<font color=red>service postgresql initdb</font>
# service postgresql initdbHint: the preferred way to do this is now "postgresql-setup initdb"Initializing database ... OK
systemctl start postgresqlsystemctl enable postgresql
systemctl status postgresql
[root@postgresql ~]# ps -ef | grep postgrespostgres 1405 1 0 16:05 ? 00:00:00 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432postgres 1406 1405 0 16:05 ? 00:00:00 postgres: logger processpostgres 1408 1405 0 16:05 ? 00:00:00 postgres: checkpointer processpostgres 1409 1405 0 16:05 ? 00:00:00 postgres: writer processpostgres 1410 1405 0 16:05 ? 00:00:00 postgres: wal writer processpostgres 1411 1405 0 16:05 ? 00:00:00 postgres: autovacuum launcher processpostgres 1412 1405 0 16:05 ? 00:00:00 postgres: stats collector processroot 1440 1131 0 16:07 pts/0 00:00:00 grep --color=auto postgres[root@postgresql ~]#
# ss -tunpl | grep postgrestcp 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 5432tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1349/postgrestcp6 0 0 ::1:5432 :::* LISTEN 1349/postgres
[root@postgresql ~]# su postgres[postgres@postgresql root]$
[root@postgresql ~]# su postgres[postgres@postgresql root]$ psql -U postgrescould not change directory to "/root"psql (9.2.24)Type "help" for help.postgres=## 使用 \l 用于查看已经存在的数据库:postgres=# \lList of databasesName | Owner | Encoding | Collate | Ctype | Access privileges-----------+----------+-----------+---------+-------+-----------------------postgres | postgres | SQL_ASCII | C | C |template0 | postgres | SQL_ASCII | C | C | =c/postgres +| | | | | postgres=CTc/postgrestemplate1 | postgres | SQL_ASCII | C | C | =c/postgres +| | | | | postgres=CTc/postgres(3 rows)postgres=## 进入命令行工具,可以使用 \help 来查看各个命令的语法postgres-# \help
# 创建一个 runoobdb 的数据库postgres=# CREATE DATABASE xybdiy;CREATE DATABASEpostgres=## 使用 \c + 数据库名 来进入数据库postgres=# \c xybdiyYou are now connected to database "xybdiy" as user "postgres".xybdiy=#
# 创建了一个表,表名为 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 REALxybdiy(# );NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "company_pkey" for table "company"CREATE TABLE# 使用 \d 命令来查看表格是否创建成功xybdiy=# \dList of relationsSchema | 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 NULLxybdiy(# );NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "department_pkey" for table "department"CREATE TABLExybdiy=# \dList of relationsSchema | Name | Type | Owner--------+------------+-------+----------public | company | table | postgrespublic | department | table | postgres(2 rows)xybdiy=#
# vim /var/lib/pgsql/data/postgresql.conf# 修改监听IPlisten_addresses = '*'# 打开日志采集器logging_collector = on# 设置日志目录log_directory = 'pg_log'
# vim /var/lib/pgsql/data/pg_hba.conf77 # TYPE DATABASE USER ADDRESS METHOD7879 # "local" is for Unix domain socket connections only80 local all all trust81 # IPv4 local connections:82 host all all 127.0.0.1/32 trust83 host all all 0.0.0.0/0 trust84 # IPv6 local connections:85 host all all ::1/128 md5
# systemctl restart postgresql
测试连接

测试成功后,连接

连接成功


至此,安装PostgreSQ数据库完成。
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号